Skip to content

Commit 64fd810

Browse files
authoredSep 5, 2019
Merge pull request #1065 from webpack/fix/patch
fix: support both webpack versions
2 parents 9487ee5 + 70bf934 commit 64fd810

File tree

12 files changed

+4593
-36449
lines changed

12 files changed

+4593
-36449
lines changed
 

‎bin/utils/convert-argv.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ const fs = require("fs");
33
fs.existsSync = fs.existsSync || path.existsSync;
44
const interpret = require("interpret");
55
const prepareOptions = require("./prepareOptions");
6-
const webpackConfigurationSchema = require("../config/webpackConfigurationSchema.json");
7-
const validateSchema = require("webpack").validateSchema;
8-
const WebpackOptionsValidationError = require("webpack").WebpackOptionsValidationError;
96
const findup = require("findup-sync");
7+
const validateOptions = require("./validate-options");
108

119
module.exports = function(...args) {
1210
const argv = args[1] || args[0];
@@ -137,12 +135,7 @@ module.exports = function(...args) {
137135

138136
function processConfiguredOptions(options) {
139137
if (options) {
140-
const webpackConfigurationValidationErrors = validateSchema(webpackConfigurationSchema, options);
141-
if (webpackConfigurationValidationErrors.length) {
142-
const error = new WebpackOptionsValidationError(webpackConfigurationValidationErrors);
143-
console.error(error.message, `\nReceived: ${typeof options} : ${JSON.stringify(options, null, 2)}`);
144-
process.exit(-1); // eslint-disable-line
145-
}
138+
validateOptions(options);
146139
} else {
147140
options = {};
148141
}

‎bin/utils/validate-options.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const webpackConfigurationSchema = require("../config/webpackConfigurationSchema.json");
2+
const validateSchema = require("webpack").validateSchema;
3+
4+
module.exports = function validateOptions(options) {
5+
let error;
6+
try {
7+
const errors = validateSchema(webpackConfigurationSchema, options);
8+
if (errors && errors.length > 0) {
9+
const { WebpackOptionsValidationError } = require("webpack");
10+
error = new WebpackOptionsValidationError(errors);
11+
}
12+
} catch (err) {
13+
error = err;
14+
}
15+
16+
if (error) {
17+
console.error(error.message);
18+
// eslint-disable-next-line no-process-exit
19+
process.exit(-1);
20+
}
21+
};

‎package-lock.json

+14-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
"babel-preset-jest": "24.6.0",
144144
"codecov": "3.5.0",
145145
"commitizen": "4.0.3",
146+
"commitlint": "^8.1.0",
146147
"commitlint-config-cz": "0.12.0",
147148
"conventional-changelog-cli": "2.0.21",
148149
"cz-customizable": "6.2.0",

‎packages/generate-loader/package-lock.json

+763-8,054
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/generate-plugin/package-lock.json

+763-8,054
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/generators/package-lock.json

+2,221-5,909
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/init/package-lock.json

+79-6,806
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/migrate/package-lock.json

+516-1,180
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/serve/package-lock.json

+193-6,434
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
entry: "hey"
3+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
3+
const validation = require("../../../../bin/utils/validate-options");
4+
const { run } = require("../../../testUtils");
5+
6+
test("validation", () => {
7+
const mockExit = jest.spyOn(process, "exit").mockImplementation(() => {});
8+
validation(null);
9+
expect(mockExit).toHaveBeenCalledWith(-1);
10+
mockExit.mockRestore();
11+
});
12+
13+
test("validation-success", () => {
14+
const { stdout, code } = run(__dirname, ["--config", "./options.js"]);
15+
expect(stdout).toContain("Can't resolve 'hey'");
16+
expect(code).toBe(2);
17+
});

0 commit comments

Comments
 (0)
Please sign in to comment.