Skip to content

Commit 9b2b57c

Browse files
authored
fix(build-cli): Fix readArgValues in generateEntrypoints (#25340)
This bug was introduced in `0.58.0`. `readArgValues` incorrectly dropped input arguments, always falling back to the script defaults. This is now fixed. With regression tests.
1 parent 100aeff commit 9b2b57c

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

build-tools/packages/build-cli/src/library/commands/generateEntrypoints.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ interface Options {
6767
readonly outFileSuffix: string;
6868
}
6969

70-
const optionDefaults = {
70+
/**
71+
* {@link Options} defaults.
72+
* @privateRemarks Exported for testing.
73+
*/
74+
export const optionDefaults = {
7175
mainEntrypoint: "./src/index.ts",
7276
outDir: "./lib",
7377
outFilePrefix: "",
@@ -367,16 +371,16 @@ function getOutputConfiguration(
367371
* @param commandLine - command line to extract from
368372
* @param argQuery - record of arguments to read (keys) with default values
369373
* @returns record of argument values extracted or given default value
374+
* @privateRemarks Exported for testing.
370375
*/
371-
function readArgValues(commandLine: string, argQuery: Options): Options {
372-
const values: Record<string, string | undefined> = {};
376+
export function readArgValues(commandLine: string, argQuery: Options): Options {
373377
const args = commandLine.split(" ");
374378

375379
const argValues: Record<string, string | undefined> = {};
376380
for (const argName of Object.keys(argQuery)) {
377381
const indexOfArgValue = args.indexOf(`--${argName}`) + 1;
378382
if (0 < indexOfArgValue && indexOfArgValue < args.length) {
379-
values[argName] = args[indexOfArgValue];
383+
argValues[argName] = args[indexOfArgValue];
380384
}
381385
}
382386
return {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*!
2+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
import { expect } from "chai";
7+
import { describe, it } from "mocha";
8+
import {
9+
optionDefaults,
10+
readArgValues,
11+
} from "../../../library/commands/generateEntrypoints.js";
12+
13+
describe("generateEntrypoints", () => {
14+
it("readArgValues", () => {
15+
expect(readArgValues("", optionDefaults)).to.deep.equal(optionDefaults);
16+
17+
expect(
18+
readArgValues("--outFileLegacyBeta legacy --outDir ./dist", optionDefaults),
19+
).to.deep.equal({
20+
...optionDefaults,
21+
outDir: "./dist",
22+
outFileLegacyBeta: "legacy",
23+
});
24+
25+
expect(readArgValues("--outDir ./lib", optionDefaults)).to.deep.equal({
26+
...optionDefaults,
27+
outDir: "./lib",
28+
});
29+
});
30+
});

0 commit comments

Comments
 (0)