Skip to content

Commit

Permalink
fix(web-scripts): unknown command options were parsed twice
Browse files Browse the repository at this point in the history
Upgrading `commander.js` to 5.x resulted in unknown options being parsed twice, breaking tasks in some scenarios.

For more details: tj/commander.js#1138

Fixes spotify#341
  • Loading branch information
pmowrer committed May 15, 2020
1 parent bfad099 commit d30364b
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions packages/web-scripts/src/index.ts
Expand Up @@ -56,14 +56,13 @@ program
.option('--no-types', 'do not build types target')
.action((...args) => {
const cmd = getCommand(args);
const rest = getPositionalArgs(args);
const { esm, types, cjs } = getOpts(cmd);
const t: BuildTaskDesc = {
name: 'build',
esm,
types,
cjs,
restOptions: [...parseRestOptions(cmd), ...rest],
restOptions: parseRestOptions(cmd),
};

handlePromiseResult(buildTask(t));
Expand All @@ -76,12 +75,11 @@ program
.option('--config [path]', 'path to jest config')
.action((...args) => {
const cmd = getCommand(args);
const rest = getPositionalArgs(args);
const { config } = getOpts(cmd);
const t: TestTaskDesc = {
name: 'test',
config,
restOptions: [...parseRestOptions(cmd), ...rest],
restOptions: parseRestOptions(cmd),
};

const result = testTask(t);
Expand All @@ -99,14 +97,13 @@ program
.option('--no-stylecheck', "do not run Prettier's style check")
.action((...args) => {
const cmd = getCommand(args);
const rest = getPositionalArgs(args);
const { stylecheck, typecheck, config } = getOpts(cmd);
const t: LintTaskDesc = {
name: 'lint',
config,
stylecheck,
typecheck,
restOptions: [...parseRestOptions(cmd), ...rest],
restOptions: parseRestOptions(cmd),
};

handlePromiseResult(lintTask(t));
Expand All @@ -123,13 +120,12 @@ program
)
.action((...args) => {
const cmd = getCommand(args);
const rest = getPositionalArgs(args);
const { config, path } = getOpts(cmd);
const t: FormatTaskDesc = {
name: 'format',
config,
path,
restOptions: [...parseRestOptions(cmd), ...rest],
restOptions: parseRestOptions(cmd),
};

handleSpawnResult(formatTask(t));
Expand All @@ -146,7 +142,6 @@ program
.option('--no-typecheck', 'Do not type check using TypeScript')
.action((...args) => {
const cmd = getCommand(args);
const rest = getPositionalArgs(args);
const {
tests,
typecheck,
Expand All @@ -161,7 +156,7 @@ program
jestConfig,
eslintConfig,
prettierConfig,
restOptions: [...parseRestOptions(cmd), ...rest],
restOptions: parseRestOptions(cmd),
};

handlePromiseResult(precommitTask(t));
Expand Down Expand Up @@ -195,12 +190,11 @@ program
)
.action((...args) => {
const cmd = getCommand(args);
const rest = getPositionalArgs(args);
const { threshold } = getOpts(cmd);
const t: AuditTaskDesc = {
name: 'audit',
threshold,
restOptions: [...parseRestOptions(cmd), ...rest],
restOptions: parseRestOptions(cmd),
};

handlePromiseResult(auditTask(t));
Expand All @@ -217,12 +211,11 @@ program
)
.action((...args) => {
const cmd = getCommand(args);
const rest = getPositionalArgs(args);
const { path } = getOpts(cmd);
const t: CommitTaskDesc = {
name: 'commit',
path,
restOptions: [...parseRestOptions(cmd), ...rest],
restOptions: parseRestOptions(cmd),
};

try {
Expand All @@ -243,12 +236,11 @@ program
)
.action((...args) => {
const cmd = getCommand(args);
const rest = getPositionalArgs(args);
const { config } = getOpts(cmd);
const t: CommitMsgTaskDesc = {
name: 'commitmsg',
config,
restOptions: [...parseRestOptions(cmd), ...rest],
restOptions: parseRestOptions(cmd),
};

handleSpawnResult(commitMsgTask(t));
Expand All @@ -260,10 +252,9 @@ program
.description('Run semantic-release')
.action((...args) => {
const cmd = getCommand(args);
const rest = getPositionalArgs(args);
const t: ReleaseTaskDesc = {
name: 'release',
restOptions: [...parseRestOptions(cmd), ...rest],
restOptions: parseRestOptions(cmd),
};

handleSpawnResult(releaseTask(t));
Expand Down Expand Up @@ -297,10 +288,6 @@ function getCommand(args: any[]): Command {
return args[0] as Command;
}

function getPositionalArgs(args: any[]): string[] {
return args.slice(1) as string[];
}

function getOpts(cmd: Command): { [key: string]: any } {
return cmd.opts();
}
Expand Down

0 comments on commit d30364b

Please sign in to comment.