Skip to content

Commit b7447c9

Browse files
fix: some edge cases
1 parent 2220b3e commit b7447c9

File tree

6 files changed

+39
-6
lines changed

6 files changed

+39
-6
lines changed

packages/webpack-cli/lib/webpack-cli.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,13 +1221,13 @@ class WebpackCLI {
12211221
const defaultCommandToRun = getCommandName(buildCommandOptions.name);
12221222
const hasOperand = typeof operands[0] !== 'undefined';
12231223
const operand = hasOperand ? operands[0] : defaultCommandToRun;
1224-
1224+
const isHelpOption = typeof options.help !== 'undefined';
12251225
const isHelpCommandSyntax = isCommand(operand, helpCommandOptions);
12261226

1227-
if (options.help || isHelpCommandSyntax) {
1227+
if (isHelpOption || isHelpCommandSyntax) {
12281228
let isVerbose = false;
12291229

1230-
if (options.help) {
1230+
if (isHelpOption) {
12311231
if (typeof options.help === 'string') {
12321232
if (options.help !== 'verbose') {
12331233
this.logger.error("Unknown value for '--help' option, please use '--help=verbose'");
@@ -1241,7 +1241,7 @@ class WebpackCLI {
12411241
this.program.forHelp = true;
12421242

12431243
const optionsForHelp = []
1244-
.concat(options.help && hasOperand ? [operand] : [])
1244+
.concat(isHelpOption && hasOperand ? [operand] : [])
12451245
// Syntax `webpack help [command]`
12461246
.concat(operands.slice(1))
12471247
// Syntax `webpack help [option]`
@@ -1252,9 +1252,12 @@ class WebpackCLI {
12521252
await outputHelp(optionsForHelp, isVerbose, isHelpCommandSyntax, program);
12531253
}
12541254

1255-
if (options.version || isCommand(operand, versionCommandOptions)) {
1255+
const isVersionOption = typeof options.version !== 'undefined';
1256+
const isVersionCommandSyntax = isCommand(operand, versionCommandOptions);
1257+
1258+
if (isVersionOption || isVersionCommandSyntax) {
12561259
const optionsForVersion = []
1257-
.concat(options.version ? [operand] : [])
1260+
.concat(isVersionOption ? [operand] : [])
12581261
.concat(operands.slice(1))
12591262
.concat(unknown);
12601263

test/build/config/type/function-with-env/function-with-env.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ describe('function configuration', () => {
137137
expect(existsSync(resolve(__dirname, './dist/new-empty-string.js'))).toBeTruthy();
138138
});
139139

140+
it('Supports env variable with "=" at the end', async () => {
141+
const { exitCode, stderr, stdout } = await run(__dirname, ['--env', `foo=`]);
142+
143+
expect(exitCode).toBe(0);
144+
expect(stderr).toBeFalsy();
145+
expect(stdout).toBeTruthy();
146+
// Should generate the appropriate files
147+
expect(existsSync(resolve(__dirname, './dist/equal-at-the-end.js'))).toBeTruthy();
148+
});
149+
140150
it('is able to understand multiple env flags', async () => {
141151
const { exitCode, stderr, stdout } = await run(__dirname, ['--env', 'isDev', '--env', 'verboseStats', '--env', 'envMessage']);
142152

test/build/config/type/function-with-env/webpack.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ module.exports = (env) => {
2525
},
2626
};
2727
}
28+
if (env['foo=']) {
29+
return {
30+
entry: './a.js',
31+
output: {
32+
filename: 'equal-at-the-end.js',
33+
},
34+
};
35+
}
2836
return {
2937
entry: './a.js',
3038
mode: 'development',

test/help/__snapshots__/help.test.js.snap.webpack4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ exports[`help should log error for invalid command using the "--help" option 1`]
2828

2929
exports[`help should log error for invalid flag with the "--help" option #2 1`] = `"[webpack-cli] Unknown value for '--help' option, please use '--help=verbose'"`;
3030

31+
exports[`help should log error for invalid flag with the "--help" option #2 2`] = `"[webpack-cli] Unknown value for '--help' option, please use '--help=verbose'"`;
32+
3133
exports[`help should log error for invalid flag with the "--help" option 1`] = `
3234
"[webpack-cli] Incorrect use of help
3335
[webpack-cli] Please use: 'webpack help [command] [option]' | 'webpack [command] --help'

test/help/__snapshots__/help.test.js.snap.webpack5

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ exports[`help should log error for invalid command using the "--help" option 1`]
2828

2929
exports[`help should log error for invalid flag with the "--help" option #2 1`] = `"[webpack-cli] Unknown value for '--help' option, please use '--help=verbose'"`;
3030

31+
exports[`help should log error for invalid flag with the "--help" option #2 2`] = `"[webpack-cli] Unknown value for '--help' option, please use '--help=verbose'"`;
32+
3133
exports[`help should log error for invalid flag with the "--help" option 1`] = `
3234
"[webpack-cli] Incorrect use of help
3335
[webpack-cli] Please use: 'webpack help [command] [option]' | 'webpack [command] --help'

test/help/help.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,4 +402,12 @@ describe('help', () => {
402402
expect(stderr).toMatchSnapshot();
403403
expect(stdout).toBeFalsy();
404404
});
405+
406+
it('should log error for invalid flag with the "--help" option #2', async () => {
407+
const { exitCode, stderr, stdout } = await run(__dirname, ['--help=']);
408+
409+
expect(exitCode).toBe(2);
410+
expect(stderr).toMatchSnapshot();
411+
expect(stdout).toBeFalsy();
412+
});
405413
});

0 commit comments

Comments
 (0)