Skip to content

Commit

Permalink
Merge pull request #618 from webpack/fix/watch-info
Browse files Browse the repository at this point in the history
fix(tapable): fix hook options
  • Loading branch information
evenstensberg committed Sep 29, 2018
2 parents 99f5a69 + d4e1614 commit fb6945b
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 141 deletions.
20 changes: 14 additions & 6 deletions bin/cli.js
Expand Up @@ -459,13 +459,21 @@ For more information, see https://webpack.js.org/api/cli/.`);
profile: argv.profile
}).apply(compiler);
}

if (outputOptions.infoVerbosity === "verbose") {
compiler.hooks.beforeCompile.tap("WebpackInfo", compilation => {
console.log("\nCompilation starting…\n");
});
compiler.hooks.afterCompile.tap("WebpackInfo", compilation => {
console.log("\nCompilation finished\n");
if (argv.w) {
compiler.hooks.watchRun.tap("WebpackInfo", compilation => {
const compilationName = compilation.name ? compilation.name : "";
console.log("\nCompilation " + compilationName + " starting…\n");
});
} else {
compiler.hooks.beforeRun.tap("WebpackInfo", compilation => {
const compilationName = compilation.name ? compilation.name : "";
console.log("\nCompilation " + compilationName + " starting…\n");
});
}
compiler.hooks.done.tap("WebpackInfo", compilation => {
const compilationName = compilation.name ? compilation.name : "";
console.log("\nCompilation " + compilationName + " finished\n");
});
}

Expand Down
67 changes: 32 additions & 35 deletions bin/config-yargs.js
Expand Up @@ -20,18 +20,25 @@ const resolveSchema = schema => {
const findPropertyInSchema = (schema, property, subProperty) => {
if (!schema) return null;
if (subProperty) {
if (schema[property] && typeof schema[property] === "object" && subProperty in schema[property]) {
if (
schema[property] &&
typeof schema[property] === "object" &&
subProperty in schema[property]
) {
return resolveSchema(schema[property][subProperty]);
}
} else {
if (property in schema)
return resolveSchema(schema[property]);
if (property in schema) return resolveSchema(schema[property]);
}
for (const name of nestedProperties) {
if (schema[name]) {
for (const item of schema[name]) {
const resolvedItem = resolveSchema(item);
const result = findPropertyInSchema(resolvedItem, property, subProperty);
const result = findPropertyInSchema(
resolvedItem,
property,
subProperty
);
if (result) return result;
}
}
Expand All @@ -44,7 +51,9 @@ const getSchemaInfo = (path, property, subProperty) => {
let current = optionsSchema;
for (const segment of pathSegments) {
if (segment === "*") {
current = findPropertyInSchema(current, "additionalProperties") || findPropertyInSchema(current, "items");
current =
findPropertyInSchema(current, "additionalProperties") ||
findPropertyInSchema(current, "items");
} else {
current = findPropertyInSchema(current, "properties", segment);
}
Expand Down Expand Up @@ -147,46 +156,40 @@ module.exports = function(yargs) {
},
"output-filename": {
type: "string",
describe:
getSchemaInfo("output.filename", "description"),
describe: getSchemaInfo("output.filename", "description"),
group: OUTPUT_GROUP,
defaultDescription: "[name].js",
requiresArg: true
},
"output-chunk-filename": {
type: "string",
describe:
getSchemaInfo("output.chunkFilename", "description"),
describe: getSchemaInfo("output.chunkFilename", "description"),
group: OUTPUT_GROUP,
defaultDescription:
"filename with [id] instead of [name] or [id] prefixed",
requiresArg: true
},
"output-source-map-filename": {
type: "string",
describe:
getSchemaInfo("output.sourceMapFilename", "description"),
describe: getSchemaInfo("output.sourceMapFilename", "description"),
group: OUTPUT_GROUP,
requiresArg: true
},
"output-public-path": {
type: "string",
describe:
getSchemaInfo("output.publicPath", "description"),
describe: getSchemaInfo("output.publicPath", "description"),
group: OUTPUT_GROUP,
requiresArg: true
},
"output-jsonp-function": {
type: "string",
describe:
getSchemaInfo("output.jsonpFunction", "description"),
describe: getSchemaInfo("output.jsonpFunction", "description"),
group: OUTPUT_GROUP,
requiresArg: true
},
"output-pathinfo": {
type: "boolean",
describe:
getSchemaInfo("output.pathinfo", "description"),
describe: getSchemaInfo("output.pathinfo", "description"),
group: OUTPUT_GROUP
},
"output-library": {
Expand All @@ -197,8 +200,7 @@ module.exports = function(yargs) {
},
"output-library-target": {
type: "string",
describe:
getSchemaInfo("output.libraryTarget", "description"),
describe: getSchemaInfo("output.libraryTarget", "description"),
choices: getSchemaInfo("output.libraryTarget", "enum"),
group: OUTPUT_GROUP,
requiresArg: true
Expand Down Expand Up @@ -249,22 +251,18 @@ module.exports = function(yargs) {
"watch-stdin": {
type: "boolean",
alias: "stdin",
describe:
getSchemaInfo("watchOptions.stdin", "description"),
describe: getSchemaInfo("watchOptions.stdin", "description"),
group: ADVANCED_GROUP
},
"watch-aggregate-timeout": {
describe:
getSchemaInfo("watchOptions.aggregateTimeout", "description"),
type:
getSchemaInfo("watchOptions.aggregateTimeout", "type"),
describe: getSchemaInfo("watchOptions.aggregateTimeout", "description"),
type: getSchemaInfo("watchOptions.aggregateTimeout", "type"),
group: ADVANCED_GROUP,
requiresArg: true
},
"watch-poll": {
type: "string",
describe:
getSchemaInfo("watchOptions.poll", "description"),
describe: getSchemaInfo("watchOptions.poll", "description"),
group: ADVANCED_GROUP
},
hot: {
Expand All @@ -285,15 +283,13 @@ module.exports = function(yargs) {
},
"resolve-alias": {
type: "string",
describe:
getSchemaInfo("resolve.alias", "description"),
describe: getSchemaInfo("resolve.alias", "description"),
group: RESOLVE_GROUP,
requiresArg: true
},
"resolve-extensions": {
type: "array",
describe:
getSchemaInfo("resolve.alias", "description"),
describe: getSchemaInfo("resolve.alias", "description"),
group: RESOLVE_GROUP,
requiresArg: true
},
Expand All @@ -309,15 +305,16 @@ module.exports = function(yargs) {
requiresArg: true
},
"optimize-min-chunk-size": {
describe:
getSchemaInfo("optimization.splitChunks.minSize", "description"),
describe: getSchemaInfo(
"optimization.splitChunks.minSize",
"description"
),
group: OPTIMIZE_GROUP,
requiresArg: true
},
"optimize-minimize": {
type: "boolean",
describe:
getSchemaInfo("optimization.minimize", "description"),
describe: getSchemaInfo("optimization.minimize", "description"),
group: OPTIMIZE_GROUP
},
prefetch: {
Expand Down
4 changes: 3 additions & 1 deletion packages/utils/npm-packages-exists.test.js
Expand Up @@ -23,7 +23,9 @@ describe("npmPackagesExists", () => {
});

test("resolves packages when they are available on npm", done => {
require("./npm-exists").default.mockImplementation(() => Promise.resolve(true));
require("./npm-exists").default.mockImplementation(() =>
Promise.resolve(true)
);
npmPackagesExists(["webpack-scaffold-foobar"]);
setTimeout(() => {
expect(
Expand Down
149 changes: 52 additions & 97 deletions packages/utils/recursive-parser.test.js
Expand Up @@ -2,108 +2,63 @@

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


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'"
}
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: "':)'",
foo: "Promise.resolve()",
man: "() => duper"
}
);
}
],
nice: "':)'",
foo: "Promise.resolve()",
man: "() => duper"
});

defineTest(
__dirname,
"add",
"fixture-2",
"entry",
{
objects: "are not",
super: [
"op",
{
test: new RegExp(/\.(wasm|c)$/),
loader: "'pia-loader'",
enforce: "'pre'",
include: ["asd", "'Stringy'"],
options: {
formatter: "'nao'"
}
defineTest(__dirname, "add", "fixture-2", "entry", {
objects: "are not",
super: [
"op",
{
test: new RegExp(/\.(wasm|c)$/),
loader: "'pia-loader'",
enforce: "'pre'",
include: ["asd", "'Stringy'"],
options: {
formatter: "'nao'"
}
],
nice: "'=)'",
foo: "Promise.resolve()",
man: "() => nice!!",
mode: "super-man"
}
);
}
],
nice: "'=)'",
foo: "Promise.resolve()",
man: "() => nice!!",
mode: "super-man"
});

defineTest(
__dirname,
"remove",
"fixture-3",
"resolve",
{
alias: null
}
);
defineTest(__dirname, "remove", "fixture-3", "resolve", {
alias: null
});

defineTest(
__dirname,
"remove",
"fixture-3",
"plugins",
[
"plugin2"
]
);
defineTest(__dirname, "remove", "fixture-3", "plugins", ["plugin2"]);

defineTest(
__dirname,
"remove",
"fixture-3",
"module",
{
noParse: null
}
);
defineTest(__dirname, "remove", "fixture-3", "module", {
noParse: null
});

defineTest(
__dirname,
"remove",
"fixture-3",
"entry",
{
a: null,
}
);
defineTest(__dirname, "remove", "fixture-3", "entry", {
a: null
});

defineTest(
__dirname,
"remove",
"fixture-3",
"module",
{
rules: [
{
loader: "eslint-loader",
},
]
}
);
defineTest(__dirname, "remove", "fixture-3", "module", {
rules: [
{
loader: "eslint-loader"
}
]
});
4 changes: 2 additions & 2 deletions test/binCases/watch/info-verbosity-verbose/stdin.js
Expand Up @@ -3,13 +3,13 @@
module.exports = function testAssertions(stdout, stderr, done) {
expect(stdout).toEqual(expect.anything());
expect(stdout[0]).toContain("");
expect(stdout[1]).toContain("Compilation starting…");
expect(stdout[1]).toContain("Compilation");
expect(stdout[2]).toContain("");
expect(stdout[3]).toContain("");
expect(stdout[4]).toContain("webpack is watching the files…");
expect(stdout[6]).toContain("");
expect(stdout[6]).toContain("");
expect(stdout[7]).toContain("Compilation finished");
expect(stdout[7]).toContain("Compilation");
expect(stdout[8]).toContain("");

expect(stderr).toHaveLength(0);
Expand Down

0 comments on commit fb6945b

Please sign in to comment.