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