Skip to content

Commit 00ed5a9

Browse files
committed
refactor: code
1 parent bb14837 commit 00ed5a9

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,12 @@ class WebpackCLI {
374374
name: 'env',
375375
type: (value, previous = {}) => {
376376
// for https://github.com/webpack/webpack-cli/issues/2642
377-
const regExpForSplitting = (value.match(/=/g) || []).length === 1 ? /=/ : /=(.+)/;
377+
if (value.endsWith('=')) {
378+
value.concat(`''`);
379+
}
378380

379381
// This ensures we're only splitting by the first `=`
380-
const [allKeys, val] = value.split(regExpForSplitting, 2);
382+
const [allKeys, val] = value.split(/=(.+)/, 2);
381383
const splitKeys = allKeys.split(/\.(?!$)/);
382384

383385
let prevRef = previous;

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
@@ -127,6 +127,16 @@ describe('function configuration', () => {
127127
expect(existsSync(resolve(__dirname, './dist/empty-string.js'))).toBeTruthy();
128128
});
129129

130+
it('Supports empty string with multiple "="', async () => {
131+
const { exitCode, stderr, stdout } = await run(__dirname, ['--env', `foo=bar=''`]);
132+
133+
expect(exitCode).toBe(0);
134+
expect(stderr).toBeFalsy();
135+
expect(stdout).toBeTruthy();
136+
// Should generate the appropriate files
137+
expect(existsSync(resolve(__dirname, './dist/new-empty-string.js'))).toBeTruthy();
138+
});
139+
130140
it('is able to understand multiple env flags', async () => {
131141
const { exitCode, stderr, stdout } = await run(__dirname, ['--env', 'isDev', '--env', 'verboseStats', '--env', 'envMessage']);
132142

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ module.exports = (env) => {
1717
},
1818
};
1919
}
20+
if (env.foo === `bar=''`) {
21+
return {
22+
entry: './a.js',
23+
output: {
24+
filename: 'new-empty-string.js',
25+
},
26+
};
27+
}
2028
return {
2129
entry: './a.js',
2230
mode: 'development',

0 commit comments

Comments
 (0)