source: imaps-frontend/node_modules/webpack/lib/ErrorHelpers.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const loaderFlag = "LOADER_EXECUTION";
9
10const webpackOptionsFlag = "WEBPACK_OPTIONS";
11
12/**
13 * @param {string} stack stack trace
14 * @param {string} flag flag to cut off
15 * @returns {string} stack trace without the specified flag included
16 */
17const cutOffByFlag = (stack, flag) => {
18 const errorStack = stack.split("\n");
19 for (let i = 0; i < errorStack.length; i++) {
20 if (errorStack[i].includes(flag)) {
21 errorStack.length = i;
22 }
23 }
24 return errorStack.join("\n");
25};
26
27/**
28 * @param {string} stack stack trace
29 * @returns {string} stack trace without the loader execution flag included
30 */
31const cutOffLoaderExecution = stack => cutOffByFlag(stack, loaderFlag);
32
33/**
34 * @param {string} stack stack trace
35 * @returns {string} stack trace without the webpack options flag included
36 */
37const cutOffWebpackOptions = stack => cutOffByFlag(stack, webpackOptionsFlag);
38
39/**
40 * @param {string} stack stack trace
41 * @param {string} message error message
42 * @returns {string} stack trace without the message included
43 */
44const cutOffMultilineMessage = (stack, message) => {
45 const stackSplitByLines = stack.split("\n");
46 const messageSplitByLines = message.split("\n");
47
48 /** @type {string[]} */
49 const result = [];
50
51 for (const [idx, line] of stackSplitByLines.entries()) {
52 if (!line.includes(messageSplitByLines[idx])) result.push(line);
53 }
54
55 return result.join("\n");
56};
57
58/**
59 * @param {string} stack stack trace
60 * @param {string} message error message
61 * @returns {string} stack trace without the message included
62 */
63const cutOffMessage = (stack, message) => {
64 const nextLine = stack.indexOf("\n");
65 if (nextLine === -1) {
66 return stack === message ? "" : stack;
67 }
68 const firstLine = stack.slice(0, nextLine);
69 return firstLine === message ? stack.slice(nextLine + 1) : stack;
70};
71
72/**
73 * @param {string} stack stack trace
74 * @param {string} message error message
75 * @returns {string} stack trace without the loader execution flag and message included
76 */
77const cleanUp = (stack, message) => {
78 stack = cutOffLoaderExecution(stack);
79 stack = cutOffMessage(stack, message);
80 return stack;
81};
82
83/**
84 * @param {string} stack stack trace
85 * @param {string} message error message
86 * @returns {string} stack trace without the webpack options flag and message included
87 */
88const cleanUpWebpackOptions = (stack, message) => {
89 stack = cutOffWebpackOptions(stack);
90 stack = cutOffMultilineMessage(stack, message);
91 return stack;
92};
93
94module.exports.cutOffByFlag = cutOffByFlag;
95module.exports.cutOffLoaderExecution = cutOffLoaderExecution;
96module.exports.cutOffWebpackOptions = cutOffWebpackOptions;
97module.exports.cutOffMultilineMessage = cutOffMultilineMessage;
98module.exports.cutOffMessage = cutOffMessage;
99module.exports.cleanUp = cleanUp;
100module.exports.cleanUpWebpackOptions = cleanUpWebpackOptions;
Note: See TracBrowser for help on using the repository browser.