@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
package/src/sdk/types.ts CHANGED
@@ -1,70 +1,82 @@
1
- import type { VolumeSnapshot } from "../engine-types";
2
-
3
- /* ---- Boot options ---- */
4
-
5
- export interface NodepodOptions {
6
- files?: Record<string, string | Uint8Array>;
7
- env?: Record<string, string>;
8
- workdir?: string;
9
- swUrl?: string;
10
- onServerReady?: (port: number, url: string) => void;
11
- /** Show a small "nodepod" watermark link in preview iframes. Defaults to true. */
12
- watermark?: boolean;
13
- }
14
-
15
- /* ---- Terminal ---- */
16
-
17
- export interface TerminalTheme {
18
- background?: string;
19
- foreground?: string;
20
- cursor?: string;
21
- selectionBackground?: string;
22
- black?: string;
23
- red?: string;
24
- green?: string;
25
- yellow?: string;
26
- blue?: string;
27
- magenta?: string;
28
- cyan?: string;
29
- white?: string;
30
- brightBlack?: string;
31
- brightRed?: string;
32
- brightGreen?: string;
33
- brightYellow?: string;
34
- brightBlue?: string;
35
- brightMagenta?: string;
36
- brightCyan?: string;
37
- brightWhite?: string;
38
- }
39
-
40
- export interface TerminalOptions {
41
- // xterm.js classes are peer deps, passed in as constructors
42
- Terminal: any;
43
- FitAddon?: any;
44
- WebglAddon?: any;
45
- theme?: TerminalTheme;
46
- fontSize?: number;
47
- fontFamily?: string;
48
- prompt?: (cwd: string) => string;
49
- }
50
-
51
- /* ---- Filesystem ---- */
52
-
53
- export interface StatResult {
54
- isFile: boolean;
55
- isDirectory: boolean;
56
- size: number;
57
- mtime: number;
58
- }
59
-
60
- /* ---- Snapshot ---- */
61
-
62
- export type Snapshot = VolumeSnapshot;
63
-
64
- /* ---- Spawn ---- */
65
-
66
- export interface SpawnOptions {
67
- cwd?: string;
68
- env?: Record<string, string>;
69
- signal?: AbortSignal;
70
- }
1
+ import type { VolumeSnapshot } from "../engine-types";
2
+ import type { MemoryHandlerOptions } from "../memory-handler";
3
+
4
+ /* ---- Boot options ---- */
5
+
6
+ export interface NodepodOptions {
7
+ files?: Record<string, string | Uint8Array>;
8
+ env?: Record<string, string>;
9
+ workdir?: string;
10
+ swUrl?: string;
11
+ onServerReady?: (port: number, url: string) => void;
12
+ /** Show a small "nodepod" watermark link in preview iframes. Defaults to true. */
13
+ watermark?: boolean;
14
+ /** Memory optimization settings. Omit to use defaults. */
15
+ memory?: MemoryHandlerOptions;
16
+ /** Cache installed node_modules in IndexedDB for faster re-boots. Default: true. */
17
+ enableSnapshotCache?: boolean;
18
+ }
19
+
20
+ /* ---- Terminal ---- */
21
+
22
+ export interface TerminalTheme {
23
+ background?: string;
24
+ foreground?: string;
25
+ cursor?: string;
26
+ selectionBackground?: string;
27
+ black?: string;
28
+ red?: string;
29
+ green?: string;
30
+ yellow?: string;
31
+ blue?: string;
32
+ magenta?: string;
33
+ cyan?: string;
34
+ white?: string;
35
+ brightBlack?: string;
36
+ brightRed?: string;
37
+ brightGreen?: string;
38
+ brightYellow?: string;
39
+ brightBlue?: string;
40
+ brightMagenta?: string;
41
+ brightCyan?: string;
42
+ brightWhite?: string;
43
+ }
44
+
45
+ export interface TerminalOptions {
46
+ // xterm.js classes are peer deps, passed in as constructors
47
+ Terminal: any;
48
+ FitAddon?: any;
49
+ WebglAddon?: any;
50
+ theme?: TerminalTheme;
51
+ fontSize?: number;
52
+ fontFamily?: string;
53
+ prompt?: (cwd: string) => string;
54
+ }
55
+
56
+ /* ---- Filesystem ---- */
57
+
58
+ export interface StatResult {
59
+ isFile: boolean;
60
+ isDirectory: boolean;
61
+ size: number;
62
+ mtime: number;
63
+ }
64
+
65
+ /* ---- Snapshot ---- */
66
+
67
+ export type Snapshot = VolumeSnapshot;
68
+
69
+ export interface SnapshotOptions {
70
+ /** Exclude node_modules and other auto-installable dirs. Default: true */
71
+ shallow?: boolean;
72
+ /** Auto-install deps from package.json after restoring a shallow snapshot. Default: true */
73
+ autoInstall?: boolean;
74
+ }
75
+
76
+ /* ---- Spawn ---- */
77
+
78
+ export interface SpawnOptions {
79
+ cwd?: string;
80
+ env?: Record<string, string>;
81
+ signal?: AbortSignal;
82
+ }
@@ -237,7 +237,7 @@ function esmToCjsViaAst(code: string): string {
237
237
  collectEsmCjsPatches(ast as any, code, patches);
238
238
 
239
239
  let output = code;
240
- patches.sort((a, b) => b[0] - a[0]);
240
+ patches.sort((a, b) => b[0] - a[0] || b[1] - a[1]);
241
241
  for (const [s, e, r] of patches)
242
242
  output = output.slice(0, s) + r + output.slice(e);
243
243
  return output;
@@ -439,7 +439,7 @@ export function stripTopLevelAwait(
439
439
  if (patches.length === 0) return code;
440
440
 
441
441
  let output = code;
442
- patches.sort((a, b) => b[0] - a[0]);
442
+ patches.sort((a, b) => b[0] - a[0] || b[1] - a[1]);
443
443
  for (const [start, end, replacement] of patches) {
444
444
  output = output.slice(0, start) + replacement + output.slice(end);
445
445
  }