just-bash 1.0.0 → 1.1.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.
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Custom Commands API
3
+ *
4
+ * Provides types and utilities for registering user-provided TypeScript commands.
5
+ */
6
+ import type { Command, CommandContext, ExecResult } from "./types.js";
7
+ /**
8
+ * A custom command - either a Command object or a lazy loader.
9
+ */
10
+ export type CustomCommand = Command | LazyCommand;
11
+ /**
12
+ * Lazy-loaded custom command (for code-splitting).
13
+ */
14
+ export interface LazyCommand {
15
+ name: string;
16
+ load: () => Promise<Command>;
17
+ }
18
+ /**
19
+ * Type guard to check if a custom command is lazy-loaded.
20
+ */
21
+ export declare function isLazyCommand(cmd: CustomCommand): cmd is LazyCommand;
22
+ /**
23
+ * Define a TypeScript command with type inference.
24
+ * Convenience wrapper - you can also just use the Command interface directly.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const hello = defineCommand("hello", async (args, ctx) => {
29
+ * const name = args[0] || "world";
30
+ * return { stdout: `Hello, ${name}!\n`, stderr: "", exitCode: 0 };
31
+ * });
32
+ *
33
+ * const bash = new Bash({ customCommands: [hello] });
34
+ * await bash.exec("hello Alice"); // "Hello, Alice!\n"
35
+ * ```
36
+ */
37
+ export declare function defineCommand(name: string, execute: (args: string[], ctx: CommandContext) => Promise<ExecResult>): Command;
38
+ /**
39
+ * Create a lazy-loaded wrapper for a custom command.
40
+ * The command is only loaded when first executed.
41
+ */
42
+ export declare function createLazyCustomCommand(lazy: LazyCommand): Command;
package/dist/index.d.ts CHANGED
@@ -2,11 +2,14 @@ export type { BashOptions, ExecOptions } from "./Bash.js";
2
2
  export { Bash } from "./Bash.js";
3
3
  export type { AllCommandName, CommandName, NetworkCommandName, } from "./commands/registry.js";
4
4
  export { getCommandNames, getNetworkCommandNames, } from "./commands/registry.js";
5
- export { VirtualFs } from "./fs.js";
6
- export type { BufferEncoding, CpOptions, DirectoryEntry, FileContent, FileEntry, FileInit, FileSystemFactory, FsEntry, FsStat, InitialFiles, MkdirOptions, RmOptions, SymlinkEntry, } from "./fs-interface.js";
5
+ export type { CustomCommand, LazyCommand } from "./custom-commands.js";
6
+ export { defineCommand } from "./custom-commands.js";
7
+ export { InMemoryFs } from "./fs/in-memory-fs/index.js";
8
+ export type { BufferEncoding, CpOptions, DirectoryEntry, FileContent, FileEntry, FileInit, FileSystemFactory, FsEntry, FsStat, InitialFiles, MkdirOptions, RmOptions, SymlinkEntry, } from "./fs/interface.js";
9
+ export { OverlayFs, type OverlayFsOptions } from "./fs/overlay-fs/index.js";
10
+ export { ReadWriteFs, type ReadWriteFsOptions, } from "./fs/read-write-fs/index.js";
7
11
  export type { NetworkConfig } from "./network/index.js";
8
12
  export { NetworkAccessDeniedError, RedirectNotAllowedError, TooManyRedirectsError, } from "./network/index.js";
9
- export { OverlayFs, type OverlayFsOptions } from "./overlay-fs/index.js";
10
13
  export type { CommandFinished as SandboxCommandFinished, OutputMessage, SandboxOptions, WriteFilesInput, } from "./sandbox/index.js";
11
14
  export { Command as SandboxCommand, Sandbox } from "./sandbox/index.js";
12
15
  export type { BashExecResult, Command, CommandContext, ExecResult, IFileSystem, } from "./types.js";
@@ -10,7 +10,7 @@
10
10
  * - Redirections (redirections.ts)
11
11
  */
12
12
  import type { ScriptNode } from "../ast/types.js";
13
- import type { IFileSystem } from "../fs-interface.js";
13
+ import type { IFileSystem } from "../fs/interface.js";
14
14
  import type { ExecutionLimits } from "../limits.js";
15
15
  import type { SecureFetch } from "../network/index.js";
16
16
  import type { CommandRegistry, ExecResult } from "../types.js";
@@ -46,7 +46,7 @@ export declare class Interpreter {
46
46
  * Resolution order:
47
47
  * 1. If command contains "/", resolve as a path
48
48
  * 2. Search PATH directories for the command file
49
- * 3. Fall back to registry lookup (for non-VirtualFs filesystems like OverlayFs)
49
+ * 3. Fall back to registry lookup (for non-InMemoryFs filesystems like OverlayFs)
50
50
  */
51
51
  private resolveCommand;
52
52
  /**
@@ -2,7 +2,7 @@
2
2
  * Interpreter Types
3
3
  */
4
4
  import type { CommandNode, FunctionDefNode, ScriptNode, StatementNode } from "../ast/types.js";
5
- import type { IFileSystem } from "../fs-interface.js";
5
+ import type { IFileSystem } from "../fs/interface.js";
6
6
  import type { ExecutionLimits } from "../limits.js";
7
7
  import type { SecureFetch } from "../network/index.js";
8
8
  import type { CommandRegistry, ExecResult } from "../types.js";
@@ -1,5 +1,5 @@
1
1
  import { Bash } from "../Bash.js";
2
- import type { IFileSystem } from "../fs-interface.js";
2
+ import type { IFileSystem } from "../fs/interface.js";
3
3
  import type { NetworkConfig } from "../network/index.js";
4
4
  import type { CommandFinished } from "./Command.js";
5
5
  import { Command } from "./Command.js";
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { IFileSystem } from "./fs-interface.js";
1
+ import type { IFileSystem } from "./fs/interface.js";
2
2
  import type { ExecutionLimits } from "./limits.js";
3
3
  import type { SecureFetch } from "./network/index.js";
4
4
  export interface ExecResult {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "just-bash",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "A simulated bash environment with virtual filesystem",
5
5
  "repository": {
6
6
  "type": "git",
@@ -87,7 +87,7 @@
87
87
  "build:ai": "esbuild dist/ai/index.js --bundle --platform=node --format=esm --minify --outfile=dist/bundle/ai/index.js --external:ai --external:zod --external:diff --external:minimatch --external:sprintf-js --external:turndown",
88
88
  "build:cli": "esbuild dist/cli/just-bash.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bin --entry-names=[name] --chunk-names=chunks/[name]-[hash] --banner:js='#!/usr/bin/env node'",
89
89
  "build:shell": "esbuild dist/cli/shell.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bin/shell --entry-names=[name] --chunk-names=chunks/[name]-[hash] --banner:js='#!/usr/bin/env node'",
90
- "validate": "pnpm build && pnpm typecheck && pnpm lint && pnpm knip && pnpm test:run && pnpm test:dist",
90
+ "validate": "pnpm lint && pnpm knip && pnpm typecheck && pnpm build && pnpm test:run && pnpm test:dist",
91
91
  "typecheck": "tsc --noEmit",
92
92
  "lint": "biome check .",
93
93
  "lint:fix": "biome check --write .",