@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.
- package/README.md +252 -240
- package/dist/__sw__.js +31 -5
- package/dist/{child_process-bGGe8mTj.cjs → child_process-DldQfPd9.cjs} +7431 -7435
- package/dist/child_process-DldQfPd9.cjs.map +1 -0
- package/dist/{child_process-CgnmoilU.js → child_process-eiM1_nmq.js} +8231 -8234
- package/dist/child_process-eiM1_nmq.js.map +1 -0
- package/dist/cross-origin.d.ts +2 -0
- package/dist/{index-DZpqX03n.js → index-CK6KRbI1.js} +37316 -36899
- package/dist/index-CK6KRbI1.js.map +1 -0
- package/dist/{index-NinyWmnj.cjs → index-DfyUKyNH.cjs} +39254 -38824
- package/dist/index-DfyUKyNH.cjs.map +1 -0
- package/dist/index.cjs +67 -67
- package/dist/index.mjs +61 -61
- package/dist/isolation-helpers.d.ts +3 -0
- package/dist/packages/archive-extractor.d.ts +2 -0
- package/dist/packages/version-resolver.d.ts +1 -0
- package/dist/request-proxy.d.ts +3 -0
- package/dist/script-engine.d.ts +1 -1
- package/dist/sdk/nodepod.d.ts +58 -58
- package/dist/sdk/types.d.ts +3 -0
- package/dist/threading/offload-types.d.ts +1 -0
- package/package.json +97 -97
- package/src/cross-origin.ts +75 -26
- package/src/iframe-sandbox.ts +145 -141
- package/src/isolation-helpers.ts +154 -148
- package/src/packages/archive-extractor.ts +251 -248
- package/src/packages/installer.ts +1 -0
- package/src/packages/version-resolver.ts +2 -0
- package/src/polyfills/net.ts +353 -353
- package/src/polyfills/util.ts +559 -559
- package/src/polyfills/worker_threads.ts +326 -326
- package/src/request-proxy.ts +43 -9
- package/src/script-engine.ts +3733 -3722
- package/src/sdk/nodepod.ts +8 -0
- package/src/sdk/types.ts +3 -0
- package/src/shell/shell-builtins.ts +19 -19
- package/src/threading/offload-types.ts +113 -112
- package/src/threading/offload-worker.ts +15 -0
- package/dist/child_process-CgnmoilU.js.map +0 -1
- package/dist/child_process-bGGe8mTj.cjs.map +0 -1
- package/dist/index-DZpqX03n.js.map +0 -1
- package/dist/index-NinyWmnj.cjs.map +0 -1
package/src/sdk/nodepod.ts
CHANGED
|
@@ -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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
export type
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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[] = [];
|