Skip to content

Commit 9026556

Browse files
bitpshrevenstensberg
authored andcommitted
feat: --entry should override config.entry (#155) (#358)
1 parent 2222f1d commit 9026556

File tree

8 files changed

+32
-21
lines changed

8 files changed

+32
-21
lines changed

bin/convert-argv.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ module.exports = function(...args) {
313313
}
314314
}
315315

316-
function ensureObject(parent, name) {
317-
if (typeof parent[name] !== "object" || parent[name] === null) {
316+
function ensureObject(parent, name, force) {
317+
if (force || typeof parent[name] !== "object" || parent[name] === null) {
318318
parent[name] = {};
319319
}
320320
}
@@ -347,7 +347,7 @@ module.exports = function(...args) {
347347
}
348348
},
349349
function() {
350-
ensureObject(options, "entry");
350+
ensureObject(options, "entry", true);
351351
}
352352
);
353353

@@ -567,12 +567,7 @@ module.exports = function(...args) {
567567
mapArgToBoolean("profile");
568568

569569
if (argv._.length > 0) {
570-
if (Array.isArray(options.entry) || typeof options.entry === "string") {
571-
options.entry = {
572-
main: options.entry
573-
};
574-
}
575-
ensureObject(options, "entry");
570+
ensureObject(options, "entry", true);
576571

577572
const addTo = function addTo(name, entry) {
578573
if (options.entry[name]) {

bin/webpack.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,13 @@
4747
return;
4848
}
4949

50-
const yargs = require("yargs").usage(
51-
"webpack-cli " +
52-
require("../package.json").version +
53-
"\n" +
54-
"Usage: https://webpack.js.org/api/cli/\n" +
55-
"Usage without config file: webpack <entry> [<entry>] --output [-o] <output>\n" +
56-
"Usage with config file: webpack"
57-
);
50+
const yargs = require("yargs").usage(`webpack-cli ${require("../package.json").version}
51+
52+
Usage: webpack-cli [options]
53+
webpack-cli [options] --entry <entry> --output <output>
54+
webpack-cli [options] <entries...> --output <output>
55+
56+
For more information, see https://webpack.js.org/api/cli/.`);
5857

5958
require("./config-yargs")(yargs);
6059

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
3+
module.exports = function testAssertions(code, stdout, stderr) {
4+
expect(code).toBe(0);
5+
expect(stdout).toEqual(expect.anything());
6+
expect(stdout[5]).toContain("cliEntry.js");
7+
expect(stdout[7]).toContain("index.js");
8+
expect(stderr).toHaveLength(0);
9+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--entry cliEntry=./index.js
2+
--config ./webpack.config.js
3+
--output-filename [name].js
4+
--output-chunk-filename [id].chunk.js
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const path = require("path");
2+
3+
module.exports = {
4+
entry: {
5+
configEntry: path.resolve(__dirname, "./index")
6+
}
7+
};

test/binCases/entry/non-hyphenated-args/stdin.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ module.exports = function testAssertions(code, stdout, stderr) {
44
expect(code).toBe(0);
55
expect(stdout).toEqual(expect.anything());
66
expect(stdout[5]).toContain("main.js"); // non-hyphenated arg ./a.js should create chunk "main"
7-
expect(stdout[7]).toContain("null.js");
8-
expect(stdout[9]).toMatch(/a\.js.*\{0\}/); // a.js should be in chunk 0
9-
expect(stdout[10]).toMatch(/index\.js.*\{1\}/); // index.js should be in chunk 1
7+
expect(stdout[7]).toMatch(/a\.js.*\{0\}/); // a.js should be in chunk 0
108
expect(stderr).toHaveLength(0);
119
};

test/binCases/entry/non-hyphenated-args/test.opts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
./a.js
2-
--entry ./index.js
32
--config ./webpack.config.js
43
--output-filename [name].js
54
--output-chunk-filename [id].chunk.js

0 commit comments

Comments
 (0)