Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--entry should override config.entry #358

Merged
merged 1 commit into from
Mar 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions bin/convert-argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ module.exports = function(...args) {
}
}

function ensureObject(parent, name) {
if (typeof parent[name] !== "object" || parent[name] === null) {
function ensureObject(parent, name, force) {
if (force || typeof parent[name] !== "object" || parent[name] === null) {
parent[name] = {};
}
}
Expand Down Expand Up @@ -347,7 +347,7 @@ module.exports = function(...args) {
}
},
function() {
ensureObject(options, "entry");
ensureObject(options, "entry", true);
}
);

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

if (argv._.length > 0) {
if (Array.isArray(options.entry) || typeof options.entry === "string") {
options.entry = {
main: options.entry
};
}
ensureObject(options, "entry");
ensureObject(options, "entry", true);

const addTo = function addTo(name, entry) {
if (options.entry[name]) {
Expand Down
15 changes: 7 additions & 8 deletions bin/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@
return;
}

const yargs = require("yargs").usage(
"webpack-cli " +
require("../package.json").version +
"\n" +
"Usage: https://webpack.js.org/api/cli/\n" +
"Usage without config file: webpack <entry> [<entry>] --output [-o] <output>\n" +
"Usage with config file: webpack"
);
const yargs = require("yargs").usage(`webpack-cli ${require("../package.json").version}

Usage: webpack-cli [options]
webpack-cli [options] --entry <entry> --output <output>
webpack-cli [options] <entries...> --output <output>

For more information, see https://webpack.js.org/api/cli/.`);

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

Expand Down
9 changes: 9 additions & 0 deletions test/binCases/entry/cli-override/stdin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";

module.exports = function testAssertions(code, stdout, stderr) {
expect(code).toBe(0);
expect(stdout).toEqual(expect.anything());
expect(stdout[5]).toContain("cliEntry.js");
expect(stdout[7]).toContain("index.js");
expect(stderr).toHaveLength(0);
};
4 changes: 4 additions & 0 deletions test/binCases/entry/cli-override/test.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--entry cliEntry=./index.js
--config ./webpack.config.js
--output-filename [name].js
--output-chunk-filename [id].chunk.js
7 changes: 7 additions & 0 deletions test/binCases/entry/cli-override/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require("path");

module.exports = {
entry: {
configEntry: path.resolve(__dirname, "./index")
}
};
4 changes: 1 addition & 3 deletions test/binCases/entry/non-hyphenated-args/stdin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module.exports = function testAssertions(code, stdout, stderr) {
expect(code).toBe(0);
expect(stdout).toEqual(expect.anything());
expect(stdout[5]).toContain("main.js"); // non-hyphenated arg ./a.js should create chunk "main"
expect(stdout[7]).toContain("null.js");
expect(stdout[9]).toMatch(/a\.js.*\{0\}/); // a.js should be in chunk 0
expect(stdout[10]).toMatch(/index\.js.*\{1\}/); // index.js should be in chunk 1
expect(stdout[7]).toMatch(/a\.js.*\{0\}/); // a.js should be in chunk 0
expect(stderr).toHaveLength(0);
};
1 change: 0 additions & 1 deletion test/binCases/entry/non-hyphenated-args/test.opts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
./a.js
--entry ./index.js
--config ./webpack.config.js
--output-filename [name].js
--output-chunk-filename [id].chunk.js
Expand Down