@scelar/nodepod 1.0.7 → 1.0.9

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 (42) hide show
  1. package/README.md +252 -240
  2. package/dist/__sw__.js +31 -5
  3. package/dist/{child_process-bGGe8mTj.cjs → child_process-DldQfPd9.cjs} +7431 -7435
  4. package/dist/child_process-DldQfPd9.cjs.map +1 -0
  5. package/dist/{child_process-CgnmoilU.js → child_process-eiM1_nmq.js} +8231 -8234
  6. package/dist/child_process-eiM1_nmq.js.map +1 -0
  7. package/dist/cross-origin.d.ts +2 -0
  8. package/dist/{index-DZpqX03n.js → index-CK6KRbI1.js} +37316 -36899
  9. package/dist/index-CK6KRbI1.js.map +1 -0
  10. package/dist/{index-NinyWmnj.cjs → index-DfyUKyNH.cjs} +39254 -38824
  11. package/dist/index-DfyUKyNH.cjs.map +1 -0
  12. package/dist/index.cjs +67 -67
  13. package/dist/index.mjs +61 -61
  14. package/dist/isolation-helpers.d.ts +3 -0
  15. package/dist/packages/archive-extractor.d.ts +2 -0
  16. package/dist/packages/version-resolver.d.ts +1 -0
  17. package/dist/request-proxy.d.ts +3 -0
  18. package/dist/script-engine.d.ts +1 -1
  19. package/dist/sdk/nodepod.d.ts +58 -58
  20. package/dist/sdk/types.d.ts +3 -0
  21. package/dist/threading/offload-types.d.ts +1 -0
  22. package/package.json +97 -97
  23. package/src/cross-origin.ts +75 -26
  24. package/src/iframe-sandbox.ts +145 -141
  25. package/src/isolation-helpers.ts +154 -148
  26. package/src/packages/archive-extractor.ts +251 -248
  27. package/src/packages/installer.ts +1 -0
  28. package/src/packages/version-resolver.ts +2 -0
  29. package/src/polyfills/net.ts +353 -353
  30. package/src/polyfills/util.ts +559 -559
  31. package/src/polyfills/worker_threads.ts +326 -326
  32. package/src/request-proxy.ts +43 -9
  33. package/src/script-engine.ts +3733 -3722
  34. package/src/sdk/nodepod.ts +8 -0
  35. package/src/sdk/types.ts +3 -0
  36. package/src/shell/shell-builtins.ts +19 -19
  37. package/src/threading/offload-types.ts +113 -112
  38. package/src/threading/offload-worker.ts +15 -0
  39. package/dist/child_process-CgnmoilU.js.map +0 -1
  40. package/dist/child_process-bGGe8mTj.cjs.map +0 -1
  41. package/dist/index-DZpqX03n.js.map +0 -1
  42. package/dist/index-NinyWmnj.cjs.map +0 -1
@@ -18,6 +18,7 @@ import { NodepodFS } from "./nodepod-fs";
18
18
  import { NodepodProcess } from "./nodepod-process";
19
19
  import { NodepodTerminal } from "./nodepod-terminal";
20
20
  import { ProcessManager } from "../threading/process-manager";
21
+ import { setAllowedDomains } from "../cross-origin";
21
22
  import type { ProcessHandle } from "../threading/process-handle";
22
23
  import { VFSBridge } from "../threading/vfs-bridge";
23
24
  import {
@@ -171,6 +172,13 @@ export class Nodepod {
171
172
  onServerReady: opts.onServerReady,
172
173
  });
173
174
 
175
+ // set up fetch domain whitelist (null = allow everything)
176
+ if (opts.allowedFetchDomains === null) {
177
+ setAllowedDomains(null);
178
+ } else {
179
+ setAllowedDomains(opts.allowedFetchDomains ?? []);
180
+ }
181
+
174
182
  const nodepod = new Nodepod(volume, packages, proxy, cwd, handler);
175
183
 
