Skip to content

Commit 5f9414b

Browse files
committed
fix: remove node-args, fix tests, remove stale helpers
1 parent 52c3545 commit 5f9414b

File tree

4 files changed

+21
-92
lines changed

4 files changed

+21
-92
lines changed

packages/webpack-cli/bin/cli.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
'use strict';
44
require('v8-compile-cache');
55
const importLocal = require('import-local');
6-
const parseNodeArgs = require('../lib/utils/parse-node-args');
76
const runCLI = require('../lib/bootstrap');
87

98
// Prefer the local installation of webpack-cli
@@ -14,8 +13,4 @@ process.title = 'webpack';
1413

1514
const [, , ...rawArgs] = process.argv;
1615

17-
// figure out how to inject node args at runtime
18-
// eslint-disable-next-line no-unused-vars
19-
const { cliArgs, nodeArgs } = parseNodeArgs(rawArgs);
20-
21-
runCLI(cliArgs);
16+
runCLI(rawArgs);

packages/webpack-cli/lib/utils/parse-node-args.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

test/node/node.test.js

Lines changed: 14 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,78 +2,37 @@
22
const { stat } = require('fs');
33
const { resolve } = require('path');
44
const { run } = require('../utils/test-utils');
5-
const parseNodeArgs = require('../../packages/webpack-cli/lib/utils/parse-node-args');
65

7-
describe.skip('node flags', () => {
8-
it('parseNodeArgs helper must work correctly', () => {
9-
[
10-
{
11-
rawArgs: ['--foo', '--bar', '--baz=quux'],
12-
expectedCliArgs: ['--foo', '--bar', '--baz=quux'],
13-
expectedNodeArgs: [],
14-
},
15-
{
16-
rawArgs: ['--foo', '--bar', '--baz=quux', '--node-args', '--name1=value1', '--node-args', '--name2 value2'],
17-
expectedCliArgs: ['--foo', '--bar', '--baz=quux'],
18-
expectedNodeArgs: ['--name1=value1', '--name2', 'value2'],
19-
},
20-
{
21-
rawArgs: [
22-
'--node-args',
23-
'--name1=value1',
24-
'--node-args',
25-
'--name2="value2"',
26-
'--node-args',
27-
'--name3 value3',
28-
'--node-args',
29-
'-k v',
30-
],
31-
expectedCliArgs: [],
32-
expectedNodeArgs: ['--name1=value1', '--name2="value2"', '--name3', 'value3', '-k', 'v'],
33-
},
34-
].map(({ rawArgs, expectedNodeArgs, expectedCliArgs }) => {
35-
const { nodeArgs, cliArgs } = parseNodeArgs(rawArgs);
36-
expect(nodeArgs).toEqual(expectedNodeArgs);
37-
expect(cliArgs).toEqual(expectedCliArgs);
38-
});
39-
});
40-
41-
it('is able to pass the options flags to node js', (done) => {
42-
const { stdout } = run(
43-
__dirname,
44-
[
45-
'--node-args',
46-
`--require=${resolve(__dirname, 'bootstrap.js')}`,
47-
'--node-args',
48-
`-r ${resolve(__dirname, 'bootstrap2.js')}`,
49-
'--output',
50-
'./bin/[name].bundle.js',
51-
],
52-
false,
53-
);
6+
describe('node flags', () => {
7+
it('is able to pass the options flags to node js', async (done) => {
8+
const { stdout, stderr } = await run(__dirname, ['--output', './bin/[name].bundle.js'], false, [
9+
`--require=${resolve(__dirname, 'bootstrap.js')}`,
10+
`--require=${resolve(__dirname, 'bootstrap2.js')}`,
11+
]);
5412
expect(stdout).toContain('---from bootstrap.js---');
5513
expect(stdout).toContain('---from bootstrap2.js---');
14+
expect(stderr).toBeFalsy();
5615
stat(resolve(__dirname, './bin/main.bundle.js'), (err, stats) => {
5716
expect(err).toBe(null);
5817
expect(stats.isFile()).toBe(true);
5918
done();
6019
});
6120
});
6221

63-
it('throws an error on supplying unknown flags', () => {
64-
const { stderr } = run(__dirname, ['--node-args', '--unknown']);
22+
it('throws an error on supplying unknown flags', async () => {
23+
const { stderr } = await run(__dirname, [], false, ['--unknown']);
6524
expect(stderr).toContain('bad option');
6625
});
6726

68-
it('throws an error if no values were supplied with --max-old-space-size', () => {
69-
const { stderr, stdout } = run(__dirname, ['--node-args', '--max-old-space-size']);
27+
it('throws an error if no values were supplied with --max-old-space-size', async () => {
28+
const { stderr, stdout } = await run(__dirname, [], false, ['--max-old-space-size']);
7029
expect(stderr).toContain('missing value for flag --max-old-space-size');
7130
expect(stdout).toBeFalsy();
7231
});
7332

74-
it('throws an error if an illegal value was supplied with --max-old-space-size', () => {
75-
const { stderr, stdout } = run(__dirname, ['--node-args', '--max-old-space-size=1024a']);
76-
expect(stderr).toContain('illegal value for flag --max-old-space-size');
33+
it('throws an error if an illegal value was supplied with --max-old-space-size', async () => {
34+
const { stderr, stdout } = await run(__dirname, [], true, ['--max_old_space_size=1024a']);
35+
expect(stderr).toContain('Error: illegal value for flag --max_old_space_size=1024a of type size_t');
7736
expect(stdout).toBeFalsy();
7837
});
7938
});

test/utils/test-utils.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const path = require('path');
33
const fs = require('fs');
44
const execa = require('execa');
5-
const { sync: spawnSync } = execa;
5+
const { sync: spawnSync, node: execaNode } = execa;
66
const { Writable } = require('readable-stream');
77
const concat = require('concat-stream');
88

@@ -15,16 +15,18 @@ const ENABLE_LOG_COMPILATION = process.env.ENABLE_PIPE || false;
1515
* @param {String} testCase The path to folder that contains the webpack.config.js
1616
* @param {Array} args Array of arguments to pass to webpack
1717
* @param {Boolean} setOutput Boolean that decides if a default output path will be set or not
18-
* @returns {Object} The webpack output
18+
* @returns {Object} The webpack output or Promise when nodeOptions are present
1919
*/
20-
function run(testCase, args = [], setOutput = true) {
20+
function run(testCase, args = [], setOutput = true, nodeArgs = []) {
2121
const cwd = path.resolve(testCase);
2222

2323
const outputPath = path.resolve(testCase, 'bin');
24+
const processExecutor = nodeArgs.length ? execaNode : spawnSync;
2425
const argsWithOutput = setOutput ? args.concat('--output', outputPath) : args;
25-
const result = spawnSync(WEBPACK_PATH, argsWithOutput, {
26+
const result = processExecutor(WEBPACK_PATH, argsWithOutput, {
2627
cwd,
2728
reject: false,
29+
nodeOptions: nodeArgs,
2830
stdio: ENABLE_LOG_COMPILATION ? 'inherit' : 'pipe',
2931
});
3032

0 commit comments

Comments
 (0)