Skip to content

Commit 9f195c9

Browse files
committed
move errorHelpers to CLI repo
1 parent 7bd9a33 commit 9f195c9

File tree

4 files changed

+77
-115
lines changed

4 files changed

+77
-115
lines changed

bin/convert-argv.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ module.exports = function(yargs, argv, convertOptions) {
220220
}
221221

222222
function processOptions(options) {
223-
224223
function ifArg(name, fn, init, finalize) {
225224
if (Array.isArray(argv[name])) {
226225
if (init) {
@@ -358,8 +357,8 @@ module.exports = function(yargs, argv, convertOptions) {
358357
var rule = {
359358
test: new RegExp(
360359
"\\." +
361-
name.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") +
362-
"$"
360+
name.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") +
361+
"$"
363362
), // eslint-disable-line no-useless-escape
364363
loader: binding
365364
};

bin/errorHelpers.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
4+
*/
5+
"use strict";
6+
7+
const loaderFlag = "LOADER_EXECUTION";
8+
9+
const webpackOptionsFlag = "WEBPACK_OPTIONS";
10+
11+
exports.cutOffByFlag = (stack, flag) => {
12+
stack = stack.split("\n");
13+
for (let i = 0; i < stack.length; i++)
14+
if (stack[i].indexOf(flag) >= 0) stack.length = i;
15+
return stack.join("\n");
16+
};
17+
18+
exports.cutOffLoaderExecution = stack =>
19+
exports.cutOffByFlag(stack, loaderFlag);
20+
21+
exports.cutOffWebpackOptinos = stack =>
22+
exports.cutOffByFlag(stack, webpackOptionsFlag);
23+
24+
exports.cutOffMultilineMessage = (stack, message) => {
25+
stack = stack.split("\n");
26+
message = message.split("\n");
27+
28+
return stack
29+
.reduce(
30+
(acc, line, idx) =>
31+
line.indexOf(message[idx]) < 0 ? acc.concat(line) : acc,
32+
[]
33+
)
34+
.join("\n");
35+
};
36+
37+
exports.cutOffMessage = (stack, message) => {
38+
const nextLine = stack.indexOf("\n");
39+
if (nextLine === -1) {
40+
return stack === message ? "" : stack;
41+
} else {
42+
const firstLine = stack.substr(0, nextLine);
43+
return firstLine === message ? stack.substr(nextLine + 1) : stack;
44+
}
45+
};
46+
47+
exports.cleanUp = (stack, message) => {
48+
stack = exports.cutOffLoaderExecution(stack);
49+
stack = exports.cutOffMessage(stack, message);
50+
return stack;
51+
};
52+
53+
exports.cleanUpWebpackOptions = (stack, message) => {
54+
stack = exports.cutOffWebpackOptinos(stack);
55+
stack = exports.cutOffMultilineMessage(stack, message);
56+
return stack;
57+
};

bin/webpack.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818

1919
require("v8-compile-cache");
20-
var ErrorHelpers = require("webpack/lib/ErrorHelpers");
20+
var ErrorHelpers = require("./errorHelpers");
2121

2222
const NON_COMPILATION_ARGS = [
2323
"init",
@@ -154,7 +154,8 @@
154154
"display-used-exports": {
155155
type: "boolean",
156156
group: DISPLAY_GROUP,
157-
describe: "Display information about used exports in modules (Tree Shaking)"
157+
describe:
158+
"Display information about used exports in modules (Tree Shaking)"
158159
},
159160
"display-provided-exports": {
160161
type: "boolean",
@@ -249,7 +250,8 @@
249250
}
250251

251252
var firstOptions = [].concat(options)[0];
252-
var statsPresetToOptions = require("webpack/lib/Stats.js").presetToOptions;
253+
var statsPresetToOptions = require("webpack/lib/Stats.js")
254+
.presetToOptions;
253255

254256
var outputOptions = options.stats;
255257
if (
@@ -435,7 +437,10 @@
435437
}
436438
if (firstOptions.watch || options.watch) {
437439
var watchOptions =
438-
firstOptions.watchOptions || firstOptions.watch || options.watch || {};
440+
firstOptions.watchOptions ||
441+
firstOptions.watch ||
442+
options.watch ||
443+
{};
439444
if (watchOptions.stdin) {
440445
process.stdin.on("end", function(_) {
441446
process.exit(); // eslint-disable-line

yarn.lock

Lines changed: 9 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ ajv@^4.9.1:
5858
co "^4.6.0"
5959
json-stable-stringify "^1.0.1"
6060

61-
ajv@^5.0.0, ajv@^5.1.0, ajv@^5.1.5, ajv@^5.2.3, ajv@^5.3.0:
61+
ajv@^5.0.0, ajv@^5.1.5, ajv@^5.2.3, ajv@^5.3.0:
6262
version "5.5.2"
6363
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.5.2.tgz#73b5eeca3fab653e3d3f9422b341ad42205dc965"
6464
dependencies:
@@ -266,11 +266,7 @@ aws-sign2@~0.6.0:
266266
version "0.6.0"
267267
resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.6.0.tgz#14342dd38dbcc94d0e5b87d763cd63612c0e794f"
268268

269-
aws-sign2@~0.7.0:
270-
version "0.7.0"
271-
resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8"
272-
273-
aws4@^1.2.1, aws4@^1.6.0:
269+
aws4@^1.2.1:
274270
version "1.6.0"
275271
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e"
276272

@@ -1065,18 +1061,6 @@ [email protected]:
10651061
dependencies:
10661062
hoek "2.x.x"
10671063

1068-
1069-
version "4.3.1"
1070-
resolved "https://registry.yarnpkg.com/boom/-/boom-4.3.1.tgz#4f8a3005cb4a7e3889f749030fd25b96e01d2e31"
1071-
dependencies:
1072-
hoek "4.x.x"
1073-
1074-
1075-
version "5.2.0"
1076-
resolved "https://registry.yarnpkg.com/boom/-/boom-5.2.0.tgz#5dd9da6ee3a5f302077436290cb717d3f4a54e02"
1077-
dependencies:
1078-
hoek "4.x.x"
1079-
10801064
brace-expansion@^1.1.7:
10811065
version "1.1.8"
10821066
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.8.tgz#c07b211c7c952ec1f8efd51a77ef0d1d3990a292"
@@ -1634,12 +1618,6 @@ [email protected]:
16341618
dependencies:
16351619
boom "2.x.x"
16361620

1637-
1638-
version "3.1.2"
1639-
resolved "https://registry.yarnpkg.com/cryptiles/-/cryptiles-3.1.2.tgz#a89fbb220f5ce25ec56e8c4aa8a4fd7b5b0d29fe"
1640-
dependencies:
1641-
boom "5.x.x"
1642-
16431621
crypto-browserify@^3.11.0:
16441622
version "3.12.0"
16451623
resolved "https://registry.yarnpkg.com/crypto-browserify/-/crypto-browserify-3.12.0.tgz#396cf9f3137f03e4b8e532c58f698254e00f80ec"
@@ -2225,7 +2203,7 @@ express@^4.16.2:
22252203
utils-merge "1.0.1"
22262204
vary "~1.1.2"
22272205

2228-
extend@^3.0.0, extend@~3.0.0, extend@~3.0.1:
2206+
extend@^3.0.0, extend@~3.0.0:
22292207
version "3.0.1"
22302208
resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.1.tgz#a755ea7bc1adfcc5a31ce7e762dbaadc5e636444"
22312209

@@ -2437,14 +2415,6 @@ form-data@~2.1.1:
24372415
combined-stream "^1.0.5"
24382416
mime-types "^2.1.12"
24392417

2440-
form-data@~2.3.1:
2441-
version "2.3.1"
2442-
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.1.tgz#6fb94fbd71885306d73d15cc497fe4cc4ecd44bf"
2443-
dependencies:
2444-
asynckit "^0.4.0"
2445-
combined-stream "^1.0.5"
2446-
mime-types "^2.1.12"
2447-
24482418
forwarded@~0.1.2:
24492419
version "0.1.2"
24502420
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84"
@@ -2729,24 +2699,13 @@ har-schema@^1.0.5:
27292699
version "1.0.5"
27302700
resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-1.0.5.tgz#d263135f43307c02c602afc8fe95970c0151369e"
27312701

2732-
har-schema@^2.0.0:
2733-
version "2.0.0"
2734-
resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-2.0.0.tgz#a94c2224ebcac04782a0d9035521f24735b7ec92"
2735-
27362702
har-validator@~4.2.1:
27372703
version "4.2.1"
27382704
resolved "https://registry.yarnpkg.com/har-validator/-/har-validator-4.2.1.tgz#33481d0f1bbff600dd203d75812a6a5fba002e2a"
27392705
dependencies:
27402706
ajv "^4.9.1"
27412707
har-schema "^1.0.5"
27422708

2743-
har-validator@~5.0.3:
2744-
version "5.0.3"
2745-
resolved "https://registry.yarnpkg.com/har-validator/-/har-validator-5.0.3.tgz#ba402c266194f15956ef15e0fcf242993f6a7dfd"
2746-
dependencies:
2747-
ajv "^5.1.0"
2748-
har-schema "^2.0.0"
2749-
27502709
has-ansi@^2.0.0:
27512710
version "2.0.0"
27522711
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91"
@@ -2814,15 +2773,6 @@ [email protected], hawk@~3.1.3:
28142773
hoek "2.x.x"
28152774
sntp "1.x.x"
28162775

2817-
hawk@~6.0.2:
2818-
version "6.0.2"
2819-
resolved "https://registry.yarnpkg.com/hawk/-/hawk-6.0.2.tgz#af4d914eb065f9b5ce4d9d11c1cb2126eecc3038"
2820-
dependencies:
2821-
boom "4.x.x"
2822-
cryptiles "3.x.x"
2823-
hoek "4.x.x"
2824-
sntp "2.x.x"
2825-
28262776
hmac-drbg@^1.0.0:
28272777
version "1.0.1"
28282778
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"
@@ -2835,10 +2785,6 @@ [email protected]:
28352785
version "2.16.3"
28362786
resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed"
28372787

2838-
2839-
version "4.2.0"
2840-
resolved "https://registry.yarnpkg.com/hoek/-/hoek-4.2.0.tgz#72d9d0754f7fe25ca2d01ad8f8f9a9449a89526d"
2841-
28422788
home-or-tmp@^2.0.0:
28432789
version "2.0.0"
28442790
resolved "https://registry.yarnpkg.com/home-or-tmp/-/home-or-tmp-2.0.0.tgz#e36c3f2d2cae7d746a857e38d18d5f32a7882db8"
@@ -2916,14 +2862,6 @@ http-signature@~1.1.0:
29162862
jsprim "^1.2.2"
29172863
sshpk "^1.7.0"
29182864

2919-
http-signature@~1.2.0:
2920-
version "1.2.0"
2921-
resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.2.0.tgz#9aecd925114772f3d95b65a60abb8f7c18fbace1"
2922-
dependencies:
2923-
assert-plus "^1.0.0"
2924-
jsprim "^1.2.2"
2925-
sshpk "^1.7.0"
2926-
29272865
https-browserify@^1.0.0:
29282866
version "1.0.0"
29292867
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73"
@@ -4394,7 +4332,7 @@ nyc@^11.4.1:
43944332
yargs "^10.0.3"
43954333
yargs-parser "^8.0.0"
43964334

4397-
oauth-sign@~0.8.1, oauth-sign@~0.8.2:
4335+
oauth-sign@~0.8.1:
43984336
version "0.8.2"
43994337
resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.8.2.tgz#46a6ab7f0aead8deae9ec0565780b7d4efeb9d43"
44004338

@@ -4680,10 +4618,6 @@ performance-now@^0.2.0:
46804618
version "0.2.0"
46814619
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-0.2.0.tgz#33ef30c5c77d4ea21c5a53869d91b56d8f2555e5"
46824620

4683-
performance-now@^2.1.0:
4684-
version "2.1.0"
4685-
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
4686-
46874621
pify@^2.0.0, pify@^2.3.0:
46884622
version "2.3.0"
46894623
resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c"
@@ -4864,7 +4798,7 @@ punycode@^1.2.4, punycode@^1.4.1:
48644798
version "1.4.1"
48654799
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e"
48664800

4867-
[email protected], qs@~6.5.1:
4801+
48684802
version "6.5.1"
48694803
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8"
48704804

@@ -5094,7 +5028,7 @@ replace-ext@^1.0.0:
50945028
version "1.0.0"
50955029
resolved "https://registry.yarnpkg.com/replace-ext/-/replace-ext-1.0.0.tgz#de63128373fcbf7c3ccfa4de5a480c45a67958eb"
50965030

5097-
5031+
[email protected], request@^2.79.0:
50985032
version "2.81.0"
50995033
resolved "https://registry.yarnpkg.com/request/-/request-2.81.0.tgz#c6928946a0e06c5f8d6f8a9333469ffda46298a0"
51005034
dependencies:
@@ -5121,33 +5055,6 @@ [email protected]:
51215055
tunnel-agent "^0.6.0"
51225056
uuid "^3.0.0"
51235057

5124-
request@^2.79.0:
5125-
version "2.83.0"
5126-
resolved "https://registry.yarnpkg.com/request/-/request-2.83.0.tgz#ca0b65da02ed62935887808e6f510381034e3356"
5127-
dependencies:
5128-
aws-sign2 "~0.7.0"
5129-
aws4 "^1.6.0"
5130-
caseless "~0.12.0"
5131-
combined-stream "~1.0.5"
5132-
extend "~3.0.1"
5133-
forever-agent "~0.6.1"
5134-
form-data "~2.3.1"
5135-
har-validator "~5.0.3"
5136-
hawk "~6.0.2"
5137-
http-signature "~1.2.0"
5138-
is-typedarray "~1.0.0"
5139-
isstream "~0.1.2"
5140-
json-stringify-safe "~5.0.1"
5141-
mime-types "~2.1.17"
5142-
oauth-sign "~0.8.2"
5143-
performance-now "^2.1.0"
5144-
qs "~6.5.1"
5145-
safe-buffer "^5.1.1"
5146-
stringstream "~0.0.5"
5147-
tough-cookie "~2.3.3"
5148-
tunnel-agent "^0.6.0"
5149-
uuid "^3.1.0"
5150-
51515058
require-directory@^2.1.1:
51525059
version "2.1.1"
51535060
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
@@ -5466,12 +5373,6 @@ [email protected]:
54665373
dependencies:
54675374
hoek "2.x.x"
54685375

5469-
5470-
version "2.1.0"
5471-
resolved "https://registry.yarnpkg.com/sntp/-/sntp-2.1.0.tgz#2c6cec14fedc2222739caf9b5c3d85d1cc5a2cc8"
5472-
dependencies:
5473-
hoek "4.x.x"
5474-
54755376
54765377
version "1.1.4"
54775378
resolved "https://registry.yarnpkg.com/sockjs-client/-/sockjs-client-1.1.4.tgz#5babe386b775e4cf14e7520911452654016c8b12"
@@ -5673,7 +5574,7 @@ stringify-object@^3.2.0:
56735574
is-obj "^1.0.1"
56745575
is-regexp "^1.0.0"
56755576

5676-
stringstream@~0.0.4, stringstream@~0.0.5:
5577+
stringstream@~0.0.4:
56775578
version "0.0.5"
56785579
resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.5.tgz#4e484cd4de5a0bbbee18e46307710a8a81621878"
56795580

@@ -5878,7 +5779,7 @@ to-fast-properties@^1.0.3:
58785779
version "1.0.3"
58795780
resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47"
58805781

5881-
tough-cookie@^2.3.2, tough-cookie@~2.3.0, tough-cookie@~2.3.3:
5782+
tough-cookie@^2.3.2, tough-cookie@~2.3.0:
58825783
version "2.3.3"
58835784
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.3.tgz#0b618a5565b6dea90bf3425d04d55edc475a7561"
58845785
dependencies:
@@ -6072,7 +5973,7 @@ uuid@^2.0.2:
60725973
version "2.0.3"
60735974
resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a"
60745975

6075-
uuid@^3.0.0, uuid@^3.1.0:
5976+
uuid@^3.0.0:
60765977
version "3.1.0"
60775978
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04"
60785979

0 commit comments

Comments
 (0)