Skip to content

Commit ea7c814

Browse files
authored
Merge pull request #4880 from NativeScript/fatme/fix-options
fix: parse options correctly
2 parents d6d9a05 + 172c7a7 commit ea7c814

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/options.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export class Options {
66
private static NONDASHED_OPTION_REGEX = /(.+?)[-]([a-zA-Z])(.*)/;
77

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

21+
private initialArgv: yargs.Arguments;
2222
public argv: yargs.Arguments;
2323
public options: IDictionary<IDashedOption>;
2424

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

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

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

253-
this.yargsArgv = yargs(process.argv.slice(2));
254-
this.argv = this.yargsArgv.options(<any>opts).argv;
253+
const parsed = yargs(process.argv.slice(2));
254+
this.initialArgv = parsed.argv;
255+
this.argv = parsed.options(<any>opts).argv;
255256

256257
// For backwards compatibility
257258
// Previously profileDir had a default option and calling `this.$options.profileDir` always returned valid result.

test/options.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ describe("options", () => {
292292
name: "should set hmr to true by default",
293293
expectedHmrValue: true
294294
}, {
295-
name: "set set hmr to false when --no-hmr is provided",
295+
name: "should set hmr to false when --no-hmr is provided",
296296
args: ["--no-hmr"],
297297
expectedHmrValue: false
298298
}, {
@@ -319,6 +319,7 @@ describe("options", () => {
319319
options.setupOptions(testCase.commandSpecificDashedOptions);
320320

321321
assert.equal(testCase.expectedHmrValue, options.argv.hmr);
322+
assert.isFalse(isExecutionStopped);
322323

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

0 commit comments

Comments
 (0)