Skip to content

Commit ff0ffa5

Browse files
Rob--Wrpl
authored andcommitted
fix: support multiple values after --ignore-files again (#1652)
The yargs upgrade from 6.6.0 to 13.2.1 in edebef4 broke the documented ability to pass multiple files to ignore after the `--ignore-files` (aka `-i`) parameter. This is because yargs 11 started to treat `requiresArg` as an implicit `nargs: 1`, i.e. to accept exactly one value only. This patch fixes the issue by dropping `requiresArg` and validating the number of parameters in the `execute` function instead.
1 parent 626a180 commit ff0ffa5

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/program.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ export class Program {
166166

167167
const argv = this.yargs.argv;
168168

169+
// Replacement for the "requiresArg: true" parameter until the following bug
170+
// is fixed: https://github.com/yargs/yargs/issues/1098
171+
if (argv.ignoreFiles && !argv.ignoreFiles.length) {
172+
throw new UsageError('Not enough arguments following: ignore-files');
173+
}
174+
169175
const cmd = argv._[0];
170176

171177
const version = getVersion(this.absolutePackageDir);
@@ -348,7 +354,10 @@ Example: $0 --help run.
348354
'ignored. (Example: --ignore-files=path/to/first.js ' +
349355
'path/to/second.js "**/*.log")',
350356
demandOption: false,
351-
requiresArg: true,
357+
// The following option prevents yargs>=11 from parsing multiple values,
358+
// so the minimum value requirement is enforced in execute instead.
359+
// Upstream bug: https://github.com/yargs/yargs/issues/1098
360+
// requiresArg: true,
352361
type: 'array',
353362
},
354363
'no-input': {

tests/unit/test.program.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,30 @@ describe('program.main', () => {
709709

710710
sinon.assert.called(logStream.makeVerbose);
711711
});
712+
713+
it('requires a parameter after --ignore-files', async () => {
714+
const fakeCommands = fake(commands);
715+
return execProgram(['build', '--ignore-files'], {commands: fakeCommands})
716+
.then(makeSureItFails())
717+
.catch((error) => {
718+
assert.match(
719+
error.message, /Not enough arguments following: ignore-files/);
720+
});
721+
});
722+
723+
it('supports multiple parameters after --ignore-files', async () => {
724+
const fakeCommands = fake(commands, {
725+
build: () => Promise.resolve(),
726+
});
727+
return execProgram(
728+
['build', '--ignore-files', 'f1', 'f2', '-a', 'xxx', '-i', 'f4', 'f3'],
729+
{commands: fakeCommands})
730+
.then(() => {
731+
const options = fakeCommands.build.firstCall.args[0];
732+
assert.deepEqual(options.ignoreFiles, ['f1', 'f2', 'f4', 'f3']);
733+
assert.equal(options.artifactsDir, 'xxx');
734+
});
735+
});
712736
});
713737

714738
describe('program.defaultVersionGetter', () => {

0 commit comments

Comments
 (0)