176
184
  if (opts.files) {
package/src/sdk/types.ts CHANGED
@@ -15,6 +15,9 @@ export interface NodepodOptions {
15
15
  memory?: MemoryHandlerOptions;
16
16
  /** Cache installed node_modules in IndexedDB for faster re-boots. Default: true. */
17
17
  enableSnapshotCache?: boolean;
18
+ /** domains allowed through the cors proxy. merged with built-in defaults
19
+ * (npm, github, esm.sh etc). pass null to allow everything */
20
+ allowedFetchDomains?: string[] | null;
18
21
  }
19
22
 
20
23
  /* ---- Terminal ---- */
@@ -1,19 +1,19 @@
1
- // Assembles all builtin commands from category modules into one map.
2
-
3
- import type { BuiltinFn } from "./shell-types";
4
- import { fileOpsCommands } from "./commands/file-ops";
5
- import { directoryCommands } from "./commands/directory";
6
- import { textProcessingCommands } from "./commands/text-processing";
7
- import { searchCommands } from "./commands/search";
8
- import { shellEnvCommands, setBuiltinsRef } from "./commands/shell-env";
9
-
10
- export const builtins = new Map<string, BuiltinFn>([
11
- ...fileOpsCommands,
12
- ...directoryCommands,
13
- ...textProcessingCommands,
14
- ...searchCommands,
15
- ...shellEnvCommands,
16
- ]);
17
-
18
- // shell-env needs the builtins ref for `which` and `type`
19
- setBuiltinsRef(builtins);
1
+ // Assembles all builtin commands from category modules into one map.
2
+
3
+ import type { BuiltinFn } from "./shell-types";
4
+ import { fileOpsCommands } from "./commands/file-ops";
5
+ import { directoryCommands } from "./commands/directory";
6
+ import { textProcessingCommands } from "./commands/text-processing";
7
+ import { searchCommands } from "./commands/search";
8
+ import { shellEnvCommands, setBuiltinsRef } from "./commands/shell-env";
9
+
10
+ export const builtins = new Map<string, BuiltinFn>([
11
+ ...fileOpsCommands,
12
+ ...directoryCommands,
13
+ ...textProcessingCommands,
14
+ ...searchCommands,
15
+ ...shellEnvCommands,
16
+ ]);
17
+
18
+ // shell-env needs the builtins ref for `which` and `type`
19
+ setBuiltinsRef(builtins);
@@ -1,112 +1,113 @@
1
- // Type definitions for the worker offloading system.
2
- // All types must be structured-clone compatible (postMessage-safe).
3
-
4
- // --- Task priority ---
5
-
6
- export enum TaskPriority {
7
- HIGH = 0, // runtime transforms (user waiting)
8
- NORMAL = 1, // install-time bulk transforms
9
- LOW = 2, // background pre-bundling
10
- }
11
-
12
- // --- Transform task ---
13
-
14
- export interface TransformTask {
15
- type: "transform";
16
- id: string;
17
- source: string;
18
- filePath: string;
19
- options?: {
20
- loader?: "js" | "jsx" | "ts" | "tsx";
21
- format?: "cjs" | "esm";
22
- target?: string;
23
- platform?: string;
24
- define?: Record<string, string>;
25
- };
26
- priority: TaskPriority;
27
- }
28
-
29
- export interface TransformResult {
30
- type: "transform";
31
- id: string;
32
- code: string;
33
- warnings: string[];
34
- }
35
-
36
- // --- Extract task ---
37
-
38
- export interface ExtractTask {
39
- type: "extract";
40
- id: string;
41
- tarballUrl: string;
42
- stripComponents: number;
43
- priority: TaskPriority;
44
- }
45
-
46
- export interface ExtractedFile {
47
- path: string;
48
- // UTF-8 text, or base64-encoded binary
49
- data: string;
50
- isBinary: boolean;
51
- }
52
-
53
- export interface ExtractResult {
54
- type: "extract";
55
- id: string;
56
- files: ExtractedFile[];
57
- }
58
-
59
- // --- Build task ---
60
-
61
- export interface BuildTask {
62
- type: "build";
63
- id: string;
64
- files: Record<string, string>;
65
- entryPoints?: string[];
66
- stdin?: { contents: string; resolveDir?: string; loader?: string };
67
- bundle?: boolean;
68
- format?: "iife" | "cjs" | "esm";
69
- platform?: "browser" | "node" | "neutral";
70
- target?: string | string[];
71
- minify?: boolean;
72
- external?: string[];
73
- absWorkingDir?: string;
74
- priority: TaskPriority;
75
- }
76
-
77
- export interface BuildOutputFile {
78
- path: string;
79
- text: string;
80
- }
81
-
82
- export interface BuildResult {
83
- type: "build";
84
- id: string;
85
- outputFiles: BuildOutputFile[];
86
- errors: string[];
87
- warnings: string[];
88
- }
89
-
90
- // --- Union types ---
91
-
92
- export type OffloadTask = TransformTask | ExtractTask | BuildTask;
93
- export type OffloadResult = TransformResult | ExtractResult | BuildResult;
94
-
95
- // --- Worker endpoint (exposed via Comlink) ---
96
-
97
- export interface OffloadWorkerEndpoint {
98
- init(): Promise<void>;
99
- transform(task: TransformTask): Promise<TransformResult>;
100
- extract(task: ExtractTask): Promise<ExtractResult>;
101
- build(task: BuildTask): Promise<BuildResult>;
102
- ping(): boolean;
103
- }
104
-
105
- // --- Pool config ---
106
-
107
- export interface PoolConfig {
108
- minWorkers?: number;
109
- maxWorkers?: number;
110
- idleTimeoutMs?: number;
111
- warmUpOnCreate?: boolean;
112
- }
1
+ // Type definitions for the worker offloading system.
2
+ // All types must be structured-clone compatible (postMessage-safe).
3
+
4
+ // --- Task priority ---
5
+
6
+ export enum TaskPriority {
7
+ HIGH = 0, // runtime transforms (user waiting)
8
+ NORMAL = 1, // install-time bulk transforms
9
+ LOW = 2, // background pre-bundling
10
+ }
11
+
12
+ // --- Transform task ---
13
+
14
+ export interface TransformTask {
15
+ type: "transform";
16
+ id: string;
17
+ source: string;
18
+ filePath: string;
19
+ options?: {
20
+ loader?: "js" | "jsx" | "ts" | "tsx";
21
+ format?: "cjs" | "esm";
22
+ target?: string;
23
+ platform?: string;
24
+ define?: Record<string, string>;
25
+ };
26
+ priority: TaskPriority;
27
+ }
28
+
29
+ export interface TransformResult {
30
+ type: "transform";
31
+ id: string;
32
+ code: string;
33
+ warnings: string[];
34
+ }
35
+
36
+ // --- Extract task ---
37
+
38
+ export interface ExtractTask {
39
+ type: "extract";
40
+ id: string;
41
+ tarballUrl: string;
42
+ stripComponents: number;
43
+ priority: TaskPriority;
44
+ expectedShasum?: string;
45
+ }
46
+
47
+ export interface ExtractedFile {
48
+ path: string;
49
+ // UTF-8 text, or base64-encoded binary
50
+ data: string;
51
+ isBinary: boolean;
52
+ }
53
+
54
+ export interface ExtractResult {
55
+ type: "extract";
56
+ id: string;
57
+ files: ExtractedFile[];
58
+ }
59
+
60
+ // --- Build task ---
61
+
62
+ export interface BuildTask {
63
+ type: "build";
64
+ id: string;
65
+ files: Record<string, string>;
66
+ entryPoints?: string[];
67
+ stdin?: { contents: string; resolveDir?: string; loader?: string };
68
+ bundle?: boolean;
69
+ format?: "iife" | "cjs" | "esm";
70
+ platform?: "browser" | "node" | "neutral";
71
+ target?: string | string[];
72
+ minify?: boolean;
73
+ external?: string[];
74
+ absWorkingDir?: string;
75
+ priority: TaskPriority;
76
+ }
77
+
78
+ export interface BuildOutputFile {
79
+ path: string;
80
+ text: string;
81
+ }
82
+
83
+ export interface BuildResult {
84
+ type: "build";
85
+ id: string;
86
+ outputFiles: BuildOutputFile[];
87
+ errors: string[];
88
+ warnings: string[];
89
+ }
90
+
91
+ // --- Union types ---
92
+
93
+ export type OffloadTask = TransformTask | ExtractTask | BuildTask;
94
+ export type OffloadResult = TransformResult | ExtractResult | BuildResult;
95
+
96
+ // --- Worker endpoint (exposed via Comlink) ---
97
+
98
+ export interface OffloadWorkerEndpoint {
99
+ init(): Promise<void>;
100
+ transform(task: TransformTask): Promise<TransformResult>;
101
+ extract(task: ExtractTask): Promise<ExtractResult>;
102
+ build(task: BuildTask): Promise<BuildResult>;
103
+ ping(): boolean;
104
+ }
105
+
106
+ // --- Pool config ---
107
+
108
+ export interface PoolConfig {
109
+ minWorkers?: number;
110
+ maxWorkers?: number;
111
+ idleTimeoutMs?: number;
112
+ warmUpOnCreate?: boolean;
113
+ }
@@ -267,6 +267,21 @@ const workerEndpoint: OffloadWorkerEndpoint = {
267
267
  }
268
268
 
269
269
  const compressed = new Uint8Array(await response.arrayBuffer());
270
+
271
+ // check sha1 against what the registry told us
272
+ if (task.expectedShasum) {
273
+ const hashBuffer = await crypto.subtle.digest("SHA-1", compressed);
274
+ const hashHex = Array.from(new Uint8Array(hashBuffer))
275
+ .map((b) => b.toString(16).padStart(2, "0"))
276
+ .join("");
277
+ if (hashHex !== task.expectedShasum) {
278
+ throw new Error(
279
+ `Integrity check failed for ${task.tarballUrl}: ` +
280
+ `expected shasum ${task.expectedShasum}, got ${hashHex}`,
281
+ );
282
+ }
283
+ }
284
+
270
285
  const tarBytes = pakoModule.inflate(compressed) as Uint8Array;
271
286
 
272
287
  const files: ExtractedFile[] = [];