Skip to content

Commit

Permalink
move errorHelpers to CLI repo
Browse files Browse the repository at this point in the history
  • Loading branch information
evenstensberg committed Jan 4, 2018
1 parent 7bd9a33 commit 9f195c9
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 115 deletions.
5 changes: 2 additions & 3 deletions bin/convert-argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ module.exports = function(yargs, argv, convertOptions) {
}

function processOptions(options) {

function ifArg(name, fn, init, finalize) {
if (Array.isArray(argv[name])) {
if (init) {
Expand Down Expand Up @@ -358,8 +357,8 @@ module.exports = function(yargs, argv, convertOptions) {
var rule = {
test: new RegExp(
"\\." +
name.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") +
"$"
name.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") +
"$"
), // eslint-disable-line no-useless-escape
loader: binding
};
Expand Down
57 changes: 57 additions & 0 deletions bin/errorHelpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";

const loaderFlag = "LOADER_EXECUTION";

const webpackOptionsFlag = "WEBPACK_OPTIONS";

exports.cutOffByFlag = (stack, flag) => {
stack = stack.split("\n");
for (let i = 0; i < stack.length; i++)
if (stack[i].indexOf(flag) >= 0) stack.length = i;
return stack.join("\n");
};

exports.cutOffLoaderExecution = stack =>
exports.cutOffByFlag(stack, loaderFlag);

exports.cutOffWebpackOptinos = stack =>
exports.cutOffByFlag(stack, webpackOptionsFlag);

exports.cutOffMultilineMessage = (stack, message) => {
stack = stack.split("\n");
message = message.split("\n");

return stack
.reduce(
(acc, line, idx) =>
line.indexOf(message[idx]) < 0 ? acc.concat(line) : acc,
[]
)
.join("\n");
};

exports.cutOffMessage = (stack, message) => {
const nextLine = stack.indexOf("\n");
if (nextLine === -1) {
return stack === message ? "" : stack;
} else {
const firstLine = stack.substr(0, nextLine);
return firstLine === message ? stack.substr(nextLine + 1) : stack;
}
};

exports.cleanUp = (stack, message) => {
stack = exports.cutOffLoaderExecution(stack);
stack = exports.cutOffMessage(stack, message);
return stack;
};

exports.cleanUpWebpackOptions = (stack, message) => {
stack = exports.cutOffWebpackOptinos(stack);
stack = exports.cutOffMultilineMessage(stack, message);
return stack;
};
13 changes: 9 additions & 4 deletions bin/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}

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

const NON_COMPILATION_ARGS = [
"init",
Expand Down Expand Up @@ -154,7 +154,8 @@
"display-used-exports": {
type: "boolean",
group: DISPLAY_GROUP,
describe: "Display information about used exports in modules (Tree Shaking)"
describe:
"Display information about used exports in modules (Tree Shaking)"
},
"display-provided-exports": {
type: "boolean",
Expand Down Expand Up @@ -249,7 +250,8 @@
}

var firstOptions = [].concat(options)[0];
var statsPresetToOptions = require("webpack/lib/Stats.js").presetToOptions;
var statsPresetToOptions = require("webpack/lib/Stats.js")
.presetToOptions;

var outputOptions = options.stats;
if (
Expand Down Expand Up @@ -435,7 +437,10 @@
}
if (firstOptions.watch || options.watch) {
var watchOptions =
firstOptions.watchOptions || firstOptions.watch || options.watch || {};
firstOptions.watchOptions ||
firstOptions.watch ||
options.watch ||
{};
if (watchOptions.stdin) {
process.stdin.on("end", function(_) {
process.exit(); // eslint-disable-line
Expand Down
117 changes: 9 additions & 108 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ajv@^4.9.1:
co "^4.6.0"
json-stable-stringify "^1.0.1"

ajv@^5.0.0, ajv@^5.1.0, ajv@^5.1.5, ajv@^5.2.3, ajv@^5.3.0:
ajv@^5.0.0, ajv@^5.1.5, ajv@^5.2.3, ajv@^5.3.0:
version "5.5.2"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.5.2.tgz#73b5eeca3fab653e3d3f9422b341ad42205dc965"
dependencies:
Expand Down Expand Up @@ -266,11 +266,7 @@ aws-sign2@~0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.6.0.tgz#14342dd38dbcc94d0e5b87d763cd63612c0e794f"

aws-sign2@~0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8"

aws4@^1.2.1, aws4@^1.6.0:
aws4@^1.2.1:
version "1.6.0"
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e"

Expand Down Expand Up @@ -1065,18 +1061,6 @@ [email protected]:
dependencies:
hoek "2.x.x"

[email protected]:
version "4.3.1"
resolved "https://registry.yarnpkg.com/boom/-/boom-4.3.1.tgz#4f8a3005cb4a7e3889f749030fd25b96e01d2e31"
dependencies:
hoek "4.x.x"

[email protected]:
version "5.2.0"
resolved "https://registry.yarnpkg.com/boom/-/boom-5.2.0.tgz#5dd9da6ee3a5f302077436290cb717d3f4a54e02"
dependencies:
hoek "4.x.x"

brace-expansion@^1.1.7:
version "1.1.8"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.8.tgz#c07b211c7c952ec1f8efd51a77ef0d1d3990a292"
Expand Down Expand Up @@ -1634,12 +1618,6 @@ [email protected]:
dependencies:
boom "2.x.x"

[email protected]:
version "3.1.2"
resolved "https://registry.yarnpkg.com/cryptiles/-/cryptiles-3.1.2.tgz#a89fbb220f5ce25ec56e8c4aa8a4fd7b5b0d29fe"
dependencies:
boom "5.x.x"

crypto-browserify@^3.11.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/crypto-browserify/-/crypto-browserify-3.12.0.tgz#396cf9f3137f03e4b8e532c58f698254e00f80ec"
Expand Down Expand Up @@ -2225,7 +2203,7 @@ express@^4.16.2:
utils-merge "1.0.1"
vary "~1.1.2"

extend@^3.0.0, extend@~3.0.0, extend@~3.0.1:
extend@^3.0.0, extend@~3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.1.tgz#a755ea7bc1adfcc5a31ce7e762dbaadc5e636444"

Expand Down Expand Up @@ -2437,14 +2415,6 @@ form-data@~2.1.1:
combined-stream "^1.0.5"
mime-types "^2.1.12"

form-data@~2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.1.tgz#6fb94fbd71885306d73d15cc497fe4cc4ecd44bf"
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.5"
mime-types "^2.1.12"

forwarded@~0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84"
Expand Down Expand Up @@ -2729,24 +2699,13 @@ har-schema@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-1.0.5.tgz#d263135f43307c02c602afc8fe95970c0151369e"

har-schema@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-2.0.0.tgz#a94c2224ebcac04782a0d9035521f24735b7ec92"

har-validator@~4.2.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/har-validator/-/har-validator-4.2.1.tgz#33481d0f1bbff600dd203d75812a6a5fba002e2a"
dependencies:
ajv "^4.9.1"
har-schema "^1.0.5"

har-validator@~5.0.3:
version "5.0.3"
resolved "https://registry.yarnpkg.com/har-validator/-/har-validator-5.0.3.tgz#ba402c266194f15956ef15e0fcf242993f6a7dfd"
dependencies:
ajv "^5.1.0"
har-schema "^2.0.0"

has-ansi@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91"
Expand Down Expand Up @@ -2814,15 +2773,6 @@ [email protected], hawk@~3.1.3:
hoek "2.x.x"
sntp "1.x.x"

hawk@~6.0.2:
version "6.0.2"
resolved "https://registry.yarnpkg.com/hawk/-/hawk-6.0.2.tgz#af4d914eb065f9b5ce4d9d11c1cb2126eecc3038"
dependencies:
boom "4.x.x"
cryptiles "3.x.x"
hoek "4.x.x"
sntp "2.x.x"

hmac-drbg@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"
Expand All @@ -2835,10 +2785,6 @@ [email protected]:
version "2.16.3"
resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed"

[email protected]:
version "4.2.0"
resolved "https://registry.yarnpkg.com/hoek/-/hoek-4.2.0.tgz#72d9d0754f7fe25ca2d01ad8f8f9a9449a89526d"

home-or-tmp@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/home-or-tmp/-/home-or-tmp-2.0.0.tgz#e36c3f2d2cae7d746a857e38d18d5f32a7882db8"
Expand Down Expand Up @@ -2916,14 +2862,6 @@ http-signature@~1.1.0:
jsprim "^1.2.2"
sshpk "^1.7.0"

http-signature@~1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.2.0.tgz#9aecd925114772f3d95b65a60abb8f7c18fbace1"
dependencies:
assert-plus "^1.0.0"
jsprim "^1.2.2"
sshpk "^1.7.0"

https-browserify@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73"
Expand Down Expand Up @@ -4394,7 +4332,7 @@ nyc@^11.4.1:
yargs "^10.0.3"
yargs-parser "^8.0.0"

oauth-sign@~0.8.1, oauth-sign@~0.8.2:
oauth-sign@~0.8.1:
version "0.8.2"
resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.8.2.tgz#46a6ab7f0aead8deae9ec0565780b7d4efeb9d43"

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

performance-now@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"

pify@^2.0.0, pify@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c"
Expand Down Expand Up @@ -4864,7 +4798,7 @@ punycode@^1.2.4, punycode@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e"

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

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

[email protected]:
[email protected], request@^2.79.0:
version "2.81.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.81.0.tgz#c6928946a0e06c5f8d6f8a9333469ffda46298a0"
dependencies:
Expand All @@ -5121,33 +5055,6 @@ [email protected]:
tunnel-agent "^0.6.0"
uuid "^3.0.0"

request@^2.79.0:
version "2.83.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.83.0.tgz#ca0b65da02ed62935887808e6f510381034e3356"
dependencies:
aws-sign2 "~0.7.0"
aws4 "^1.6.0"
caseless "~0.12.0"
combined-stream "~1.0.5"
extend "~3.0.1"
forever-agent "~0.6.1"
form-data "~2.3.1"
har-validator "~5.0.3"
hawk "~6.0.2"
http-signature "~1.2.0"
is-typedarray "~1.0.0"
isstream "~0.1.2"
json-stringify-safe "~5.0.1"
mime-types "~2.1.17"
oauth-sign "~0.8.2"
performance-now "^2.1.0"
qs "~6.5.1"
safe-buffer "^5.1.1"
stringstream "~0.0.5"
tough-cookie "~2.3.3"
tunnel-agent "^0.6.0"
uuid "^3.1.0"

require-directory@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
Expand Down Expand Up @@ -5466,12 +5373,6 @@ [email protected]:
dependencies:
hoek "2.x.x"

[email protected]:
version "2.1.0"
resolved "https://registry.yarnpkg.com/sntp/-/sntp-2.1.0.tgz#2c6cec14fedc2222739caf9b5c3d85d1cc5a2cc8"
dependencies:
hoek "4.x.x"

[email protected]:
version "1.1.4"
resolved "https://registry.yarnpkg.com/sockjs-client/-/sockjs-client-1.1.4.tgz#5babe386b775e4cf14e7520911452654016c8b12"
Expand Down Expand Up @@ -5673,7 +5574,7 @@ stringify-object@^3.2.0:
is-obj "^1.0.1"
is-regexp "^1.0.0"

stringstream@~0.0.4, stringstream@~0.0.5:
stringstream@~0.0.4:
version "0.0.5"
resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.5.tgz#4e484cd4de5a0bbbee18e46307710a8a81621878"

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

tough-cookie@^2.3.2, tough-cookie@~2.3.0, tough-cookie@~2.3.3:
tough-cookie@^2.3.2, tough-cookie@~2.3.0:
version "2.3.3"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.3.tgz#0b618a5565b6dea90bf3425d04d55edc475a7561"
dependencies:
Expand Down Expand Up @@ -6072,7 +5973,7 @@ uuid@^2.0.2:
version "2.0.3"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a"

uuid@^3.0.0, uuid@^3.1.0:
uuid@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04"

Expand Down

0 comments on commit 9f195c9

Please sign in to comment.