@secure-exec/core 0.1.0-rc.1

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 (81) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +7 -0
  3. package/dist/bridge/active-handles.d.ts +21 -0
  4. package/dist/bridge/active-handles.js +60 -0
  5. package/dist/bridge/child-process.d.ts +90 -0
  6. package/dist/bridge/child-process.js +606 -0
  7. package/dist/bridge/fs.d.ts +281 -0
  8. package/dist/bridge/fs.js +2151 -0
  9. package/dist/bridge/index.d.ts +10 -0
  10. package/dist/bridge/index.js +41 -0
  11. package/dist/bridge/module.d.ts +75 -0
  12. package/dist/bridge/module.js +308 -0
  13. package/dist/bridge/network.d.ts +249 -0
  14. package/dist/bridge/network.js +1416 -0
  15. package/dist/bridge/os.d.ts +13 -0
  16. package/dist/bridge/os.js +256 -0
  17. package/dist/bridge/polyfills.d.ts +2 -0
  18. package/dist/bridge/polyfills.js +11 -0
  19. package/dist/bridge/process.d.ts +86 -0
  20. package/dist/bridge/process.js +938 -0
  21. package/dist/bridge-setup.d.ts +6 -0
  22. package/dist/bridge-setup.js +9 -0
  23. package/dist/bridge.js +11538 -0
  24. package/dist/esm-compiler.d.ts +14 -0
  25. package/dist/esm-compiler.js +68 -0
  26. package/dist/fs-helpers.d.ts +23 -0
  27. package/dist/fs-helpers.js +41 -0
  28. package/dist/generated/isolate-runtime.d.ts +19 -0
  29. package/dist/generated/isolate-runtime.js +21 -0
  30. package/dist/generated/polyfills.d.ts +82 -0
  31. package/dist/generated/polyfills.js +82 -0
  32. package/dist/index.d.ts +30 -0
  33. package/dist/index.js +25 -0
  34. package/dist/isolate-runtime/apply-custom-global-policy.js +54 -0
  35. package/dist/isolate-runtime/apply-timing-mitigation-freeze.js +44 -0
  36. package/dist/isolate-runtime/apply-timing-mitigation-off.js +14 -0
  37. package/dist/isolate-runtime/bridge-attach.js +29 -0
  38. package/dist/isolate-runtime/bridge-initial-globals.js +246 -0
  39. package/dist/isolate-runtime/eval-script-result.js +8 -0
  40. package/dist/isolate-runtime/global-exposure-helpers.js +36 -0
  41. package/dist/isolate-runtime/init-commonjs-module-globals.js +28 -0
  42. package/dist/isolate-runtime/override-process-cwd.js +8 -0
  43. package/dist/isolate-runtime/override-process-env.js +8 -0
  44. package/dist/isolate-runtime/require-setup.js +650 -0
  45. package/dist/isolate-runtime/set-commonjs-file-globals.js +36 -0
  46. package/dist/isolate-runtime/set-stdin-data.js +10 -0
  47. package/dist/isolate-runtime/setup-dynamic-import.js +64 -0
  48. package/dist/isolate-runtime/setup-fs-facade.js +48 -0
  49. package/dist/module-resolver.d.ts +25 -0
  50. package/dist/module-resolver.js +264 -0
  51. package/dist/package-bundler.d.ts +36 -0
  52. package/dist/package-bundler.js +497 -0
  53. package/dist/python-runtime.d.ts +16 -0
  54. package/dist/python-runtime.js +45 -0
  55. package/dist/runtime-driver.d.ts +62 -0
  56. package/dist/runtime-driver.js +1 -0
  57. package/dist/runtime.d.ts +31 -0
  58. package/dist/runtime.js +69 -0
  59. package/dist/shared/api-types.d.ts +71 -0
  60. package/dist/shared/api-types.js +1 -0
  61. package/dist/shared/bridge-contract.d.ts +302 -0
  62. package/dist/shared/bridge-contract.js +82 -0
  63. package/dist/shared/console-formatter.d.ts +22 -0
  64. package/dist/shared/console-formatter.js +157 -0
  65. package/dist/shared/constants.d.ts +3 -0
  66. package/dist/shared/constants.js +3 -0
  67. package/dist/shared/errors.d.ts +16 -0
  68. package/dist/shared/errors.js +21 -0
  69. package/dist/shared/esm-utils.d.ts +28 -0
  70. package/dist/shared/esm-utils.js +97 -0
  71. package/dist/shared/global-exposure.d.ts +38 -0
  72. package/dist/shared/global-exposure.js +406 -0
  73. package/dist/shared/in-memory-fs.d.ts +42 -0
  74. package/dist/shared/in-memory-fs.js +341 -0
  75. package/dist/shared/permissions.d.ts +38 -0
  76. package/dist/shared/permissions.js +283 -0
  77. package/dist/shared/require-setup.d.ts +6 -0
  78. package/dist/shared/require-setup.js +9 -0
  79. package/dist/types.d.ts +206 -0
  80. package/dist/types.js +1 -0
  81. package/package.json +107 -0
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ (() => {
3
+ // isolate-runtime/src/common/global-access.ts
4
+ function isObjectLike(value) {
5
+ return value !== null && (typeof value === "object" || typeof value === "function");
6
+ }
7
+
8
+ // isolate-runtime/src/common/global-exposure.ts
9
+ function defineRuntimeGlobalBinding(name, value, mutable) {
10
+ Object.defineProperty(globalThis, name, {
11
+ value,
12
+ writable: mutable,
13
+ configurable: mutable,
14
+ enumerable: true
15
+ });
16
+ }
17
+ function createRuntimeGlobalExposer(mutable) {
18
+ return (name, value) => {
19
+ defineRuntimeGlobalBinding(name, value, mutable);
20
+ };
21
+ }
22
+ function getRuntimeExposeCustomGlobal() {
23
+ if (typeof globalThis.__runtimeExposeCustomGlobal === "function") {
24
+ return globalThis.__runtimeExposeCustomGlobal;
25
+ }
26
+ return createRuntimeGlobalExposer(false);
27
+ }
28
+
29
+ // isolate-runtime/src/inject/setup-dynamic-import.ts
30
+ var __runtimeExposeCustomGlobal = getRuntimeExposeCustomGlobal();
31
+ var __dynamicImportConfig = globalThis.__runtimeDynamicImportConfig ?? {};
32
+ var __fallbackReferrer = typeof __dynamicImportConfig.referrerPath === "string" && __dynamicImportConfig.referrerPath.length > 0 ? __dynamicImportConfig.referrerPath : "/";
33
+ var __dynamicImportHandler = async function(specifier, fromPath) {
34
+ const request = String(specifier);
35
+ const referrer = typeof fromPath === "string" && fromPath.length > 0 ? fromPath : __fallbackReferrer;
36
+ const allowRequireFallback = request.endsWith(".cjs") || request.endsWith(".json");
37
+ const namespace = await globalThis._dynamicImport.apply(
38
+ void 0,
39
+ [request, referrer],
40
+ { result: { promise: true } }
41
+ );
42
+ if (namespace !== null) {
43
+ return namespace;
44
+ }
45
+ if (!allowRequireFallback) {
46
+ throw new Error("Cannot find module '" + request + "'");
47
+ }
48
+ const runtimeRequire = globalThis.require;
49
+ if (typeof runtimeRequire !== "function") {
50
+ throw new Error("Cannot find module '" + request + "'");
51
+ }
52
+ const mod = runtimeRequire(request);
53
+ const namespaceFallback = { default: mod };
54
+ if (isObjectLike(mod)) {
55
+ for (const key of Object.keys(mod)) {
56
+ if (!(key in namespaceFallback)) {
57
+ namespaceFallback[key] = mod[key];
58
+ }
59
+ }
60
+ }
61
+ return namespaceFallback;
62
+ };
63
+ __runtimeExposeCustomGlobal("__dynamicImport", __dynamicImportHandler);
64
+ })();
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ (() => {
3
+ // isolate-runtime/src/common/global-exposure.ts
4
+ function defineRuntimeGlobalBinding(name, value, mutable) {
5
+ Object.defineProperty(globalThis, name, {
6
+ value,
7
+ writable: mutable,
8
+ configurable: mutable,
9
+ enumerable: true
10
+ });
11
+ }
12
+ function createRuntimeGlobalExposer(mutable) {
13
+ return (name, value) => {
14
+ defineRuntimeGlobalBinding(name, value, mutable);
15
+ };
16
+ }
17
+ function getRuntimeExposeCustomGlobal() {
18
+ if (typeof globalThis.__runtimeExposeCustomGlobal === "function") {
19
+ return globalThis.__runtimeExposeCustomGlobal;
20
+ }
21
+ return createRuntimeGlobalExposer(false);
22
+ }
23
+
24
+ // isolate-runtime/src/inject/setup-fs-facade.ts
25
+ var __runtimeExposeCustomGlobal = getRuntimeExposeCustomGlobal();
26
+ var __fsFacade = {
27
+ readFile: globalThis._fsReadFile,
28
+ writeFile: globalThis._fsWriteFile,
29
+ readFileBinary: globalThis._fsReadFileBinary,
30
+ writeFileBinary: globalThis._fsWriteFileBinary,
31
+ readDir: globalThis._fsReadDir,
32
+ mkdir: globalThis._fsMkdir,
33
+ rmdir: globalThis._fsRmdir,
34
+ exists: globalThis._fsExists,
35
+ stat: globalThis._fsStat,
36
+ unlink: globalThis._fsUnlink,
37
+ rename: globalThis._fsRename,
38
+ chmod: globalThis._fsChmod,
39
+ chown: globalThis._fsChown,
40
+ link: globalThis._fsLink,
41
+ symlink: globalThis._fsSymlink,
42
+ readlink: globalThis._fsReadlink,
43
+ lstat: globalThis._fsLstat,
44
+ truncate: globalThis._fsTruncate,
45
+ utimes: globalThis._fsUtimes
46
+ };
47
+ __runtimeExposeCustomGlobal("_fs", __fsFacade);
48
+ })();
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Module classification and resolution helpers.
3
+ *
4
+ * Node built-ins are split into three tiers:
5
+ * - Bridge modules: fully polyfilled by the bridge (fs, process, http, etc.)
6
+ * - Deferred core modules: known but not yet bridge-supported; surfaced via
7
+ * deferred stubs in require paths and polyfills/wrappers in ESM paths
8
+ * - Unsupported core modules: known but intentionally unimplemented
9
+ *
10
+ * Everything else falls through to node-stdlib-browser polyfills or node_modules.
11
+ */
12
+ /**
13
+ * Known named exports for each built-in module. Used by the ESM wrapper
14
+ * generator to create `export const X = _builtin.X;` re-exports so that
15
+ * `import { readFile } from 'fs'` works inside the isolate.
16
+ */
17
+ export declare const BUILTIN_NAMED_EXPORTS: Record<string, string[]>;
18
+ /**
19
+ * Normalize a module specifier to its canonical form if it's a known built-in.
20
+ * Returns null for non-builtin specifiers.
21
+ * Preserves the `node:` prefix when present, strips it otherwise.
22
+ */
23
+ export declare function normalizeBuiltinSpecifier(request: string): string | null;
24
+ /** Extract the directory portion of a path (lightweight dirname without node:path). */
25
+ export declare function getPathDir(path: string): string;
@@ -0,0 +1,264 @@
1
+ /**
2
+ * Module classification and resolution helpers.
3
+ *
4
+ * Node built-ins are split into three tiers:
5
+ * - Bridge modules: fully polyfilled by the bridge (fs, process, http, etc.)
6
+ * - Deferred core modules: known but not yet bridge-supported; surfaced via
7
+ * deferred stubs in require paths and polyfills/wrappers in ESM paths
8
+ * - Unsupported core modules: known but intentionally unimplemented
9
+ *
10
+ * Everything else falls through to node-stdlib-browser polyfills or node_modules.
11
+ */
12
+ import stdLibBrowser from "node-stdlib-browser";
13
+ /** Check if a module has a polyfill available via node-stdlib-browser. */
14
+ function hasPolyfill(moduleName) {
15
+ const name = moduleName.replace(/^node:/, "");
16
+ const polyfill = stdLibBrowser[name];
17
+ return polyfill !== undefined && polyfill !== null;
18
+ }
19
+ /** Modules with full bridge implementations injected into the isolate. */
20
+ const BRIDGE_MODULES = [
21
+ "fs",
22
+ "fs/promises",
23
+ "module",
24
+ "os",
25
+ "http",
26
+ "https",
27
+ "http2",
28
+ "dns",
29
+ "child_process",
30
+ "process",
31
+ "v8",
32
+ ];
33
+ /**
34
+ * Recognized built-ins that lack bridge support.
35
+ * Runtime handling differs by path (require stubs vs ESM/polyfill handling).
36
+ */
37
+ const DEFERRED_CORE_MODULES = [
38
+ "net",
39
+ "tls",
40
+ "readline",
41
+ "perf_hooks",
42
+ "async_hooks",
43
+ "worker_threads",
44
+ "diagnostics_channel",
45
+ ];
46
+ /** Built-ins that are intentionally unimplemented (throw on use). */
47
+ const UNSUPPORTED_CORE_MODULES = [
48
+ "dgram",
49
+ "cluster",
50
+ "wasi",
51
+ "inspector",
52
+ "repl",
53
+ "trace_events",
54
+ "domain",
55
+ ];
56
+ const KNOWN_BUILTIN_MODULES = new Set([
57
+ ...BRIDGE_MODULES,
58
+ ...DEFERRED_CORE_MODULES,
59
+ ...UNSUPPORTED_CORE_MODULES,
60
+ "assert",
61
+ "buffer",
62
+ "constants",
63
+ "crypto",
64
+ "events",
65
+ "path",
66
+ "querystring",
67
+ "stream",
68
+ "stream/web",
69
+ "string_decoder",
70
+ "timers",
71
+ "tty",
72
+ "url",
73
+ "util",
74
+ "vm",
75
+ "zlib",
76
+ ]);
77
+ /**
78
+ * Known named exports for each built-in module. Used by the ESM wrapper
79
+ * generator to create `export const X = _builtin.X;` re-exports so that
80
+ * `import { readFile } from 'fs'` works inside the isolate.
81
+ */
82
+ export const BUILTIN_NAMED_EXPORTS = {
83
+ fs: [
84
+ "promises",
85
+ "readFileSync",
86
+ "writeFileSync",
87
+ "appendFileSync",
88
+ "existsSync",
89
+ "statSync",
90
+ "mkdirSync",
91
+ "readdirSync",
92
+ "createReadStream",
93
+ "createWriteStream",
94
+ ],
95
+ "fs/promises": [
96
+ "access",
97
+ "readFile",
98
+ "writeFile",
99
+ "appendFile",
100
+ "copyFile",
101
+ "cp",
102
+ "open",
103
+ "opendir",
104
+ "mkdir",
105
+ "mkdtemp",
106
+ "readdir",
107
+ "rename",
108
+ "stat",
109
+ "lstat",
110
+ "chmod",
111
+ "chown",
112
+ "utimes",
113
+ "truncate",
114
+ "unlink",
115
+ "rm",
116
+ "rmdir",
117
+ "realpath",
118
+ "readlink",
119
+ "symlink",
120
+ "link",
121
+ ],
122
+ module: [
123
+ "createRequire",
124
+ "Module",
125
+ "isBuiltin",
126
+ "builtinModules",
127
+ "SourceMap",
128
+ "syncBuiltinESMExports",
129
+ ],
130
+ os: [
131
+ "arch",
132
+ "platform",
133
+ "tmpdir",
134
+ "homedir",
135
+ "hostname",
136
+ "type",
137
+ "release",
138
+ "constants",
139
+ ],
140
+ http: [
141
+ "request",
142
+ "get",
143
+ "createServer",
144
+ "Server",
145
+ "IncomingMessage",
146
+ "ServerResponse",
147
+ "Agent",
148
+ "METHODS",
149
+ "STATUS_CODES",
150
+ ],
151
+ https: ["request", "get", "createServer", "Agent", "globalAgent"],
152
+ dns: ["lookup", "resolve", "resolve4", "resolve6", "promises"],
153
+ child_process: [
154
+ "spawn",
155
+ "spawnSync",
156
+ "exec",
157
+ "execSync",
158
+ "execFile",
159
+ "execFileSync",
160
+ "fork",
161
+ ],
162
+ process: [
163
+ "argv",
164
+ "env",
165
+ "cwd",
166
+ "chdir",
167
+ "exit",
168
+ "pid",
169
+ "platform",
170
+ "version",
171
+ "versions",
172
+ "stdout",
173
+ "stderr",
174
+ "stdin",
175
+ "nextTick",
176
+ ],
177
+ path: [
178
+ "sep",
179
+ "delimiter",
180
+ "basename",
181
+ "dirname",
182
+ "extname",
183
+ "format",
184
+ "isAbsolute",
185
+ "join",
186
+ "normalize",
187
+ "parse",
188
+ "relative",
189
+ "resolve",
190
+ ],
191
+ async_hooks: [
192
+ "AsyncLocalStorage",
193
+ "AsyncResource",
194
+ "createHook",
195
+ "executionAsyncId",
196
+ "triggerAsyncId",
197
+ ],
198
+ perf_hooks: [
199
+ "performance",
200
+ "PerformanceObserver",
201
+ "PerformanceEntry",
202
+ "monitorEventLoopDelay",
203
+ "createHistogram",
204
+ "constants",
205
+ ],
206
+ diagnostics_channel: [
207
+ "channel",
208
+ "hasSubscribers",
209
+ "tracingChannel",
210
+ "Channel",
211
+ ],
212
+ stream: [
213
+ "Readable",
214
+ "Writable",
215
+ "Duplex",
216
+ "Transform",
217
+ "PassThrough",
218
+ "Stream",
219
+ "pipeline",
220
+ "finished",
221
+ "promises",
222
+ "addAbortSignal",
223
+ "compose",
224
+ ],
225
+ "stream/web": [
226
+ "ReadableStream",
227
+ "ReadableStreamDefaultReader",
228
+ "ReadableStreamBYOBReader",
229
+ "ReadableStreamBYOBRequest",
230
+ "ReadableByteStreamController",
231
+ "ReadableStreamDefaultController",
232
+ "TransformStream",
233
+ "TransformStreamDefaultController",
234
+ "WritableStream",
235
+ "WritableStreamDefaultWriter",
236
+ "WritableStreamDefaultController",
237
+ "ByteLengthQueuingStrategy",
238
+ "CountQueuingStrategy",
239
+ "TextEncoderStream",
240
+ "TextDecoderStream",
241
+ "CompressionStream",
242
+ "DecompressionStream",
243
+ ],
244
+ };
245
+ /**
246
+ * Normalize a module specifier to its canonical form if it's a known built-in.
247
+ * Returns null for non-builtin specifiers.
248
+ * Preserves the `node:` prefix when present, strips it otherwise.
249
+ */
250
+ export function normalizeBuiltinSpecifier(request) {
251
+ const moduleName = request.replace(/^node:/, "");
252
+ if (KNOWN_BUILTIN_MODULES.has(moduleName) || hasPolyfill(moduleName)) {
253
+ return request.startsWith("node:") ? `node:${moduleName}` : moduleName;
254
+ }
255
+ return null;
256
+ }
257
+ /** Extract the directory portion of a path (lightweight dirname without node:path). */
258
+ export function getPathDir(path) {
259
+ const normalizedPath = path.replace(/\\/g, "/");
260
+ const lastSlash = normalizedPath.lastIndexOf("/");
261
+ if (lastSlash <= 0)
262
+ return "/";
263
+ return normalizedPath.slice(0, lastSlash);
264
+ }
@@ -0,0 +1,36 @@
1
+ import type { VirtualFileSystem } from "./types.js";
2
+ type ResolveMode = "require" | "import";
3
+ interface PackageJson {
4
+ main?: string;
5
+ type?: "module" | "commonjs";
6
+ exports?: unknown;
7
+ imports?: unknown;
8
+ }
9
+ /** Caches for module resolution to avoid redundant VFS probes. */
10
+ export interface ResolutionCache {
11
+ /** Top-level resolution results keyed by `request\0fromDir\0mode` */
12
+ resolveResults: Map<string, string | null>;
13
+ /** Parsed package.json content by path */
14
+ packageJsonResults: Map<string, PackageJson | null>;
15
+ /** File existence by path */
16
+ existsResults: Map<string, boolean>;
17
+ /** Stat results by path (null = ENOENT) */
18
+ statResults: Map<string, {
19
+ isDirectory: boolean;
20
+ } | null>;
21
+ }
22
+ export declare function createResolutionCache(): ResolutionCache;
23
+ /**
24
+ * Resolve a module request to an absolute path in the virtual filesystem
25
+ */
26
+ export declare function resolveModule(request: string, fromDir: string, fs: VirtualFileSystem, mode?: ResolveMode, cache?: ResolutionCache): Promise<string | null>;
27
+ /**
28
+ * Load a file's content from the virtual filesystem
29
+ */
30
+ export declare function loadFile(path: string, fs: VirtualFileSystem): Promise<string | null>;
31
+ /**
32
+ * Legacy function - bundle a package from node_modules (simple approach)
33
+ * This is kept for backwards compatibility but the new dynamic resolution is preferred
34
+ */
35
+ export declare function bundlePackage(packageName: string, fs: VirtualFileSystem): Promise<string | null>;
36
+ export {};