@vltpkg/output 0.0.0-2 → 0.0.0-21
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/dist/esm/error.d.ts +28 -0
- package/dist/esm/error.d.ts.map +1 -0
- package/dist/esm/error.js +46 -0
- package/dist/esm/error.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +19 -9
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type ErrorCause = Record<string, unknown> & {
|
|
2
|
+
cause?: ErrorCause;
|
|
3
|
+
};
|
|
4
|
+
export type ParsedError = {
|
|
5
|
+
name: string;
|
|
6
|
+
message: string;
|
|
7
|
+
stack?: string;
|
|
8
|
+
cause?: ErrorCause | ParsedError;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Parse an unknown value into an error. Will also take enumerable properties
|
|
13
|
+
* from legacy style Node errors and treat them as the cause.
|
|
14
|
+
*/
|
|
15
|
+
export declare const parseError: (err: unknown) => null | ParsedError;
|
|
16
|
+
/**
|
|
17
|
+
* Find the root error from an unknown value, optionally matching a code.
|
|
18
|
+
*/
|
|
19
|
+
export declare const findRootError: (v: unknown, match?: {
|
|
20
|
+
code?: string;
|
|
21
|
+
}) => ParsedError | null;
|
|
22
|
+
/**
|
|
23
|
+
* Find the root error from an unknown value and throw if one is not found.
|
|
24
|
+
*/
|
|
25
|
+
export declare const asRootError: (v: unknown, match?: {
|
|
26
|
+
code?: string;
|
|
27
|
+
}) => Omit<ParsedError, "cause"> & Required<Pick<ParsedError, "cause">>;
|
|
28
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACjD,KAAK,CAAC,EAAE,UAAU,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,UAAU,GAAG,WAAW,CAAA;IAChC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,QAAS,OAAO,KAAG,IAAI,GAAG,WAsBhD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,MACrB,OAAO,UACF;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KACxB,WAAW,GAAG,IAKhB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,MACnB,OAAO,UACF;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KACxB,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,GAC3B,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAMpC,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isError, isObject } from '@vltpkg/types';
|
|
2
|
+
/**
|
|
3
|
+
* Parse an unknown value into an error. Will also take enumerable properties
|
|
4
|
+
* from legacy style Node errors and treat them as the cause.
|
|
5
|
+
*/
|
|
6
|
+
export const parseError = (err) => {
|
|
7
|
+
if (!isError(err)) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
// Assume that if the error has enumerable properties, then
|
|
11
|
+
// it is a legacy error and does not also have a cause.
|
|
12
|
+
const enumerable = Object.fromEntries(Object.entries(err));
|
|
13
|
+
if (Object.keys(enumerable).length) {
|
|
14
|
+
err.cause = enumerable;
|
|
15
|
+
return err;
|
|
16
|
+
}
|
|
17
|
+
if (isObject(err.cause)) {
|
|
18
|
+
if (isError(err.cause.cause)) {
|
|
19
|
+
err.cause.cause = parseError(err.cause.cause);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else if (isError(err.cause)) {
|
|
23
|
+
err.cause = parseError(err.cause);
|
|
24
|
+
}
|
|
25
|
+
return err;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Find the root error from an unknown value, optionally matching a code.
|
|
29
|
+
*/
|
|
30
|
+
export const findRootError = (v, match) => {
|
|
31
|
+
const err = parseError(v);
|
|
32
|
+
return !err || (match?.code && err.cause?.code !== match.code) ?
|
|
33
|
+
null
|
|
34
|
+
: err;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Find the root error from an unknown value and throw if one is not found.
|
|
38
|
+
*/
|
|
39
|
+
export const asRootError = (v, match) => {
|
|
40
|
+
const err = findRootError(v, match);
|
|
41
|
+
if (!err)
|
|
42
|
+
throw v;
|
|
43
|
+
err.cause = err.cause ?? {};
|
|
44
|
+
return err;
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAcjD;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAY,EAAsB,EAAE;IAC7D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAClB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,2DAA2D;IAC3D,uDAAuD;IACvD,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAA;IAC1D,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,EAAE,CAAC;QACnC,GAAG,CAAC,KAAK,GAAG,UAAU,CAAA;QACtB,OAAO,GAAkB,CAAA;IAC3B,CAAC;IAED,IAAI,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACxB,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC/C,CAAC;IACH,CAAC;SAAM,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,GAAG,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACnC,CAAC;IAED,OAAO,GAAkB,CAAA;AAC3B,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,CAAU,EACV,KAAyB,EACL,EAAE;IACtB,MAAM,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;IACzB,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,EAAE,IAAI,IAAI,GAAG,CAAC,KAAK,EAAE,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5D,IAAI;QACN,CAAC,CAAC,GAAG,CAAA;AACT,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,CAAU,EACV,KAAyB,EAEY,EAAE;IACvC,MAAM,GAAG,GAAG,aAAa,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;IACnC,IAAI,CAAC,GAAG;QAAE,MAAM,CAAC,CAAA;IACjB,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,IAAI,EAAE,CAAA;IAC3B,OAAO,GAC+B,CAAA;AACxC,CAAC,CAAA","sourcesContent":["import { isError, isObject } from '@vltpkg/types'\n\nexport type ErrorCause = Record<string, unknown> & {\n cause?: ErrorCause\n}\n\nexport type ParsedError = {\n name: string\n message: string\n stack?: string\n cause?: ErrorCause | ParsedError\n [key: string]: unknown\n}\n\n/**\n * Parse an unknown value into an error. Will also take enumerable properties\n * from legacy style Node errors and treat them as the cause.\n */\nexport const parseError = (err: unknown): null | ParsedError => {\n if (!isError(err)) {\n return null\n }\n\n // Assume that if the error has enumerable properties, then\n // it is a legacy error and does not also have a cause.\n const enumerable = Object.fromEntries(Object.entries(err))\n if (Object.keys(enumerable).length) {\n err.cause = enumerable\n return err as ParsedError\n }\n\n if (isObject(err.cause)) {\n if (isError(err.cause.cause)) {\n err.cause.cause = parseError(err.cause.cause)\n }\n } else if (isError(err.cause)) {\n err.cause = parseError(err.cause)\n }\n\n return err as ParsedError\n}\n\n/**\n * Find the root error from an unknown value, optionally matching a code.\n */\nexport const findRootError = (\n v: unknown,\n match?: { code?: string },\n): ParsedError | null => {\n const err = parseError(v)\n return !err || (match?.code && err.cause?.code !== match.code) ?\n null\n : err\n}\n\n/**\n * Find the root error from an unknown value and throw if one is not found.\n */\nexport const asRootError = (\n v: unknown,\n match?: { code?: string },\n): Omit<ParsedError, 'cause'> &\n Required<Pick<ParsedError, 'cause'>> => {\n const err = findRootError(v, match)\n if (!err) throw v\n err.cause = err.cause ?? {}\n return err as Omit<ParsedError, 'cause'> &\n Required<Pick<ParsedError, 'cause'>>\n}\n"]}
|
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,aAAa,CAAA;AAatC,MAAM,OAAO,aAAa;IAChB,OAAO,GAAG,IAAI,YAAY,EAAE,CAAA;IAEpC,IAAI,CAAyB,SAAY,EAAE,OAAkB;QAC3D,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IACvC,CAAC;IAED,EAAE,CACA,SAAY,EACZ,OAAqC;QAErC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IACrC,CAAC;IAED,GAAG,CACD,SAAY,EACZ,OAAqC;QAErC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IACtC,CAAC;CACF;AAED,+CAA+C;AAC/C,6DAA6D;AAC7D,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,aAAa,EAAE,CAAA;AAE1C,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,GAAiB,EACjB,KAAiC,EACjC,EAAE;IACF,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAA;AACzC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAiC,EAAE,EAAE;IAC7D,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAA;IACnD,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;AACjE,CAAC,CAAA","sourcesContent":["import EventEmitter from 'node:events'\n\nexport type Events = {\n request: {\n url: URL | string\n state: 'start' | 'complete' | '304' | 'cache'\n }\n graphStep: {\n step: 'build' | 'actual' | 'reify'\n state: 'start' | 'stop'\n }\n}\n\nexport class OutputEmitter {\n private emitter = new EventEmitter()\n\n emit<T extends keyof Events>(eventName: T, payload: Events[T]) {\n this.emitter.emit(eventName, payload)\n }\n\n on<T extends keyof Events>(\n eventName: T,\n handler: (payload: Events[T]) => void,\n ) {\n this.emitter.on(eventName, handler)\n }\n\n off<T extends keyof Events>(\n eventName: T,\n handler: (payload: Events[T]) => void,\n ) {\n this.emitter.off(eventName, handler)\n }\n}\n\n// Exported event emitter to coordinate events.\n// There must be one version of output across the entire CLI.\nexport const emitter = new OutputEmitter()\n\nexport const logRequest = (\n url: URL | string,\n state: Events['request']['state'],\n) => {\n emitter.emit('request', { url, state })\n}\n\nexport const graphStep = (step: Events['graphStep']['step']) => {\n emitter.emit('graphStep', { step, state: 'start' })\n return () => emitter.emit('graphStep', { step, state: 'stop' })\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vltpkg/output",
|
|
3
3
|
"description": "Generate output from the vlt CLI",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-21",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
@@ -15,20 +15,23 @@
|
|
|
15
15
|
],
|
|
16
16
|
"exports": {
|
|
17
17
|
"./package.json": "./package.json",
|
|
18
|
-
".": "./src/index.ts"
|
|
18
|
+
".": "./src/index.ts",
|
|
19
|
+
"./error": "./src/error.ts"
|
|
19
20
|
}
|
|
20
21
|
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@vltpkg/types": "0.0.0-21"
|
|
24
|
+
},
|
|
21
25
|
"devDependencies": {
|
|
22
|
-
"@eslint/js": "^9.
|
|
23
|
-
"@types/
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"prettier": "^3.4.2",
|
|
26
|
+
"@eslint/js": "^9.28.0",
|
|
27
|
+
"@types/node": "^22.15.29",
|
|
28
|
+
"eslint": "^9.28.0",
|
|
29
|
+
"prettier": "^3.6.0",
|
|
27
30
|
"tap": "^21.1.0",
|
|
28
31
|
"tshy": "^3.0.2",
|
|
29
|
-
"typedoc": "0.27.
|
|
32
|
+
"typedoc": "~0.27.9",
|
|
30
33
|
"typescript": "5.7.3",
|
|
31
|
-
"typescript-eslint": "^8.
|
|
34
|
+
"typescript-eslint": "^8.33.1"
|
|
32
35
|
},
|
|
33
36
|
"license": "BSD-2-Clause-Patent",
|
|
34
37
|
"engines": {
|
|
@@ -47,6 +50,12 @@
|
|
|
47
50
|
"types": "./dist/esm/index.d.ts",
|
|
48
51
|
"default": "./dist/esm/index.js"
|
|
49
52
|
}
|
|
53
|
+
},
|
|
54
|
+
"./error": {
|
|
55
|
+
"import": {
|
|
56
|
+
"types": "./dist/esm/error.d.ts",
|
|
57
|
+
"default": "./dist/esm/error.js"
|
|
58
|
+
}
|
|
50
59
|
}
|
|
51
60
|
},
|
|
52
61
|
"files": [
|
|
@@ -60,6 +69,7 @@
|
|
|
60
69
|
"snap": "tap",
|
|
61
70
|
"test": "tap",
|
|
62
71
|
"posttest": "tsc --noEmit",
|
|
72
|
+
"tshy": "tshy",
|
|
63
73
|
"typecheck": "tsc --noEmit"
|
|
64
74
|
}
|
|
65
75
|
}
|