Skip to content

Commit

Permalink
fix: spawn new process for executor
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanv committed Aug 11, 2020
1 parent ddddaac commit 98023d1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
10 changes: 5 additions & 5 deletions packages/webpack-cli/__tests__/cli-executer.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
jest.mock('../lib/bootstrap');
jest.mock('../lib/runner');
jest.mock('enquirer');

const runCLI = require('../lib/bootstrap');
runCLI.mockImplementation(() => {});
const runner = require('../lib/runner');
runner.mockImplementation(() => {});

describe('CLI Executer', () => {
let cliExecuter = null;
Expand Down Expand Up @@ -48,8 +48,8 @@ describe('CLI Executer', () => {
await cliExecuter();

// ensure that the webpack runCLI is called
expect(runCLI.mock.calls.length).toEqual(1);
expect(runCLI.mock.calls[0]).toEqual([[], ['--config', 'test1', '--entry', 'test2', '--progress']]);
expect(runner.mock.calls.length).toEqual(1);
expect(runner.mock.calls[0]).toEqual([[], ['--config', 'test1', '--entry', 'test2', '--progress']]);

// check that webpack options are actually being displayed that
// the user can select from
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-cli/lib/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async function runCLI(cliArgs) {
parsedArgs.unknownArgs.forEach((unknown) => {
logger.warn('Unknown argument:', unknown);
});
cliExecuter();
await cliExecuter();
return;
}
const parsedArgsOpts = parsedArgs.opts;
Expand Down
10 changes: 10 additions & 0 deletions packages/webpack-cli/lib/runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const execa = require('execa');
const cliPath = require.resolve('./bootstrap.js');

function runner(nodeArgs, cliArgs) {
execa('node', [...nodeArgs, cliPath, ...cliArgs], { stdio: 'inherit' }).catch((e) => {
process.exit(e.exitCode);
});
}

module.exports = runner;
4 changes: 2 additions & 2 deletions packages/webpack-cli/lib/utils/cli-executer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { MultiSelect, Input } = require('enquirer');
const { cyan } = require('colorette');
const logger = require('./logger');
const cliArgs = require('./cli-flags').core;
const runCLI = require('../bootstrap');
const runner = require('../runner');

async function prompter() {
const args = [];
Expand Down Expand Up @@ -56,7 +56,7 @@ async function run() {
const args = await prompter();
process.stdout.write('\n');
logger.info('Executing CLI\n');
runCLI(args);
await runner([], args);
} catch (err) {
logger.error(`Action Interrupted, use ${cyan('webpack-cli help')} to see possible options.`);
}
Expand Down

0 comments on commit 98023d1

Please sign in to comment.