just-bash 2.9.7 → 2.10.0

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 CHANGED
@@ -26,6 +26,7 @@ Supports optional network access via `curl` with secure-by-default URL filtering
26
26
  - [Default Layout](#default-layout)
27
27
  - [Network Access](#network-access)
28
28
  - [Execution Protection](#execution-protection)
29
+ - [AST Transform Plugins](#ast-transform-plugins)
29
30
  - [Development](#development)
30
31
 
31
32
  ## Security model
@@ -435,6 +436,30 @@ const env = new Bash({
435
436
 
436
437
  All limits have sensible defaults. Error messages include hints on which limit to increase. Feel free to increase if your scripts intentionally go beyond them.
437
438
 
439
+ ## AST Transform Plugins
440
+
441
+ Parse bash scripts into an AST, run transform plugins, and serialize back to executable bash. Useful for instrumenting scripts (e.g., capturing per-command stdout/stderr) or analyzing them (e.g., extracting command names) before execution.
442
+
443
+ ```typescript
444
+ import { Bash, BashTransformPipeline, TeePlugin, CommandCollectorPlugin } from "just-bash";
445
+
446
+ // Standalone pipeline — output can be run by any shell
447
+ const pipeline = new BashTransformPipeline()
448
+ .use(new TeePlugin({ outputDir: "/tmp/logs" }))
449
+ .use(new CommandCollectorPlugin());
450
+ const result = pipeline.transform("echo hello | grep hello");
451
+ result.script; // transformed bash string
452
+ result.metadata.commands; // ["echo", "grep", "tee"]
453
+
454
+ // Integrated API — exec() auto-applies transforms and returns metadata
455
+ const bash = new Bash();
456
+ bash.registerTransformPlugin(new CommandCollectorPlugin());
457
+ const execResult = await bash.exec("echo hello | grep hello");
458
+ execResult.metadata?.commands; // ["echo", "grep"]
459
+ ```
460
+
461
+ See [src/transform/README.md](src/transform/README.md) for the full API, built-in plugins, and how to write custom plugins.
462
+
438
463
  ## Development
439
464
 
440
465
  ```bash
package/dist/Bash.d.ts CHANGED
@@ -13,6 +13,7 @@ import type { IFileSystem, InitialFiles } from "./fs/interface.js";
13
13
  import { type ExecutionLimits } from "./limits.js";
14
14
  import { type NetworkConfig } from "./network/index.js";
15
15
  import type { DefenseInDepthConfig } from "./security/types.js";
16
+ import type { BashTransformResult, TransformPlugin } from "./transform/types.js";
16
17
  import type { BashExecResult, Command, FeatureCoverageWriter, TraceCallback } from "./types.js";
17
18
  export type { ExecutionLimits } from "./limits.js";
18
19
  /**
@@ -167,6 +168,7 @@ export declare class Bash {
167
168
  private logger?;
168
169
  private defenseInDepthConfig?;
169
170
  private coverageWriter?;
171
+ private transformPlugins;
170
172
  private state;
171
173
  constructor(options?: BashOptions);
172
174
  registerCommand(command: Command): void;
@@ -176,4 +178,6 @@ export declare class Bash {
176
178
  writeFile(path: string, content: string): Promise<void>;
177
179
  getCwd(): string;
178
180
  getEnv(): Record<string, string>;
181
+ registerTransformPlugin(plugin: TransformPlugin<any>): void;
182
+ transform(commandLine: string): BashTransformResult;
179
183
  }
@@ -6,6 +6,8 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
6
  });
7
7
 
8
8
  // src/commands/python3/worker.ts
9
+ import { createRequire } from "node:module";
10
+ import { dirname } from "node:path";
9
11
  import { parentPort, workerData } from "node:worker_threads";
10
12
  import { loadPyodide } from "pyodide";
11
13
 
@@ -208,9 +210,9 @@ var IS_BROWSER = typeof __BROWSER__ !== "undefined" && __BROWSER__;
208
210
  var AsyncLocalStorageClass = null;
209
211
  if (!IS_BROWSER) {
210
212
  try {
211
- const { createRequire } = await import("node:module");
212
- const require2 = createRequire(import.meta.url);
213
- const asyncHooks = require2("node:async_hooks");
213
+ const { createRequire: createRequire2 } = await import("node:module");
214
+ const require3 = createRequire2(import.meta.url);
215
+ const asyncHooks = require3("node:async_hooks");
214
216
  AsyncLocalStorageClass = asyncHooks.AsyncLocalStorage;
215
217
  } catch (e) {
216
218
  console.debug(
@@ -1314,6 +1316,8 @@ var SyncFsBackend = class {
1314
1316
  // src/commands/python3/worker.ts
1315
1317
  var pyodideInstance = null;
1316
1318
  var pyodideLoading = null;
1319
+ var require2 = createRequire(import.meta.url);
1320
+ var pyodideIndexURL = `${dirname(require2.resolve("pyodide/pyodide.mjs"))}/`;
1317
1321
  async function getPyodide() {
1318
1322
  if (pyodideInstance) {
1319
1323
  return pyodideInstance;
@@ -1321,7 +1325,7 @@ async function getPyodide() {
1321
1325
  if (pyodideLoading) {
1322
1326
  return pyodideLoading;
1323
1327
  }
1324
- pyodideLoading = loadPyodide();
1328
+ pyodideLoading = loadPyodide({ indexURL: pyodideIndexURL });
1325
1329
  pyodideInstance = await pyodideLoading;
1326
1330
  return pyodideInstance;
1327
1331
  }