Skip to content

Commit

Permalink
feat(webpack-cli): allow multiple entries
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jun 7, 2020
1 parent fef65fa commit a061b83
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/webpack-cli/lib/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions packages/webpack-cli/lib/groups/BasicGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class BasicGroup extends GroupHelper {

run() {
this.resolveFlags();
console.log(this);
return this.opts;
}
}
Expand Down
26 changes: 26 additions & 0 deletions test/entry/multiple-entries/multi-entries.test.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
1 change: 1 addition & 0 deletions test/entry/multiple-entries/src/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello from a.js');
1 change: 1 addition & 0 deletions test/entry/multiple-entries/src/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello from b.js');
1 change: 1 addition & 0 deletions test/entry/multiple-entries/src/c.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello from c.js');

0 comments on commit a061b83

Please sign in to comment.