Skip to content

Commit 9aed0dc

Browse files
committed
fix(tapable): fix hook options
1 parent 3844671 commit 9aed0dc

File tree

4 files changed

+101
-139
lines changed

4 files changed

+101
-139
lines changed

bin/cli.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,13 +459,21 @@ For more information, see https://webpack.js.org/api/cli/.`);
459459
profile: argv.profile
460460
}).apply(compiler);
461461
}
462-
463462
if (outputOptions.infoVerbosity === "verbose") {
464-
compiler.hooks.beforeCompile.tap("WebpackInfo", compilation => {
465-
console.log("\nCompilation starting…\n");
466-
});
467-
compiler.hooks.afterCompile.tap("WebpackInfo", compilation => {
468-
console.log("\nCompilation finished\n");
463+
if (argv.w) {
464+
compiler.hooks.watchRun.tap("WebpackInfo", compilation => {
465+
const compilationName = compilation.name ? compilation.name : "";
466+
console.log("\nCompilation " + compilationName + " starting…\n");
467+
});
468+
} else {
469+
compiler.hooks.beforeRun.tap("WebpackInfo", compilation => {
470+
const compilationName = compilation.name ? compilation.name : "";
471+
console.log("\nCompilation " + compilationName + " starting…\n");
472+
});
473+
}
474+
compiler.hooks.done.tap("WebpackInfo", compilation => {
475+
const compilationName = compilation.name ? compilation.name : "";
476+
console.log("\nCompilation " + compilationName + " finished\n");
469477
});
470478
}
471479

bin/config-yargs.js

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,25 @@ const resolveSchema = schema => {
2020
const findPropertyInSchema = (schema, property, subProperty) => {
2121
if (!schema) return null;
2222
if (subProperty) {
23-
if (schema[property] && typeof schema[property] === "object" && subProperty in schema[property]) {
23+
if (
24+
schema[property] &&
25+
typeof schema[property] === "object" &&
26+
subProperty in schema[property]
27+
) {
2428
return resolveSchema(schema[property][subProperty]);
2529
}
2630
} else {
27-
if (property in schema)
28-
return resolveSchema(schema[property]);
31+
if (property in schema) return resolveSchema(schema[property]);
2932
}
3033
for (const name of nestedProperties) {
3134
if (schema[name]) {
3235
for (const item of schema[name]) {
3336
const resolvedItem = resolveSchema(item);
34-
const result = findPropertyInSchema(resolvedItem, property, subProperty);
37+
const result = findPropertyInSchema(
38+
resolvedItem,
39+
property,
40+
subProperty
41+
);
3542
if (result) return result;
3643
}
3744
}
@@ -44,7 +51,9 @@ const getSchemaInfo = (path, property, subProperty) => {
4451
let current = optionsSchema;
4552
for (const segment of pathSegments) {
4653
if (segment === "*") {
47-
current = findPropertyInSchema(current, "additionalProperties") || findPropertyInSchema(current, "items");
54+
current =
55+
findPropertyInSchema(current, "additionalProperties") ||
56+
findPropertyInSchema(current, "items");
4857
} else {
4958
current = findPropertyInSchema(current, "properties", segment);
5059
}
@@ -147,46 +156,40 @@ module.exports = function(yargs) {
147156
},
148157
"output-filename": {
149158
type: "string",
150-
describe:
151-
getSchemaInfo("output.filename", "description"),
159+
describe: getSchemaInfo("output.filename", "description"),
152160
group: OUTPUT_GROUP,
153161
defaultDescription: "[name].js",
154162
requiresArg: true
155163
},
156164
"output-chunk-filename": {
157165
type: "string",
158-
describe:
159-
getSchemaInfo("output.chunkFilename", "description"),
166+
describe: getSchemaInfo("output.chunkFilename", "description"),
160167
group: OUTPUT_GROUP,
161168
defaultDescription:
162169
"filename with [id] instead of [name] or [id] prefixed",
163170
requiresArg: true
164171
},
165172
"output-source-map-filename": {
166173
type: "string",
167-
describe:
168-
getSchemaInfo("output.sourceMapFilename", "description"),
174+
describe: getSchemaInfo("output.sourceMapFilename", "description"),
169175
group: OUTPUT_GROUP,
170176
requiresArg: true
171177
},
172178
"output-public-path": {
173179
type: "string",
174-
describe:
175-
getSchemaInfo("output.publicPath", "description"),
180+
describe: getSchemaInfo("output.publicPath", "description"),
176181
group: OUTPUT_GROUP,
177182
requiresArg: true
178183
},
179184
"output-jsonp-function": {
180185
type: "string",
181-
describe:
182-
getSchemaInfo("output.jsonpFunction", "description"),
186+
describe: getSchemaInfo("output.jsonpFunction", "description"),
183187
group: OUTPUT_GROUP,
184188
requiresArg: true
185189
},
186190
"output-pathinfo": {
187191
type: "boolean",
188-
describe:
189-
getSchemaInfo("output.pathinfo", "description"),
192+
describe: getSchemaInfo("output.pathinfo", "description"),
190193
group: OUTPUT_GROUP
191194
},
192195
"output-library": {
@@ -197,8 +200,7 @@ module.exports = function(yargs) {
197200
},
198201
"output-library-target": {
199202
type: "string",
200-
describe:
201-
getSchemaInfo("output.libraryTarget", "description"),
203+
describe: getSchemaInfo("output.libraryTarget", "description"),
202204
choices: getSchemaInfo("output.libraryTarget", "enum"),
203205
group: OUTPUT_GROUP,
204206
requiresArg: true
@@ -249,22 +251,18 @@ module.exports = function(yargs) {
249251
"watch-stdin": {
250252
type: "boolean",
251253
alias: "stdin",
252-
describe:
253-
getSchemaInfo("watchOptions.stdin", "description"),
254+
describe: getSchemaInfo("watchOptions.stdin", "description"),
254255
group: ADVANCED_GROUP
255256
},
256257
"watch-aggregate-timeout": {
257-
describe:
258-
getSchemaInfo("watchOptions.aggregateTimeout", "description"),
259-
type:
260-
getSchemaInfo("watchOptions.aggregateTimeout", "type"),
258+
describe: getSchemaInfo("watchOptions.aggregateTimeout", "description"),
259+
type: getSchemaInfo("watchOptions.aggregateTimeout", "type"),
261260
group: ADVANCED_GROUP,
262261
requiresArg: true
263262
},
264263
"watch-poll": {
265264
type: "string",
266-
describe:
267-
getSchemaInfo("watchOptions.poll", "description"),
265+
describe: getSchemaInfo("watchOptions.poll", "description"),
268266
group: ADVANCED_GROUP
269267
},
270268
hot: {
@@ -285,15 +283,13 @@ module.exports = function(yargs) {
285283
},
286284
"resolve-alias": {
287285
type: "string",
288-
describe:
289-
getSchemaInfo("resolve.alias", "description"),
286+
describe: getSchemaInfo("resolve.alias", "description"),
290287
group: RESOLVE_GROUP,
291288
requiresArg: true
292289
},
293290
"resolve-extensions": {
294291
type: "array",
295-
describe:
296-
getSchemaInfo("resolve.alias", "description"),
292+
describe: getSchemaInfo("resolve.alias", "description"),
297293
group: RESOLVE_GROUP,
298294
requiresArg: true
299295
},
@@ -309,15 +305,16 @@ module.exports = function(yargs) {
309305
requiresArg: true
310306
},
311307
"optimize-min-chunk-size": {
312-
describe:
313-
getSchemaInfo("optimization.splitChunks.minSize", "description"),
308+
describe: getSchemaInfo(
309+
"optimization.splitChunks.minSize",
310+
"description"
311+
),
314312
group: OPTIMIZE_GROUP,
315313
requiresArg: true
316314
},
317315
"optimize-minimize": {
318316
type: "boolean",
319-
describe:
320-
getSchemaInfo("optimization.minimize", "description"),
317+
describe: getSchemaInfo("optimization.minimize", "description"),
321318
group: OPTIMIZE_GROUP
322319
},
323320
prefetch: {

packages/utils/npm-packages-exists.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ describe("npmPackagesExists", () => {
2323
});
2424

2525
test("resolves packages when they are available on npm", done => {
26-
require("./npm-exists").default.mockImplementation(() => Promise.resolve(true));
26+
require("./npm-exists").default.mockImplementation(() =>
27+
Promise.resolve(true)
28+
);
2729
npmPackagesExists(["webpack-scaffold-foobar"]);
2830
setTimeout(() => {
2931
expect(

packages/utils/recursive-parser.test.js

Lines changed: 52 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -2,108 +2,63 @@
22

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

5-
6-
defineTest(
7-
__dirname,
8-
"init",
9-
"fixture-1",
10-
"entry",
11-
{
12-
objects: "are",
13-
super: [
14-
"yeah",
15-
{
16-
test: new RegExp(/\.(js|vue)$/),
17-
loader: "'eslint-loader'",
18-
enforce: "'pre'",
19-
include: ["customObj", "'Stringy'"],
20-
options: {
21-
formatter: "'someOption'"
22-
}
5+
defineTest(__dirname, "init", "fixture-1", "entry", {
6+
objects: "are",
7+
super: [
8+
"yeah",
9+
{
10+
test: new RegExp(/\.(js|vue)$/),
11+
loader: "'eslint-loader'",
12+
enforce: "'pre'",
13+
include: ["customObj", "'Stringy'"],
14+
options: {
15+
formatter: "'someOption'"
2316
}
24-
],
25-
nice: "':)'",
26-
foo: "Promise.resolve()",
27-
man: "() => duper"
28-
}
29-
);
17+
}
18+
],
19+
nice: "':)'",
20+
foo: "Promise.resolve()",
21+
man: "() => duper"
22+
});
3023

31-
defineTest(
32-
__dirname,
33-
"add",
34-
"fixture-2",
35-
"entry",
36-
{
37-
objects: "are not",
38-
super: [
39-
"op",
40-
{
41-
test: new RegExp(/\.(wasm|c)$/),
42-
loader: "'pia-loader'",
43-
enforce: "'pre'",
44-
include: ["asd", "'Stringy'"],
45-
options: {
46-
formatter: "'nao'"
47-
}
24+
defineTest(__dirname, "add", "fixture-2", "entry", {
25+
objects: "are not",
26+
super: [
27+
"op",
28+
{
29+
test: new RegExp(/\.(wasm|c)$/),
30+
loader: "'pia-loader'",
31+
enforce: "'pre'",
32+
include: ["asd", "'Stringy'"],
33+
options: {
34+
formatter: "'nao'"
4835
}
49-
],
50-
nice: "'=)'",
51-
foo: "Promise.resolve()",
52-
man: "() => nice!!",
53-
mode: "super-man"
54-
}
55-
);
36+
}
37+
],
38+
nice: "'=)'",
39+
foo: "Promise.resolve()",
40+
man: "() => nice!!",
41+
mode: "super-man"
42+
});
5643

57-
defineTest(
58-
__dirname,
59-
"remove",
60-
"fixture-3",
61-
"resolve",
62-
{
63-
alias: null
64-
}
65-
);
44+
defineTest(__dirname, "remove", "fixture-3", "resolve", {
45+
alias: null
46+
});
6647

67-
defineTest(
68-
__dirname,
69-
"remove",
70-
"fixture-3",
71-
"plugins",
72-
[
73-
"plugin2"
74-
]
75-
);
48+
defineTest(__dirname, "remove", "fixture-3", "plugins", ["plugin2"]);
7649

77-
defineTest(
78-
__dirname,
79-
"remove",
80-
"fixture-3",
81-
"module",
82-
{
83-
noParse: null
84-
}
85-
);
50+
defineTest(__dirname, "remove", "fixture-3", "module", {
51+
noParse: null
52+
});
8653

87-
defineTest(
88-
__dirname,
89-
"remove",
90-
"fixture-3",
91-
"entry",
92-
{
93-
a: null,
94-
}
95-
);
54+
defineTest(__dirname, "remove", "fixture-3", "entry", {
55+
a: null
56+
});
9657

97-
defineTest(
98-
__dirname,
99-
"remove",
100-
"fixture-3",
101-
"module",
102-
{
103-
rules: [
104-
{
105-
loader: "eslint-loader",
106-
},
107-
]
108-
}
109-
);
58+
defineTest(__dirname, "remove", "fixture-3", "module", {
59+
rules: [
60+
{
61+
loader: "eslint-loader"
62+
}
63+
]
64+
});

0 commit comments

Comments
 (0)