1 | "use strict";
|
2 |
|
3 | const {
|
4 | sep
|
5 | } = require(`path`);
|
6 |
|
7 |
|
8 | const regexpEscape = str => str.replace(/[-[/{}()*+?.\\^$|]/g, `\\$&`);
|
9 |
|
10 | const cleanPaths = (str, separator = sep) => {
|
11 | const stack = process.cwd().split(separator);
|
12 |
|
13 | while (stack.length > 1) {
|
14 | const currentPath = stack.join(separator);
|
15 | const currentRegex = new RegExp(regexpEscape(currentPath), `g`);
|
16 | str = str.replace(currentRegex, `$SNIP`);
|
17 | const currentPath2 = stack.join(separator + separator);
|
18 | const currentRegex2 = new RegExp(regexpEscape(currentPath2), `g`);
|
19 | str = str.replace(currentRegex2, `$SNIP`);
|
20 | stack.pop();
|
21 | }
|
22 |
|
23 | return str;
|
24 | };
|
25 |
|
26 |
|
27 | const sanitizeError = (error, pathSeparator = sep) => {
|
28 |
|
29 | if (error.stderr) error.stderr = String(error.stderr);
|
30 | if (error.stdout) error.stdout = String(error.stdout)
|
31 | ;
|
32 | [`envPairs`, `options`, `output`].forEach(key => delete error[key]);
|
33 |
|
34 | error = JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)));
|
35 | const errorString = JSON.stringify(error);
|
36 |
|
37 | return cleanPaths(errorString, pathSeparator);
|
38 | };
|
39 |
|
40 | module.exports = {
|
41 | sanitizeError,
|
42 | cleanPaths
|
43 | }; |
\ | No newline at end of file |