1- import { aliasCommand , unaliasCommand } from "./commands/alias/alias.js" ;
2- import { awkCommand } from "./commands/awk/awk.js" ;
3- import { basenameCommand } from "./commands/basename/basename.js" ;
4- import { bashCommand , shCommand } from "./commands/bash/bash.js" ;
5- import { catCommand } from "./commands/cat/cat.js" ;
6- import { chmodCommand } from "./commands/chmod/chmod.js" ;
7- import { clearCommand } from "./commands/clear/clear.js" ;
8- import { cpCommand } from "./commands/cp/cp.js" ;
9- import { cutCommand } from "./commands/cut/cut.js" ;
10- import { dirnameCommand } from "./commands/dirname/dirname.js" ;
11- import { duCommand } from "./commands/du/du.js" ;
12- // Import commands
13- import { echoCommand } from "./commands/echo/echo.js" ;
14- import { envCommand , printenvCommand } from "./commands/env/env.js" ;
15- import { findCommand } from "./commands/find/find.js" ;
16- import { grepCommand } from "./commands/grep/grep.js" ;
17- import { headCommand } from "./commands/head/head.js" ;
18- import { historyCommand } from "./commands/history/history.js" ;
19- import { lnCommand } from "./commands/ln/ln.js" ;
20- import { lsCommand } from "./commands/ls/ls.js" ;
21- import { mkdirCommand } from "./commands/mkdir/mkdir.js" ;
22- import { mvCommand } from "./commands/mv/mv.js" ;
23- import { printfCommand } from "./commands/printf/printf.js" ;
24- import { pwdCommand } from "./commands/pwd/pwd.js" ;
25- import { readlinkCommand } from "./commands/readlink/readlink.js" ;
26- import { rmCommand } from "./commands/rm/rm.js" ;
27- import { sedCommand } from "./commands/sed/sed.js" ;
28- import { sortCommand } from "./commands/sort/sort.js" ;
29- import { statCommand } from "./commands/stat/stat.js" ;
30- import { tailCommand } from "./commands/tail/tail.js" ;
31- import { teeCommand } from "./commands/tee/tee.js" ;
32- import { touchCommand } from "./commands/touch/touch.js" ;
33- import { trCommand } from "./commands/tr/tr.js" ;
34- import { treeCommand } from "./commands/tree/tree.js" ;
35- import { falseCommand , trueCommand } from "./commands/true/true.js" ;
36- import { uniqCommand } from "./commands/uniq/uniq.js" ;
37- import { wcCommand } from "./commands/wc/wc.js" ;
38- import { xargsCommand } from "./commands/xargs/xargs.js" ;
1+ import { createLazyCommands } from "./commands/registry.js" ;
392import { type IFileSystem , VirtualFs } from "./fs.js" ;
3+ import type { FileContent } from "./fs-interface.js" ;
404import {
415 GlobExpander ,
426 type Pipeline ,
@@ -60,7 +24,7 @@ export interface BashEnvOptions {
6024 * Initial files to populate the virtual filesystem.
6125 * Only used when fs is not provided.
6226 */
63- files ?: Record < string , string > ;
27+ files ?: Record < string , FileContent > ;
6428 /**
6529 * Environment variables
6630 */
@@ -90,7 +54,7 @@ export interface BashEnvOptions {
9054}
9155
9256export class BashEnv {
93- private fs : IFileSystem ;
57+ readonly fs : IFileSystem ;
9458 private cwd : string ;
9559 private env : Record < string , string > ;
9660 private commands : CommandRegistry = new Map ( ) ;
@@ -150,48 +114,11 @@ export class BashEnv {
150114 }
151115 }
152116
153- // Register built-in commands
154- this . registerCommand ( echoCommand ) ;
155- this . registerCommand ( catCommand ) ;
156- this . registerCommand ( lsCommand ) ;
157- this . registerCommand ( mkdirCommand ) ;
158- this . registerCommand ( pwdCommand ) ;
159- this . registerCommand ( touchCommand ) ;
160- this . registerCommand ( rmCommand ) ;
161- this . registerCommand ( cpCommand ) ;
162- this . registerCommand ( mvCommand ) ;
163- this . registerCommand ( headCommand ) ;
164- this . registerCommand ( tailCommand ) ;
165- this . registerCommand ( wcCommand ) ;
166- this . registerCommand ( grepCommand ) ;
167- this . registerCommand ( sortCommand ) ;
168- this . registerCommand ( uniqCommand ) ;
169- this . registerCommand ( findCommand ) ;
170- this . registerCommand ( sedCommand ) ;
171- this . registerCommand ( cutCommand ) ;
172- this . registerCommand ( trCommand ) ;
173- this . registerCommand ( trueCommand ) ;
174- this . registerCommand ( falseCommand ) ;
175- this . registerCommand ( basenameCommand ) ;
176- this . registerCommand ( dirnameCommand ) ;
177- this . registerCommand ( teeCommand ) ;
178- this . registerCommand ( xargsCommand ) ;
179- this . registerCommand ( envCommand ) ;
180- this . registerCommand ( printenvCommand ) ;
181- this . registerCommand ( treeCommand ) ;
182- this . registerCommand ( statCommand ) ;
183- this . registerCommand ( duCommand ) ;
184- this . registerCommand ( awkCommand ) ;
185- this . registerCommand ( chmodCommand ) ;
186- this . registerCommand ( clearCommand ) ;
187- this . registerCommand ( aliasCommand ) ;
188- this . registerCommand ( unaliasCommand ) ;
189- this . registerCommand ( historyCommand ) ;
190- this . registerCommand ( lnCommand ) ;
191- this . registerCommand ( readlinkCommand ) ;
192- this . registerCommand ( printfCommand ) ;
193- this . registerCommand ( bashCommand ) ;
194- this . registerCommand ( shCommand ) ;
117+ // Register built-in commands with lazy loading
118+ // Commands are registered eagerly but implementations load on first use
119+ for ( const cmd of createLazyCommands ( ) ) {
120+ this . registerCommand ( cmd ) ;
121+ }
195122 }
196123
197124 registerCommand ( command : Command ) : void {
0 commit comments