@idlebox/node 1.3.2 → 1.3.3
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/lib/cjs/__create_index.generated.cjs +17 -19
- package/lib/cjs/__create_index.generated.cjs.map +1 -1
- package/lib/cjs/__create_index.generated.d.cts +9 -8
- package/lib/cjs/asyncLoad.cjs +2 -2
- package/lib/cjs/asyncLoad.cjs.map +1 -1
- package/lib/cjs/fs/exists.cjs +38 -12
- package/lib/cjs/fs/exists.cjs.map +1 -1
- package/lib/esm/__create_index.generated.d.mts +9 -8
- package/lib/esm/__create_index.generated.mjs +8 -10
- package/lib/esm/__create_index.generated.mjs.map +1 -1
- package/lib/esm/asyncLoad.mjs +1 -1
- package/lib/esm/asyncLoad.mjs.map +1 -1
- package/lib/esm/fs/exists.mjs +32 -9
- package/lib/esm/fs/exists.mjs.map +1 -1
- package/package.json +1 -1
- package/src/asyncLoad.ts +1 -1
- package/src/fs/exists.ts +35 -10
- package/lib/cjs/error/pretty.cjs +0 -226
- package/lib/cjs/error/pretty.cjs.map +0 -10
- package/lib/esm/error/pretty.mjs +0 -220
- package/lib/esm/error/pretty.mjs.map +0 -10
- package/src/error/pretty.ts +0 -240
|
@@ -3,24 +3,8 @@
|
|
|
3
3
|
// @ts-ignore
|
|
4
4
|
/* eslint-disable */
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.streamToBuffer = exports.streamHasEnd = exports.streamPromise = exports.BlackHoleStream = exports.nodeResolvePathArray = exports.lrelative = exports.getAllPathUpToRoot = exports.findPackageRoot = exports.findUpUntilSync = exports.findUpUntil = exports.WrappedTerminalConsole = exports.writeFileIfChange = exports.writeFileIfChangeSync = exports.createTempFolder = exports.emptyDir = exports.commandInPathSync = exports.commandInPath = exports.dumpEventEmitterEmit = exports.ERRNO_LINUX = exports.getNpmConfigValue = exports.sha256 = exports.md5 = exports.respawnInScope = exports.trySpawnInScope = exports.spawnRecreateEventHandlers = exports.findBinary = exports.PathEnvironment = exports.PATH_SEPARATOR = exports.cleanupEnvironment = exports.deleteEnvironment = exports.getEnvironment = exports.
|
|
6
|
+
exports.streamToBuffer = exports.streamHasEnd = exports.streamPromise = exports.BlackHoleStream = exports.relativePath = exports.osTempDir = exports.normalizePath = exports.resolvePath = exports.nodeResolvePathArray = exports.lrelative = exports.getAllPathUpToRoot = exports.findPackageRoot = exports.findUpUntilSync = exports.findUpUntil = exports.WrappedTerminalConsole = exports.writeFileIfChange = exports.writeFileIfChangeSync = exports.createTempFolder = exports.emptyDir = exports.commandInPathSync = exports.commandInPath = exports.dumpEventEmitterEmit = exports.ERRNO_LINUX = exports.getNpmConfigValue = exports.sha256 = exports.md5 = exports.respawnInScope = exports.trySpawnInScope = exports.spawnRecreateEventHandlers = exports.findBinary = exports.PathEnvironment = exports.PATH_SEPARATOR = exports.cleanupEnvironment = exports.deleteEnvironment = exports.getEnvironment = exports.isTypeError = exports.isExistsError = exports.isNotExistsError = exports.readFileIfExists = exports.exists = exports.execLazyError = exports.printLine = exports.spawnGetEverything = exports.spawnGetOutput = exports.spawnGetOutputSync = exports.spawnWithoutOutput = exports.spawnWithoutOutputSync = exports.checkChildProcessResult = exports.runMain = exports.ExitError = void 0;
|
|
7
7
|
exports.HexDumpLoggerStream = exports.LoggerStream = exports.drainStream = exports.disposableStream = exports.CollectingStream = exports.RawCollectingStream = void 0;
|
|
8
|
-
var resolvePath_js_1 = require("./path-resolve/resolvePath.cjs");
|
|
9
|
-
Object.defineProperty(exports, "resolvePath", { enumerable: true, get: function () { return resolvePath_js_1.resolvePath; } });
|
|
10
|
-
var resolvePath_js_2 = require("./path-resolve/resolvePath.cjs");
|
|
11
|
-
Object.defineProperty(exports, "normalizePath", { enumerable: true, get: function () { return resolvePath_js_2.normalizePath; } });
|
|
12
|
-
var resolvePath_js_3 = require("./path-resolve/resolvePath.cjs");
|
|
13
|
-
Object.defineProperty(exports, "osTempDir", { enumerable: true, get: function () { return resolvePath_js_3.osTempDir; } });
|
|
14
|
-
var resolvePath_js_4 = require("./path-resolve/resolvePath.cjs");
|
|
15
|
-
Object.defineProperty(exports, "relativePath", { enumerable: true, get: function () { return resolvePath_js_4.relativePath; } });
|
|
16
|
-
/* error/pretty.ts */
|
|
17
|
-
// Identifiers
|
|
18
|
-
var pretty_js_1 = require("./error/pretty.cjs");
|
|
19
|
-
Object.defineProperty(exports, "setErrorLogRoot", { enumerable: true, get: function () { return pretty_js_1.setErrorLogRoot; } });
|
|
20
|
-
var pretty_js_2 = require("./error/pretty.cjs");
|
|
21
|
-
Object.defineProperty(exports, "prettyPrintError", { enumerable: true, get: function () { return pretty_js_2.prettyPrintError; } });
|
|
22
|
-
var pretty_js_3 = require("./error/pretty.cjs");
|
|
23
|
-
Object.defineProperty(exports, "prettyFormatError", { enumerable: true, get: function () { return pretty_js_3.prettyFormatError; } });
|
|
24
8
|
var asyncLoad_js_1 = require("./asyncLoad.cjs");
|
|
25
9
|
Object.defineProperty(exports, "ExitError", { enumerable: true, get: function () { return asyncLoad_js_1.ExitError; } });
|
|
26
10
|
var asyncLoad_js_2 = require("./asyncLoad.cjs");
|
|
@@ -48,9 +32,15 @@ Object.defineProperty(exports, "execLazyError", { enumerable: true, get: functio
|
|
|
48
32
|
/* fs/exists.ts */
|
|
49
33
|
// Identifiers
|
|
50
34
|
var exists_js_1 = require("./fs/exists.cjs");
|
|
51
|
-
Object.defineProperty(exports, "
|
|
35
|
+
Object.defineProperty(exports, "exists", { enumerable: true, get: function () { return exists_js_1.exists; } });
|
|
52
36
|
var exists_js_2 = require("./fs/exists.cjs");
|
|
53
|
-
Object.defineProperty(exports, "
|
|
37
|
+
Object.defineProperty(exports, "readFileIfExists", { enumerable: true, get: function () { return exists_js_2.readFileIfExists; } });
|
|
38
|
+
var exists_js_3 = require("./fs/exists.cjs");
|
|
39
|
+
Object.defineProperty(exports, "isNotExistsError", { enumerable: true, get: function () { return exists_js_3.isNotExistsError; } });
|
|
40
|
+
var exists_js_4 = require("./fs/exists.cjs");
|
|
41
|
+
Object.defineProperty(exports, "isExistsError", { enumerable: true, get: function () { return exists_js_4.isExistsError; } });
|
|
42
|
+
var exists_js_5 = require("./fs/exists.cjs");
|
|
43
|
+
Object.defineProperty(exports, "isTypeError", { enumerable: true, get: function () { return exists_js_5.isTypeError; } });
|
|
54
44
|
var getEnvironment_js_1 = require("./environment/getEnvironment.cjs");
|
|
55
45
|
Object.defineProperty(exports, "getEnvironment", { enumerable: true, get: function () { return getEnvironment_js_1.getEnvironment; } });
|
|
56
46
|
var getEnvironment_js_2 = require("./environment/getEnvironment.cjs");
|
|
@@ -141,6 +131,14 @@ Object.defineProperty(exports, "lrelative", { enumerable: true, get: function ()
|
|
|
141
131
|
// Identifiers
|
|
142
132
|
var nodeResolvePathArray_js_1 = require("./path-resolve/nodeResolvePathArray.cjs");
|
|
143
133
|
Object.defineProperty(exports, "nodeResolvePathArray", { enumerable: true, get: function () { return nodeResolvePathArray_js_1.nodeResolvePathArray; } });
|
|
134
|
+
var resolvePath_js_1 = require("./path-resolve/resolvePath.cjs");
|
|
135
|
+
Object.defineProperty(exports, "resolvePath", { enumerable: true, get: function () { return resolvePath_js_1.resolvePath; } });
|
|
136
|
+
var resolvePath_js_2 = require("./path-resolve/resolvePath.cjs");
|
|
137
|
+
Object.defineProperty(exports, "normalizePath", { enumerable: true, get: function () { return resolvePath_js_2.normalizePath; } });
|
|
138
|
+
var resolvePath_js_3 = require("./path-resolve/resolvePath.cjs");
|
|
139
|
+
Object.defineProperty(exports, "osTempDir", { enumerable: true, get: function () { return resolvePath_js_3.osTempDir; } });
|
|
140
|
+
var resolvePath_js_4 = require("./path-resolve/resolvePath.cjs");
|
|
141
|
+
Object.defineProperty(exports, "relativePath", { enumerable: true, get: function () { return resolvePath_js_4.relativePath; } });
|
|
144
142
|
/* stream/blackHoleStream.ts */
|
|
145
143
|
// Identifiers
|
|
146
144
|
var blackHoleStream_js_1 = require("./stream/blackHoleStream.cjs");
|
|
@@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CAA0C;AACzC,cAAc;AACd,mFAA4E;AAApE,+HAAA,oBAAoB,OAAA;AAK5B,iEAA0D;AAAlD,6GAAA,WAAW,OAAA;AAEnB,iEAA4D;AAApD,+GAAA,aAAa,OAAA;AACrB,iEAAwD;AAAhD,2GAAA,SAAS,OAAA;AACjB,iEAA2D;AAAnD,8GAAA,YAAY,OAAA;AACrB,+BAA+B;AAC9B,cAAc;AACd,mEAA4D;AAApD,qHAAA,eAAe,OAAA;AACxB,6BAA6B;AAC5B,cAAc;AACd,+DAAwD;AAAhD,iHAAA,aAAa,OAAA;AACrB,+DAAuD;AAA/C,gHAAA,YAAY,OAAA;AACrB,gCAAgC;AAC/B,cAAc;AACd,qEAA4D;AAApD,qHAAA,cAAc,OAAA;AACtB,qEAAiE;AAAzD,0HAAA,mBAAmB,OAAA;AAC3B,qEAA8D;AAAtD,uHAAA,gBAAgB,OAAA;AACzB,gCAAgC;AAC/B,cAAc;AACd,qEAA8D;AAAtD,uHAAA,gBAAgB,OAAA;AACzB,2BAA2B;AAC1B,cAAc;AACd,2DAAoD;AAA5C,6GAAA,WAAW,OAAA;AAInB,6DAAsD;AAA9C,+GAAA,YAAY,OAAA;AACpB,6DAA6D;AAArD,sHAAA,mBAAmB,OAAA"
|
|
10
10
|
}
|
|
@@ -6,6 +6,7 @@ import { IDisposable } from '@idlebox/common';
|
|
|
6
6
|
import { Options } from 'execa';
|
|
7
7
|
import { PathArray } from '@idlebox/common';
|
|
8
8
|
import { Readable } from 'stream';
|
|
9
|
+
import { readFile } from 'fs/promises';
|
|
9
10
|
import { Transform } from 'stream';
|
|
10
11
|
import { WrappedConsole } from '@idlebox/common';
|
|
11
12
|
import { WrappedConsoleOptions } from '@idlebox/common';
|
|
@@ -191,8 +192,6 @@ export declare function execLazyError(cmd: string, args: string[], spawnOptions?
|
|
|
191
192
|
|
|
192
193
|
export declare function exists(path: string): Promise<boolean>;
|
|
193
194
|
|
|
194
|
-
export declare function existsSync(path: string): boolean;
|
|
195
|
-
|
|
196
195
|
export declare class ExitError extends Error {
|
|
197
196
|
readonly code: number;
|
|
198
197
|
constructor(message: string, code?: number);
|
|
@@ -244,10 +243,16 @@ export declare interface IEnvironmentResult {
|
|
|
244
243
|
name: string;
|
|
245
244
|
}
|
|
246
245
|
|
|
246
|
+
export declare function isExistsError(e: any): boolean;
|
|
247
|
+
|
|
248
|
+
export declare function isNotExistsError(e: any): boolean;
|
|
249
|
+
|
|
247
250
|
export declare interface ISpawnAdditionOptions {
|
|
248
251
|
verbose?: boolean;
|
|
249
252
|
}
|
|
250
253
|
|
|
254
|
+
export declare function isTypeError(e: any): boolean;
|
|
255
|
+
|
|
251
256
|
export declare interface JoinPathFunction {
|
|
252
257
|
(from: string, to: string): string;
|
|
253
258
|
}
|
|
@@ -287,10 +292,6 @@ export declare class PathEnvironment extends PathArray {
|
|
|
287
292
|
save(): void;
|
|
288
293
|
}
|
|
289
294
|
|
|
290
|
-
export declare function prettyFormatError(e: Error): string;
|
|
291
|
-
|
|
292
|
-
export declare function prettyPrintError(type: string, e: Error): void;
|
|
293
|
-
|
|
294
295
|
export declare function printLine(char?: string): void;
|
|
295
296
|
|
|
296
297
|
declare type ProcessEnv = Record<string, string> & {
|
|
@@ -306,6 +307,8 @@ export declare class RawCollectingStream extends Writable {
|
|
|
306
307
|
promise(): Promise<Buffer>;
|
|
307
308
|
}
|
|
308
309
|
|
|
310
|
+
export declare const readFileIfExists: typeof readFile;
|
|
311
|
+
|
|
309
312
|
export declare const relativePath: JoinPathFunction;
|
|
310
313
|
|
|
311
314
|
export declare const resolvePath: ResolvePathFunction;
|
|
@@ -335,8 +338,6 @@ export declare function respawnInScope(mainFunc: Function): unknown | never;
|
|
|
335
338
|
**/
|
|
336
339
|
export declare function runMain(main: AsyncMainFunction): void;
|
|
337
340
|
|
|
338
|
-
export declare function setErrorLogRoot(_root: string): void;
|
|
339
|
-
|
|
340
341
|
export declare function sha256(data: Buffer): string;
|
|
341
342
|
|
|
342
343
|
export declare function spawnGetEverything({ exec, cwd, env, addonPath }: ICommand): Promise<string | undefined>;
|
package/lib/cjs/asyncLoad.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runMain = exports.ExitError = void 0;
|
|
4
|
-
const
|
|
4
|
+
const common_1 = require("@idlebox/common");
|
|
5
5
|
class ExitError extends Error {
|
|
6
6
|
code;
|
|
7
7
|
constructor(message, code = 1) {
|
|
@@ -24,7 +24,7 @@ function runMain(main) {
|
|
|
24
24
|
console.error(e.message);
|
|
25
25
|
process.exit(1);
|
|
26
26
|
}
|
|
27
|
-
(0,
|
|
27
|
+
(0, common_1.prettyPrintError)('build-script', e);
|
|
28
28
|
return e.code || 1;
|
|
29
29
|
})
|
|
30
30
|
.then((code) => {
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
"../../src/asyncLoad.ts"
|
|
7
7
|
],
|
|
8
8
|
"names": [],
|
|
9
|
-
"mappings": ";;;AAAA
|
|
9
|
+
"mappings": ";;;AAAA,4CAAmD;AAInD,MAAa,SAAU,SAAQ,KAAK;IACU;IAA7C,YAAY,OAAe,EAAkB,OAAe,CAAC;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QAD6B,SAAI,GAAJ,IAAI,CAAY;IAE7D,CAAC;CACD;AAJD,8BAIC;AAED;;;;;IAKI;AACJ,SAAgB,OAAO,CAAC,IAAuB;IAC9C,OAAO,CAAC,OAAO,EAAE;SACf,IAAI,CAAC,IAAI,CAAC;SACV,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACZ,IAAI,CAAC,YAAY,SAAS,EAAE;YAC3B,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;YACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SAChB;QAED,IAAA,yBAAgB,EAAC,cAAc,EAAE,CAAC,CAAC,CAAC;QACpC,OAAO,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;IACpB,CAAC,CAAC;SACD,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QACd,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;AACL,CAAC;AAfD,0BAeC"
|
|
10
10
|
}
|
package/lib/cjs/fs/exists.cjs
CHANGED
|
@@ -1,22 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.exists = exports.existsSync = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
3
|
+
exports.isTypeError = exports.isExistsError = exports.isNotExistsError = exports.readFileIfExists = exports.exists = exports.existsSync = void 0;
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
var fs_1 = require("fs");
|
|
6
|
+
Object.defineProperty(exports, "existsSync", { enumerable: true, get: function () { return fs_1.existsSync; } });
|
|
7
|
+
async function exists(path) {
|
|
6
8
|
try {
|
|
7
|
-
(0,
|
|
9
|
+
(0, promises_1.access)(path);
|
|
8
10
|
return true;
|
|
9
11
|
}
|
|
10
12
|
catch (e) {
|
|
11
|
-
|
|
13
|
+
if (isNotExistsError(e))
|
|
14
|
+
return false;
|
|
15
|
+
throw e;
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
|
-
exports.existsSync = existsSync;
|
|
15
|
-
function exists(path) {
|
|
16
|
-
return new Promise((resolve) => {
|
|
17
|
-
const wrappedCallback = (err) => (err ? resolve(false) : resolve(true));
|
|
18
|
-
(0, fs_1.access)(path, wrappedCallback);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
18
|
exports.exists = exists;
|
|
19
|
+
exports.readFileIfExists = _readFileIfExists;
|
|
20
|
+
async function _readFileIfExists(file, encoding) {
|
|
21
|
+
try {
|
|
22
|
+
return await (0, promises_1.readFile)(file, encoding);
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
if (isNotExistsError(e)) {
|
|
26
|
+
if (typeof encoding === 'string' || typeof encoding?.encoding === 'string') {
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return Buffer.allocUnsafe(0);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
throw e;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function isNotExistsError(e) {
|
|
37
|
+
return e.code === 'ENOENT';
|
|
38
|
+
}
|
|
39
|
+
exports.isNotExistsError = isNotExistsError;
|
|
40
|
+
function isExistsError(e) {
|
|
41
|
+
return e.code === 'EEXIST';
|
|
42
|
+
}
|
|
43
|
+
exports.isExistsError = isExistsError;
|
|
44
|
+
function isTypeError(e) {
|
|
45
|
+
return e.code === 'EISDIR' || e.code === 'ENOTDIR';
|
|
46
|
+
}
|
|
47
|
+
exports.isTypeError = isTypeError;
|
|
22
48
|
//# sourceMappingURL=exists.cjs.map
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
"../../../src/fs/exists.ts"
|
|
7
7
|
],
|
|
8
8
|
"names": [],
|
|
9
|
-
"mappings": ";;;
|
|
9
|
+
"mappings": ";;;AACA,0CAA+C;AAC/C,yBAAgC;AAAvB,gGAAA,UAAU,OAAA;AAEZ,KAAK,UAAU,MAAM,CAAC,IAAY;IACxC,IAAI;QACH,IAAA,iBAAM,EAAC,IAAI,CAAC,CAAC;QACb,OAAO,IAAI,CAAC;KACZ;IAAC,OAAO,CAAM,EAAE;QAChB,IAAI,gBAAgB,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QACtC,MAAM,CAAC,CAAC;KACR;AACF,CAAC;AARD,wBAQC;AAEY,QAAA,gBAAgB,GAAoB,iBAAwB,CAAC;AAE1E,KAAK,UAAU,iBAAiB,CAAC,IAAY,EAAE,QAAwD;IACtG,IAAI;QACH,OAAO,MAAM,IAAA,mBAAQ,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;KACtC;IAAC,OAAO,CAAM,EAAE;QAChB,IAAI,gBAAgB,CAAC,CAAC,CAAC,EAAE;YACxB,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,OAAO,QAAQ,EAAE,QAAQ,KAAK,QAAQ,EAAE;gBAC3E,OAAO,EAAE,CAAC;aACV;iBAAM;gBACN,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;aAC7B;SACD;QACD,MAAM,CAAC,CAAC;KACR;AACF,CAAC;AAED,SAAgB,gBAAgB,CAAC,CAAM;IACtC,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC;AAC5B,CAAC;AAFD,4CAEC;AAED,SAAgB,aAAa,CAAC,CAAM;IACnC,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC;AAC5B,CAAC;AAFD,sCAEC;AAED,SAAgB,WAAW,CAAC,CAAM;IACjC,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC;AACpD,CAAC;AAFD,kCAEC"
|
|
10
10
|
}
|
|
@@ -6,6 +6,7 @@ import { IDisposable } from '@idlebox/common';
|
|
|
6
6
|
import { Options } from 'execa';
|
|
7
7
|
import { PathArray } from '@idlebox/common';
|
|
8
8
|
import { Readable } from 'stream';
|
|
9
|
+
import { readFile } from 'fs/promises';
|
|
9
10
|
import { Transform } from 'stream';
|
|
10
11
|
import { WrappedConsole } from '@idlebox/common';
|
|
11
12
|
import { WrappedConsoleOptions } from '@idlebox/common';
|
|
@@ -191,8 +192,6 @@ export declare function execLazyError(cmd: string, args: string[], spawnOptions?
|
|
|
191
192
|
|
|
192
193
|
export declare function exists(path: string): Promise<boolean>;
|
|
193
194
|
|
|
194
|
-
export declare function existsSync(path: string): boolean;
|
|
195
|
-
|
|
196
195
|
export declare class ExitError extends Error {
|
|
197
196
|
readonly code: number;
|
|
198
197
|
constructor(message: string, code?: number);
|
|
@@ -244,10 +243,16 @@ export declare interface IEnvironmentResult {
|
|
|
244
243
|
name: string;
|
|
245
244
|
}
|
|
246
245
|
|
|
246
|
+
export declare function isExistsError(e: any): boolean;
|
|
247
|
+
|
|
248
|
+
export declare function isNotExistsError(e: any): boolean;
|
|
249
|
+
|
|
247
250
|
export declare interface ISpawnAdditionOptions {
|
|
248
251
|
verbose?: boolean;
|
|
249
252
|
}
|
|
250
253
|
|
|
254
|
+
export declare function isTypeError(e: any): boolean;
|
|
255
|
+
|
|
251
256
|
export declare interface JoinPathFunction {
|
|
252
257
|
(from: string, to: string): string;
|
|
253
258
|
}
|
|
@@ -287,10 +292,6 @@ export declare class PathEnvironment extends PathArray {
|
|
|
287
292
|
save(): void;
|
|
288
293
|
}
|
|
289
294
|
|
|
290
|
-
export declare function prettyFormatError(e: Error): string;
|
|
291
|
-
|
|
292
|
-
export declare function prettyPrintError(type: string, e: Error): void;
|
|
293
|
-
|
|
294
295
|
export declare function printLine(char?: string): void;
|
|
295
296
|
|
|
296
297
|
declare type ProcessEnv = Record<string, string> & {
|
|
@@ -306,6 +307,8 @@ export declare class RawCollectingStream extends Writable {
|
|
|
306
307
|
promise(): Promise<Buffer>;
|
|
307
308
|
}
|
|
308
309
|
|
|
310
|
+
export declare const readFileIfExists: typeof readFile;
|
|
311
|
+
|
|
309
312
|
export declare const relativePath: JoinPathFunction;
|
|
310
313
|
|
|
311
314
|
export declare const resolvePath: ResolvePathFunction;
|
|
@@ -335,8 +338,6 @@ export declare function respawnInScope(mainFunc: Function): unknown | never;
|
|
|
335
338
|
**/
|
|
336
339
|
export declare function runMain(main: AsyncMainFunction): void;
|
|
337
340
|
|
|
338
|
-
export declare function setErrorLogRoot(_root: string): void;
|
|
339
|
-
|
|
340
341
|
export declare function sha256(data: Buffer): string;
|
|
341
342
|
|
|
342
343
|
export declare function spawnGetEverything({ exec, cwd, env, addonPath }: ICommand): Promise<string | undefined>;
|
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
// DO NOT EDIT THIS FILE
|
|
2
2
|
// @ts-ignore
|
|
3
3
|
/* eslint-disable */
|
|
4
|
-
export { resolvePath } from "./path-resolve/resolvePath.mjs";
|
|
5
|
-
export { normalizePath } from "./path-resolve/resolvePath.mjs";
|
|
6
|
-
export { osTempDir } from "./path-resolve/resolvePath.mjs";
|
|
7
|
-
export { relativePath } from "./path-resolve/resolvePath.mjs";
|
|
8
|
-
/* error/pretty.ts */
|
|
9
|
-
// Identifiers
|
|
10
|
-
export { setErrorLogRoot } from "./error/pretty.mjs";
|
|
11
|
-
export { prettyPrintError } from "./error/pretty.mjs";
|
|
12
|
-
export { prettyFormatError } from "./error/pretty.mjs";
|
|
13
4
|
export { ExitError } from "./asyncLoad.mjs";
|
|
14
5
|
export { runMain } from "./asyncLoad.mjs";
|
|
15
6
|
/* child_process/error.ts */
|
|
@@ -26,8 +17,11 @@ export { printLine } from "./cli-io/output.mjs";
|
|
|
26
17
|
export { execLazyError } from "./child_process/lateError.mjs";
|
|
27
18
|
/* fs/exists.ts */
|
|
28
19
|
// Identifiers
|
|
29
|
-
export { existsSync } from "./fs/exists.mjs";
|
|
30
20
|
export { exists } from "./fs/exists.mjs";
|
|
21
|
+
export { readFileIfExists } from "./fs/exists.mjs";
|
|
22
|
+
export { isNotExistsError } from "./fs/exists.mjs";
|
|
23
|
+
export { isExistsError } from "./fs/exists.mjs";
|
|
24
|
+
export { isTypeError } from "./fs/exists.mjs";
|
|
31
25
|
export { getEnvironment } from "./environment/getEnvironment.mjs";
|
|
32
26
|
export { deleteEnvironment } from "./environment/getEnvironment.mjs";
|
|
33
27
|
export { cleanupEnvironment } from "./environment/getEnvironment.mjs";
|
|
@@ -91,6 +85,10 @@ export { lrelative } from "./path-resolve/lrelative.mjs";
|
|
|
91
85
|
/* path-resolve/nodeResolvePathArray.ts */
|
|
92
86
|
// Identifiers
|
|
93
87
|
export { nodeResolvePathArray } from "./path-resolve/nodeResolvePathArray.mjs";
|
|
88
|
+
export { resolvePath } from "./path-resolve/resolvePath.mjs";
|
|
89
|
+
export { normalizePath } from "./path-resolve/resolvePath.mjs";
|
|
90
|
+
export { osTempDir } from "./path-resolve/resolvePath.mjs";
|
|
91
|
+
export { relativePath } from "./path-resolve/resolvePath.mjs";
|
|
94
92
|
/* stream/blackHoleStream.ts */
|
|
95
93
|
// Identifiers
|
|
96
94
|
export { BlackHoleStream } from "./stream/blackHoleStream.mjs";
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
"../../src/__create_index.generated.ts"
|
|
7
7
|
],
|
|
8
8
|
"names": [],
|
|
9
|
-
"mappings": "AAAA,wBAAwB;AACxB,aAAa;AACb,oBAAoB;
|
|
9
|
+
"mappings": "AAAA,wBAAwB;AACxB,aAAa;AACb,oBAAoB;AAOnB,OAAO,EAAC,SAAS,EAAC,wBAAuB;AACzC,OAAO,EAAC,OAAO,EAAC,wBAAuB;AACxC,4BAA4B;AAC3B,cAAc;AACd,OAAO,EAAC,uBAAuB,EAAC,kCAAiC;AAIjE,OAAO,EAAC,sBAAsB,EAAC,kCAAiC;AAChE,OAAO,EAAC,kBAAkB,EAAC,kCAAiC;AAC5D,OAAO,EAAC,kBAAkB,EAAC,kCAAiC;AAC5D,OAAO,EAAC,cAAc,EAAC,kCAAiC;AACxD,OAAO,EAAC,kBAAkB,EAAC,kCAAiC;AAC7D,sBAAsB;AACrB,cAAc;AACd,OAAO,EAAC,SAAS,EAAC,4BAA2B;AAI7C,OAAO,EAAC,aAAa,EAAC,sCAAqC;AAC5D,kBAAkB;AACjB,cAAc;AACd,OAAO,EAAC,MAAM,EAAC,wBAAuB;AACtC,OAAO,EAAC,gBAAgB,EAAC,wBAAuB;AAChD,OAAO,EAAC,gBAAgB,EAAC,wBAAuB;AAChD,OAAO,EAAC,aAAa,EAAC,wBAAuB;AAC7C,OAAO,EAAC,WAAW,EAAC,wBAAuB;AAI3C,OAAO,EAAC,cAAc,EAAC,yCAAwC;AAC/D,OAAO,EAAC,iBAAiB,EAAC,yCAAwC;AAClE,OAAO,EAAC,kBAAkB,EAAC,yCAAwC;AACpE,o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,CAAC,OAAO,CAAC,CAAC;QAD6B,SAAI,GAAJ,IAAI,CAAY;IAE7D,CAAC;CACD;AAED;;;;;IAKI;AACJ,MAAM,UAAU,OAAO,CAAC,IAAuB;IAC9C,OAAO,CAAC,OAAO,EAAE;SACf,IAAI,CAAC,IAAI,CAAC;SACV,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACZ,IAAI,CAAC,YAAY,SAAS,EAAE;YAC3B,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;YACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SAChB;QAED,gBAAgB,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC;QACpC,OAAO,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;IACpB,CAAC,CAAC;SACD,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QACd,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;AACL,CAAC"
|
|
10
10
|
}
|
package/lib/esm/fs/exists.mjs
CHANGED
|
@@ -1,17 +1,40 @@
|
|
|
1
|
-
import { access,
|
|
2
|
-
export
|
|
1
|
+
import { access, readFile } from 'fs/promises';
|
|
2
|
+
export { existsSync } from 'fs';
|
|
3
|
+
export async function exists(path) {
|
|
3
4
|
try {
|
|
4
|
-
|
|
5
|
+
access(path);
|
|
5
6
|
return true;
|
|
6
7
|
}
|
|
7
8
|
catch (e) {
|
|
8
|
-
|
|
9
|
+
if (isNotExistsError(e))
|
|
10
|
+
return false;
|
|
11
|
+
throw e;
|
|
9
12
|
}
|
|
10
13
|
}
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
14
|
+
export const readFileIfExists = _readFileIfExists;
|
|
15
|
+
async function _readFileIfExists(file, encoding) {
|
|
16
|
+
try {
|
|
17
|
+
return await readFile(file, encoding);
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
if (isNotExistsError(e)) {
|
|
21
|
+
if (typeof encoding === 'string' || typeof encoding?.encoding === 'string') {
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return Buffer.allocUnsafe(0);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
throw e;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function isNotExistsError(e) {
|
|
32
|
+
return e.code === 'ENOENT';
|
|
33
|
+
}
|
|
34
|
+
export function isExistsError(e) {
|
|
35
|
+
return e.code === 'EEXIST';
|
|
36
|
+
}
|
|
37
|
+
export function isTypeError(e) {
|
|
38
|
+
return e.code === 'EISDIR' || e.code === 'ENOTDIR';
|
|
16
39
|
}
|
|
17
40
|
//# sourceMappingURL=exists.mjs.map
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
"../../../src/fs/exists.ts"
|
|
7
7
|
],
|
|
8
8
|
"names": [],
|
|
9
|
-
"mappings": "
|
|
9
|
+
"mappings": "AACA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAEhC,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,IAAY;IACxC,IAAI;QACH,MAAM,CAAC,IAAI,CAAC,CAAC;QACb,OAAO,IAAI,CAAC;KACZ;IAAC,OAAO,CAAM,EAAE;QAChB,IAAI,gBAAgB,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QACtC,MAAM,CAAC,CAAC;KACR;AACF,CAAC;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAoB,iBAAwB,CAAC;AAE1E,KAAK,UAAU,iBAAiB,CAAC,IAAY,EAAE,QAAwD;IACtG,IAAI;QACH,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;KACtC;IAAC,OAAO,CAAM,EAAE;QAChB,IAAI,gBAAgB,CAAC,CAAC,CAAC,EAAE;YACxB,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,OAAO,QAAQ,EAAE,QAAQ,KAAK,QAAQ,EAAE;gBAC3E,OAAO,EAAE,CAAC;aACV;iBAAM;gBACN,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;aAC7B;SACD;QACD,MAAM,CAAC,CAAC;KACR;AACF,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,CAAM;IACtC,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,CAAM;IACnC,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,CAAM;IACjC,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC;AACpD,CAAC"
|
|
10
10
|
}
|
package/package.json
CHANGED
package/src/asyncLoad.ts
CHANGED
package/src/fs/exists.ts
CHANGED
|
@@ -1,17 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ObjectEncodingOptions } from 'fs';
|
|
2
|
+
import { access, readFile } from 'fs/promises';
|
|
3
|
+
export { existsSync } from 'fs';
|
|
2
4
|
|
|
3
|
-
export function
|
|
5
|
+
export async function exists(path: string) {
|
|
4
6
|
try {
|
|
5
|
-
|
|
7
|
+
access(path);
|
|
6
8
|
return true;
|
|
7
|
-
} catch (e) {
|
|
8
|
-
return false;
|
|
9
|
+
} catch (e: any) {
|
|
10
|
+
if (isNotExistsError(e)) return false;
|
|
11
|
+
throw e;
|
|
9
12
|
}
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
export const readFileIfExists: typeof readFile = _readFileIfExists as any;
|
|
16
|
+
|
|
17
|
+
async function _readFileIfExists(file: string, encoding?: NodeJS.BufferEncoding | ObjectEncodingOptions) {
|
|
18
|
+
try {
|
|
19
|
+
return await readFile(file, encoding);
|
|
20
|
+
} catch (e: any) {
|
|
21
|
+
if (isNotExistsError(e)) {
|
|
22
|
+
if (typeof encoding === 'string' || typeof encoding?.encoding === 'string') {
|
|
23
|
+
return '';
|
|
24
|
+
} else {
|
|
25
|
+
return Buffer.allocUnsafe(0);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
throw e;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function isNotExistsError(e: any) {
|
|
33
|
+
return e.code === 'ENOENT';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function isExistsError(e: any) {
|
|
37
|
+
return e.code === 'EEXIST';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function isTypeError(e: any) {
|
|
41
|
+
return e.code === 'EISDIR' || e.code === 'ENOTDIR';
|
|
17
42
|
}
|
package/lib/cjs/error/pretty.cjs
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prettyFormatError = exports.prettyPrintError = exports.setErrorLogRoot = void 0;
|
|
4
|
-
const common_1 = require("@idlebox/common");
|
|
5
|
-
const resolvePath_1 = require("../path-resolve/resolvePath.cjs");
|
|
6
|
-
const regNormal = /^\s+at ([^\/\s]+)(?: \[as ([^\]]+)])? \(((?:node|file):\/*)?([^:]+)(:\d+)?(:\d+)\)$/;
|
|
7
|
-
var regNormalMatch;
|
|
8
|
-
(function (regNormalMatch) {
|
|
9
|
-
regNormalMatch[regNormalMatch["fn"] = 1] = "fn";
|
|
10
|
-
regNormalMatch[regNormalMatch["fnAlias"] = 2] = "fnAlias";
|
|
11
|
-
regNormalMatch[regNormalMatch["fileSchema"] = 3] = "fileSchema";
|
|
12
|
-
regNormalMatch[regNormalMatch["file"] = 4] = "file";
|
|
13
|
-
regNormalMatch[regNormalMatch["row"] = 5] = "row";
|
|
14
|
-
regNormalMatch[regNormalMatch["column"] = 6] = "column";
|
|
15
|
-
})(regNormalMatch || (regNormalMatch = {}));
|
|
16
|
-
const regFunctionOnly = /^\s+at ([^\/\\\s]+(?: \[as ([^\]]+)])?)$/;
|
|
17
|
-
var regFunctionMatch;
|
|
18
|
-
(function (regFunctionMatch) {
|
|
19
|
-
regFunctionMatch[regFunctionMatch["fn"] = 1] = "fn";
|
|
20
|
-
regFunctionMatch[regFunctionMatch["fnAlias"] = 2] = "fnAlias";
|
|
21
|
-
})(regFunctionMatch || (regFunctionMatch = {}));
|
|
22
|
-
const regFileOnly = /^\s+at ([^:]+)(:\d+)?(:\d+)$/;
|
|
23
|
-
var regFileOnlyMatch;
|
|
24
|
-
(function (regFileOnlyMatch) {
|
|
25
|
-
regFileOnlyMatch[regFileOnlyMatch["file"] = 1] = "file";
|
|
26
|
-
regFileOnlyMatch[regFileOnlyMatch["row"] = 2] = "row";
|
|
27
|
-
regFileOnlyMatch[regFileOnlyMatch["column"] = 3] = "column";
|
|
28
|
-
})(regFileOnlyMatch || (regFileOnlyMatch = {}));
|
|
29
|
-
const regSimpleFrame = /^\s+at ([^(]+) \(<anonymous>\)$/;
|
|
30
|
-
var regSimpleFrameMatch;
|
|
31
|
-
(function (regSimpleFrameMatch) {
|
|
32
|
-
regSimpleFrameMatch[regSimpleFrameMatch["fn"] = 1] = "fn";
|
|
33
|
-
})(regSimpleFrameMatch || (regSimpleFrameMatch = {}));
|
|
34
|
-
let root = process.cwd();
|
|
35
|
-
function setErrorLogRoot(_root) {
|
|
36
|
-
root = _root;
|
|
37
|
-
}
|
|
38
|
-
exports.setErrorLogRoot = setErrorLogRoot;
|
|
39
|
-
let notify_printed = false;
|
|
40
|
-
function prettyPrintError(type, e) {
|
|
41
|
-
if (process.env.DISABLE_PRETTY_ERROR) {
|
|
42
|
-
console.error('[${type}] %s', e.stack || e.message);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
console.error(`------------------------------------------
|
|
46
|
-
[${type}] ${prettyFormatError(e)}`);
|
|
47
|
-
if (!notify_printed) {
|
|
48
|
-
notify_printed = true;
|
|
49
|
-
console.error('\x1B[2muse env.DISABLE_PRETTY_ERROR=yes to see original error stack\x1B[0m');
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.prettyPrintError = prettyPrintError;
|
|
53
|
-
function red(s) {
|
|
54
|
-
return `\x1B[38;5;9m${s}\x1B[0m`;
|
|
55
|
-
}
|
|
56
|
-
function prettyFormatError(e) {
|
|
57
|
-
if (!e || !e.message) {
|
|
58
|
-
return red('Unknown Error') + '\n' + new Error().stack?.split('\n').slice(3).join('\n');
|
|
59
|
-
}
|
|
60
|
-
if (!e.stack) {
|
|
61
|
-
return red(e.message + '\nNo stack trace');
|
|
62
|
-
}
|
|
63
|
-
const stackStr = e.stack.replace(/file:\/\//, '').split(/\n/g);
|
|
64
|
-
debugger;
|
|
65
|
-
let first = stackStr.shift();
|
|
66
|
-
const stack = stackStr.map((line) => {
|
|
67
|
-
if (regNormal.test(line)) {
|
|
68
|
-
const m = regNormal.exec(line);
|
|
69
|
-
return {
|
|
70
|
-
fn: m[regNormalMatch.fn],
|
|
71
|
-
as: m[regNormalMatch.fnAlias],
|
|
72
|
-
fileSchema: m[regNormalMatch.fileSchema],
|
|
73
|
-
file: m[regNormalMatch.file],
|
|
74
|
-
line: parseInt(m[regNormalMatch.row].slice(1)),
|
|
75
|
-
col: parseInt(m[regNormalMatch.column].slice(1)),
|
|
76
|
-
abs: (0, common_1.isAbsolute)(m[regNormalMatch.file]),
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
else if (regFunctionOnly.test(line)) {
|
|
80
|
-
const m = regFunctionOnly.exec(line);
|
|
81
|
-
return {
|
|
82
|
-
fn: m[regFunctionMatch.fn],
|
|
83
|
-
as: m[regFunctionMatch.fnAlias],
|
|
84
|
-
file: undefined,
|
|
85
|
-
line: undefined,
|
|
86
|
-
col: undefined,
|
|
87
|
-
abs: false,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
else if (regFileOnly.test(line)) {
|
|
91
|
-
const m = regFileOnly.exec(line);
|
|
92
|
-
return {
|
|
93
|
-
fn: undefined,
|
|
94
|
-
as: undefined,
|
|
95
|
-
file: m[regFileOnlyMatch.file],
|
|
96
|
-
line: parseInt(m[regFileOnlyMatch.row].slice(1)),
|
|
97
|
-
col: parseInt(m[regFileOnlyMatch.column].slice(1)),
|
|
98
|
-
abs: (0, common_1.isAbsolute)(m[regFileOnlyMatch.file]),
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
else if (regSimpleFrame.test(line)) {
|
|
102
|
-
const m = regSimpleFrame.exec(line);
|
|
103
|
-
return {
|
|
104
|
-
fn: m[regSimpleFrameMatch.fn],
|
|
105
|
-
as: undefined,
|
|
106
|
-
file: '<anonymous>',
|
|
107
|
-
line: undefined,
|
|
108
|
-
col: undefined,
|
|
109
|
-
abs: false,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
return { raw: line.replace(/^ /, '') };
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
const stackOutput = stack
|
|
117
|
-
.filter(ignoreSomeFiles)
|
|
118
|
-
.map(translateFunction)
|
|
119
|
-
.map(({ raw, fn, file, as, abs, line, col, fileSchema }) => {
|
|
120
|
-
let ret;
|
|
121
|
-
if (raw) {
|
|
122
|
-
return raw;
|
|
123
|
-
}
|
|
124
|
-
if (abs) {
|
|
125
|
-
const isNodeModule = file?.includes('/node_modules/');
|
|
126
|
-
const color = fn ? (isNodeModule ? '4' : '14') : '8';
|
|
127
|
-
ret = ` at \x1b[38;5;${color}m`;
|
|
128
|
-
if (as && fn && fn.startsWith('Object.')) {
|
|
129
|
-
ret += as + ' [export]';
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
ret += formatFunctionName(fn, as);
|
|
133
|
-
}
|
|
134
|
-
ret += '\x1b[0m';
|
|
135
|
-
if (file) {
|
|
136
|
-
ret += ' (';
|
|
137
|
-
if (!isNodeModule) {
|
|
138
|
-
ret += '\x1b[38;5;2m';
|
|
139
|
-
}
|
|
140
|
-
ret += formatFileLine(fileSchema, file, line, col);
|
|
141
|
-
ret += '\x1B[0m)';
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
ret = '\x1B[2m at ';
|
|
146
|
-
if (fn) {
|
|
147
|
-
ret += fn;
|
|
148
|
-
}
|
|
149
|
-
if (file) {
|
|
150
|
-
if (fn) {
|
|
151
|
-
ret += ' (';
|
|
152
|
-
}
|
|
153
|
-
ret += formatFileLine(fileSchema, file, line, col);
|
|
154
|
-
if (fn) {
|
|
155
|
-
ret += ')';
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
ret += '\x1B[0m';
|
|
159
|
-
}
|
|
160
|
-
return ret;
|
|
161
|
-
});
|
|
162
|
-
if (e.code) {
|
|
163
|
-
first = first.replace(/^(\S+):/, (_, name) => {
|
|
164
|
-
return `${name}(code ${e.code}):`;
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
return first + '\n' + stackOutput.join('\n');
|
|
168
|
-
}
|
|
169
|
-
exports.prettyFormatError = prettyFormatError;
|
|
170
|
-
function formatFileLine(schema, file, row, col) {
|
|
171
|
-
let rel = file;
|
|
172
|
-
if (schema !== 'node:') {
|
|
173
|
-
rel = (0, resolvePath_1.relativePath)(root, file);
|
|
174
|
-
if (rel.startsWith('..')) {
|
|
175
|
-
rel = file;
|
|
176
|
-
}
|
|
177
|
-
else if (!rel.startsWith('.')) {
|
|
178
|
-
rel = './' + rel;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return `${schema || ''}${rel}${row ? `:${row}` : ''}${col ? `:${col}` : ''}`;
|
|
182
|
-
}
|
|
183
|
-
function formatFunctionName(fn, as) {
|
|
184
|
-
if (fn) {
|
|
185
|
-
if (as) {
|
|
186
|
-
return `${fn} [as ${as}]`;
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
return fn;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
return '[anonymous]';
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
function translateFunction(data) {
|
|
197
|
-
if (!data.fn) {
|
|
198
|
-
return data;
|
|
199
|
-
}
|
|
200
|
-
if (data.fn === 'Timeout._onTimeout') {
|
|
201
|
-
data.fn = 'setTimeout';
|
|
202
|
-
}
|
|
203
|
-
if (data.fn.startsWith('Timeout.') && data.as === '_onTimeout') {
|
|
204
|
-
data.fn = 'setTimeout->' + data.fn.slice(8);
|
|
205
|
-
delete data.as;
|
|
206
|
-
}
|
|
207
|
-
return data;
|
|
208
|
-
}
|
|
209
|
-
function ignoreSomeFiles({ file }) {
|
|
210
|
-
if (!file) {
|
|
211
|
-
return true;
|
|
212
|
-
}
|
|
213
|
-
if (file === 'internal/timers.js') {
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
|
-
if (file.startsWith('internal/modules/cjs/loader')) {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
if (!file.includes('/')) {
|
|
220
|
-
if (file.startsWith('_stream_')) {
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return true;
|
|
225
|
-
}
|
|
226
|
-
//# sourceMappingURL=pretty.cjs.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"file": "pretty.cjs",
|
|
4
|
-
"sourceRoot": "",
|
|
5
|
-
"sources": [
|
|
6
|
-
"../../../src/error/pretty.ts"
|
|
7
|
-
],
|
|
8
|
-
"names": [],
|
|
9
|
-
"mappings": ";;;AAAA,4CAA6C;AAC7C,iEAA2D;AAE3D,MAAM,SAAS,GAAG,qFAAqF,CAAC;AAExG,IAAW,cAOV;AAPD,WAAW,cAAc;IACxB,+CAAM,CAAA;IACN,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,KAAK,CAAC;KACb;IACD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACxB,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE;YAChC,OAAO,KAAK,CAAC;SACb;KACD;IACD,OAAO,IAAI,CAAC;AACb,CAAC"
|
|
10
|
-
}
|
package/lib/esm/error/pretty.mjs
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import { isAbsolute } from '@idlebox/common';
|
|
2
|
-
import { relativePath } from "../path-resolve/resolvePath.mjs";
|
|
3
|
-
const regNormal = /^\s+at ([^\/\s]+)(?: \[as ([^\]]+)])? \(((?:node|file):\/*)?([^:]+)(:\d+)?(:\d+)\)$/;
|
|
4
|
-
var regNormalMatch;
|
|
5
|
-
(function (regNormalMatch) {
|
|
6
|
-
regNormalMatch[regNormalMatch["fn"] = 1] = "fn";
|
|
7
|
-
regNormalMatch[regNormalMatch["fnAlias"] = 2] = "fnAlias";
|
|
8
|
-
regNormalMatch[regNormalMatch["fileSchema"] = 3] = "fileSchema";
|
|
9
|
-
regNormalMatch[regNormalMatch["file"] = 4] = "file";
|
|
10
|
-
regNormalMatch[regNormalMatch["row"] = 5] = "row";
|
|
11
|
-
regNormalMatch[regNormalMatch["column"] = 6] = "column";
|
|
12
|
-
})(regNormalMatch || (regNormalMatch = {}));
|
|
13
|
-
const regFunctionOnly = /^\s+at ([^\/\\\s]+(?: \[as ([^\]]+)])?)$/;
|
|
14
|
-
var regFunctionMatch;
|
|
15
|
-
(function (regFunctionMatch) {
|
|
16
|
-
regFunctionMatch[regFunctionMatch["fn"] = 1] = "fn";
|
|
17
|
-
regFunctionMatch[regFunctionMatch["fnAlias"] = 2] = "fnAlias";
|
|
18
|
-
})(regFunctionMatch || (regFunctionMatch = {}));
|
|
19
|
-
const regFileOnly = /^\s+at ([^:]+)(:\d+)?(:\d+)$/;
|
|
20
|
-
var regFileOnlyMatch;
|
|
21
|
-
(function (regFileOnlyMatch) {
|
|
22
|
-
regFileOnlyMatch[regFileOnlyMatch["file"] = 1] = "file";
|
|
23
|
-
regFileOnlyMatch[regFileOnlyMatch["row"] = 2] = "row";
|
|
24
|
-
regFileOnlyMatch[regFileOnlyMatch["column"] = 3] = "column";
|
|
25
|
-
})(regFileOnlyMatch || (regFileOnlyMatch = {}));
|
|
26
|
-
const regSimpleFrame = /^\s+at ([^(]+) \(<anonymous>\)$/;
|
|
27
|
-
var regSimpleFrameMatch;
|
|
28
|
-
(function (regSimpleFrameMatch) {
|
|
29
|
-
regSimpleFrameMatch[regSimpleFrameMatch["fn"] = 1] = "fn";
|
|
30
|
-
})(regSimpleFrameMatch || (regSimpleFrameMatch = {}));
|
|
31
|
-
let root = process.cwd();
|
|
32
|
-
export function setErrorLogRoot(_root) {
|
|
33
|
-
root = _root;
|
|
34
|
-
}
|
|
35
|
-
let notify_printed = false;
|
|
36
|
-
export function prettyPrintError(type, e) {
|
|
37
|
-
if (process.env.DISABLE_PRETTY_ERROR) {
|
|
38
|
-
console.error('[${type}] %s', e.stack || e.message);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
console.error(`------------------------------------------
|
|
42
|
-
[${type}] ${prettyFormatError(e)}`);
|
|
43
|
-
if (!notify_printed) {
|
|
44
|
-
notify_printed = true;
|
|
45
|
-
console.error('\x1B[2muse env.DISABLE_PRETTY_ERROR=yes to see original error stack\x1B[0m');
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function red(s) {
|
|
49
|
-
return `\x1B[38;5;9m${s}\x1B[0m`;
|
|
50
|
-
}
|
|
51
|
-
export function prettyFormatError(e) {
|
|
52
|
-
if (!e || !e.message) {
|
|
53
|
-
return red('Unknown Error') + '\n' + new Error().stack?.split('\n').slice(3).join('\n');
|
|
54
|
-
}
|
|
55
|
-
if (!e.stack) {
|
|
56
|
-
return red(e.message + '\nNo stack trace');
|
|
57
|
-
}
|
|
58
|
-
const stackStr = e.stack.replace(/file:\/\//, '').split(/\n/g);
|
|
59
|
-
debugger;
|
|
60
|
-
let first = stackStr.shift();
|
|
61
|
-
const stack = stackStr.map((line) => {
|
|
62
|
-
if (regNormal.test(line)) {
|
|
63
|
-
const m = regNormal.exec(line);
|
|
64
|
-
return {
|
|
65
|
-
fn: m[1 /* regNormalMatch.fn */],
|
|
66
|
-
as: m[2 /* regNormalMatch.fnAlias */],
|
|
67
|
-
fileSchema: m[3 /* regNormalMatch.fileSchema */],
|
|
68
|
-
file: m[4 /* regNormalMatch.file */],
|
|
69
|
-
line: parseInt(m[5 /* regNormalMatch.row */].slice(1)),
|
|
70
|
-
col: parseInt(m[6 /* regNormalMatch.column */].slice(1)),
|
|
71
|
-
abs: isAbsolute(m[4 /* regNormalMatch.file */]),
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
else if (regFunctionOnly.test(line)) {
|
|
75
|
-
const m = regFunctionOnly.exec(line);
|
|
76
|
-
return {
|
|
77
|
-
fn: m[1 /* regFunctionMatch.fn */],
|
|
78
|
-
as: m[2 /* regFunctionMatch.fnAlias */],
|
|
79
|
-
file: undefined,
|
|
80
|
-
line: undefined,
|
|
81
|
-
col: undefined,
|
|
82
|
-
abs: false,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
else if (regFileOnly.test(line)) {
|
|
86
|
-
const m = regFileOnly.exec(line);
|
|
87
|
-
return {
|
|
88
|
-
fn: undefined,
|
|
89
|
-
as: undefined,
|
|
90
|
-
file: m[1 /* regFileOnlyMatch.file */],
|
|
91
|
-
line: parseInt(m[2 /* regFileOnlyMatch.row */].slice(1)),
|
|
92
|
-
col: parseInt(m[3 /* regFileOnlyMatch.column */].slice(1)),
|
|
93
|
-
abs: isAbsolute(m[1 /* regFileOnlyMatch.file */]),
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
else if (regSimpleFrame.test(line)) {
|
|
97
|
-
const m = regSimpleFrame.exec(line);
|
|
98
|
-
return {
|
|
99
|
-
fn: m[1 /* regSimpleFrameMatch.fn */],
|
|
100
|
-
as: undefined,
|
|
101
|
-
file: '<anonymous>',
|
|
102
|
-
line: undefined,
|
|
103
|
-
col: undefined,
|
|
104
|
-
abs: false,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
return { raw: line.replace(/^ /, '') };
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
const stackOutput = stack
|
|
112
|
-
.filter(ignoreSomeFiles)
|
|
113
|
-
.map(translateFunction)
|
|
114
|
-
.map(({ raw, fn, file, as, abs, line, col, fileSchema }) => {
|
|
115
|
-
let ret;
|
|
116
|
-
if (raw) {
|
|
117
|
-
return raw;
|
|
118
|
-
}
|
|
119
|
-
if (abs) {
|
|
120
|
-
const isNodeModule = file?.includes('/node_modules/');
|
|
121
|
-
const color = fn ? (isNodeModule ? '4' : '14') : '8';
|
|
122
|
-
ret = ` at \x1b[38;5;${color}m`;
|
|
123
|
-
if (as && fn && fn.startsWith('Object.')) {
|
|
124
|
-
ret += as + ' [export]';
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
ret += formatFunctionName(fn, as);
|
|
128
|
-
}
|
|
129
|
-
ret += '\x1b[0m';
|
|
130
|
-
if (file) {
|
|
131
|
-
ret += ' (';
|
|
132
|
-
if (!isNodeModule) {
|
|
133
|
-
ret += '\x1b[38;5;2m';
|
|
134
|
-
}
|
|
135
|
-
ret += formatFileLine(fileSchema, file, line, col);
|
|
136
|
-
ret += '\x1B[0m)';
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
ret = '\x1B[2m at ';
|
|
141
|
-
if (fn) {
|
|
142
|
-
ret += fn;
|
|
143
|
-
}
|
|
144
|
-
if (file) {
|
|
145
|
-
if (fn) {
|
|
146
|
-
ret += ' (';
|
|
147
|
-
}
|
|
148
|
-
ret += formatFileLine(fileSchema, file, line, col);
|
|
149
|
-
if (fn) {
|
|
150
|
-
ret += ')';
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
ret += '\x1B[0m';
|
|
154
|
-
}
|
|
155
|
-
return ret;
|
|
156
|
-
});
|
|
157
|
-
if (e.code) {
|
|
158
|
-
first = first.replace(/^(\S+):/, (_, name) => {
|
|
159
|
-
return `${name}(code ${e.code}):`;
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
return first + '\n' + stackOutput.join('\n');
|
|
163
|
-
}
|
|
164
|
-
function formatFileLine(schema, file, row, col) {
|
|
165
|
-
let rel = file;
|
|
166
|
-
if (schema !== 'node:') {
|
|
167
|
-
rel = relativePath(root, file);
|
|
168
|
-
if (rel.startsWith('..')) {
|
|
169
|
-
rel = file;
|
|
170
|
-
}
|
|
171
|
-
else if (!rel.startsWith('.')) {
|
|
172
|
-
rel = './' + rel;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return `${schema || ''}${rel}${row ? `:${row}` : ''}${col ? `:${col}` : ''}`;
|
|
176
|
-
}
|
|
177
|
-
function formatFunctionName(fn, as) {
|
|
178
|
-
if (fn) {
|
|
179
|
-
if (as) {
|
|
180
|
-
return `${fn} [as ${as}]`;
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
return fn;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
return '[anonymous]';
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
function translateFunction(data) {
|
|
191
|
-
if (!data.fn) {
|
|
192
|
-
return data;
|
|
193
|
-
}
|
|
194
|
-
if (data.fn === 'Timeout._onTimeout') {
|
|
195
|
-
data.fn = 'setTimeout';
|
|
196
|
-
}
|
|
197
|
-
if (data.fn.startsWith('Timeout.') && data.as === '_onTimeout') {
|
|
198
|
-
data.fn = 'setTimeout->' + data.fn.slice(8);
|
|
199
|
-
delete data.as;
|
|
200
|
-
}
|
|
201
|
-
return data;
|
|
202
|
-
}
|
|
203
|
-
function ignoreSomeFiles({ file }) {
|
|
204
|
-
if (!file) {
|
|
205
|
-
return true;
|
|
206
|
-
}
|
|
207
|
-
if (file === 'internal/timers.js') {
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
if (file.startsWith('internal/modules/cjs/loader')) {
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
if (!file.includes('/')) {
|
|
214
|
-
if (file.startsWith('_stream_')) {
|
|
215
|
-
return false;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return true;
|
|
219
|
-
}
|
|
220
|
-
//# sourceMappingURL=pretty.mjs.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"file": "pretty.mjs",
|
|
4
|
-
"sourceRoot": "",
|
|
5
|
-
"sources": [
|
|
6
|
-
"../../../src/error/pretty.ts"
|
|
7
|
-
],
|
|
8
|
-
"names": [],
|
|
9
|
-
"mappings": "AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,wCAAoC;AAE3D,MAAM,SAAS,GAAG,qFAAqF,CAAC;AAExG,IAAW,cAOV;AAPD,WAAW,cAAc;IACxB,+CAAM,CAAA;IACN,yDAAO,CAAA;IACP,+DAAU,CAAA;IACV,mDAAI,CAAA;IACJ,iDAAG,CAAA;IACH,uDAAM,CAAA;AACP,CAAC,EAPU,cAAc,KAAd,cAAc,QAOxB;AAED,MAAM,eAAe,GAAG,0CAA0C,CAAC;AAEnE,IAAW,gBAGV;AAHD,WAAW,gBAAgB;IAC1B,mDAAM,CAAA;IACN,6DAAO,CAAA;AACR,CAAC,EAHU,gBAAgB,KAAhB,gBAAgB,QAG1B;AAED,MAAM,WAAW,GAAG,8BAA8B,CAAC;AAEnD,IAAW,gBAIV;AAJD,WAAW,gBAAgB;IAC1B,uDAAQ,CAAA;IACR,qDAAG,CAAA;IACH,2DAAM,CAAA;AACP,CAAC,EAJU,gBAAgB,KAAhB,gBAAgB,QAI1B;AAED,MAAM,cAAc,GAAG,iCA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CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC,EAAE,CAAC;KACf;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED,SAAS,eAAe,CAAC,EAAE,IAAI,EAAiB;IAC/C,IAAI,CAAC,IAAI,EAAE;QACV,OAAO,IAAI,CAAC;KACZ;IACD,IAAI,IAAI,KAAK,oBAAoB,EAAE;QAClC,OAAO,KAAK,CAAC;KACb;IACD,IAAI,IAAI,CAAC,UAAU,CAAC,6BAA6B,CAAC,EAAE;QACnD,OAAO,KAAK,CAAC;KACb;IACD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACxB,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE;YAChC,OAAO,KAAK,CAAC;SACb;KACD;IACD,OAAO,IAAI,CAAC;AACb,CAAC"
|
|
10
|
-
}
|
package/src/error/pretty.ts
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { isAbsolute } from '@idlebox/common';
|
|
2
|
-
import { relativePath } from '../path-resolve/resolvePath';
|
|
3
|
-
|
|
4
|
-
const regNormal = /^\s+at ([^\/\s]+)(?: \[as ([^\]]+)])? \(((?:node|file):\/*)?([^:]+)(:\d+)?(:\d+)\)$/;
|
|
5
|
-
|
|
6
|
-
const enum regNormalMatch {
|
|
7
|
-
fn = 1,
|
|
8
|
-
fnAlias,
|
|
9
|
-
fileSchema,
|
|
10
|
-
file,
|
|
11
|
-
row,
|
|
12
|
-
column,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const regFunctionOnly = /^\s+at ([^\/\\\s]+(?: \[as ([^\]]+)])?)$/;
|
|
16
|
-
|
|
17
|
-
const enum regFunctionMatch {
|
|
18
|
-
fn = 1,
|
|
19
|
-
fnAlias,
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const regFileOnly = /^\s+at ([^:]+)(:\d+)?(:\d+)$/;
|
|
23
|
-
|
|
24
|
-
const enum regFileOnlyMatch {
|
|
25
|
-
file = 1,
|
|
26
|
-
row,
|
|
27
|
-
column,
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const regSimpleFrame = /^\s+at ([^(]+) \(<anonymous>\)$/;
|
|
31
|
-
|
|
32
|
-
const enum regSimpleFrameMatch {
|
|
33
|
-
fn = 1,
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let root = process.cwd();
|
|
37
|
-
|
|
38
|
-
export function setErrorLogRoot(_root: string) {
|
|
39
|
-
root = _root;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
interface IInternalData {
|
|
43
|
-
raw?: string;
|
|
44
|
-
fn?: string;
|
|
45
|
-
as?: string;
|
|
46
|
-
file?: string;
|
|
47
|
-
fileSchema?: string; // 'node' | 'file';
|
|
48
|
-
line?: number;
|
|
49
|
-
col?: number;
|
|
50
|
-
abs?: boolean;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let notify_printed = false;
|
|
54
|
-
export function prettyPrintError(type: string, e: Error) {
|
|
55
|
-
if (process.env.DISABLE_PRETTY_ERROR) {
|
|
56
|
-
console.error('[${type}] %s', e.stack || e.message);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
console.error(`------------------------------------------
|
|
60
|
-
[${type}] ${prettyFormatError(e)}`);
|
|
61
|
-
|
|
62
|
-
if (!notify_printed) {
|
|
63
|
-
notify_printed = true;
|
|
64
|
-
console.error('\x1B[2muse env.DISABLE_PRETTY_ERROR=yes to see original error stack\x1B[0m');
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function red(s: string) {
|
|
69
|
-
return `\x1B[38;5;9m${s}\x1B[0m`;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function prettyFormatError(e: Error) {
|
|
73
|
-
if (!e || !e.message) {
|
|
74
|
-
return red('Unknown Error') + '\n' + new Error().stack?.split('\n').slice(3).join('\n');
|
|
75
|
-
}
|
|
76
|
-
if (!e.stack) {
|
|
77
|
-
return red(e.message + '\nNo stack trace');
|
|
78
|
-
}
|
|
79
|
-
const stackStr = e.stack.replace(/file:\/\//, '').split(/\n/g);
|
|
80
|
-
debugger;
|
|
81
|
-
let first = stackStr.shift()!;
|
|
82
|
-
const stack: IInternalData[] = stackStr.map((line) => {
|
|
83
|
-
if (regNormal.test(line)) {
|
|
84
|
-
const m = regNormal.exec(line)!;
|
|
85
|
-
return {
|
|
86
|
-
fn: m[regNormalMatch.fn],
|
|
87
|
-
as: m[regNormalMatch.fnAlias],
|
|
88
|
-
fileSchema: m[regNormalMatch.fileSchema],
|
|
89
|
-
file: m[regNormalMatch.file],
|
|
90
|
-
line: parseInt(m[regNormalMatch.row].slice(1)),
|
|
91
|
-
col: parseInt(m[regNormalMatch.column].slice(1)),
|
|
92
|
-
abs: isAbsolute(m[regNormalMatch.file]),
|
|
93
|
-
};
|
|
94
|
-
} else if (regFunctionOnly.test(line)) {
|
|
95
|
-
const m = regFunctionOnly.exec(line)!;
|
|
96
|
-
return {
|
|
97
|
-
fn: m[regFunctionMatch.fn],
|
|
98
|
-
as: m[regFunctionMatch.fnAlias],
|
|
99
|
-
file: undefined,
|
|
100
|
-
line: undefined,
|
|
101
|
-
col: undefined,
|
|
102
|
-
abs: false,
|
|
103
|
-
};
|
|
104
|
-
} else if (regFileOnly.test(line)) {
|
|
105
|
-
const m = regFileOnly.exec(line)!;
|
|
106
|
-
return {
|
|
107
|
-
fn: undefined,
|
|
108
|
-
as: undefined,
|
|
109
|
-
file: m[regFileOnlyMatch.file],
|
|
110
|
-
line: parseInt(m[regFileOnlyMatch.row].slice(1)),
|
|
111
|
-
col: parseInt(m[regFileOnlyMatch.column].slice(1)),
|
|
112
|
-
abs: isAbsolute(m[regFileOnlyMatch.file]),
|
|
113
|
-
};
|
|
114
|
-
} else if (regSimpleFrame.test(line)) {
|
|
115
|
-
const m = regSimpleFrame.exec(line)!;
|
|
116
|
-
return {
|
|
117
|
-
fn: m[regSimpleFrameMatch.fn],
|
|
118
|
-
as: undefined,
|
|
119
|
-
file: '<anonymous>',
|
|
120
|
-
line: undefined,
|
|
121
|
-
col: undefined,
|
|
122
|
-
abs: false,
|
|
123
|
-
};
|
|
124
|
-
} else {
|
|
125
|
-
return { raw: line.replace(/^ /, '') };
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
const stackOutput = stack
|
|
129
|
-
.filter(ignoreSomeFiles)
|
|
130
|
-
.map(translateFunction)
|
|
131
|
-
.map(({ raw, fn, file, as, abs, line, col, fileSchema }) => {
|
|
132
|
-
let ret;
|
|
133
|
-
if (raw) {
|
|
134
|
-
return raw;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (abs) {
|
|
138
|
-
const isNodeModule = file?.includes('/node_modules/');
|
|
139
|
-
const color = fn ? (isNodeModule ? '4' : '14') : '8';
|
|
140
|
-
ret = ` at \x1b[38;5;${color}m`;
|
|
141
|
-
if (as && fn && fn.startsWith('Object.')) {
|
|
142
|
-
ret += as + ' [export]';
|
|
143
|
-
} else {
|
|
144
|
-
ret += formatFunctionName(fn, as);
|
|
145
|
-
}
|
|
146
|
-
ret += '\x1b[0m';
|
|
147
|
-
if (file) {
|
|
148
|
-
ret += ' (';
|
|
149
|
-
if (!isNodeModule) {
|
|
150
|
-
ret += '\x1b[38;5;2m';
|
|
151
|
-
}
|
|
152
|
-
ret += formatFileLine(fileSchema, file, line, col);
|
|
153
|
-
ret += '\x1B[0m)';
|
|
154
|
-
}
|
|
155
|
-
} else {
|
|
156
|
-
ret = '\x1B[2m at ';
|
|
157
|
-
if (fn) {
|
|
158
|
-
ret += fn;
|
|
159
|
-
}
|
|
160
|
-
if (file) {
|
|
161
|
-
if (fn) {
|
|
162
|
-
ret += ' (';
|
|
163
|
-
}
|
|
164
|
-
ret += formatFileLine(fileSchema, file, line, col);
|
|
165
|
-
if (fn) {
|
|
166
|
-
ret += ')';
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
ret += '\x1B[0m';
|
|
170
|
-
}
|
|
171
|
-
return ret;
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
if ((e as any).code) {
|
|
175
|
-
first = first.replace(/^(\S+):/, (_, name) => {
|
|
176
|
-
return `${name}(code ${(e as any).code}):`;
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return first + '\n' + stackOutput.join('\n');
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function formatFileLine(schema: string | undefined, file: string, row?: number, col?: number) {
|
|
184
|
-
let rel = file;
|
|
185
|
-
|
|
186
|
-
if (schema !== 'node:') {
|
|
187
|
-
rel = relativePath(root, file);
|
|
188
|
-
if (rel.startsWith('..')) {
|
|
189
|
-
rel = file;
|
|
190
|
-
} else if (!rel.startsWith('.')) {
|
|
191
|
-
rel = './' + rel;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return `${schema || ''}${rel}${row ? `:${row}` : ''}${col ? `:${col}` : ''}`;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function formatFunctionName(fn?: string, as?: string) {
|
|
199
|
-
if (fn) {
|
|
200
|
-
if (as) {
|
|
201
|
-
return `${fn} [as ${as}]`;
|
|
202
|
-
} else {
|
|
203
|
-
return fn;
|
|
204
|
-
}
|
|
205
|
-
} else {
|
|
206
|
-
return '[anonymous]';
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function translateFunction(data: IInternalData): IInternalData {
|
|
211
|
-
if (!data.fn) {
|
|
212
|
-
return data;
|
|
213
|
-
}
|
|
214
|
-
if (data.fn === 'Timeout._onTimeout') {
|
|
215
|
-
data.fn = 'setTimeout';
|
|
216
|
-
}
|
|
217
|
-
if (data.fn.startsWith('Timeout.') && data.as === '_onTimeout') {
|
|
218
|
-
data.fn = 'setTimeout->' + data.fn.slice(8);
|
|
219
|
-
delete data.as;
|
|
220
|
-
}
|
|
221
|
-
return data;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
function ignoreSomeFiles({ file }: IInternalData): boolean {
|
|
225
|
-
if (!file) {
|
|
226
|
-
return true;
|
|
227
|
-
}
|
|
228
|
-
if (file === 'internal/timers.js') {
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
if (file.startsWith('internal/modules/cjs/loader')) {
|
|
232
|
-
return false;
|
|
233
|
-
}
|
|
234
|
-
if (!file.includes('/')) {
|
|
235
|
-
if (file.startsWith('_stream_')) {
|
|
236
|
-
return false;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return true;
|
|
240
|
-
}
|