first-base 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/dist/find-root-dir.js +0 -83
- package/dist/index.d.ts +0 -73
- package/dist/index.js +0 -221
- package/dist/index.js.flow +0 -42
- package/dist/sanitizers.js +0 -32
package/package.json
CHANGED
package/dist/find-root-dir.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
4
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
5
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
6
|
-
var fs = require("fs");
|
|
7
|
-
var _require = require("nice-path"),
|
|
8
|
-
Path = _require.Path;
|
|
9
|
-
var strongRootDirIndicators = [".git", ".hg"];
|
|
10
|
-
var weakRootDirIndicators = ["package-lock.json", ".gitignore", ".hgignore"];
|
|
11
|
-
var veryWeakRootDirIndicators = ["package.json", "README.md"];
|
|
12
|
-
function hasFile(dir, filename) {
|
|
13
|
-
var fullPath = dir.concat(filename).toString();
|
|
14
|
-
try {
|
|
15
|
-
return fs.existsSync(fullPath);
|
|
16
|
-
} catch (err) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function findRootDir(startingDir) {
|
|
21
|
-
var start = new Path(startingDir).normalize();
|
|
22
|
-
var searchDirs = [start];
|
|
23
|
-
var currentPath = start.replaceLast([]);
|
|
24
|
-
while (currentPath.segments.length > 0) {
|
|
25
|
-
searchDirs.push(currentPath);
|
|
26
|
-
currentPath = currentPath.replaceLast([]);
|
|
27
|
-
}
|
|
28
|
-
for (var _i = 0, _searchDirs = searchDirs; _i < _searchDirs.length; _i++) {
|
|
29
|
-
var dir = _searchDirs[_i];
|
|
30
|
-
var _iterator = _createForOfIteratorHelper(strongRootDirIndicators),
|
|
31
|
-
_step;
|
|
32
|
-
try {
|
|
33
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
34
|
-
var indicator = _step.value;
|
|
35
|
-
if (hasFile(dir, indicator)) {
|
|
36
|
-
return dir.toString();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
} catch (err) {
|
|
40
|
-
_iterator.e(err);
|
|
41
|
-
} finally {
|
|
42
|
-
_iterator.f();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
for (var _i2 = 0, _searchDirs2 = searchDirs; _i2 < _searchDirs2.length; _i2++) {
|
|
46
|
-
var _dir = _searchDirs2[_i2];
|
|
47
|
-
var _iterator2 = _createForOfIteratorHelper(weakRootDirIndicators),
|
|
48
|
-
_step2;
|
|
49
|
-
try {
|
|
50
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
51
|
-
var _indicator = _step2.value;
|
|
52
|
-
if (hasFile(_dir, _indicator)) {
|
|
53
|
-
return _dir.toString();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
} catch (err) {
|
|
57
|
-
_iterator2.e(err);
|
|
58
|
-
} finally {
|
|
59
|
-
_iterator2.f();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
for (var _i3 = 0, _searchDirs3 = searchDirs; _i3 < _searchDirs3.length; _i3++) {
|
|
63
|
-
var _dir2 = _searchDirs3[_i3];
|
|
64
|
-
var _iterator3 = _createForOfIteratorHelper(veryWeakRootDirIndicators),
|
|
65
|
-
_step3;
|
|
66
|
-
try {
|
|
67
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
68
|
-
var _indicator2 = _step3.value;
|
|
69
|
-
if (hasFile(_dir2, _indicator2)) {
|
|
70
|
-
return _dir2.toString();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
} catch (err) {
|
|
74
|
-
_iterator3.e(err);
|
|
75
|
-
} finally {
|
|
76
|
-
_iterator3.f();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return start.toString();
|
|
80
|
-
}
|
|
81
|
-
module.exports = {
|
|
82
|
-
findRootDir: findRootDir
|
|
83
|
-
};
|
package/dist/index.d.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
export type Options = {
|
|
2
|
-
cwd?: string;
|
|
3
|
-
env?: { [varName: string]: any };
|
|
4
|
-
argv0?: string;
|
|
5
|
-
detached?: boolean;
|
|
6
|
-
uid?: number;
|
|
7
|
-
gid?: number;
|
|
8
|
-
shell?: boolean | string;
|
|
9
|
-
windowsVerbatimArguments?: boolean;
|
|
10
|
-
windowsHide?: boolean;
|
|
11
|
-
pty?: boolean;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type RunContext = {
|
|
15
|
-
result: {
|
|
16
|
-
stdout: string;
|
|
17
|
-
stderr: string;
|
|
18
|
-
code: null | number;
|
|
19
|
-
error: null | Error;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Same as {@link RunContext.result}, but with {@link sanitizers} run on
|
|
23
|
-
* stdout/stderr.
|
|
24
|
-
*/
|
|
25
|
-
cleanResult(): {
|
|
26
|
-
stdout: string;
|
|
27
|
-
stderr: string;
|
|
28
|
-
code: null | number;
|
|
29
|
-
error: null | Error;
|
|
30
|
-
};
|
|
31
|
-
completion: Promise<void>;
|
|
32
|
-
debug(): RunContext;
|
|
33
|
-
outputContains(value: string | RegExp): Promise<void>;
|
|
34
|
-
clearOutputContainsBuffer(): void;
|
|
35
|
-
// TODO: Should be string | Buffer, but idk how to use Buffer since they might not be using node types
|
|
36
|
-
write(data: any): void;
|
|
37
|
-
close(stream: "stdin" | "stdout" | "stderr"): void;
|
|
38
|
-
kill(signal?: string): void;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const spawn: ((cmd: string) => RunContext) &
|
|
42
|
-
((cmd: string, args: Array<string>) => RunContext) &
|
|
43
|
-
((cmd: string, options: Options) => RunContext) &
|
|
44
|
-
((cmd: string, args: Array<string>, options: Options) => RunContext);
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* An array of functions that will be run on stdout/stderr when calling
|
|
48
|
-
* {@link RunContext.cleanResult}.
|
|
49
|
-
*
|
|
50
|
-
* By default, it contains 5 functions, which are run in order:
|
|
51
|
-
*
|
|
52
|
-
* - `stripAnsi`: Removes ANSI control characters
|
|
53
|
-
* - `replaceRootDir`: Replaces eg `/home/suchipi/Code/first-base/src/index.js` with `<rootDir>/src/index.js`
|
|
54
|
-
* - This function searches upwards for the root dir using a heuristic, and caches results in the {@link Map} `replaceRootDir.cache`.
|
|
55
|
-
* - The heuristic is:
|
|
56
|
-
* - Look upwards for a folder containing `.git` or `.hg`
|
|
57
|
-
* - if none is found, look upwards for a folder containing `package-lock.json`, `.gitignore` or `.hgignore`,
|
|
58
|
-
* - if none is found, look upwards for a folder containing `package.json` or `README.md`
|
|
59
|
-
* - if none is found, consider the present working directory to be the root dir.
|
|
60
|
-
* - `replaceCwd`: Replaces the current working directory with `<cwd>`
|
|
61
|
-
* - `collapseStackTrace`: For Node.JS-style stack traces, replaces the long chain of "at ..." lines with a single "at somewhere" line
|
|
62
|
-
* - `omitThrowLineNumber`: For Node.JS error source display, removes the line number
|
|
63
|
-
*
|
|
64
|
-
* You can remove them or replace them or add to them by mutating the `sanitizers` Array.
|
|
65
|
-
*/
|
|
66
|
-
export const sanitizers: Array<(str: string) => string>;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* All runs that have been spawned which haven't reached completion.
|
|
70
|
-
*
|
|
71
|
-
* It may be beneficial to clean these up in a test timeout handler or etc.
|
|
72
|
-
*/
|
|
73
|
-
export const allInflightRunContexts: Set<RunContext>;
|
package/dist/index.js
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
-
var normalSpawn = require("child_process").spawn;
|
|
5
|
-
var stripAnsi = require("strip-ansi");
|
|
6
|
-
var _require = require("./sanitizers"),
|
|
7
|
-
sanitizers = _require.sanitizers;
|
|
8
|
-
var allInflightRunContexts = new Set();
|
|
9
|
-
|
|
10
|
-
// Run a child process and return a "run context" object
|
|
11
|
-
// to interact with it. Function signature is the same as
|
|
12
|
-
// child_process spawn, except you can pass `pty: true` in
|
|
13
|
-
// options to run the process in a psuedo-tty.
|
|
14
|
-
var spawn = function spawn(cmd, argsOrOptions, passedOptions) {
|
|
15
|
-
var args;
|
|
16
|
-
var options;
|
|
17
|
-
if (Array.isArray(argsOrOptions)) {
|
|
18
|
-
args = argsOrOptions;
|
|
19
|
-
} else if (_typeof(argsOrOptions) === "object") {
|
|
20
|
-
options = argsOrOptions;
|
|
21
|
-
}
|
|
22
|
-
if (passedOptions && !options) {
|
|
23
|
-
options = passedOptions;
|
|
24
|
-
}
|
|
25
|
-
if (!args) {
|
|
26
|
-
args = [];
|
|
27
|
-
}
|
|
28
|
-
if (!options) {
|
|
29
|
-
options = {};
|
|
30
|
-
}
|
|
31
|
-
var child;
|
|
32
|
-
var stdin;
|
|
33
|
-
var stdout;
|
|
34
|
-
var stderr;
|
|
35
|
-
var unreffable;
|
|
36
|
-
var running;
|
|
37
|
-
var _debug = false;
|
|
38
|
-
var outputContainsBuffer = "";
|
|
39
|
-
var pendingOutputContainsRequests = new Set();
|
|
40
|
-
var debugLog = function debugLog() {
|
|
41
|
-
if (_debug) {
|
|
42
|
-
var _console;
|
|
43
|
-
(_console = console).log.apply(_console, arguments);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
var runContext = {
|
|
47
|
-
result: {
|
|
48
|
-
// All of the stdout and stderr the process has written so far.
|
|
49
|
-
stdout: "",
|
|
50
|
-
stderr: "",
|
|
51
|
-
// Exit status code, if the process has finished.
|
|
52
|
-
code: null,
|
|
53
|
-
// if the process errored out, this will be the Error
|
|
54
|
-
error: null
|
|
55
|
-
},
|
|
56
|
-
// Return a version of result which has had the string sanitizers run on it
|
|
57
|
-
cleanResult: function cleanResult() {
|
|
58
|
-
return Object.assign({}, runContext.result, {
|
|
59
|
-
stdout: sanitizers.reduce(function (str, transformFn) {
|
|
60
|
-
return transformFn(str);
|
|
61
|
-
}, runContext.result.stdout),
|
|
62
|
-
stderr: sanitizers.reduce(function (str, transformFn) {
|
|
63
|
-
return transformFn(str);
|
|
64
|
-
}, runContext.result.stderr)
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
// Promise that gets resolved when the child process completes.
|
|
68
|
-
completion: null,
|
|
69
|
-
debug: function debug() {
|
|
70
|
-
_debug = true;
|
|
71
|
-
return this;
|
|
72
|
-
},
|
|
73
|
-
// Returns a Promise that resolves once the child process output
|
|
74
|
-
// (combined stdout and stderr) contains the passed string or
|
|
75
|
-
// matches the passed RegExp. Ignores ansi control characters.
|
|
76
|
-
outputContains: function outputContains(value) {
|
|
77
|
-
debugLog("Waiting for output to contain ".concat(JSON.stringify(value), "..."));
|
|
78
|
-
return new Promise(function (resolve, reject) {
|
|
79
|
-
var request = {
|
|
80
|
-
value: value
|
|
81
|
-
};
|
|
82
|
-
request.resolve = function () {
|
|
83
|
-
pendingOutputContainsRequests["delete"](request);
|
|
84
|
-
resolve();
|
|
85
|
-
};
|
|
86
|
-
request.reject = function () {
|
|
87
|
-
pendingOutputContainsRequests["delete"](request);
|
|
88
|
-
reject();
|
|
89
|
-
};
|
|
90
|
-
pendingOutputContainsRequests.add(request);
|
|
91
|
-
});
|
|
92
|
-
},
|
|
93
|
-
clearOutputContainsBuffer: function clearOutputContainsBuffer() {
|
|
94
|
-
outputContainsBuffer = "";
|
|
95
|
-
},
|
|
96
|
-
// Call this function to write into stdin.
|
|
97
|
-
write: function write(data) {
|
|
98
|
-
stdin.write(data);
|
|
99
|
-
},
|
|
100
|
-
// Call this function to close stdin, stdout, or stderr.
|
|
101
|
-
close: function close(stream) {
|
|
102
|
-
switch (String(stream).toLowerCase()) {
|
|
103
|
-
case "stdin":
|
|
104
|
-
{
|
|
105
|
-
stdin.end();
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
case "stdout":
|
|
109
|
-
{
|
|
110
|
-
stdout.end();
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
case "stderr":
|
|
114
|
-
{
|
|
115
|
-
stderr.end();
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
default:
|
|
119
|
-
{
|
|
120
|
-
throw new Error("Invalid stream name: '".concat(stream, "'. Valid names are 'stdin', 'stdout', or 'stderr'."));
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
// Call this function to send a signal to the child process.
|
|
125
|
-
// You can pass "SIGTERM", "SIGKILL", etc. Defaults to "SIGINT".
|
|
126
|
-
kill: function kill() {
|
|
127
|
-
var signal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "SIGINT";
|
|
128
|
-
if (running) {
|
|
129
|
-
child.kill(signal);
|
|
130
|
-
}
|
|
131
|
-
if (unreffable) {
|
|
132
|
-
unreffable.unref();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
if (options.pty) {
|
|
137
|
-
var ptySpawn = require("@lydell/node-pty").spawn;
|
|
138
|
-
child = ptySpawn(cmd, args, options);
|
|
139
|
-
stdin = child;
|
|
140
|
-
stdout = child;
|
|
141
|
-
stderr = null; // no way to tell between stdout and stderr with pty
|
|
142
|
-
unreffable = child.socket;
|
|
143
|
-
} else {
|
|
144
|
-
child = normalSpawn(cmd, args, options);
|
|
145
|
-
stdin = child.stdin;
|
|
146
|
-
stdout = child.stdout;
|
|
147
|
-
stderr = child.stderr;
|
|
148
|
-
unreffable = child;
|
|
149
|
-
}
|
|
150
|
-
running = true;
|
|
151
|
-
allInflightRunContexts.add(runContext);
|
|
152
|
-
var checkForPendingOutputRequestsToResolve = function checkForPendingOutputRequestsToResolve() {
|
|
153
|
-
pendingOutputContainsRequests.forEach(function (request) {
|
|
154
|
-
if (typeof request.value === "string") {
|
|
155
|
-
if (stripAnsi(outputContainsBuffer).indexOf(request.value) != -1) {
|
|
156
|
-
request.resolve();
|
|
157
|
-
}
|
|
158
|
-
} else if (request.value instanceof RegExp) {
|
|
159
|
-
if (request.value.test(stripAnsi(outputContainsBuffer))) {
|
|
160
|
-
request.resolve();
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
};
|
|
165
|
-
stdout.setEncoding("utf-8");
|
|
166
|
-
var handleStdoutData = function handleStdoutData(data) {
|
|
167
|
-
runContext.result.stdout += data;
|
|
168
|
-
outputContainsBuffer += data;
|
|
169
|
-
debugLog("STDOUT: ".concat(data.toString()));
|
|
170
|
-
checkForPendingOutputRequestsToResolve();
|
|
171
|
-
};
|
|
172
|
-
if (stdout.onData) {
|
|
173
|
-
// the pty instance returned by node-pty
|
|
174
|
-
// requires attaching handlers differently
|
|
175
|
-
stdout.onData(handleStdoutData);
|
|
176
|
-
} else {
|
|
177
|
-
stdout.on("data", handleStdoutData);
|
|
178
|
-
}
|
|
179
|
-
if (stderr) {
|
|
180
|
-
stderr.setEncoding("utf-8");
|
|
181
|
-
|
|
182
|
-
// this is never a pty instance,
|
|
183
|
-
// so we don't need to deal with onData here:
|
|
184
|
-
stderr.on("data", function (data) {
|
|
185
|
-
runContext.result.stderr += data;
|
|
186
|
-
outputContainsBuffer += data;
|
|
187
|
-
debugLog("STDERR: ".concat(data.toString()));
|
|
188
|
-
checkForPendingOutputRequestsToResolve();
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
runContext.completion = new Promise(function (resolve) {
|
|
192
|
-
var finish = function finish(reason) {
|
|
193
|
-
debugLog("Process ".concat(reason));
|
|
194
|
-
debugLog(runContext.result);
|
|
195
|
-
running = false;
|
|
196
|
-
allInflightRunContexts["delete"](runContext);
|
|
197
|
-
resolve();
|
|
198
|
-
pendingOutputContainsRequests.forEach(function (request) {
|
|
199
|
-
request.reject(new Error("Child process ".concat(reason, " before its output contained the requested content: ").concat(request.value)));
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
child.once("exit", function (code) {
|
|
203
|
-
runContext.result.code = code;
|
|
204
|
-
finish("exited");
|
|
205
|
-
});
|
|
206
|
-
child.once("error", function (error) {
|
|
207
|
-
if (_typeof(error) === "object" && error !== null && error.code === "EIO") {
|
|
208
|
-
// not real; process is about to exit
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
runContext.result.error = error;
|
|
212
|
-
finish("errored");
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
return runContext;
|
|
216
|
-
};
|
|
217
|
-
module.exports = {
|
|
218
|
-
spawn: spawn,
|
|
219
|
-
sanitizers: sanitizers,
|
|
220
|
-
allInflightRunContexts: allInflightRunContexts
|
|
221
|
-
};
|
package/dist/index.js.flow
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
export type Options = {
|
|
3
|
-
cwd?: ?string,
|
|
4
|
-
env?: ?{ [varName: string]: any },
|
|
5
|
-
argv0?: ?string,
|
|
6
|
-
detached?: ?boolean,
|
|
7
|
-
uid?: ?number,
|
|
8
|
-
gid?: ?number,
|
|
9
|
-
shell?: ?boolean | string,
|
|
10
|
-
windowsVerbatimArguments?: ?boolean,
|
|
11
|
-
windowsHide?: ?boolean,
|
|
12
|
-
pty?: ?boolean,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type RunContext = {
|
|
16
|
-
result: {
|
|
17
|
-
stdout: string,
|
|
18
|
-
stderr: string,
|
|
19
|
-
code: null | number,
|
|
20
|
-
error: null | Error,
|
|
21
|
-
},
|
|
22
|
-
completion: Promise<void>,
|
|
23
|
-
debug(): RunContext,
|
|
24
|
-
outputContains(value: string | RegExp): Promise<void>,
|
|
25
|
-
clearOutputContainsBuffer(): void,
|
|
26
|
-
write(data: string | Buffer): void,
|
|
27
|
-
close(stream: "stdin" | "stdout" | "stderr"): void,
|
|
28
|
-
kill(signal?: string): void,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
interface Exports {
|
|
32
|
-
spawn(cmd: string): RunContext;
|
|
33
|
-
spawn(cmd: string, args: Array<string>): RunContext;
|
|
34
|
-
spawn(cmd: string, options: Options): RunContext;
|
|
35
|
-
spawn(cmd: string, args: Array<string>, options: Options): RunContext;
|
|
36
|
-
|
|
37
|
-
sanitizers: Array<(str: string) => string>;
|
|
38
|
-
|
|
39
|
-
allInflightRunContexts: Set<RunContext>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
declare module.exports: Exports;
|
package/dist/sanitizers.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var stripAnsi = require("strip-ansi");
|
|
4
|
-
var _require = require("./find-root-dir"),
|
|
5
|
-
findRootDir = _require.findRootDir;
|
|
6
|
-
function escapeRegex(str) {
|
|
7
|
-
return str.replace(/[/\-\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
8
|
-
}
|
|
9
|
-
var sanitizers = [stripAnsi, Object.assign(function replaceRootDir(str) {
|
|
10
|
-
var here = process.cwd();
|
|
11
|
-
var rootDir = replaceRootDir.cache.get(here) || findRootDir(here);
|
|
12
|
-
replaceRootDir.cache.set(here, rootDir);
|
|
13
|
-
return str.replace(new RegExp(escapeRegex(rootDir), "g"), "<rootDir>");
|
|
14
|
-
}, {
|
|
15
|
-
cache: new Map()
|
|
16
|
-
}), function replaceCwd(str) {
|
|
17
|
-
return str.replace(new RegExp(escapeRegex(process.cwd()), "g"), "<cwd>");
|
|
18
|
-
}, function collapseStackTrace(str) {
|
|
19
|
-
return str
|
|
20
|
-
// replace stack trace lines with a single "at somewhere" line
|
|
21
|
-
// explanation of regexp:
|
|
22
|
-
// newline, optional ansi escape, zero or more whitespace(s), "at",
|
|
23
|
-
// whitespace(s), several non-newline characters... and that whole
|
|
24
|
-
// thing can happen more than once
|
|
25
|
-
.replaceAll(/(?:\n(?:\x1B\[\d+m)?(\s*)at\s+[^\n]+)+/g, "\n$1at somewhere");
|
|
26
|
-
}, function omitThrowLineNumber(str) {
|
|
27
|
-
// omit line number from eg. "<rootDir>/dist/match.js:57\n\t\t\t\tthrow"
|
|
28
|
-
return str.replaceAll(/(\.js):\d+(\s+throw)/g, "$1$2");
|
|
29
|
-
}];
|
|
30
|
-
module.exports = {
|
|
31
|
-
sanitizers: sanitizers
|
|
32
|
-
};
|