Skip to content

Commit ae725c8

Browse files
committed
fix: warn on unknown, plugin
1 parent b835e71 commit ae725c8

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

lib/bootstrap.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const isCommandUsed = commands =>
2121
});
2222

2323
const resolveNegatedArgs = args => {
24-
args._unknown.forEach(arg => {
24+
args._unknown.forEach((arg, idx) => {
2525
if (arg.includes('--') || arg.includes('--no')) {
2626
const argPair = arg.split('=');
2727
const optName = arg.includes('--no') ? argPair[0].slice(5) : argPair[0].slice(2);
@@ -32,10 +32,12 @@ const resolveNegatedArgs = args => {
3232
} else if (argValue === 'true') {
3333
argValue = true;
3434
}
35-
3635
const cliFlag = core.find(opt => opt.name === optName);
37-
args[cliFlag.group][optName] = argValue;
38-
args._all[optName] = argValue;
36+
if(cliFlag) {
37+
args[cliFlag.group][optName] = argValue;
38+
args._all[optName] = argValue;
39+
args._unknown[idx] = null;
40+
}
3941
}
4042
});
4143
}
@@ -62,6 +64,9 @@ async function runCLI(cli, commandIsUsed) {
6264
args = cmdArgs(core, { stopAtFirstUnknown: false, partial: true });
6365
if (args._unknown) {
6466
resolveNegatedArgs(args);
67+
args._unknown.filter(e => e).forEach(unknown => {
68+
process.cliLogger.warn('Unknown argument:', unknown);
69+
});
6570
}
6671
const result = await cli.run(args, core);
6772
if (!result) {
@@ -94,7 +99,7 @@ async function runCLI(cli, commandIsUsed) {
9499

95100
await cli.run(args, core);
96101
console.log('\n')
97-
process.cliLogger.warn(`duplicate flags found, defaulting to last set value`);
102+
process.cliLogger.warn(`Duplicate flags found, defaulting to last set value`);
98103
}
99104
else {
100105
process.cliLogger.error(err);

lib/groups/advanced.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class AdvancedGroup extends GroupHelper {
5959
}
6060
}
6161
if (args.prefetch) {
62-
const PrefetchPlugin = require('webpack').PrefetchPlugin;
63-
const prefetchVal = new PrefetchPlugin(null, args.prefetch[0]);
62+
const { PrefetchPlugin } = require('webpack');
63+
const prefetchVal = new PrefetchPlugin(null, args.prefetch);
6464
if (this.opts.options && this.opts.options.plugins) {
6565
this.opts.options.plugins.unshift(prefetchVal);
6666
} else {

lib/utils/cli-flags.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ module.exports = {
9999
type: String,
100100
description: 'Output location of the file generated by webpack',
101101
},
102+
{
103+
name: 'plugin',
104+
group: ADVANCED_GROUP,
105+
type: String,
106+
description: 'Load a given plugin'
107+
},
102108
{
103109
name: 'global',
104110
alias: 'g',
@@ -146,7 +152,6 @@ module.exports = {
146152
{
147153
name: 'prefetch',
148154
type: String,
149-
multiple: true,
150155
group: ADVANCED_GROUP,
151156
description: 'Prefetch this request',
152157
},

test/config/basic/basic-config.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { run, extractSummary } = require('../../utils/test-utils');
66
describe('basic config file', () => {
77
it('is able to understand and parse a very basic configuration file', done => {
88
const { stdout, stderr } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--output', './binary/a.bundle.js']);
9-
expect(stderr).toContain('duplicate flags found, defaulting to last set value');
9+
expect(stderr).toContain('Duplicate flags found, defaulting to last set value');
1010
expect(stdout).not.toBe(undefined);
1111
const summary = extractSummary(stdout);
1212
const outputDir = 'basic/binary';

test/entry/defaults-index/entry-multi-args.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('single entry flag index present', () => {
2323

2424
it('finds default index file, compiles and overrides with flags successfully', done => {
2525
const { stdout, stderr } = run(__dirname, ['--output', 'bin/main.js']);
26-
expect(stderr).toContain('duplicate flags found, defaulting to last set value');
26+
expect(stderr).toContain('Duplicate flags found, defaulting to last set value');
2727
const summary = extractSummary(stdout);
2828
const outputDir = 'entry/defaults-index/bin';
2929

test/help/__snapshots__/help-single-arg.test.js.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ Options
3333
--progress string Print compilation progress during build
3434
--help Outputs list of supported flags
3535
-o, --output string Output location of the file generated by webpack
36+
--plugin string Load a given plugin
3637
-g, --global string[] Declares and exposes a global variable
3738
-t, --target string Sets the build target
3839
-w, --watch Watch for files changes
3940
-h, --hot Enables Hot Module Replacement
4041
--debug Switch loaders to debug mode
4142
-s, --sourcemap string Determine source maps to use
42-
--prefetch string[] Prefetch this request
43+
--prefetch string Prefetch this request
4344
-j, --json Prints result as JSON
4445
-d, --dev Run development build
4546
-p, --prod Run production build

0 commit comments

Comments
 (0)