From c261aa4d7691e61e67698c754a95dec3140f8ccb Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sun, 7 Jun 2020 15:09:45 +0530 Subject: [PATCH] feat(webpack-cli): allow multiple entries --- packages/webpack-cli/lib/bootstrap.js | 21 ++++++++++----- .../multiple-entries/multi-entries.test.js | 26 +++++++++++++++++++ test/entry/multiple-entries/src/a.js | 1 + test/entry/multiple-entries/src/b.js | 1 + test/entry/multiple-entries/src/c.js | 1 + 5 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 test/entry/multiple-entries/multi-entries.test.js create mode 100644 test/entry/multiple-entries/src/a.js create mode 100644 test/entry/multiple-entries/src/b.js create mode 100644 test/entry/multiple-entries/src/c.js diff --git a/packages/webpack-cli/lib/bootstrap.js b/packages/webpack-cli/lib/bootstrap.js index 07c27567955..a088a32e671 100644 --- a/packages/webpack-cli/lib/bootstrap.js +++ b/packages/webpack-cli/lib/bootstrap.js @@ -49,14 +49,21 @@ async function runCLI(cli, commandIsUsed) { // if the unknown arg starts with a '-', it will be considered // an unknown flag rather than an entry let entry; - if (parsedArgs.unknownArgs.length === 1 && !parsedArgs.unknownArgs[0].startsWith('-')) { - entry = parsedArgs.unknownArgs[0]; - } else if (parsedArgs.unknownArgs.length > 0) { - parsedArgs.unknownArgs - .filter((e) => e) - .forEach((unknown) => { - logger.warn('Unknown argument:', unknown); + if (parsedArgs.unknownArgs.length > 0 && !parsedArgs.unknownArgs[0].startsWith('-')) { + if (parsedArgs.unknownArgs.length === 1) { + entry = parsedArgs.unknownArgs[0]; + } else { + entry = []; + parsedArgs.unknownArgs.forEach((unknown) => { + if (!unknown.startsWith('-')) { + entry.push(unknown); + } }); + } + } else if (parsedArgs.unknownArgs.length > 0) { + parsedArgs.unknownArgs.forEach((unknown) => { + logger.warn('Unknown argument:', unknown); + }); cliExecuter(); return; } diff --git a/test/entry/multiple-entries/multi-entries.test.js b/test/entry/multiple-entries/multi-entries.test.js new file mode 100644 index 00000000000..a6d6dcb18dc --- /dev/null +++ b/test/entry/multiple-entries/multi-entries.test.js @@ -0,0 +1,26 @@ +'use strict'; + +const { run } = require('../../utils/test-utils'); +const { stat, readFile } = require('fs'); +const { resolve } = require('path'); + +describe('entry flag', () => { + it('should allow multiple entry files', (done) => { + const { stderr, stdout } = run(__dirname, ['src/a.js', 'src/b.js', 'src/c.js']); + expect(stderr).toBeFalsy(); + expect(stdout).toBeTruthy(); + + stat(resolve(__dirname, './bin/main.js'), (err, stats) => { + expect(err).toBe(null); + expect(stats.isFile()).toBe(true); + done(); + }); + readFile(resolve(__dirname, './bin/main.js'), 'utf-8', (err, data) => { + expect(err).toBe(null); + expect(data).toContain('Hello from a.js'); + expect(data).toContain('Hello from b.js'); + expect(data).toContain('Hello from c.js'); + done(); + }); + }); +}); diff --git a/test/entry/multiple-entries/src/a.js b/test/entry/multiple-entries/src/a.js new file mode 100644 index 00000000000..5b4dd8b52eb --- /dev/null +++ b/test/entry/multiple-entries/src/a.js @@ -0,0 +1 @@ +console.log('Hello from a.js'); diff --git a/test/entry/multiple-entries/src/b.js b/test/entry/multiple-entries/src/b.js new file mode 100644 index 00000000000..4eb2d45c855 --- /dev/null +++ b/test/entry/multiple-entries/src/b.js @@ -0,0 +1 @@ +console.log('Hello from b.js'); diff --git a/test/entry/multiple-entries/src/c.js b/test/entry/multiple-entries/src/c.js new file mode 100644 index 00000000000..68ea4af8491 --- /dev/null +++ b/test/entry/multiple-entries/src/c.js @@ -0,0 +1 @@ +console.log('Hello from c.js');