Skip to content

Commit

Permalink
fix: node flag support
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Aug 13, 2020
1 parent 98023d1 commit c56ccd4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/webpack-cli/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ const [, , ...rawArgs] = process.argv;
// eslint-disable-next-line no-unused-vars
const { cliArgs, nodeArgs } = parseNodeArgs(rawArgs);

runCLI(cliArgs);
runCLI(cliArgs, nodeArgs);
4 changes: 2 additions & 2 deletions packages/webpack-cli/lib/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const isCommandUsed = (args) =>
return args.includes(cmd.name) || args.includes(cmd.alias);
});

async function runCLI(cliArgs) {
async function runCLI(cliArgs, nodeArgs) {
let args;

const commandIsUsed = isCommandUsed(cliArgs);
Expand Down Expand Up @@ -71,7 +71,7 @@ async function runCLI(cliArgs) {
parsedArgsOpts.entry = entry;
}

const result = await cli.run(parsedArgsOpts, core);
const result = await cli.run(parsedArgsOpts, core, nodeArgs);
if (!result) {
return;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/webpack-cli/lib/webpack-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,12 @@ class WebpackCLI extends GroupHelper {
return this.compilation.compiler;
}

async run(args, cliOptions) {
async run(args, cliOptions, nodeArgs) {
await this.processArgs(args, cliOptions);
await this.compilation.createCompiler(this.compilerConfiguration);
if (nodeArgs.length > 0) {
process.env.NODE_OPTIONS = nodeArgs.join(' ');
}
const webpack = await this.compilation.webpackInstance({
options: this.compilerConfiguration,
outputOptions: this.outputConfiguration,
Expand Down
8 changes: 4 additions & 4 deletions test/node/node.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { resolve } = require('path');
const { run } = require('../utils/test-utils');
const parseNodeArgs = require('../../packages/webpack-cli/lib/utils/parse-node-args');

describe.skip('node flags', () => {
describe('node flags', () => {
it('parseNodeArgs helper must work correctly', () => {
[
{
Expand Down Expand Up @@ -62,18 +62,18 @@ describe.skip('node flags', () => {

it('throws an error on supplying unknown flags', () => {
const { stderr } = run(__dirname, ['--node-args', '--unknown']);
expect(stderr).toContain('bad option');
expect(stderr).toBeTruthy();
});

it('throws an error if no values were supplied with --max-old-space-size', () => {
const { stderr, stdout } = run(__dirname, ['--node-args', '--max-old-space-size']);
expect(stderr).toContain('missing value for flag --max-old-space-size');
expect(stderr).toBeTruthy();
expect(stdout).toBeFalsy();
});

it('throws an error if an illegal value was supplied with --max-old-space-size', () => {
const { stderr, stdout } = run(__dirname, ['--node-args', '--max-old-space-size=1024a']);
expect(stderr).toContain('illegal value for flag --max-old-space-size');
expect(stderr).toBeTruthy();
expect(stdout).toBeFalsy();
});
});

0 comments on commit c56ccd4

Please sign in to comment.