sandboxedjs 0.1.23 → 0.1.25

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/dist/index.d.cts CHANGED
@@ -1605,38 +1605,21 @@ interface ContainerOptions {
1605
1605
  /** Invoked when an in-container HTTP server starts listening. */
1606
1606
  onServerReady?: (port: number, url: string) => void;
1607
1607
  /**
1608
- * Supply the Nodepod instance instead of letting the container boot one.
1608
+ * Run on a JavaScript runtime you booted yourself.
1609
1609
  *
1610
- * The default path imports `@scelar/nodepod/headless`, which installs a
1611
- * `worker_threads` host and is the right choice on Node. In a browser you
1612
- * boot Nodepod's browser build yourself (it needs a service worker) and hand
1613
- * the instance over:
1610
+ * The container boots a {@link LocalRuntimePod} when this is omitted, which
1611
+ * is what almost every caller wants. Pass one to share a single runtime
1612
+ * across containers, to seed it differently, or to substitute an
1613
+ * implementation of your own — anything satisfying {@link RuntimePod} works.
1614
1614
  *
1615
1615
  * ```ts
1616
- * import { Nodepod } from "@scelar/nodepod";
1617
- * const pod = await Nodepod.boot({ ... });
1618
- * const box = await createContainer({ pod });
1616
+ * const pod = await LocalRuntimePod.boot({ workdir: "/app" });
1617
+ * const box = await createContainer({ pod, cwd: "/app" });
1619
1618
  * ```
1620
1619
  */
1621
1620
  pod?: RuntimePod;
1622
- /**
1623
- * JavaScript runtime implementation. `sandboxedjs` selects the new
1624
- * clean-room engine while it completes compatibility validation.
1625
- */
1626
- runtime?: "sandboxedjs" | "nodepod";
1627
1621
  /** Python runtime settings; a browser host uses this to locate the wasm. */
1628
1622
  python?: PythonOptions;
1629
- /**
1630
- * Forwarded to Nodepod when this package boots it in a browser. `swUrl`
1631
- * points at the service worker if you serve it somewhere other than
1632
- * `/__sw__.js`; `serviceWorker: false` skips registration entirely, which
1633
- * also disables preview iframes.
1634
- */
1635
- browser?: {
1636
- swUrl?: string;
1637
- serviceWorker?: boolean;
1638
- watermark?: boolean;
1639
- };
1640
1623
  }
