Skip to content

Commit d30364b

Browse files
committed
fix(web-scripts): unknown command options were parsed twice
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
1 parent bfad099 commit d30364b

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

packages/web-scripts/src/index.ts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,13 @@ program
5656
.option('--no-types', 'do not build types target')
5757
.action((...args) => {
5858
const cmd = getCommand(args);
59-
const rest = getPositionalArgs(args);
6059
const { esm, types, cjs } = getOpts(cmd);
6160
const t: BuildTaskDesc = {
6261
name: 'build',
6362
esm,
6463
types,
6564
cjs,
66-
restOptions: [...parseRestOptions(cmd), ...rest],
65+
restOptions: parseRestOptions(cmd),
6766
};
6867

6968
handlePromiseResult(buildTask(t));
@@ -76,12 +75,11 @@ program
7675
.option('--config [path]', 'path to jest config')
7776
.action((...args) => {
7877
const cmd = getCommand(args);
79-
const rest = getPositionalArgs(args);
8078
const { config } = getOpts(cmd);
8179
const t: TestTaskDesc = {
8280
name: 'test',
8381
config,
84-
restOptions: [...parseRestOptions(cmd), ...rest],
82+
restOptions: parseRestOptions(cmd),
8583
};
8684

8785
const result = testTask(t);
@@ -99,14 +97,13 @@ program
9997
.option('--no-stylecheck', "do not run Prettier's style check")
10098
.action((...args) => {
10199
const cmd = getCommand(args);
102-
const rest = getPositionalArgs(args);
103100
const { stylecheck, typecheck, config } = getOpts(cmd);
104101
const t: LintTaskDesc = {
105102
name: 'lint',
106103
config,
107104
stylecheck,
108105
typecheck,
109-
restOptions: [...parseRestOptions(cmd), ...rest],
106+
restOptions: parseRestOptions(cmd),
110107
};
111108

112109
handlePromiseResult(lintTask(t));
@@ -123,13 +120,12 @@ program
123120
)
124121
.action((...args) => {
125122
const cmd = getCommand(args);
126-
const rest = getPositionalArgs(args);
127123
const { config, path } = getOpts(cmd);
128124
const t: FormatTaskDesc = {
129125
name: 'format',
130126
config,
131127
path,
132-
restOptions: [...parseRestOptions(cmd), ...rest],
128+
restOptions: parseRestOptions(cmd),
133129
};
134130

135131
handleSpawnResult(formatTask(t));
@@ -146,7 +142,6 @@ program
146142
.option('--no-typecheck', 'Do not type check using TypeScript')
147143
.action((...args) => {
148144
const cmd = getCommand(args);
149-
const rest = getPositionalArgs(args);
150145
const {
151146
tests,
152147
typecheck,
@@ -161,7 +156,7 @@ program
161156
jestConfig,
162157
eslintConfig,
163158
prettierConfig,
164-
restOptions: [...parseRestOptions(cmd), ...rest],
159+
restOptions: parseRestOptions(cmd),
165160
};
166161

167162
handlePromiseResult(precommitTask(t));
@@ -195,12 +190,11 @@ program
195190
)
196191
.action((...args) => {
197192
const cmd = getCommand(args);
198-
const rest = getPositionalArgs(args);
199193
const { threshold } = getOpts(cmd);
200194
const t: AuditTaskDesc = {
201195
name: 'audit',
202196
threshold,
203-
restOptions: [...parseRestOptions(cmd), ...rest],
197+
restOptions: parseRestOptions(cmd),
204198
};
205199

206200
handlePromiseResult(auditTask(t));
@@ -217,12 +211,11 @@ program
217211
)
218212
.action((...args) => {
219213
const cmd = getCommand(args);
220-
const rest = getPositionalArgs(args);
221214
const { path } = getOpts(cmd);
222215
const t: CommitTaskDesc = {
223216
name: 'commit',
224217
path,
225-
restOptions: [...parseRestOptions(cmd), ...rest],
218+
restOptions: parseRestOptions(cmd),
226219
};
227220

228221
try {
@@ -243,12 +236,11 @@ program
243236
)
244237
.action((...args) => {
245238
const cmd = getCommand(args);
246-
const rest = getPositionalArgs(args);
247239
const { config } = getOpts(cmd);
248240
const t: CommitMsgTaskDesc = {
249241
name: 'commitmsg',
250242
config,
251-
restOptions: [...parseRestOptions(cmd), ...rest],
243+
restOptions: parseRestOptions(cmd),
252244
};
253245

254246
handleSpawnResult(commitMsgTask(t));
@@ -260,10 +252,9 @@ program
260252
.description('Run semantic-release')
261253
.action((...args) => {
262254
const cmd = getCommand(args);
263-
const rest = getPositionalArgs(args);
264255
const t: ReleaseTaskDesc = {
265256
name: 'release',
266-
restOptions: [...parseRestOptions(cmd), ...rest],
257+
restOptions: parseRestOptions(cmd),
267258
};
268259

269260
handleSpawnResult(releaseTask(t));
@@ -297,10 +288,6 @@ function getCommand(args: any[]): Command {
297288
return args[0] as Command;
298289
}
299290

300-
function getPositionalArgs(args: any[]): string[] {
301-
return args.slice(1) as string[];
302-
}
303-
304291
function getOpts(cmd: Command): { [key: string]: any } {
305292
return cmd.opts();
306293
}

0 commit comments

Comments
 (0)