Skip to content

Commit ecba9ef

Browse files
authored
[Customization] Fix import edge cases in template-dpg (#27824)
1 parent 82215a9 commit ecba9ef

39 files changed

+632
-244
lines changed

common/tools/dev-tool/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@
8585
"cross-env": "^7.0.3",
8686
"downlevel-dts": "~0.10.0",
8787
"eslint": "^8.54.0",
88+
"karma": "^6.4.2",
8889
"mkdirp": "^3.0.1",
8990
"mocha": "^10.0.0",
90-
"karma": "^6.4.2",
9191
"rimraf": "^5.0.5"
9292
}
9393
}

common/tools/dev-tool/src/commands/run/check-api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ export default leafCommand(commandInfo, async () => {
123123
if (!projectInfo.packageJson.typesVersions) return [defaultTypesFile];
124124

125125
// Look for an entry with a key that our version of TS satisfies
126-
const firstMatchingVersion = Object.entries(projectInfo.packageJson.typesVersions!).find(
127-
([v]) => semver.satisfies(tsVersion, v),
126+
const firstMatchingVersion = Object.entries(projectInfo.packageJson.typesVersions).find(([v]) =>
127+
semver.satisfies(tsVersion, v),
128128
);
129129

130130
if (firstMatchingVersion === undefined) {

common/tools/dev-tool/src/commands/run/testBrowser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const commandInfo = makeCommandInfo(
1212

1313
export default leafCommand(commandInfo, async (options) => {
1414
const karmaArgs = options["--"]?.length
15-
? options["--"]?.join(" ")
15+
? options["--"].join(" ")
1616
: `${(await isModuleProject()) ? "karma.conf.cjs" : ""} --single-run`;
1717
return runTestsWithProxyTool({
1818
command: `karma start ${karmaArgs}`,

common/tools/dev-tool/src/commands/run/testNodeJSInput.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default leafCommand(commandInfo, async (options) => {
3232
opt.includes("**") && !opt.startsWith("'") && !opt.startsWith('"') ? `"${opt}"` : opt,
3333
);
3434
const mochaArgs = updatedArgs?.length
35-
? updatedArgs?.join(" ")
35+
? updatedArgs.join(" ")
3636
: '--timeout 5000000 "dist-esm/test/{,!(browser)/**/}/*.spec.js"';
3737
const command = {
3838
command: `c8 mocha ${defaultMochaArgs} ${mochaArgs}`,

common/tools/dev-tool/src/commands/run/testNodeTSInput.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default leafCommand(commandInfo, async (options) => {
3131
opt.includes("**") && !opt.startsWith("'") && !opt.startsWith('"') ? `"${opt}"` : opt,
3232
);
3333
const mochaArgs = updatedArgs?.length
34-
? updatedArgs?.join(" ")
34+
? updatedArgs.join(" ")
3535
: '--timeout 1200000 --exclude "test/**/browser/*.spec.ts" "test/**/*.spec.ts"';
3636
const command = {
3737
command: isModuleProj

common/tools/dev-tool/src/commands/run/vendored.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ function makeCommandExecutor(commandName: string): (...args: string[]) => Promis
3434
const command = spawn(commandPath, args, { stdio: "inherit" });
3535

3636
// If the command exited 0, then we treat that as a success
37-
command.on("exit", (code) => resolve(code === 0));
37+
command.on("exit", (code) => {
38+
resolve(code === 0);
39+
});
3840
command.on("error", reject);
3941
});
4042
}

common/tools/dev-tool/src/config/rollup.base.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const { debug } = createPrinter("rollup.base.config");
2323

2424
interface PackageJson {
2525
name: string;
26-
module: string;
26+
module?: string;
2727
dependencies: Record<string, string>;
2828
devDependencies: Record<string, string>;
2929
}

common/tools/dev-tool/src/framework/command.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ export function subCommand<Info extends CommandInfo<CommandOptions>>(
8787
return true;
8888
}
8989

90-
const commandName = options.args[0];
91-
const commandArgs = options.args.slice(1);
90+
const commandName = options.args[0] as string | undefined;
91+
const commandArgs = options.args.slice(1) as string[] | undefined;
9292

9393
if (commandName === undefined) {
9494
log.error("No sub-command provided.");
@@ -98,12 +98,11 @@ export function subCommand<Info extends CommandInfo<CommandOptions>>(
9898

9999
const extraArgs = options["--"];
100100

101-
const fullArgs =
102-
extraArgs !== undefined && extraArgs.length > 0
103-
? [...commandArgs, "--", ...extraArgs]
104-
: commandArgs;
101+
const fullArgs = [commandArgs, extraArgs?.length && ["--", extraArgs]]
102+
.flat(2)
103+
.filter((arg): arg is string => typeof arg === "string");
105104

106-
log.debug(`$ ${commandName} ${fullArgs.join(" ") ?? ""}`);
105+
log.debug(`$ ${commandName} ${fullArgs.join(" ")}`);
107106

108107
if (Object.prototype.hasOwnProperty.call(commands, commandName)) {
109108
const commandModule = await commands[commandName]();

common/tools/dev-tool/src/framework/parseOptions.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,16 @@ export function parseOptions<Opts extends CommandOptions>(
112112

113113
const result: ParsedOptions = { help: argMap.help, args: argMap._, "--": argMap["--"] };
114114

115-
function expectType<T>(key: string, value: T, expected: string): void {
115+
function expectType<T extends string | boolean | Array<string | boolean> | undefined>(
116+
key: string,
117+
value: T,
118+
expected: string,
119+
): void {
116120
if (Array.isArray(value)) {
117121
parseError(`Too many arguments for "${key}"`);
118122
throw new Error(`More than one value for "${key}" was given, but only one was expected`);
119123
} else if (typeof value !== expected && typeof value !== "undefined") {
120-
parseError(`Bad argument: "${key}" = ${value}`);
124+
parseError(`Bad argument: "${key}" = ${value.toString()}`);
121125
throw new Error(
122126
`Value of argument "${key}" was a ${typeof value} but a ${expected} was expected.`,
123127
);

common/tools/dev-tool/src/migrations/onboard/test-proxy-asset-sync.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export default createMigration(
3232

3333
// Optional validation
3434
async validate(ctx) {
35-
const assetsJson = JSON.parse(
36-
(await readFile(path.join(ctx.project.path, "assets.json"))).toString("utf-8"),
37-
) as AssetsJson;
35+
const assetsJson: Partial<AssetsJson> = await readFile(
36+
path.join(ctx.project.path, "assets.json"),
37+
).then((buf) => JSON.parse(buf.toString("utf-8")));
3838

3939
// Check that the assets.json file is well formed and that we didn't get a bad generation.
4040
if (

0 commit comments

Comments
 (0)