1641
1624
  interface ExecOptions {
1642
1625
  cwd?: string;
@@ -1860,13 +1843,13 @@ declare function exitCodeForSignal(sig: string): number;
1860
1843
  /**
1861
1844
  * The identity the container reports for itself.
1862
1845
  *
1863
- * The release string deliberately matches what Nodepod's `os.release()` returns
1864
- * inside a spawned Node process, so `uname -r` and
1865
- * `node -p "os.release()"` agree.
1846
+ * The runtime's `os.release()` is built from these same constants, so `uname -r`
1847
+ * and `node -p "os.release()"` agree inside the container — a program that
1848
+ * checks the platform gets one answer whichever way it asks.
1866
1849
  */
1867
1850
  declare const KERNEL_NAME = "Linux";
1868
1851
  declare const KERNEL_RELEASE = "5.10.0";
1869
- declare const OS_RELEASE = "PRETTY_NAME=\"SandboxedJS 1.0 (nodepod)\"\nNAME=\"SandboxedJS\"\nVERSION_ID=\"1.0\"\nVERSION=\"1.0 (nodepod)\"\nVERSION_CODENAME=nodepod\nID=sandboxedjs\nID_LIKE=debian\nHOME_URL=\"https://github.com/R1ck404/Nodepod\"\nSUPPORT_URL=\"https://www.npmjs.com/package/sandboxedjs\"\n";
1852
+ declare const OS_RELEASE = "PRETTY_NAME=\"SandboxedJS 1.0 (sandbox)\"\nNAME=\"SandboxedJS\"\nVERSION_ID=\"1.0\"\nVERSION=\"1.0 (sandbox)\"\nVERSION_CODENAME=sandbox\nID=sandboxedjs\nID_LIKE=debian\nHOME_URL=\"https://www.npmjs.com/package/sandboxedjs\"\nSUPPORT_URL=\"https://www.npmjs.com/package/sandboxedjs\"\n";
1870
1853
  interface UnameInfo {
1871
1854
  sysname: string;
1872
1855
  nodename: string;
@@ -2137,8 +2120,9 @@ declare function buildRootfs(vfs: Vfs, opts?: RootfsOptions): void;
2137
2120
  declare const NODE_VERSION = "v22.12.0";
2138
2121
 
2139
2122
  /**
2140
- * Package managers: `npm`/`npx`/`yarn`/`pnpm` on top of Nodepod's installer,
2141
- * and an `apt`-shaped front end for the things a container image would ship.
2123
+ * Package managers: `npm`/`npx`/`yarn`/`pnpm` on top of the runtime's package
2124
+ * installer, and an `apt`-shaped front end for the things a container image
2125
+ * would ship.
2142
2126
  */
2143
2127
 
2144
2128
  declare const NPM_VERSION = "10.9.0";
@@ -2416,6 +2400,8 @@ declare class VirtualHttpServer extends EventEmitter {
2416
2400
  }
2417
2401
  declare class VirtualHttpRouter {
2418
2402
  private readonly servers;
2403
+ /** Notified when a server begins listening, for `onServerReady`. */
2404
+ onListen: ((port: number) => void) | undefined;
2419
2405
  register(port: number, server: VirtualHttpServer, owner: string): void;
2420
2406
  unregister(port: number, server: VirtualHttpServer): void;
2421
2407
  activePorts(owner?: string): number[];
@@ -2438,6 +2424,8 @@ interface CoreModulesOptions {
2438
2424
  };
2439
2425
  /** Backs `child_process`; without it the module reports as unavailable. */
2440
2426
  spawnChild?: SpawnChild;
2427
+ /** File holding the process's standard input, exposed as descriptor 0. */
2428
+ stdinPath?: string;
2441
2429
  }
2442
2430
  /** Build the core-module table injected into each isolated JS worker. */
2443
2431
  declare function createCoreModules(options: CoreModulesOptions): {
@@ -2489,6 +2477,8 @@ interface LocalRuntimeOptions {
2489
2477
  files?: Record<string, string | Uint8Array>;
2490
2478
  registry?: string;
2491
2479
  fetch?: typeof globalThis.fetch;
2480
+ /** Invoked when a program inside the runtime starts listening on a port. */
2481
+ onServerReady?: (port: number, url: string) => void;
2492
2482
  /** Extra package substitutions, merged over {@link WASM_ALIASES}. */
2493
2483
  aliases?: Record<string, string>;
2494
2484
  /** Modules supplied by the host rather than resolved from the volume. */
@@ -2537,6 +2527,7 @@ declare class LocalRuntimePod implements RuntimePod {
2537
2527
  private readonly env;
2538
2528
  private readonly aliases;
2539
2529
  private readonly modules;
2530
+ private readonly esbuild;
2540
2531
  private constructor();
2541
2532
  static boot(options?: LocalRuntimeOptions): Promise<LocalRuntimePod>;
2542
2533
  spawn(command: string, args?: string[], options?: Record<string, unknown>): Promise<RuntimeProcess>;
@@ -2544,9 +2535,16 @@ declare class LocalRuntimePod implements RuntimePod {
2544
2535
  * Wait until the process has either started serving or genuinely run out of
2545
2536
  * work.
2546
2537
  *
2547
- * Timers are the observable half of the event loop, so a process with none
2548
- * outstanding and no port open has finished — and, being the common case for
2549
- * a plain script, is settled without waiting at all.
2538
+ * Two different kinds of pending work have to be waited on. Callbacks queued
2539
+ * as microtasks or `nextTick` — which is most of what streams and promise
2540
+ * chains are built from — need only for the current turn to end, so a few
2541
+ * turns of the macrotask queue are yielded first. Without that, a script
2542
+ * whose last act is `process.stdin.on("data", …)` exits before its own
2543
+ * handler runs and produces no output at all. Timers are the part that can
2544
+ * outlive any number of turns, so those are then polled until none remain.
2545
+ *
2546
+ * A plain script that has genuinely finished falls straight through both,
2547
+ * costing a handful of empty turns.
2550
2548
  */
2551
2549
  private settle;
2552
2550
  request(_port: number, _init?: Record<string, unknown>): Promise<RuntimeHttpResponse>;
package/dist/index.d.ts CHANGED
@@ -1605,38 +1605,21 @@ interface ContainerOptions {
1605
1605
  /** Invoked when an in-container HTTP server starts listening. */
1606
1606
  onServerReady?: (port: number, url: string) => void;
1607
1607
  /**
1608
- * Supply the Nodepod instance instead of letting the container boot one.
1608
+ * Run on a JavaScript runtime you booted yourself.
1609
1609
  *
1610
- * The default path imports `@scelar/nodepod/headless`, which installs a
1611
- * `worker_threads` host and is the right choice on Node. In a browser you
1612
- * boot Nodepod's browser build yourself (it needs a service worker) and hand
1613
- * the instance over:
1610
+ * The container boots a {@link LocalRuntimePod} when this is omitted, which
1611
+ * is what almost every caller wants. Pass one to share a single runtime
1612
+ * across containers, to seed it differently, or to substitute an
1613
+ * implementation of your own — anything satisfying {@link RuntimePod} works.
1614
1614
  *
1615
1615
  * ```ts
1616
- * import { Nodepod } from "@scelar/nodepod";
1617
- * const pod = await Nodepod.boot({ ... });
1618
- * const box = await createContainer({ pod });
1616
+ * const pod = await LocalRuntimePod.boot({ workdir: "/app" });
1617
+ * const box = await createContainer({ pod, cwd: "/app" });
1619
1618
  * ```
1620
1619
  */
1621
1620
  pod?: RuntimePod;
1622
- /**
1623
- * JavaScript runtime implementation. `sandboxedjs` selects the new
1624
- * clean-room engine while it completes compatibility validation.
1625
- */
1626
- runtime?: "sandboxedjs" | "nodepod";
1627
1621
  /** Python runtime settings; a browser host uses this to locate the wasm. */
1628
1622
  python?: PythonOptions;
1629
- /**
1630
- * Forwarded to Nodepod when this package boots it in a browser. `swUrl`
1631
- * points at the service worker if you serve it somewhere other than
1632
- * `/__sw__.js`; `serviceWorker: false` skips registration entirely, which
1633
- * also disables preview iframes.
1634
- */
1635
- browser?: {
1636
- swUrl?: string;
1637
- serviceWorker?: boolean;
1638
- watermark?: boolean;
1639
- };
1640
1623
  }
1641
1624
  interface ExecOptions {
1642
1625
  cwd?: string;
@@ -1860,13 +1843,13 @@ declare function exitCodeForSignal(sig: string): number;
1860
1843
  /**
1861
1844
  * The identity the container reports for itself.
1862
1845
  *
1863
- * The release string deliberately matches what Nodepod's `os.release()` returns
1864
- * inside a spawned Node process, so `uname -r` and
1865
- * `node -p "os.release()"` agree.
1846
+ * The runtime's `os.release()` is built from these same constants, so `uname -r`
1847
+ * and `node -p "os.release()"` agree inside the container — a program that
1848
+ * checks the platform gets one answer whichever way it asks.
1866
1849
  */
1867
1850
  declare const KERNEL_NAME = "Linux";
1868
1851
  declare const KERNEL_RELEASE = "5.10.0";
1869
- declare const OS_RELEASE = "PRETTY_NAME=\"SandboxedJS 1.0 (nodepod)\"\nNAME=\"SandboxedJS\"\nVERSION_ID=\"1.0\"\nVERSION=\"1.0 (nodepod)\"\nVERSION_CODENAME=nodepod\nID=sandboxedjs\nID_LIKE=debian\nHOME_URL=\"https://github.com/R1ck404/Nodepod\"\nSUPPORT_URL=\"https://www.npmjs.com/package/sandboxedjs\"\n";
1852
+ declare const OS_RELEASE = "PRETTY_NAME=\"SandboxedJS 1.0 (sandbox)\"\nNAME=\"SandboxedJS\"\nVERSION_ID=\"1.0\"\nVERSION=\"1.0 (sandbox)\"\nVERSION_CODENAME=sandbox\nID=sandboxedjs\nID_LIKE=debian\nHOME_URL=\"https://www.npmjs.com/package/sandboxedjs\"\nSUPPORT_URL=\"https://www.npmjs.com/package/sandboxedjs\"\n";
1870
1853
  interface UnameInfo {
1871
1854
  sysname: string;
1872
1855
  nodename: string;
@@ -2137,8 +2120,9 @@ declare function buildRootfs(vfs: Vfs, opts?: RootfsOptions): void;
2137
2120
  declare const NODE_VERSION = "v22.12.0";
2138
2121
 
2139
2122
  /**
2140
- * Package managers: `npm`/`npx`/`yarn`/`pnpm` on top of Nodepod's installer,
2141
- * and an `apt`-shaped front end for the things a container image would ship.
2123
+ * Package managers: `npm`/`npx`/`yarn`/`pnpm` on top of the runtime's package
2124
+ * installer, and an `apt`-shaped front end for the things a container image
2125
+ * would ship.
2142
2126
  */
2143
2127
 
2144
2128
  declare const NPM_VERSION = "10.9.0";
@@ -2416,6 +2400,8 @@ declare class VirtualHttpServer extends EventEmitter {
2416
2400
  }
2417
2401
  declare class VirtualHttpRouter {
2418
2402
  private readonly servers;
2403
+ /** Notified when a server begins listening, for `onServerReady`. */
2404
+ onListen: ((port: number) => void) | undefined;
2419
2405
  register(port: number, server: VirtualHttpServer, owner: string): void;
2420
2406
  unregister(port: number, server: VirtualHttpServer): void;
2421
2407
  activePorts(owner?: string): number[];
@@ -2438,6 +2424,8 @@ interface CoreModulesOptions {
2438
2424
  };
2439
2425
  /** Backs `child_process`; without it the module reports as unavailable. */
2440
2426
  spawnChild?: SpawnChild;
2427
+ /** File holding the process's standard input, exposed as descriptor 0. */
2428
+ stdinPath?: string;
2441
2429
  }
2442
2430
  /** Build the core-module table injected into each isolated JS worker. */
2443
2431
  declare function createCoreModules(options: CoreModulesOptions): {
@@ -2489,6 +2477,8 @@ interface LocalRuntimeOptions {
2489
2477
  files?: Record<string, string | Uint8Array>;
2490
2478
  registry?: string;
2491
2479
  fetch?: typeof globalThis.fetch;
2480
+ /** Invoked when a program inside the runtime starts listening on a port. */
2481
+ onServerReady?: (port: number, url: string) => void;
2492
2482
  /** Extra package substitutions, merged over {@link WASM_ALIASES}. */
2493
2483
  aliases?: Record<string, string>;
2494
2484
  /** Modules supplied by the host rather than resolved from the volume. */
@@ -2537,6 +2527,7 @@ declare class LocalRuntimePod implements RuntimePod {
2537
2527
  private readonly env;
2538
2528
  private readonly aliases;
2539
2529
  private readonly modules;
2530
+ private readonly esbuild;
2540
2531
  private constructor();
2541
2532
  static boot(options?: LocalRuntimeOptions): Promise<LocalRuntimePod>;
2542
2533
  spawn(command: string, args?: string[], options?: Record<string, unknown>): Promise<RuntimeProcess>;
@@ -2544,9 +2535,16 @@ declare class LocalRuntimePod implements RuntimePod {
2544
2535
  * Wait until the process has either started serving or genuinely run out of
2545
2536
  * work.
2546
2537
  *
2547
- * Timers are the observable half of the event loop, so a process with none
2548
- * outstanding and no port open has finished — and, being the common case for
2549
- * a plain script, is settled without waiting at all.
2538
+ * Two different kinds of pending work have to be waited on. Callbacks queued
2539
+ * as microtasks or `nextTick` — which is most of what streams and promise
2540
+ * chains are built from — need only for the current turn to end, so a few
2541
+ * turns of the macrotask queue are yielded first. Without that, a script
2542
+ * whose last act is `process.stdin.on("data", …)` exits before its own
2543
+ * handler runs and produces no output at all. Timers are the part that can
2544
+ * outlive any number of turns, so those are then polled until none remain.
2545
+ *
2546
+ * A plain script that has genuinely finished falls straight through both,
2547
+ * costing a handful of empty turns.
2550
2548
  */
2551
2549
  private settle;
2552
2550
  request(_port: number, _init?: Record<string, unknown>): Promise<RuntimeHttpResponse>;