sandboxedjs 0.1.25 → 0.1.26

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
@@ -1,4 +1,4 @@
1
- import EventEmitter from 'events';
1
+ import EventEmitter from 'events/events.js';
2
2
  import streamModule from 'stream-browserify';
3
3
 
4
4
  /** The handle a pod's process manager returns. */
@@ -81,7 +81,12 @@ interface RuntimeProcessResult {
81
81
  }
82
82
  interface RuntimeProcess {
83
83
  readonly completion: Promise<RuntimeProcessResult>;
84
- on(event: "output" | "error" | "exit", listener: (...args: any[]) => void): this;
84
+ /**
85
+ * `output` and `error` carry stdout and stderr; `exit` the code. `rawmode`
86
+ * reports the program turning terminal raw mode on or off, which a terminal
87
+ * needs so that it stops echoing input the program is drawing itself.
88
+ */
89
+ on(event: "output" | "error" | "exit" | "rawmode", listener: (...args: any[]) => void): this;
85
90
  write(data: string): void;
86
91
  kill(signal?: string): void;
87
92
  }
@@ -390,6 +395,14 @@ declare class Pipe implements InputStream, OutputStream {
390
395
  isTTY: boolean;
391
396
  /** Set on pipes owned by an outside caller, who may never call `end()`. */
392
397
  interactive: boolean;
398
+ /**
399
+ * Set while the running program has put the terminal in raw mode.
400
+ *
401
+ * A program in raw mode draws its own input — a prompt library redraws the
402
+ * whole line on every keystroke — so the terminal must stop echoing, or
403
+ * every character appears twice.
404
+ */
405
+ rawMode: boolean;
393
406
  columns: number | undefined;
394
407
  rows: number | undefined;
395
408
  get closed(): boolean;
@@ -2262,6 +2275,16 @@ declare class CommonJsEngine {
2262
2275
  main: CommonJsModule | null;
2263
2276
  /** `package.json` per directory; resolution reads them constantly. */
2264
2277
  private readonly manifests;
2278
+ private evaluationDepth;
2279
+ /**
2280
+ * Is a module body running synchronously right now?
2281
+ *
2282
+ * `process.exit` unwinds by throwing, and that is only safe while one of
2283
+ * this engine's own frames is on the stack to catch it. Thrown from a later
2284
+ * callback — a stream handler, a timer — it would escape into whichever
2285
+ * library called that callback and surface as an unrelated crash.
2286
+ */
2287
+ get isEvaluating(): boolean;
2265
2288
  constructor(volume: RuntimeVolume, options?: Omit<CommonJsEngineOptions, "volume">);
2266
2289
  /**
2267
2290
  * Evaluate an entry point.
@@ -2426,12 +2449,31 @@ interface CoreModulesOptions {
2426
2449
  spawnChild?: SpawnChild;
2427
2450
  /** File holding the process's standard input, exposed as descriptor 0. */
2428
2451
  stdinPath?: string;
2452
+ /** Keep `process.stdin` open and fed by {@link writeStdin} rather than ending it. */
2453
+ interactiveStdin?: boolean;
2454
+ /** Report the standard streams as a terminal, which is what makes CLIs prompt. */
2455
+ tty?: boolean;
2456
+ /** Called when the program turns raw mode on or off. */
2457
+ onRawMode?: (enabled: boolean) => void;
2429
2458
  }
2430
2459
  /** Build the core-module table injected into each isolated JS worker. */
2431
2460
  declare function createCoreModules(options: CoreModulesOptions): {
2432
2461
  builtins: Record<string, unknown>;
2433
2462
  globals: Record<string, unknown>;
2434
2463
  process: Record<string, any>;
2464
+ /** Deliver a chunk of input to an interactive `process.stdin`. */
2465
+ writeStdin(data: string): void;
2466
+ /** Signal end-of-input to an interactive `process.stdin`. */
2467
+ endStdin(): void;
2468
+ /**
2469
+ * Is the program waiting on input?
2470
+ *
2471
+ * Node keeps a process alive for an open stdin only while something is
2472
+ * actually reading it, and that distinction matters here: a CLI sitting on a
2473
+ * prompt has no timers pending and would otherwise look finished, while a
2474
+ * program that never touches stdin must still be allowed to exit.
2475
+ */
2476
+ readingStdin(): boolean;
2435
2477
  /**
2436
2478
  * How many timers this process still has outstanding.
2437
2479
  *
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import EventEmitter from 'events';
1
+ import EventEmitter from 'events/events.js';
2
2
  import streamModule from 'stream-browserify';
3
3
 
4
4
  /** The handle a pod's process manager returns. */
@@ -81,7 +81,12 @@ interface RuntimeProcessResult {
81
81
  }
82
82
  interface RuntimeProcess {
83
83
  readonly completion: Promise<RuntimeProcessResult>;
84
- on(event: "output" | "error" | "exit", listener: (...args: any[]) => void): this;
84
+ /**
85
+ * `output` and `error` carry stdout and stderr; `exit` the code. `rawmode`
86
+ * reports the program turning terminal raw mode on or off, which a terminal
87
+ * needs so that it stops echoing input the program is drawing itself.
88
+ */
89
+ on(event: "output" | "error" | "exit" | "rawmode", listener: (...args: any[]) => void): this;
85
90
  write(data: string): void;
86
91
  kill(signal?: string): void;
87
92
  }
@@ -390,6 +395,14 @@ declare class Pipe implements InputStream, OutputStream {
390
395
  isTTY: boolean;
391
396
  /** Set on pipes owned by an outside caller, who may never call `end()`. */
392
397
  interactive: boolean;
398
+ /**
399
+ * Set while the running program has put the terminal in raw mode.
400
+ *
401
+ * A program in raw mode draws its own input — a prompt library redraws the
402
+ * whole line on every keystroke — so the terminal must stop echoing, or
403
+ * every character appears twice.
404
+ */
405
+ rawMode: boolean;
393
406
  columns: number | undefined;
394
407
  rows: number | undefined;
395
408
  get closed(): boolean;
@@ -2262,6 +2275,16 @@ declare class CommonJsEngine {
2262
2275
  main: CommonJsModule | null;
2263
2276
  /** `package.json` per directory; resolution reads them constantly. */
2264
2277
  private readonly manifests;
2278
+ private evaluationDepth;
2279
+ /**
2280
+ * Is a module body running synchronously right now?
2281
+ *
2282
+ * `process.exit` unwinds by throwing, and that is only safe while one of
2283
+ * this engine's own frames is on the stack to catch it. Thrown from a later
2284
+ * callback — a stream handler, a timer — it would escape into whichever
2285
+ * library called that callback and surface as an unrelated crash.
2286
+ */
2287
+ get isEvaluating(): boolean;
2265
2288
  constructor(volume: RuntimeVolume, options?: Omit<CommonJsEngineOptions, "volume">);
2266
2289
  /**
2267
2290
  * Evaluate an entry point.
@@ -2426,12 +2449,31 @@ interface CoreModulesOptions {
2426
2449
  spawnChild?: SpawnChild;
2427
2450
  /** File holding the process's standard input, exposed as descriptor 0. */
2428
2451
  stdinPath?: string;
2452
+ /** Keep `process.stdin` open and fed by {@link writeStdin} rather than ending it. */
2453
+ interactiveStdin?: boolean;
2454
+ /** Report the standard streams as a terminal, which is what makes CLIs prompt. */
2455
+ tty?: boolean;
2456
+ /** Called when the program turns raw mode on or off. */
2457
+ onRawMode?: (enabled: boolean) => void;
2429
2458
  }
2430
2459
  /** Build the core-module table injected into each isolated JS worker. */
2431
2460
  declare function createCoreModules(options: CoreModulesOptions): {
2432
2461
  builtins: Record<string, unknown>;
2433
2462
  globals: Record<string, unknown>;
2434
2463
  process: Record<string, any>;
2464
+ /** Deliver a chunk of input to an interactive `process.stdin`. */
2465
+ writeStdin(data: string): void;
2466
+ /** Signal end-of-input to an interactive `process.stdin`. */
2467
+ endStdin(): void;
2468
+ /**
2469
+ * Is the program waiting on input?
2470
+ *
2471
+ * Node keeps a process alive for an open stdin only while something is
2472
+ * actually reading it, and that distinction matters here: a CLI sitting on a
2473
+ * prompt has no timers pending and would otherwise look finished, while a
2474
+ * program that never touches stdin must still be allowed to exit.
2475
+ */
2476
+ readingStdin(): boolean;
2435
2477
  /**
2436
2478
  * How many timers this process still has outstanding.
2437
2479
  *