Skip to content

fix: parse options correctly #4880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export class Options {
private static NONDASHED_OPTION_REGEX = /(.+?)[-]([a-zA-Z])(.*)/;

private optionsWhiteList = ["ui", "recursive", "reporter", "require", "timeout", "_", "$0"]; // These options shouldn't be validated
private yargsArgv: yargs.Argv;
private globalOptions: IDictionary<IDashedOption> = {
log: { type: OptionType.String, hasSensitiveValue: false },
verbose: { type: OptionType.Boolean, alias: "v", hasSensitiveValue: false },
Expand All @@ -19,6 +18,7 @@ export class Options {
_: { type: OptionType.String, hasSensitiveValue: false }
};

private initialArgv: yargs.Arguments;
public argv: yargs.Arguments;
public options: IDictionary<IDashedOption>;

Expand All @@ -31,7 +31,7 @@ export class Options {
this.argv.bundle = "webpack";

// Check if the user has explicitly provide --hmr and --release options from command line
if (this.yargsArgv.argv.release && this.yargsArgv.argv.hmr) {
if (this.initialArgv.release && this.initialArgv.hmr) {
this.$errors.failWithoutHelp("The options --release and --hmr cannot be used simultaneously.");
}

Expand Down Expand Up @@ -250,8 +250,9 @@ export class Options {
opts[this.getDashedOptionName(key)] = value;
});

this.yargsArgv = yargs(process.argv.slice(2));
this.argv = this.yargsArgv.options(<any>opts).argv;
const parsed = yargs(process.argv.slice(2));
this.initialArgv = parsed.argv;
this.argv = parsed.options(<any>opts).argv;

// For backwards compatibility
// Previously profileDir had a default option and calling `this.$options.profileDir` always returned valid result.
Expand Down
3 changes: 2 additions & 1 deletion test/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ describe("options", () => {
name: "should set hmr to true by default",
expectedHmrValue: true
}, {
name: "set set hmr to false when --no-hmr is provided",
name: "should set hmr to false when --no-hmr is provided",
args: ["--no-hmr"],
expectedHmrValue: false
}, {
Expand All @@ -319,6 +319,7 @@ describe("options", () => {
options.setupOptions(testCase.commandSpecificDashedOptions);

assert.equal(testCase.expectedHmrValue, options.argv.hmr);
assert.isFalse(isExecutionStopped);

(testCase.args || []).forEach(arg => process.argv.pop());
});
Expand Down