Skip to content

Commit

Permalink
fix: warn on unknown, plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
evenstensberg committed Sep 30, 2019
1 parent b835e71 commit ae725c8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
15 changes: 10 additions & 5 deletions lib/bootstrap.js
Expand Up @@ -21,7 +21,7 @@ const isCommandUsed = commands =>
});

const resolveNegatedArgs = args => {
args._unknown.forEach(arg => {
args._unknown.forEach((arg, idx) => {
if (arg.includes('--') || arg.includes('--no')) {
const argPair = arg.split('=');
const optName = arg.includes('--no') ? argPair[0].slice(5) : argPair[0].slice(2);
Expand All @@ -32,10 +32,12 @@ const resolveNegatedArgs = args => {
} else if (argValue === 'true') {
argValue = true;
}

const cliFlag = core.find(opt => opt.name === optName);
args[cliFlag.group][optName] = argValue;
args._all[optName] = argValue;
if(cliFlag) {
args[cliFlag.group][optName] = argValue;
args._all[optName] = argValue;
args._unknown[idx] = null;
}
}
});
}
Expand All @@ -62,6 +64,9 @@ async function runCLI(cli, commandIsUsed) {
args = cmdArgs(core, { stopAtFirstUnknown: false, partial: true });
if (args._unknown) {
resolveNegatedArgs(args);
args._unknown.filter(e => e).forEach(unknown => {
process.cliLogger.warn('Unknown argument:', unknown);
});
}
const result = await cli.run(args, core);
if (!result) {
Expand Down Expand Up @@ -94,7 +99,7 @@ async function runCLI(cli, commandIsUsed) {

await cli.run(args, core);
console.log('\n')
process.cliLogger.warn(`duplicate flags found, defaulting to last set value`);
process.cliLogger.warn(`Duplicate flags found, defaulting to last set value`);
}
else {
process.cliLogger.error(err);
Expand Down
4 changes: 2 additions & 2 deletions lib/groups/advanced.js
Expand Up @@ -59,8 +59,8 @@ class AdvancedGroup extends GroupHelper {
}
}
if (args.prefetch) {
const PrefetchPlugin = require('webpack').PrefetchPlugin;
const prefetchVal = new PrefetchPlugin(null, args.prefetch[0]);
const { PrefetchPlugin } = require('webpack');
const prefetchVal = new PrefetchPlugin(null, args.prefetch);
if (this.opts.options && this.opts.options.plugins) {
this.opts.options.plugins.unshift(prefetchVal);
} else {
Expand Down
7 changes: 6 additions & 1 deletion lib/utils/cli-flags.js
Expand Up @@ -99,6 +99,12 @@ module.exports = {
type: String,
description: 'Output location of the file generated by webpack',
},
{
name: 'plugin',
group: ADVANCED_GROUP,
type: String,
description: 'Load a given plugin'
},
{
name: 'global',
alias: 'g',
Expand Down Expand Up @@ -146,7 +152,6 @@ module.exports = {
{
name: 'prefetch',
type: String,
multiple: true,
group: ADVANCED_GROUP,
description: 'Prefetch this request',
},
Expand Down
2 changes: 1 addition & 1 deletion test/config/basic/basic-config.test.js
Expand Up @@ -6,7 +6,7 @@ const { run, extractSummary } = require('../../utils/test-utils');
describe('basic config file', () => {
it('is able to understand and parse a very basic configuration file', done => {
const { stdout, stderr } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--output', './binary/a.bundle.js']);
expect(stderr).toContain('duplicate flags found, defaulting to last set value');
expect(stderr).toContain('Duplicate flags found, defaulting to last set value');
expect(stdout).not.toBe(undefined);
const summary = extractSummary(stdout);
const outputDir = 'basic/binary';
Expand Down
2 changes: 1 addition & 1 deletion test/entry/defaults-index/entry-multi-args.test.js
Expand Up @@ -23,7 +23,7 @@ describe('single entry flag index present', () => {

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

Expand Down
3 changes: 2 additions & 1 deletion test/help/__snapshots__/help-single-arg.test.js.snap
Expand Up @@ -33,13 +33,14 @@ Options
--progress string Print compilation progress during build
--help Outputs list of supported flags
-o, --output string Output location of the file generated by webpack
--plugin string Load a given plugin
-g, --global string[] Declares and exposes a global variable
-t, --target string Sets the build target
-w, --watch Watch for files changes
-h, --hot Enables Hot Module Replacement
--debug Switch loaders to debug mode
-s, --sourcemap string Determine source maps to use
--prefetch string[] Prefetch this request
--prefetch string Prefetch this request
-j, --json Prints result as JSON
-d, --dev Run development build
-p, --prod Run production build
Expand Down

0 comments on commit ae725c8

Please sign in to comment.