@scelar/nodepod 1.0.0
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/LICENSE +43 -0
- package/README.md +240 -0
- package/dist/child_process-BJOMsZje.js +8233 -0
- package/dist/child_process-BJOMsZje.js.map +1 -0
- package/dist/child_process-Cj8vOcuc.cjs +7434 -0
- package/dist/child_process-Cj8vOcuc.cjs.map +1 -0
- package/dist/index-Cb1Cgdnd.js +35308 -0
- package/dist/index-Cb1Cgdnd.js.map +1 -0
- package/dist/index-DsMGS-xc.cjs +37195 -0
- package/dist/index-DsMGS-xc.cjs.map +1 -0
- package/dist/index.cjs +65 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +59 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +95 -0
- package/src/__tests__/smoke.test.ts +11 -0
- package/src/constants/cdn-urls.ts +18 -0
- package/src/constants/config.ts +236 -0
- package/src/cross-origin.ts +26 -0
- package/src/engine-factory.ts +176 -0
- package/src/engine-types.ts +56 -0
- package/src/helpers/byte-encoding.ts +39 -0
- package/src/helpers/digest.ts +9 -0
- package/src/helpers/event-loop.ts +96 -0
- package/src/helpers/wasm-cache.ts +133 -0
- package/src/iframe-sandbox.ts +141 -0
- package/src/index.ts +192 -0
- package/src/isolation-helpers.ts +148 -0
- package/src/memory-volume.ts +941 -0
- package/src/module-transformer.ts +368 -0
- package/src/packages/archive-extractor.ts +248 -0
- package/src/packages/browser-bundler.ts +284 -0
- package/src/packages/installer.ts +396 -0
- package/src/packages/registry-client.ts +131 -0
- package/src/packages/version-resolver.ts +411 -0
- package/src/polyfills/assert.ts +384 -0
- package/src/polyfills/async_hooks.ts +144 -0
- package/src/polyfills/buffer.ts +628 -0
- package/src/polyfills/child_process.ts +2288 -0
- package/src/polyfills/chokidar.ts +336 -0
- package/src/polyfills/cluster.ts +106 -0
- package/src/polyfills/console.ts +136 -0
- package/src/polyfills/constants.ts +123 -0
- package/src/polyfills/crypto.ts +885 -0
- package/src/polyfills/dgram.ts +87 -0
- package/src/polyfills/diagnostics_channel.ts +76 -0
- package/src/polyfills/dns.ts +134 -0
- package/src/polyfills/domain.ts +68 -0
- package/src/polyfills/esbuild.ts +854 -0
- package/src/polyfills/events.ts +276 -0
- package/src/polyfills/fs.ts +2888 -0
- package/src/polyfills/fsevents.ts +79 -0
- package/src/polyfills/http.ts +1449 -0
- package/src/polyfills/http2.ts +199 -0
- package/src/polyfills/https.ts +76 -0
- package/src/polyfills/inspector.ts +62 -0
- package/src/polyfills/lightningcss.ts +105 -0
- package/src/polyfills/module.ts +191 -0
- package/src/polyfills/net.ts +353 -0
- package/src/polyfills/os.ts +238 -0
- package/src/polyfills/path.ts +206 -0
- package/src/polyfills/perf_hooks.ts +102 -0
- package/src/polyfills/process.ts +690 -0
- package/src/polyfills/punycode.ts +159 -0
- package/src/polyfills/querystring.ts +93 -0
- package/src/polyfills/quic.ts +118 -0
- package/src/polyfills/readdirp.ts +229 -0
- package/src/polyfills/readline.ts +692 -0
- package/src/polyfills/repl.ts +134 -0
- package/src/polyfills/rollup.ts +119 -0
- package/src/polyfills/sea.ts +33 -0
- package/src/polyfills/sqlite.ts +78 -0
- package/src/polyfills/stream.ts +1620 -0
- package/src/polyfills/string_decoder.ts +25 -0
- package/src/polyfills/tailwindcss-oxide.ts +309 -0
- package/src/polyfills/test.ts +197 -0
- package/src/polyfills/timers.ts +32 -0
- package/src/polyfills/tls.ts +105 -0
- package/src/polyfills/trace_events.ts +50 -0
- package/src/polyfills/tty.ts +71 -0
- package/src/polyfills/url.ts +174 -0
- package/src/polyfills/util.ts +559 -0
- package/src/polyfills/v8.ts +126 -0
- package/src/polyfills/vm.ts +132 -0
- package/src/polyfills/volume-registry.ts +15 -0
- package/src/polyfills/wasi.ts +44 -0
- package/src/polyfills/worker_threads.ts +326 -0
- package/src/polyfills/ws.ts +595 -0
- package/src/polyfills/zlib.ts +881 -0
- package/src/request-proxy.ts +716 -0
- package/src/script-engine.ts +3375 -0
- package/src/sdk/nodepod-fs.ts +93 -0
- package/src/sdk/nodepod-process.ts +86 -0
- package/src/sdk/nodepod-terminal.ts +350 -0
- package/src/sdk/nodepod.ts +509 -0
- package/src/sdk/types.ts +70 -0
- package/src/shell/commands/bun.ts +121 -0
- package/src/shell/commands/directory.ts +297 -0
- package/src/shell/commands/file-ops.ts +525 -0
- package/src/shell/commands/git.ts +2142 -0
- package/src/shell/commands/node.ts +80 -0
- package/src/shell/commands/npm.ts +198 -0
- package/src/shell/commands/pm-types.ts +45 -0
- package/src/shell/commands/pnpm.ts +82 -0
- package/src/shell/commands/search.ts +264 -0
- package/src/shell/commands/shell-env.ts +352 -0
- package/src/shell/commands/text-processing.ts +1152 -0
- package/src/shell/commands/yarn.ts +84 -0
- package/src/shell/shell-builtins.ts +19 -0
- package/src/shell/shell-helpers.ts +250 -0
- package/src/shell/shell-interpreter.ts +514 -0
- package/src/shell/shell-parser.ts +429 -0
- package/src/shell/shell-types.ts +85 -0
- package/src/syntax-transforms.ts +561 -0
- package/src/threading/engine-worker.ts +64 -0
- package/src/threading/inline-worker.ts +372 -0
- package/src/threading/offload-types.ts +112 -0
- package/src/threading/offload-worker.ts +383 -0
- package/src/threading/offload.ts +271 -0
- package/src/threading/process-context.ts +92 -0
- package/src/threading/process-handle.ts +275 -0
- package/src/threading/process-manager.ts +956 -0
- package/src/threading/process-worker-entry.ts +854 -0
- package/src/threading/shared-vfs.ts +352 -0
- package/src/threading/sync-channel.ts +135 -0
- package/src/threading/task-queue.ts +177 -0
- package/src/threading/vfs-bridge.ts +231 -0
- package/src/threading/worker-pool.ts +233 -0
- package/src/threading/worker-protocol.ts +358 -0
- package/src/threading/worker-vfs.ts +218 -0
- package/src/types/externals.d.ts +38 -0
- package/src/types/fs-streams.ts +142 -0
- package/src/types/manifest.ts +17 -0
- package/src/worker-sandbox.ts +90 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
// Node.js assert polyfill
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/* ------------------------------------------------------------------ */
|
|
5
|
+
/* AssertionError */
|
|
6
|
+
/* ------------------------------------------------------------------ */
|
|
7
|
+
|
|
8
|
+
export interface AssertionError extends Error {
|
|
9
|
+
actual: unknown;
|
|
10
|
+
expected: unknown;
|
|
11
|
+
operator: string;
|
|
12
|
+
generatedMessage: boolean;
|
|
13
|
+
code: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface AssertionErrorConstructor {
|
|
17
|
+
new (info: {
|
|
18
|
+
message?: string;
|
|
19
|
+
actual?: unknown;
|
|
20
|
+
expected?: unknown;
|
|
21
|
+
operator?: string;
|
|
22
|
+
stackStartFn?: Function;
|
|
23
|
+
}): AssertionError;
|
|
24
|
+
(this: any, info: {
|
|
25
|
+
message?: string;
|
|
26
|
+
actual?: unknown;
|
|
27
|
+
expected?: unknown;
|
|
28
|
+
operator?: string;
|
|
29
|
+
stackStartFn?: Function;
|
|
30
|
+
}): void;
|
|
31
|
+
prototype: any;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const AssertionError = function AssertionError(this: any, info: {
|
|
35
|
+
message?: string;
|
|
36
|
+
actual?: unknown;
|
|
37
|
+
expected?: unknown;
|
|
38
|
+
operator?: string;
|
|
39
|
+
stackStartFn?: Function;
|
|
40
|
+
}) {
|
|
41
|
+
if (!this) return;
|
|
42
|
+
const text =
|
|
43
|
+
info.message ??
|
|
44
|
+
`${formatValue(info.actual)} ${info.operator ?? '=='} ${formatValue(info.expected)}`;
|
|
45
|
+
Error.call(this, text);
|
|
46
|
+
this.message = text;
|
|
47
|
+
this.name = 'AssertionError';
|
|
48
|
+
this.actual = info.actual;
|
|
49
|
+
this.expected = info.expected;
|
|
50
|
+
this.operator = info.operator ?? '';
|
|
51
|
+
this.generatedMessage = !info.message;
|
|
52
|
+
this.code = 'ERR_ASSERTION';
|
|
53
|
+
if (Error.captureStackTrace && info.stackStartFn) {
|
|
54
|
+
Error.captureStackTrace(this, info.stackStartFn);
|
|
55
|
+
}
|
|
56
|
+
} as unknown as AssertionErrorConstructor;
|
|
57
|
+
|
|
58
|
+
Object.setPrototypeOf(AssertionError.prototype, Error.prototype);
|
|
59
|
+
|
|
60
|
+
function formatValue(v: unknown): string {
|
|
61
|
+
try { return JSON.stringify(v); } catch { return String(v); }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* ------------------------------------------------------------------ */
|
|
65
|
+
/* Deep comparison engine */
|
|
66
|
+
/* ------------------------------------------------------------------ */
|
|
67
|
+
|
|
68
|
+
function deepMatch(a: unknown, b: unknown): boolean {
|
|
69
|
+
if (Object.is(a, b)) return true;
|
|
70
|
+
if (a === null || b === null || a === undefined || b === undefined) return a === b;
|
|
71
|
+
if (typeof a !== typeof b) return false;
|
|
72
|
+
|
|
73
|
+
// NaN
|
|
74
|
+
if (typeof a === 'number' && Number.isNaN(a) && Number.isNaN(b as number)) return true;
|
|
75
|
+
|
|
76
|
+
// Dates
|
|
77
|
+
if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
|
|
78
|
+
|
|
79
|
+
// RegExp
|
|
80
|
+
if (a instanceof RegExp && b instanceof RegExp)
|
|
81
|
+
return a.source === b.source && a.flags === b.flags;
|
|
82
|
+
|
|
83
|
+
// Arrays
|
|
84
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
85
|
+
if (a.length !== b.length) return false;
|
|
86
|
+
for (let i = 0; i < a.length; i++) if (!deepMatch(a[i], b[i])) return false;
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Typed arrays
|
|
91
|
+
if (a instanceof Uint8Array && b instanceof Uint8Array) {
|
|
92
|
+
if (a.length !== b.length) return false;
|
|
93
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Map
|
|
98
|
+
if (a instanceof Map && b instanceof Map) {
|
|
99
|
+
if (a.size !== b.size) return false;
|
|
100
|
+
for (const [k, v] of a) if (!b.has(k) || !deepMatch(v, b.get(k))) return false;
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Set
|
|
105
|
+
if (a instanceof Set && b instanceof Set) {
|
|
106
|
+
if (a.size !== b.size) return false;
|
|
107
|
+
for (const v of a) {
|
|
108
|
+
if (!b.has(v)) {
|
|
109
|
+
let found = false;
|
|
110
|
+
for (const bv of b) { if (deepMatch(v, bv)) { found = true; break; } }
|
|
111
|
+
if (!found) return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Plain objects
|
|
118
|
+
if (typeof a === 'object' && typeof b === 'object') {
|
|
119
|
+
const ka = Object.keys(a as object);
|
|
120
|
+
const kb = Object.keys(b as object);
|
|
121
|
+
if (ka.length !== kb.length) return false;
|
|
122
|
+
for (const k of ka) {
|
|
123
|
+
if (!Object.prototype.hasOwnProperty.call(b, k)) return false;
|
|
124
|
+
if (!deepMatch((a as any)[k], (b as any)[k])) return false;
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/* ------------------------------------------------------------------ */
|
|
133
|
+
/* Throw helper */
|
|
134
|
+
/* ------------------------------------------------------------------ */
|
|
135
|
+
|
|
136
|
+
function raiseIf(cond: boolean, info: ConstructorParameters<typeof AssertionError>[0], msg?: string | Error): void {
|
|
137
|
+
if (!cond) return;
|
|
138
|
+
if (msg instanceof Error) throw msg;
|
|
139
|
+
if (msg !== undefined) info.message = msg;
|
|
140
|
+
throw new AssertionError(info);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/* ------------------------------------------------------------------ */
|
|
144
|
+
/* Main assert function */
|
|
145
|
+
/* ------------------------------------------------------------------ */
|
|
146
|
+
|
|
147
|
+
function assert(value: unknown, message?: string | Error): asserts value {
|
|
148
|
+
raiseIf(!value, { actual: value, expected: true, operator: '==', stackStartFn: assert }, message ?? 'Value is falsy');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/* ---- ok ---- */
|
|
152
|
+
|
|
153
|
+
assert.ok = function ok(value: unknown, message?: string | Error): asserts value {
|
|
154
|
+
raiseIf(!value, { actual: value, expected: true, operator: '==', stackStartFn: ok }, message ?? 'Value is falsy');
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/* ---- equal / notEqual (loose) ---- */
|
|
158
|
+
|
|
159
|
+
assert.equal = function equal(actual: unknown, expected: unknown, message?: string | Error): void {
|
|
160
|
+
raiseIf(actual != expected, { actual, expected, operator: '==', stackStartFn: equal }, message);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
assert.notEqual = function notEqual(actual: unknown, expected: unknown, message?: string | Error): void {
|
|
164
|
+
raiseIf(actual == expected, { actual, expected, operator: '!=', stackStartFn: notEqual }, message);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/* ---- strictEqual / notStrictEqual ---- */
|
|
168
|
+
|
|
169
|
+
assert.strictEqual = function strictEqual(actual: unknown, expected: unknown, message?: string | Error): void {
|
|
170
|
+
raiseIf(actual !== expected, { actual, expected, operator: '===', stackStartFn: strictEqual }, message);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
assert.notStrictEqual = function notStrictEqual(actual: unknown, expected: unknown, message?: string | Error): void {
|
|
174
|
+
raiseIf(actual === expected, { actual, expected, operator: '!==', stackStartFn: notStrictEqual }, message);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/* ---- deepEqual / deepStrictEqual ---- */
|
|
178
|
+
|
|
179
|
+
assert.deepEqual = function deepEqual<T>(actual: T, expected: T, message?: string | Error): void {
|
|
180
|
+
raiseIf(!deepMatch(actual, expected), { actual, expected, operator: 'deepEqual', stackStartFn: deepEqual }, message);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
assert.deepStrictEqual = function deepStrictEqual<T>(actual: T, expected: T, message?: string | Error): void {
|
|
184
|
+
raiseIf(!deepMatch(actual, expected), { actual, expected, operator: 'deepStrictEqual', stackStartFn: deepStrictEqual }, message);
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
assert.notDeepStrictEqual = function notDeepStrictEqual<T>(actual: T, expected: T, message?: string | Error): void {
|
|
188
|
+
raiseIf(deepMatch(actual, expected), { actual, expected, operator: 'notDeepStrictEqual', stackStartFn: notDeepStrictEqual }, message);
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/* ---- throws ---- */
|
|
192
|
+
|
|
193
|
+
assert.throws = function throws(
|
|
194
|
+
fn: () => unknown,
|
|
195
|
+
validatorOrMsg?: RegExp | Function | Error | { message?: RegExp | string; code?: string } | string,
|
|
196
|
+
msg?: string
|
|
197
|
+
): void {
|
|
198
|
+
let caught = false;
|
|
199
|
+
let thrown: unknown;
|
|
200
|
+
try { fn(); } catch (e) { caught = true; thrown = e; }
|
|
201
|
+
|
|
202
|
+
if (!caught) {
|
|
203
|
+
throw new AssertionError({
|
|
204
|
+
message: typeof validatorOrMsg === 'string' ? validatorOrMsg : (msg ?? 'Expected function to throw'),
|
|
205
|
+
operator: 'throws',
|
|
206
|
+
stackStartFn: throws,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (validatorOrMsg !== undefined && typeof validatorOrMsg !== 'string') {
|
|
211
|
+
validateThrown(thrown, validatorOrMsg, msg, throws);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
/* ---- doesNotThrow ---- */
|
|
216
|
+
|
|
217
|
+
assert.doesNotThrow = function doesNotThrow(
|
|
218
|
+
fn: () => unknown,
|
|
219
|
+
validatorOrMsg?: RegExp | Function | string,
|
|
220
|
+
msg?: string
|
|
221
|
+
): void {
|
|
222
|
+
try { fn(); } catch (e) {
|
|
223
|
+
if (validatorOrMsg === undefined || typeof validatorOrMsg === 'string') {
|
|
224
|
+
throw new AssertionError({
|
|
225
|
+
message: typeof validatorOrMsg === 'string' ? validatorOrMsg : (msg ?? 'Unexpected throw'),
|
|
226
|
+
actual: e, operator: 'doesNotThrow', stackStartFn: doesNotThrow,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
if (validatorOrMsg instanceof RegExp) {
|
|
230
|
+
const m = e instanceof Error ? e.message : String(e);
|
|
231
|
+
if (validatorOrMsg.test(m)) {
|
|
232
|
+
throw new AssertionError({ message: msg ?? 'Unexpected matching throw', actual: e, expected: validatorOrMsg, operator: 'doesNotThrow', stackStartFn: doesNotThrow });
|
|
233
|
+
}
|
|
234
|
+
} else if (typeof validatorOrMsg === 'function' && e instanceof (validatorOrMsg as any)) {
|
|
235
|
+
throw new AssertionError({ message: msg ?? 'Unexpected throw of matching type', actual: e, expected: validatorOrMsg, operator: 'doesNotThrow', stackStartFn: doesNotThrow });
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
/* ---- rejects ---- */
|
|
241
|
+
|
|
242
|
+
assert.rejects = async function rejects(
|
|
243
|
+
asyncFn: Promise<unknown> | (() => Promise<unknown>),
|
|
244
|
+
validatorOrMsg?: RegExp | Function | Error | { message?: RegExp | string; code?: string } | string,
|
|
245
|
+
msg?: string
|
|
246
|
+
): Promise<void> {
|
|
247
|
+
const p = typeof asyncFn === 'function' ? asyncFn() : asyncFn;
|
|
248
|
+
let caught = false;
|
|
249
|
+
let thrown: unknown;
|
|
250
|
+
try { await p; } catch (e) { caught = true; thrown = e; }
|
|
251
|
+
|
|
252
|
+
if (!caught) {
|
|
253
|
+
throw new AssertionError({
|
|
254
|
+
message: typeof validatorOrMsg === 'string' ? validatorOrMsg : (msg ?? 'Expected rejection'),
|
|
255
|
+
operator: 'rejects', stackStartFn: rejects,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (validatorOrMsg !== undefined && typeof validatorOrMsg !== 'string') {
|
|
260
|
+
validateThrown(thrown, validatorOrMsg, msg, rejects);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
/* ---- doesNotReject ---- */
|
|
265
|
+
|
|
266
|
+
assert.doesNotReject = async function doesNotReject(
|
|
267
|
+
asyncFn: Promise<unknown> | (() => Promise<unknown>),
|
|
268
|
+
validatorOrMsg?: RegExp | Function | string,
|
|
269
|
+
msg?: string
|
|
270
|
+
): Promise<void> {
|
|
271
|
+
const p = typeof asyncFn === 'function' ? asyncFn() : asyncFn;
|
|
272
|
+
try { await p; } catch (e) {
|
|
273
|
+
if (validatorOrMsg === undefined || typeof validatorOrMsg === 'string') {
|
|
274
|
+
throw new AssertionError({
|
|
275
|
+
message: typeof validatorOrMsg === 'string' ? validatorOrMsg : (msg ?? 'Unexpected rejection'),
|
|
276
|
+
actual: e, operator: 'doesNotReject', stackStartFn: doesNotReject,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
if (validatorOrMsg instanceof RegExp) {
|
|
280
|
+
const m = e instanceof Error ? e.message : String(e);
|
|
281
|
+
if (validatorOrMsg.test(m)) {
|
|
282
|
+
throw new AssertionError({ message: msg ?? 'Unexpected matching rejection', actual: e, expected: validatorOrMsg, operator: 'doesNotReject', stackStartFn: doesNotReject });
|
|
283
|
+
}
|
|
284
|
+
} else if (typeof validatorOrMsg === 'function' && e instanceof (validatorOrMsg as any)) {
|
|
285
|
+
throw new AssertionError({ message: msg ?? 'Unexpected rejection of matching type', actual: e, expected: validatorOrMsg, operator: 'doesNotReject', stackStartFn: doesNotReject });
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/* ---- fail ---- */
|
|
291
|
+
|
|
292
|
+
assert.fail = function fail(
|
|
293
|
+
msgOrActual?: string | unknown,
|
|
294
|
+
expected?: unknown,
|
|
295
|
+
message?: string,
|
|
296
|
+
operator?: string
|
|
297
|
+
): never {
|
|
298
|
+
if (arguments.length <= 1) {
|
|
299
|
+
throw new AssertionError({
|
|
300
|
+
message: typeof msgOrActual === 'string' ? msgOrActual : 'Failed',
|
|
301
|
+
stackStartFn: fail,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
throw new AssertionError({
|
|
305
|
+
message,
|
|
306
|
+
actual: msgOrActual,
|
|
307
|
+
expected,
|
|
308
|
+
operator: operator ?? 'fail',
|
|
309
|
+
stackStartFn: fail,
|
|
310
|
+
});
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
/* ---- match / doesNotMatch ---- */
|
|
314
|
+
|
|
315
|
+
assert.match = function match(str: string, re: RegExp, message?: string | Error): void {
|
|
316
|
+
raiseIf(!re.test(str), { actual: str, expected: re, operator: 'match', stackStartFn: match }, message);
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
assert.doesNotMatch = function doesNotMatch(str: string, re: RegExp, message?: string | Error): void {
|
|
320
|
+
raiseIf(re.test(str), { actual: str, expected: re, operator: 'doesNotMatch', stackStartFn: doesNotMatch }, message);
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
/* ---- ifError ---- */
|
|
324
|
+
|
|
325
|
+
assert.ifError = function ifError(value: unknown): void {
|
|
326
|
+
if (value === null || value === undefined) return;
|
|
327
|
+
if (value instanceof Error) throw value;
|
|
328
|
+
throw new AssertionError({
|
|
329
|
+
message: `ifError received unwanted value: ${value}`,
|
|
330
|
+
actual: value,
|
|
331
|
+
expected: null,
|
|
332
|
+
operator: 'ifError',
|
|
333
|
+
stackStartFn: ifError,
|
|
334
|
+
});
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
/* ---- metadata ---- */
|
|
338
|
+
|
|
339
|
+
assert.AssertionError = AssertionError;
|
|
340
|
+
assert.strict = assert;
|
|
341
|
+
|
|
342
|
+
/* ------------------------------------------------------------------ */
|
|
343
|
+
/* Internal: validate a thrown/rejected value */
|
|
344
|
+
/* ------------------------------------------------------------------ */
|
|
345
|
+
|
|
346
|
+
function validateThrown(
|
|
347
|
+
thrown: unknown,
|
|
348
|
+
validator: RegExp | Function | Error | { message?: RegExp | string; code?: string },
|
|
349
|
+
msg: string | undefined,
|
|
350
|
+
caller: Function
|
|
351
|
+
): void {
|
|
352
|
+
if (validator instanceof RegExp) {
|
|
353
|
+
const text = thrown instanceof Error ? thrown.message : String(thrown);
|
|
354
|
+
if (!validator.test(text)) {
|
|
355
|
+
throw new AssertionError({ message: msg ?? 'Error message did not match', actual: thrown, expected: validator, operator: 'throws', stackStartFn: caller });
|
|
356
|
+
}
|
|
357
|
+
} else if (typeof validator === 'function') {
|
|
358
|
+
if (!(thrown instanceof (validator as any))) {
|
|
359
|
+
throw new AssertionError({ message: msg ?? 'Error type mismatch', actual: thrown, expected: validator, operator: 'throws', stackStartFn: caller });
|
|
360
|
+
}
|
|
361
|
+
} else if (typeof validator === 'object') {
|
|
362
|
+
const spec = validator as { message?: RegExp | string; code?: string };
|
|
363
|
+
const err = thrown as Error & { code?: string };
|
|
364
|
+
if (spec.message !== undefined) {
|
|
365
|
+
const errMsg = err.message ?? String(thrown);
|
|
366
|
+
if (spec.message instanceof RegExp) {
|
|
367
|
+
if (!spec.message.test(errMsg))
|
|
368
|
+
throw new AssertionError({ message: msg ?? 'Error message mismatch', actual: errMsg, expected: spec.message, operator: 'throws', stackStartFn: caller });
|
|
369
|
+
} else if (errMsg !== spec.message) {
|
|
370
|
+
throw new AssertionError({ message: msg ?? 'Error message mismatch', actual: errMsg, expected: spec.message, operator: 'throws', stackStartFn: caller });
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
if (spec.code !== undefined && err.code !== spec.code) {
|
|
374
|
+
throw new AssertionError({ message: msg ?? 'Error code mismatch', actual: err.code, expected: spec.code, operator: 'throws', stackStartFn: caller });
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/* ------------------------------------------------------------------ */
|
|
380
|
+
/* Exports */
|
|
381
|
+
/* ------------------------------------------------------------------ */
|
|
382
|
+
|
|
383
|
+
export default assert;
|
|
384
|
+
export { assert };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// stub - AsyncLocalStorage uses a simple stack, rest is no-op
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/* ------------------------------------------------------------------ */
|
|
5
|
+
/* AsyncResource */
|
|
6
|
+
/* ------------------------------------------------------------------ */
|
|
7
|
+
|
|
8
|
+
export interface AsyncResource {
|
|
9
|
+
runInAsyncScope<R>(fn: (...a: any[]) => R, thisArg?: unknown, ...args: any[]): R;
|
|
10
|
+
emitDestroy(): this;
|
|
11
|
+
asyncId(): number;
|
|
12
|
+
triggerAsyncId(): number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const AsyncResource = function AsyncResource(this: any, _kind: string, _opts?: object) {
|
|
16
|
+
if (!this) return;
|
|
17
|
+
} as unknown as { new(_kind: string, _opts?: object): AsyncResource; prototype: any; bind<F extends (...a: any[]) => any>(fn: F, _kind?: string): F };
|
|
18
|
+
|
|
19
|
+
AsyncResource.prototype.runInAsyncScope = function runInAsyncScope<R>(
|
|
20
|
+
fn: (...a: any[]) => R,
|
|
21
|
+
thisArg?: unknown,
|
|
22
|
+
...args: any[]
|
|
23
|
+
): R {
|
|
24
|
+
return fn.apply(thisArg, args);
|
|
25
|
+
};
|
|
26
|
+
AsyncResource.prototype.emitDestroy = function emitDestroy() { return this; };
|
|
27
|
+
AsyncResource.prototype.asyncId = function asyncId(): number { return 0; };
|
|
28
|
+
AsyncResource.prototype.triggerAsyncId = function triggerAsyncId(): number { return 0; };
|
|
29
|
+
|
|
30
|
+
AsyncResource.bind = function bind<F extends (...a: any[]) => any>(fn: F, _kind?: string): F {
|
|
31
|
+
return fn;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/* ------------------------------------------------------------------ */
|
|
35
|
+
/* AsyncLocalStorage */
|
|
36
|
+
/* ------------------------------------------------------------------ */
|
|
37
|
+
|
|
38
|
+
export interface AsyncLocalStorage<T> {
|
|
39
|
+
disable(): void;
|
|
40
|
+
getStore(): T | undefined;
|
|
41
|
+
run<R>(store: T, fn: (...args: any[]) => R, ...args: any[]): R;
|
|
42
|
+
exit<R>(fn: (...args: any[]) => R, ...args: any[]): R;
|
|
43
|
+
enterWith(store: T): void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const AsyncLocalStorage = function AsyncLocalStorage(this: any) {
|
|
47
|
+
if (!this) return;
|
|
48
|
+
this._store = undefined;
|
|
49
|
+
} as unknown as { new<T>(): AsyncLocalStorage<T>; prototype: any };
|
|
50
|
+
|
|
51
|
+
AsyncLocalStorage.prototype.disable = function disable(): void {};
|
|
52
|
+
|
|
53
|
+
AsyncLocalStorage.prototype.getStore = function getStore() {
|
|
54
|
+
return this._store;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
AsyncLocalStorage.prototype.run = function run(store: any, fn: (...args: any[]) => any, ...args: any[]) {
|
|
58
|
+
const prev = this._store;
|
|
59
|
+
this._store = store;
|
|
60
|
+
try {
|
|
61
|
+
const result = fn(...args);
|
|
62
|
+
// For async functions, keep the store active until the promise settles
|
|
63
|
+
if (result && typeof (result as any).then === "function") {
|
|
64
|
+
(result as any).then(
|
|
65
|
+
() => { this._store = prev; },
|
|
66
|
+
() => { this._store = prev; },
|
|
67
|
+
);
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
this._store = prev;
|
|
71
|
+
return result;
|
|
72
|
+
} catch (e) {
|
|
73
|
+
this._store = prev;
|
|
74
|
+
throw e;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
AsyncLocalStorage.prototype.exit = function exit(fn: (...args: any[]) => any, ...args: any[]) {
|
|
79
|
+
const prev = this._store;
|
|
80
|
+
this._store = undefined;
|
|
81
|
+
try {
|
|
82
|
+
const result = fn(...args);
|
|
83
|
+
if (result && typeof (result as any).then === "function") {
|
|
84
|
+
(result as any).then(
|
|
85
|
+
() => { this._store = prev; },
|
|
86
|
+
() => { this._store = prev; },
|
|
87
|
+
);
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
this._store = prev;
|
|
91
|
+
return result;
|
|
92
|
+
} catch (e) {
|
|
93
|
+
this._store = prev;
|
|
94
|
+
throw e;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
AsyncLocalStorage.prototype.enterWith = function enterWith(store: any): void {
|
|
99
|
+
this._store = store;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/* ------------------------------------------------------------------ */
|
|
103
|
+
/* Hook API */
|
|
104
|
+
/* ------------------------------------------------------------------ */
|
|
105
|
+
|
|
106
|
+
export interface AsyncHook {
|
|
107
|
+
enable(): AsyncHook;
|
|
108
|
+
disable(): AsyncHook;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function createHook(_callbacks: object): AsyncHook {
|
|
112
|
+
const hook: AsyncHook = {
|
|
113
|
+
enable() {
|
|
114
|
+
return hook;
|
|
115
|
+
},
|
|
116
|
+
disable() {
|
|
117
|
+
return hook;
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
return hook;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function executionAsyncId(): number {
|
|
124
|
+
return 0;
|
|
125
|
+
}
|
|
126
|
+
export function executionAsyncResource(): object {
|
|
127
|
+
return {};
|
|
128
|
+
}
|
|
129
|
+
export function triggerAsyncId(): number {
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/* ------------------------------------------------------------------ */
|
|
134
|
+
/* Default export */
|
|
135
|
+
/* ------------------------------------------------------------------ */
|
|
136
|
+
|
|
137
|
+
export default {
|
|
138
|
+
AsyncResource,
|
|
139
|
+
AsyncLocalStorage,
|
|
140
|
+
createHook,
|
|
141
|
+
executionAsyncId,
|
|
142
|
+
executionAsyncResource,
|
|
143
|
+
triggerAsyncId,
|
|
144
|
+
};
|