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