Skip to content

Commit

Permalink
fix(tapable): fix hook options
Browse files Browse the repository at this point in the history
  • Loading branch information
evenstensberg committed Sep 29, 2018
1 parent 3844671 commit 9aed0dc
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 139 deletions.
20 changes: 14 additions & 6 deletions bin/cli.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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"
}
]
});

0 comments on commit 9aed0dc

Please sign in to comment.