@scelar/nodepod 1.0.3 → 1.0.5
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/__sw__.js +642 -642
- package/dist/{child_process-hmVqFcF7.cjs → child_process-B9qsOKHs.cjs} +7434 -7434
- package/dist/child_process-B9qsOKHs.cjs.map +1 -0
- package/dist/{child_process-D6oDN2MX.js → child_process-PY34i_6n.js} +8233 -8233
- package/dist/child_process-PY34i_6n.js.map +1 -0
- package/dist/{index-BO1i013L.cjs → index-CyhVjVJU.cjs} +38383 -37240
- package/dist/index-CyhVjVJU.cjs.map +1 -0
- package/dist/index-D8Hn2kWU.js +36455 -0
- package/dist/index-D8Hn2kWU.js.map +1 -0
- package/dist/index.cjs +67 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +88 -86
- package/dist/index.mjs +61 -59
- package/dist/memory-handler.d.ts +57 -0
- package/dist/memory-volume.d.ts +157 -147
- package/dist/packages/installer.d.ts +44 -41
- package/dist/persistence/idb-cache.d.ts +7 -0
- package/dist/polyfills/wasi.d.ts +45 -4
- package/dist/script-engine.d.ts +84 -81
- package/dist/sdk/nodepod-process.d.ts +29 -28
- package/dist/sdk/nodepod.d.ts +59 -39
- package/dist/sdk/types.d.ts +64 -53
- package/dist/threading/process-manager.d.ts +1 -1
- package/dist/threading/worker-protocol.d.ts +1 -1
- package/package.json +1 -1
- package/src/index.ts +194 -192
- package/src/memory-handler.ts +168 -0
- package/src/memory-volume.ts +78 -8
- package/src/packages/installer.ts +49 -1
- package/src/packages/version-resolver.ts +421 -411
- package/src/persistence/idb-cache.ts +107 -0
- package/src/polyfills/child_process.ts +2288 -2288
- package/src/polyfills/events.ts +6 -2
- package/src/polyfills/fs.ts +2888 -2888
- package/src/polyfills/http.ts +1450 -1449
- package/src/polyfills/process.ts +27 -1
- package/src/polyfills/stream.ts +1621 -1620
- package/src/polyfills/wasi.ts +1306 -44
- package/src/polyfills/zlib.ts +881 -881
- package/src/request-proxy.ts +716 -716
- package/src/script-engine.ts +444 -118
- package/src/sdk/nodepod-process.ts +94 -86
- package/src/sdk/nodepod.ts +571 -509
- package/src/sdk/types.ts +82 -70
- package/src/syntax-transforms.ts +2 -2
- package/src/threading/offload-worker.ts +383 -383
- package/src/threading/offload.ts +271 -271
- package/src/threading/process-manager.ts +967 -956
- package/src/threading/process-worker-entry.ts +858 -854
- package/src/threading/worker-protocol.ts +358 -358
- package/dist/child_process-D6oDN2MX.js.map +0 -1
- package/dist/child_process-hmVqFcF7.cjs.map +0 -1
- package/dist/index-Ale2oba_.js +0 -35412
- package/dist/index-Ale2oba_.js.map +0 -1
- package/dist/index-BO1i013L.cjs.map +0 -1
|
@@ -1,86 +1,94 @@
|
|
|
1
|
-
// Process handle returned by nodepod.spawn().
|
|
2
|
-
// Emits 'output', 'error', 'exit'. Has write() for stdin and kill() to abort.
|
|
3
|
-
|
|
4
|
-
import { EventEmitter } from "../polyfills/events";
|
|
5
|
-
|
|
6
|
-
export class NodepodProcess extends EventEmitter {
|
|
7
|
-
private _abortController = new AbortController();
|
|
8
|
-
private _resolve!: (r: {
|
|
9
|
-
stdout: string;
|
|
10
|
-
stderr: string;
|
|
11
|
-
exitCode: number;
|
|
12
|
-
}) => void;
|
|
13
|
-
private _stdout = "";
|
|
14
|
-
private _stderr = "";
|
|
15
|
-
private _exitCode: number | null = null;
|
|
16
|
-
private _sendStdinFn: ((data: string) => void) | null = null;
|
|
17
|
-
private _killFn: (() => void) | null = null;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
this.emit("
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (this.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
this.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
1
|
+
// Process handle returned by nodepod.spawn().
|
|
2
|
+
// Emits 'output', 'error', 'exit'. Has write() for stdin and kill() to abort.
|
|
3
|
+
|
|
4
|
+
import { EventEmitter } from "../polyfills/events";
|
|
5
|
+
|
|
6
|
+
export class NodepodProcess extends EventEmitter {
|
|
7
|
+
private _abortController = new AbortController();
|
|
8
|
+
private _resolve!: (r: {
|
|
9
|
+
stdout: string;
|
|
10
|
+
stderr: string;
|
|
11
|
+
exitCode: number;
|
|
12
|
+
}) => void;
|
|
13
|
+
private _stdout = "";
|
|
14
|
+
private _stderr = "";
|
|
15
|
+
private _exitCode: number | null = null;
|
|
16
|
+
private _sendStdinFn: ((data: string) => void) | null = null;
|
|
17
|
+
private _killFn: (() => void) | null = null;
|
|
18
|
+
private _maxOutputBytes: number;
|
|
19
|
+
|
|
20
|
+
// Resolves when the process exits -- use `await proc.completion`
|
|
21
|
+
readonly completion: Promise<{
|
|
22
|
+
stdout: string;
|
|
23
|
+
stderr: string;
|
|
24
|
+
exitCode: number;
|
|
25
|
+
}>;
|
|
26
|
+
|
|
27
|
+
constructor(maxOutputBytes = 4_194_304) {
|
|
28
|
+
super();
|
|
29
|
+
this._maxOutputBytes = maxOutputBytes;
|
|
30
|
+
this.completion = new Promise((resolve) => {
|
|
31
|
+
this._resolve = resolve;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_setSendStdin(fn: (data: string) => void): void {
|
|
36
|
+
this._sendStdinFn = fn;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
_setKillFn(fn: () => void): void {
|
|
40
|
+
this._killFn = fn;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
_pushStdout(chunk: string): void {
|
|
44
|
+
this._stdout += chunk;
|
|
45
|
+
if (this._stdout.length > this._maxOutputBytes) {
|
|
46
|
+
this._stdout = this._stdout.slice(-Math.floor(this._maxOutputBytes * 0.75));
|
|
47
|
+
}
|
|
48
|
+
this.emit("output", chunk);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
_pushStderr(chunk: string): void {
|
|
52
|
+
this._stderr += chunk;
|
|
53
|
+
if (this._stderr.length > this._maxOutputBytes) {
|
|
54
|
+
this._stderr = this._stderr.slice(-Math.floor(this._maxOutputBytes * 0.75));
|
|
55
|
+
}
|
|
56
|
+
this.emit("error", chunk);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Idempotent -- safe to call twice
|
|
60
|
+
_finish(exitCode: number): void {
|
|
61
|
+
if (this._exitCode !== null) return;
|
|
62
|
+
this._exitCode = exitCode;
|
|
63
|
+
this.emit("exit", exitCode);
|
|
64
|
+
this._resolve({
|
|
65
|
+
stdout: this._stdout,
|
|
66
|
+
stderr: this._stderr,
|
|
67
|
+
exitCode,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get signal(): AbortSignal {
|
|
72
|
+
return this._abortController.signal;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get exited(): boolean {
|
|
76
|
+
return this._exitCode !== null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
write(data: string): void {
|
|
80
|
+
if (this._sendStdinFn) this._sendStdinFn(data);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
kill(): void {
|
|
84
|
+
this._abortController.abort();
|
|
85
|
+
if (this._killFn) this._killFn();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
on(event: "output", handler: (chunk: string) => void): this;
|
|
89
|
+
on(event: "error", handler: (chunk: string) => void): this;
|
|
90
|
+
on(event: "exit", handler: (code: number) => void): this;
|
|
91
|
+
on(event: string, handler: (...args: any[]) => void): this {
|
|
92
|
+
return super.on(event, handler) as this;
|
|
93
|
+
}
|
|
94
|
+
}
|