@secure-exec/nodejs 0.2.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 (68) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +7 -0
  3. package/dist/bindings.d.ts +31 -0
  4. package/dist/bindings.js +67 -0
  5. package/dist/bridge/active-handles.d.ts +22 -0
  6. package/dist/bridge/active-handles.js +112 -0
  7. package/dist/bridge/child-process.d.ts +99 -0
  8. package/dist/bridge/child-process.js +672 -0
  9. package/dist/bridge/dispatch.d.ts +2 -0
  10. package/dist/bridge/dispatch.js +40 -0
  11. package/dist/bridge/fs.d.ts +502 -0
  12. package/dist/bridge/fs.js +3307 -0
  13. package/dist/bridge/index.d.ts +10 -0
  14. package/dist/bridge/index.js +41 -0
  15. package/dist/bridge/module.d.ts +75 -0
  16. package/dist/bridge/module.js +325 -0
  17. package/dist/bridge/network.d.ts +1093 -0
  18. package/dist/bridge/network.js +8651 -0
  19. package/dist/bridge/os.d.ts +13 -0
  20. package/dist/bridge/os.js +256 -0
  21. package/dist/bridge/polyfills.d.ts +9 -0
  22. package/dist/bridge/polyfills.js +67 -0
  23. package/dist/bridge/process.d.ts +121 -0
  24. package/dist/bridge/process.js +1382 -0
  25. package/dist/bridge/whatwg-url.d.ts +67 -0
  26. package/dist/bridge/whatwg-url.js +712 -0
  27. package/dist/bridge-contract.d.ts +774 -0
  28. package/dist/bridge-contract.js +172 -0
  29. package/dist/bridge-handlers.d.ts +199 -0
  30. package/dist/bridge-handlers.js +4263 -0
  31. package/dist/bridge-loader.d.ts +9 -0
  32. package/dist/bridge-loader.js +87 -0
  33. package/dist/bridge-setup.d.ts +1 -0
  34. package/dist/bridge-setup.js +3 -0
  35. package/dist/bridge.js +21652 -0
  36. package/dist/builtin-modules.d.ts +25 -0
  37. package/dist/builtin-modules.js +312 -0
  38. package/dist/default-network-adapter.d.ts +13 -0
  39. package/dist/default-network-adapter.js +351 -0
  40. package/dist/driver.d.ts +87 -0
  41. package/dist/driver.js +191 -0
  42. package/dist/esm-compiler.d.ts +14 -0
  43. package/dist/esm-compiler.js +68 -0
  44. package/dist/execution-driver.d.ts +37 -0
  45. package/dist/execution-driver.js +977 -0
  46. package/dist/host-network-adapter.d.ts +7 -0
  47. package/dist/host-network-adapter.js +279 -0
  48. package/dist/index.d.ts +20 -0
  49. package/dist/index.js +23 -0
  50. package/dist/isolate-bootstrap.d.ts +86 -0
  51. package/dist/isolate-bootstrap.js +125 -0
  52. package/dist/ivm-compat.d.ts +7 -0
  53. package/dist/ivm-compat.js +31 -0
  54. package/dist/kernel-runtime.d.ts +58 -0
  55. package/dist/kernel-runtime.js +535 -0
  56. package/dist/module-access.d.ts +75 -0
  57. package/dist/module-access.js +606 -0
  58. package/dist/module-resolver.d.ts +8 -0
  59. package/dist/module-resolver.js +150 -0
  60. package/dist/os-filesystem.d.ts +42 -0
  61. package/dist/os-filesystem.js +161 -0
  62. package/dist/package-bundler.d.ts +36 -0
  63. package/dist/package-bundler.js +497 -0
  64. package/dist/polyfills.d.ts +17 -0
  65. package/dist/polyfills.js +97 -0
  66. package/dist/worker-adapter.d.ts +21 -0
  67. package/dist/worker-adapter.js +34 -0
  68. package/package.json +123 -0
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Get the raw compiled bridge.js code.
3
+ * This is the IIFE that creates the global `bridge` object.
4
+ */
5
+ export declare function getRawBridgeCode(): string;
6
+ /**
7
+ * Get isolate script code that publishes the compiled bridge to `globalThis.bridge`.
8
+ */
9
+ export declare function getBridgeAttachCode(): string;
@@ -0,0 +1,87 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import * as esbuild from "esbuild";
5
+ import { getIsolateRuntimeSource } from "@secure-exec/core";
6
+ // Resolve this package's root for bridge source and compiled bundle.
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
+ const packageRoot = path.resolve(__dirname, "..");
9
+ // Cache the bridge code
10
+ let bridgeCodeCache = null;
11
+ /** Locate the bridge TypeScript source for on-demand compilation (dev only). */
12
+ function findBridgeSourcePath() {
13
+ const candidates = [
14
+ path.join(packageRoot, "src", "bridge", "index.ts"),
15
+ ];
16
+ for (const candidate of candidates) {
17
+ if (fs.existsSync(candidate))
18
+ return candidate;
19
+ }
20
+ return null;
21
+ }
22
+ /** Walk a directory tree and return the newest file modification time. */
23
+ function getLatestMtimeMs(dir) {
24
+ let latest = 0;
25
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
26
+ const entryPath = path.join(dir, entry.name);
27
+ if (entry.isDirectory()) {
28
+ latest = Math.max(latest, getLatestMtimeMs(entryPath));
29
+ }
30
+ else if (entry.isFile()) {
31
+ latest = Math.max(latest, fs.statSync(entryPath).mtimeMs);
32
+ }
33
+ }
34
+ return latest;
35
+ }
36
+ /**
37
+ * Auto-compile the bridge IIFE bundle from TypeScript source if stale.
38
+ * Skips rebuilding when the existing bundle is newer than all source files.
39
+ */
40
+ function ensureBridgeBundle(bridgePath) {
41
+ const sourcePath = findBridgeSourcePath();
42
+ // Fall back to an existing bridge bundle when source is unavailable.
43
+ if (!sourcePath) {
44
+ if (fs.existsSync(bridgePath))
45
+ return;
46
+ throw new Error("bridge.js not found and source is unavailable. Run `pnpm -C packages/nodejs build:bridge`.");
47
+ }
48
+ const shouldBuild = (() => {
49
+ if (!fs.existsSync(bridgePath))
50
+ return true;
51
+ const sourceDir = path.dirname(sourcePath);
52
+ const sourceMtime = getLatestMtimeMs(sourceDir);
53
+ const bundleMtime = fs.statSync(bridgePath).mtimeMs;
54
+ return sourceMtime > bundleMtime;
55
+ })();
56
+ if (!shouldBuild)
57
+ return;
58
+ fs.mkdirSync(path.dirname(bridgePath), { recursive: true });
59
+ const result = esbuild.buildSync({
60
+ entryPoints: [sourcePath],
61
+ bundle: true,
62
+ format: "iife",
63
+ globalName: "bridge",
64
+ outfile: bridgePath,
65
+ });
66
+ if (result.errors.length > 0) {
67
+ throw new Error(`Failed to build bridge.js: ${result.errors[0].text}`);
68
+ }
69
+ }
70
+ /**
71
+ * Get the raw compiled bridge.js code.
72
+ * This is the IIFE that creates the global `bridge` object.
73
+ */
74
+ export function getRawBridgeCode() {
75
+ if (!bridgeCodeCache) {
76
+ const bridgePath = path.join(packageRoot, "dist", "bridge.js");
77
+ ensureBridgeBundle(bridgePath);
78
+ bridgeCodeCache = fs.readFileSync(bridgePath, "utf8");
79
+ }
80
+ return bridgeCodeCache;
81
+ }
82
+ /**
83
+ * Get isolate script code that publishes the compiled bridge to `globalThis.bridge`.
84
+ */
85
+ export function getBridgeAttachCode() {
86
+ return getIsolateRuntimeSource("bridgeAttach");
87
+ }
@@ -0,0 +1 @@
1
+ export { emitConsoleEvent, stripDangerousEnv, createProcessConfigForExecution, } from "./bridge-handlers.js";
@@ -0,0 +1,3 @@
1
+ // Bridge setup utilities — functions kept for backward compatibility.
2
+ // The main bridge handler logic is in bridge-handlers.ts.
3
+ export { emitConsoleEvent, stripDangerousEnv, createProcessConfigForExecution, } from "./bridge-handlers.js";