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

fix(cli): show help flag when defaults fail #466

Merged
merged 11 commits into from
Jun 2, 2018
11 changes: 11 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,17 @@ For more information, see https://webpack.js.org/api/cli/.`);
);
} else if (stats.hash !== lastHash) {
lastHash = stats.hash;
if (stats.compilation && stats.compilation.errors.length !== 0) {
const errors = stats.compilation.errors;
if (errors[0].name === "EntryModuleNotFoundError") {
console.error(
"\n\u001b[1m\u001b[31mInsufficient number of arguments or no entry found."
);
console.error(
"\u001b[1m\u001b[31mAlternatively, run 'webpack(-cli) --help' for usage info.\u001b[39m\u001b[22m\n"
);
}
}
const statsString = stats.toString(outputOptions);
const delimiter = outputOptions.buildDelimiter
? `${outputOptions.buildDelimiter}\n`
Expand Down
38 changes: 16 additions & 22 deletions packages/utils/recursive-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@

const defineTest = require("./defineTest");

defineTest(
__dirname,
"entry",
"fixture-1",
{
objects: "are",
super: [
"yeah",
{
test: new RegExp(/\.(js|vue)$/),
loader: "'eslint-loader'",
enforce: "'pre'",
include: ["customObj", "'Stringy'"],
options: {
formatter: "'someOption'"
}
defineTest(__dirname, "init", "fixture-1", "entry", {
objects: "are",
super: [
"yeah",
{
test: new RegExp(/\.(js|vue)$/),
loader: "'eslint-loader'",
enforce: "'pre'",
include: ["customObj", "'Stringy'"],
options: {
formatter: "'someOption'"
}
],
nice: "':)'",
man: "() => duper"
},
"init"
);
}
],
nice: "':)'",
man: "() => duper"
});
10 changes: 3 additions & 7 deletions test/binCases/no-options/development/stdin.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
"use strict";

module.exports = function testAssertions(code, stdout, stderr) {
expect(code).toBe(2);
expect(code).toBe(0);
expect(stdout).toEqual(expect.anything());
expect(stdout[0]).toContain("Hash: ");
expect(stdout[1]).toContain("Version: ");
expect(stdout[2]).toContain("Time: ");
expect(stdout[4]).toContain("");
expect(stdout[5]).toContain("ERROR in Entry module not found");
expect(stdout[6]).toContain("");
expect(stdout[3]).toContain("Insufficient number of arguments provided");
expect(stdout[4]).toContain("Alternatively, run `webpack(-cli) --help` for usage info");
expect(stderr).toHaveLength(0);
};
13 changes: 3 additions & 10 deletions test/binCases/no-options/none/stdin.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
"use strict";

module.exports = function testAssertions(code, stdout, stderr) {
expect(code).toBe(2);
expect(code).toBe(0);
expect(stdout).toEqual(expect.anything());
expect(stdout[0]).toContain("Hash: ");
expect(stdout[1]).toContain("Version: ");
expect(stdout[2]).toContain("Time: ");
expect(stdout[4]).toContain("");
expect(stdout[5]).toContain("WARNING");
expect(stdout[6]).toContain("The \'mode\' option has not been set");
expect(stdout[7]).toContain("You can also set it to \'none\'");
expect(stdout[8]).toContain("");
expect(stdout[9]).toContain("ERROR in Entry module not found");
expect(stdout[3]).toContain("Insufficient number of arguments provided");
expect(stdout[4]).toContain("Alternatively, run `webpack(-cli) --help` for usage info");
expect(stderr).toHaveLength(0);
};
10 changes: 3 additions & 7 deletions test/binCases/no-options/production/stdin.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
"use strict";

module.exports = function testAssertions(code, stdout, stderr) {
expect(code).toBe(2);
expect(code).toBe(0);
expect(stdout).toEqual(expect.anything());
expect(stdout[0]).toContain("Hash: ");
expect(stdout[1]).toContain("Version: ");
expect(stdout[2]).toContain("Time: ");
expect(stdout[4]).toContain("");
expect(stdout[5]).toContain("ERROR in Entry module not found");
expect(stdout[6]).toContain("");
expect(stdout[3]).toContain("Insufficient number of arguments provided");
expect(stdout[4]).toContain("Alternatively, run `webpack(-cli) --help` for usage info");
expect(stderr).toHaveLength(0);
};
5 changes: 5 additions & 0 deletions test/binCases/no-options/stdin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

module.exports = function testAssertions(code, stdout, stderr) {
expect(stdout[3]).toContain("Insufficient number of arguments provided");
};