typescript-virtual-container 1.4.2 → 1.4.4
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/.vscode/settings.json +2 -1
- package/README.md +209 -54
- package/benchmark-results.txt +21 -21
- package/builds/self-standalone.js +196 -189
- package/builds/self-standalone.js.map +4 -4
- package/builds/standalone-wo-sftp.js +167 -160
- package/builds/standalone-wo-sftp.js.map +4 -4
- package/builds/standalone.js +169 -162
- package/builds/standalone.js.map +4 -4
- package/builds/web-full-api.min.js +5 -5
- package/builds/web-full-api.min.js.map +3 -3
- package/builds/web.min.js +5 -5
- package/builds/web.min.js.map +3 -3
- package/bun.lock +4 -6
- package/examples/web.min.js +5 -5
- package/package.json +4 -3
- package/src/Honeypot/index.d.ts.map +1 -0
- package/src/SSHClient/index.d.ts.map +1 -0
- package/src/SSHMimic/exec.d.ts.map +1 -0
- package/src/SSHMimic/executor.d.ts.map +1 -0
- package/src/SSHMimic/hostKey.d.ts.map +1 -0
- package/src/SSHMimic/index.d.ts.map +1 -0
- package/src/SSHMimic/loginBanner.d.ts.map +1 -0
- package/src/SSHMimic/loginFormat.d.ts.map +1 -0
- package/src/SSHMimic/prompt.d.ts.map +1 -0
- package/src/SSHMimic/sftp.d.ts.map +1 -0
- package/src/VirtualFileSystem/binaryPack.d.ts.map +1 -0
- package/{dist → src}/VirtualFileSystem/index.d.ts +47 -0
- package/src/VirtualFileSystem/index.d.ts.map +1 -0
- package/{dist → src}/VirtualFileSystem/index.js +159 -0
- package/src/VirtualFileSystem/index.ts +173 -8
- package/src/VirtualFileSystem/internalTypes.d.ts.map +1 -0
- package/src/VirtualFileSystem/path.d.ts.map +1 -0
- package/src/VirtualPackageManager/index.d.ts.map +1 -0
- package/{dist → src}/VirtualShell/index.d.ts +29 -0
- package/src/VirtualShell/index.d.ts.map +1 -0
- package/{dist → src}/VirtualShell/index.js +29 -0
- package/src/VirtualShell/index.ts +36 -0
- package/src/VirtualShell/shell.d.ts.map +1 -0
- package/src/VirtualShell/shellParser.d.ts.map +1 -0
- package/{dist → src}/VirtualShell/shellParser.js +30 -2
- package/src/VirtualShell/shellParser.ts +29 -3
- package/src/VirtualUserManager/index.d.ts.map +1 -0
- package/src/bun.d.ts +1 -0
- package/src/commands/adduser.d.ts.map +1 -0
- package/src/commands/alias.d.ts.map +1 -0
- package/src/commands/apt.d.ts.map +1 -0
- package/src/commands/awk.d.ts.map +1 -0
- package/{dist → src}/commands/awk.js +1 -2
- package/src/commands/awk.ts +1 -2
- package/src/commands/base64.d.ts.map +1 -0
- package/src/commands/cat.d.ts.map +1 -0
- package/src/commands/cd.d.ts.map +1 -0
- package/{dist → src}/commands/cd.js +2 -2
- package/src/commands/cd.ts +2 -2
- package/src/commands/chmod.d.ts.map +1 -0
- package/src/commands/clear.d.ts.map +1 -0
- package/src/commands/command-helpers.d.ts.map +1 -0
- package/src/commands/cp.d.ts.map +1 -0
- package/src/commands/curl.d.ts.map +1 -0
- package/src/commands/cut.d.ts.map +1 -0
- package/src/commands/date.d.ts.map +1 -0
- package/src/commands/declare.d.ts.map +1 -0
- package/src/commands/deluser.d.ts.map +1 -0
- package/src/commands/df.d.ts.map +1 -0
- package/src/commands/diff.d.ts.map +1 -0
- package/src/commands/dpkg.d.ts.map +1 -0
- package/src/commands/du.d.ts.map +1 -0
- package/src/commands/echo.d.ts.map +1 -0
- package/src/commands/env.d.ts.map +1 -0
- package/src/commands/exit.d.ts.map +1 -0
- package/src/commands/export.d.ts.map +1 -0
- package/{dist → src}/commands/export.js +5 -3
- package/src/commands/export.ts +5 -3
- package/src/commands/find.d.ts.map +1 -0
- package/src/commands/free.d.ts.map +1 -0
- package/src/commands/grep.d.ts.map +1 -0
- package/src/commands/groups.d.ts.map +1 -0
- package/src/commands/gzip.d.ts.map +1 -0
- package/src/commands/head.d.ts.map +1 -0
- package/src/commands/help.d.ts.map +1 -0
- package/src/commands/helpers.d.ts.map +1 -0
- package/{dist → src}/commands/helpers.js +3 -0
- package/src/commands/helpers.ts +3 -0
- package/src/commands/history.d.ts.map +1 -0
- package/src/commands/hostname.d.ts.map +1 -0
- package/src/commands/htop.d.ts.map +1 -0
- package/src/commands/id.d.ts.map +1 -0
- package/src/commands/index.d.ts.map +1 -0
- package/src/commands/kill.d.ts.map +1 -0
- package/src/commands/ln.d.ts.map +1 -0
- package/src/commands/ls.d.ts.map +1 -0
- package/src/commands/ls.js +200 -0
- package/src/commands/ls.ts +210 -41
- package/src/commands/lsb-release.d.ts.map +1 -0
- package/src/commands/man.d.ts.map +1 -0
- package/src/commands/mkdir.d.ts.map +1 -0
- package/src/commands/mv.d.ts.map +1 -0
- package/src/commands/nano.d.ts.map +1 -0
- package/src/commands/neofetch.d.ts.map +1 -0
- package/src/commands/node.d.ts.map +1 -0
- package/src/commands/npm.d.ts.map +1 -0
- package/src/commands/passwd.d.ts.map +1 -0
- package/src/commands/ping.d.ts.map +1 -0
- package/src/commands/printf.d.ts.map +1 -0
- package/src/commands/ps.d.ts.map +1 -0
- package/src/commands/pwd.d.ts.map +1 -0
- package/src/commands/python.d.ts.map +1 -0
- package/src/commands/read.d.ts.map +1 -0
- package/src/commands/registry.d.ts.map +1 -0
- package/{dist → src}/commands/registry.js +2 -0
- package/src/commands/registry.ts +2 -0
- package/src/commands/rm.d.ts.map +1 -0
- package/src/commands/runtime.d.ts.map +1 -0
- package/{dist → src}/commands/runtime.js +64 -3
- package/src/commands/runtime.ts +86 -6
- package/src/commands/sed.d.ts.map +1 -0
- package/src/commands/seq.d.ts +4 -0
- package/src/commands/seq.d.ts.map +1 -0
- package/src/commands/seq.js +50 -0
- package/src/commands/seq.ts +43 -0
- package/src/commands/set.d.ts.map +1 -0
- package/src/commands/sh.d.ts +3 -0
- package/src/commands/sh.d.ts.map +1 -0
- package/{dist → src}/commands/sh.js +158 -11
- package/src/commands/sh.ts +148 -20
- package/src/commands/shift.d.ts.map +1 -0
- package/src/commands/sleep.d.ts.map +1 -0
- package/src/commands/sort.d.ts.map +1 -0
- package/src/commands/source.d.ts.map +1 -0
- package/src/commands/stat.d.ts.map +1 -0
- package/src/commands/su.d.ts.map +1 -0
- package/src/commands/sudo.d.ts.map +1 -0
- package/src/commands/tail.d.ts.map +1 -0
- package/src/commands/tar.d.ts.map +1 -0
- package/src/commands/tee.d.ts.map +1 -0
- package/src/commands/test.d.ts.map +1 -0
- package/src/commands/test.ts +4 -2
- package/src/commands/touch.d.ts.map +1 -0
- package/src/commands/tr.d.ts.map +1 -0
- package/src/commands/tree.d.ts.map +1 -0
- package/src/commands/true.d.ts.map +1 -0
- package/src/commands/type.d.ts.map +1 -0
- package/src/commands/uname.d.ts.map +1 -0
- package/src/commands/uniq.d.ts.map +1 -0
- package/src/commands/unset.d.ts.map +1 -0
- package/src/commands/uptime.d.ts.map +1 -0
- package/src/commands/wc.d.ts.map +1 -0
- package/{dist → src}/commands/wc.js +1 -1
- package/src/commands/wc.ts +1 -1
- package/src/commands/wget.d.ts.map +1 -0
- package/src/commands/which.d.ts.map +1 -0
- package/src/commands/who.d.ts.map +1 -0
- package/src/commands/whoami.d.ts.map +1 -0
- package/src/commands/xargs.d.ts.map +1 -0
- package/src/index.d.ts.map +1 -0
- package/src/modules/linuxRootfs.d.ts +59 -0
- package/src/modules/linuxRootfs.d.ts.map +1 -0
- package/src/modules/linuxRootfs.js +619 -0
- package/src/modules/linuxRootfs.ts +420 -231
- package/src/modules/neofetch.d.ts.map +1 -0
- package/src/modules/shellInteractive.d.ts.map +1 -0
- package/src/modules/shellRuntime.d.ts.map +1 -0
- package/{dist → src}/self-standalone.d.ts.map +1 -1
- package/src/standalone-wo-sftp.d.ts.map +1 -0
- package/{dist → src}/standalone.d.ts.map +1 -1
- package/{dist → src}/types/commands.d.ts +1 -1
- package/src/types/commands.d.ts.map +1 -0
- package/src/types/commands.ts +1 -1
- package/{dist → src}/types/pipeline.d.ts +6 -0
- package/src/types/pipeline.d.ts.map +1 -0
- package/src/types/pipeline.ts +6 -0
- package/src/types/streams.d.ts.map +1 -0
- package/{dist → src}/types/vfs.d.ts +15 -0
- package/src/types/vfs.d.ts.map +1 -0
- package/src/types/vfs.ts +17 -0
- package/{dist → src}/utils/expand.d.ts +11 -2
- package/src/utils/expand.d.ts.map +1 -0
- package/src/utils/expand.js +476 -0
- package/src/utils/expand.ts +281 -28
- package/src/utils/perfLogger.d.ts.map +1 -0
- package/src/utils/tokenize.d.ts.map +1 -0
- package/{dist → src}/utils/tokenize.js +40 -0
- package/src/utils/tokenize.ts +20 -0
- package/src/utils/vfsDiff.d.ts.map +1 -0
- package/src/web-api.d.ts.map +1 -0
- package/src/web-full.d.ts.map +1 -0
- package/src/web.d.ts.map +1 -0
- package/tests/command-helpers.test.d.ts +2 -0
- package/tests/command-helpers.test.d.ts.map +1 -0
- package/tests/command-helpers.test.js +92 -0
- package/tests/command-helpers.test.ts +80 -0
- package/tests/commands-admin-net.test.d.ts +2 -0
- package/tests/commands-admin-net.test.d.ts.map +1 -0
- package/tests/commands-admin-net.test.js +353 -0
- package/tests/commands-admin-net.test.ts +441 -0
- package/tests/commands-advanced.test.d.ts +2 -0
- package/tests/commands-advanced.test.d.ts.map +1 -0
- package/tests/commands-advanced.test.js +378 -0
- package/tests/commands-advanced.test.ts +456 -0
- package/tests/commands-core.test.d.ts +2 -0
- package/tests/commands-core.test.d.ts.map +1 -0
- package/tests/commands-core.test.js +477 -0
- package/tests/commands-core.test.ts +562 -0
- package/tests/commands-missing.test.d.ts +2 -0
- package/tests/commands-missing.test.d.ts.map +1 -0
- package/tests/commands-missing.test.js +470 -0
- package/tests/commands-missing.test.ts +570 -0
- package/tests/commands-specific-units.test.d.ts +2 -0
- package/tests/commands-specific-units.test.d.ts.map +1 -0
- package/tests/commands-specific-units.test.js +264 -0
- package/tests/commands-specific-units.test.ts +327 -0
- package/tests/commands-text-sys.test.d.ts +2 -0
- package/tests/commands-text-sys.test.d.ts.map +1 -0
- package/tests/commands-text-sys.test.js +366 -0
- package/tests/commands-text-sys.test.ts +445 -0
- package/tests/expand.test.d.ts +2 -0
- package/tests/expand.test.d.ts.map +1 -0
- package/tests/expand.test.js +138 -0
- package/tests/expand.test.ts +170 -0
- package/tests/helpers.test.d.ts +2 -0
- package/tests/helpers.test.d.ts.map +1 -0
- package/tests/helpers.test.js +52 -0
- package/tests/helpers.test.ts +75 -0
- package/tests/new-features.test.d.ts +2 -0
- package/tests/new-features.test.d.ts.map +1 -0
- package/tests/new-features.test.js +850 -0
- package/tests/parser-executor.test.d.ts +2 -0
- package/tests/parser-executor.test.d.ts.map +1 -0
- package/tests/parser-executor.test.js +25 -0
- package/tests/sftp.test.d.ts +2 -0
- package/tests/sftp.test.d.ts.map +1 -0
- package/tests/sftp.test.js +246 -0
- package/tests/ssh-exec.test.d.ts +2 -0
- package/tests/ssh-exec.test.d.ts.map +1 -0
- package/tests/ssh-exec.test.js +39 -0
- package/tests/test-helper.d.ts +56 -0
- package/tests/test-helper.d.ts.map +1 -0
- package/tests/test-helper.js +71 -0
- package/tests/test-helper.ts +79 -0
- package/tests/users.test.d.ts +2 -0
- package/tests/users.test.d.ts.map +1 -0
- package/tests/users.test.js +71 -0
- package/tests/web.test.d.ts +2 -0
- package/tests/web.test.d.ts.map +1 -0
- package/tests/web.test.js +149 -0
- package/tsconfig.json +2 -4
- package/dist/Honeypot/index.d.ts.map +0 -1
- package/dist/SSHClient/index.d.ts.map +0 -1
- package/dist/SSHMimic/exec.d.ts.map +0 -1
- package/dist/SSHMimic/executor.d.ts.map +0 -1
- package/dist/SSHMimic/hostKey.d.ts.map +0 -1
- package/dist/SSHMimic/index.d.ts.map +0 -1
- package/dist/SSHMimic/loginBanner.d.ts.map +0 -1
- package/dist/SSHMimic/loginFormat.d.ts.map +0 -1
- package/dist/SSHMimic/prompt.d.ts.map +0 -1
- package/dist/SSHMimic/sftp.d.ts.map +0 -1
- package/dist/VirtualFileSystem/binaryPack.d.ts.map +0 -1
- package/dist/VirtualFileSystem/index.d.ts.map +0 -1
- package/dist/VirtualFileSystem/internalTypes.d.ts.map +0 -1
- package/dist/VirtualFileSystem/path.d.ts.map +0 -1
- package/dist/VirtualPackageManager/index.d.ts.map +0 -1
- package/dist/VirtualShell/index.d.ts.map +0 -1
- package/dist/VirtualShell/shell.d.ts.map +0 -1
- package/dist/VirtualShell/shellParser.d.ts.map +0 -1
- package/dist/VirtualUserManager/index.d.ts.map +0 -1
- package/dist/commands/adduser.d.ts.map +0 -1
- package/dist/commands/alias.d.ts.map +0 -1
- package/dist/commands/apt.d.ts.map +0 -1
- package/dist/commands/awk.d.ts.map +0 -1
- package/dist/commands/base64.d.ts.map +0 -1
- package/dist/commands/cat.d.ts.map +0 -1
- package/dist/commands/cd.d.ts.map +0 -1
- package/dist/commands/chmod.d.ts.map +0 -1
- package/dist/commands/clear.d.ts.map +0 -1
- package/dist/commands/command-helpers.d.ts.map +0 -1
- package/dist/commands/cp.d.ts.map +0 -1
- package/dist/commands/curl.d.ts.map +0 -1
- package/dist/commands/cut.d.ts.map +0 -1
- package/dist/commands/date.d.ts.map +0 -1
- package/dist/commands/declare.d.ts.map +0 -1
- package/dist/commands/deluser.d.ts.map +0 -1
- package/dist/commands/df.d.ts.map +0 -1
- package/dist/commands/diff.d.ts.map +0 -1
- package/dist/commands/dpkg.d.ts.map +0 -1
- package/dist/commands/du.d.ts.map +0 -1
- package/dist/commands/echo.d.ts.map +0 -1
- package/dist/commands/env.d.ts.map +0 -1
- package/dist/commands/exit.d.ts.map +0 -1
- package/dist/commands/export.d.ts.map +0 -1
- package/dist/commands/find.d.ts.map +0 -1
- package/dist/commands/free.d.ts.map +0 -1
- package/dist/commands/grep.d.ts.map +0 -1
- package/dist/commands/groups.d.ts.map +0 -1
- package/dist/commands/gzip.d.ts.map +0 -1
- package/dist/commands/head.d.ts.map +0 -1
- package/dist/commands/help.d.ts.map +0 -1
- package/dist/commands/helpers.d.ts.map +0 -1
- package/dist/commands/history.d.ts.map +0 -1
- package/dist/commands/hostname.d.ts.map +0 -1
- package/dist/commands/htop.d.ts.map +0 -1
- package/dist/commands/id.d.ts.map +0 -1
- package/dist/commands/index.d.ts.map +0 -1
- package/dist/commands/kill.d.ts.map +0 -1
- package/dist/commands/ln.d.ts.map +0 -1
- package/dist/commands/ls.d.ts.map +0 -1
- package/dist/commands/ls.js +0 -67
- package/dist/commands/lsb-release.d.ts.map +0 -1
- package/dist/commands/man.d.ts.map +0 -1
- package/dist/commands/mkdir.d.ts.map +0 -1
- package/dist/commands/mv.d.ts.map +0 -1
- package/dist/commands/nano.d.ts.map +0 -1
- package/dist/commands/neofetch.d.ts.map +0 -1
- package/dist/commands/node.d.ts.map +0 -1
- package/dist/commands/npm.d.ts.map +0 -1
- package/dist/commands/passwd.d.ts.map +0 -1
- package/dist/commands/ping.d.ts.map +0 -1
- package/dist/commands/printf.d.ts.map +0 -1
- package/dist/commands/ps.d.ts.map +0 -1
- package/dist/commands/pwd.d.ts.map +0 -1
- package/dist/commands/python.d.ts.map +0 -1
- package/dist/commands/read.d.ts.map +0 -1
- package/dist/commands/registry.d.ts.map +0 -1
- package/dist/commands/rm.d.ts.map +0 -1
- package/dist/commands/runtime.d.ts.map +0 -1
- package/dist/commands/sed.d.ts.map +0 -1
- package/dist/commands/set.d.ts.map +0 -1
- package/dist/commands/sh.d.ts +0 -9
- package/dist/commands/sh.d.ts.map +0 -1
- package/dist/commands/shift.d.ts.map +0 -1
- package/dist/commands/sleep.d.ts.map +0 -1
- package/dist/commands/sort.d.ts.map +0 -1
- package/dist/commands/source.d.ts.map +0 -1
- package/dist/commands/stat.d.ts.map +0 -1
- package/dist/commands/su.d.ts.map +0 -1
- package/dist/commands/sudo.d.ts.map +0 -1
- package/dist/commands/tail.d.ts.map +0 -1
- package/dist/commands/tar.d.ts.map +0 -1
- package/dist/commands/tee.d.ts.map +0 -1
- package/dist/commands/test.d.ts.map +0 -1
- package/dist/commands/touch.d.ts.map +0 -1
- package/dist/commands/tr.d.ts.map +0 -1
- package/dist/commands/tree.d.ts.map +0 -1
- package/dist/commands/true.d.ts.map +0 -1
- package/dist/commands/type.d.ts.map +0 -1
- package/dist/commands/uname.d.ts.map +0 -1
- package/dist/commands/uniq.d.ts.map +0 -1
- package/dist/commands/unset.d.ts.map +0 -1
- package/dist/commands/uptime.d.ts.map +0 -1
- package/dist/commands/wc.d.ts.map +0 -1
- package/dist/commands/wget.d.ts.map +0 -1
- package/dist/commands/which.d.ts.map +0 -1
- package/dist/commands/who.d.ts.map +0 -1
- package/dist/commands/whoami.d.ts.map +0 -1
- package/dist/commands/xargs.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/modules/linuxRootfs.d.ts +0 -41
- package/dist/modules/linuxRootfs.d.ts.map +0 -1
- package/dist/modules/linuxRootfs.js +0 -440
- package/dist/modules/neofetch.d.ts.map +0 -1
- package/dist/modules/shellInteractive.d.ts.map +0 -1
- package/dist/modules/shellRuntime.d.ts.map +0 -1
- package/dist/standalone-wo-sftp.d.ts.map +0 -1
- package/dist/types/commands.d.ts.map +0 -1
- package/dist/types/pipeline.d.ts.map +0 -1
- package/dist/types/streams.d.ts.map +0 -1
- package/dist/types/vfs.d.ts.map +0 -1
- package/dist/utils/expand.d.ts.map +0 -1
- package/dist/utils/expand.js +0 -183
- package/dist/utils/perfLogger.d.ts.map +0 -1
- package/dist/utils/tokenize.d.ts.map +0 -1
- package/dist/utils/vfsDiff.d.ts.map +0 -1
- package/dist/web-api.d.ts.map +0 -1
- package/dist/web-full.d.ts.map +0 -1
- package/dist/web.d.ts.map +0 -1
- package/tests/bun-test-shim.ts +0 -9
- /package/{dist → src}/Honeypot/index.d.ts +0 -0
- /package/{dist → src}/Honeypot/index.js +0 -0
- /package/{dist → src}/SSHClient/index.d.ts +0 -0
- /package/{dist → src}/SSHClient/index.js +0 -0
- /package/{dist → src}/SSHMimic/exec.d.ts +0 -0
- /package/{dist → src}/SSHMimic/exec.js +0 -0
- /package/{dist → src}/SSHMimic/executor.d.ts +0 -0
- /package/{dist → src}/SSHMimic/executor.js +0 -0
- /package/{dist → src}/SSHMimic/hostKey.d.ts +0 -0
- /package/{dist → src}/SSHMimic/hostKey.js +0 -0
- /package/{dist → src}/SSHMimic/index.d.ts +0 -0
- /package/{dist → src}/SSHMimic/index.js +0 -0
- /package/{dist → src}/SSHMimic/loginBanner.d.ts +0 -0
- /package/{dist → src}/SSHMimic/loginBanner.js +0 -0
- /package/{dist → src}/SSHMimic/loginFormat.d.ts +0 -0
- /package/{dist → src}/SSHMimic/loginFormat.js +0 -0
- /package/{dist → src}/SSHMimic/prompt.d.ts +0 -0
- /package/{dist → src}/SSHMimic/prompt.js +0 -0
- /package/{dist → src}/SSHMimic/sftp.d.ts +0 -0
- /package/{dist → src}/SSHMimic/sftp.js +0 -0
- /package/{dist → src}/VirtualFileSystem/binaryPack.d.ts +0 -0
- /package/{dist → src}/VirtualFileSystem/binaryPack.js +0 -0
- /package/{dist → src}/VirtualFileSystem/internalTypes.d.ts +0 -0
- /package/{dist → src}/VirtualFileSystem/internalTypes.js +0 -0
- /package/{dist → src}/VirtualFileSystem/path.d.ts +0 -0
- /package/{dist → src}/VirtualFileSystem/path.js +0 -0
- /package/{dist → src}/VirtualPackageManager/index.d.ts +0 -0
- /package/{dist → src}/VirtualPackageManager/index.js +0 -0
- /package/{dist → src}/VirtualShell/shell.d.ts +0 -0
- /package/{dist → src}/VirtualShell/shell.js +0 -0
- /package/{dist → src}/VirtualShell/shellParser.d.ts +0 -0
- /package/{dist → src}/VirtualUserManager/index.d.ts +0 -0
- /package/{dist → src}/VirtualUserManager/index.js +0 -0
- /package/{dist → src}/commands/adduser.d.ts +0 -0
- /package/{dist → src}/commands/adduser.js +0 -0
- /package/{dist → src}/commands/alias.d.ts +0 -0
- /package/{dist → src}/commands/alias.js +0 -0
- /package/{dist → src}/commands/apt.d.ts +0 -0
- /package/{dist → src}/commands/apt.js +0 -0
- /package/{dist → src}/commands/awk.d.ts +0 -0
- /package/{dist → src}/commands/base64.d.ts +0 -0
- /package/{dist → src}/commands/base64.js +0 -0
- /package/{dist → src}/commands/cat.d.ts +0 -0
- /package/{dist → src}/commands/cat.js +0 -0
- /package/{dist → src}/commands/cd.d.ts +0 -0
- /package/{dist → src}/commands/chmod.d.ts +0 -0
- /package/{dist → src}/commands/chmod.js +0 -0
- /package/{dist → src}/commands/clear.d.ts +0 -0
- /package/{dist → src}/commands/clear.js +0 -0
- /package/{dist → src}/commands/command-helpers.d.ts +0 -0
- /package/{dist → src}/commands/command-helpers.js +0 -0
- /package/{dist → src}/commands/cp.d.ts +0 -0
- /package/{dist → src}/commands/cp.js +0 -0
- /package/{dist → src}/commands/curl.d.ts +0 -0
- /package/{dist → src}/commands/curl.js +0 -0
- /package/{dist → src}/commands/cut.d.ts +0 -0
- /package/{dist → src}/commands/cut.js +0 -0
- /package/{dist → src}/commands/date.d.ts +0 -0
- /package/{dist → src}/commands/date.js +0 -0
- /package/{dist → src}/commands/declare.d.ts +0 -0
- /package/{dist → src}/commands/declare.js +0 -0
- /package/{dist → src}/commands/deluser.d.ts +0 -0
- /package/{dist → src}/commands/deluser.js +0 -0
- /package/{dist → src}/commands/df.d.ts +0 -0
- /package/{dist → src}/commands/df.js +0 -0
- /package/{dist → src}/commands/diff.d.ts +0 -0
- /package/{dist → src}/commands/diff.js +0 -0
- /package/{dist → src}/commands/dpkg.d.ts +0 -0
- /package/{dist → src}/commands/dpkg.js +0 -0
- /package/{dist → src}/commands/du.d.ts +0 -0
- /package/{dist → src}/commands/du.js +0 -0
- /package/{dist → src}/commands/echo.d.ts +0 -0
- /package/{dist → src}/commands/echo.js +0 -0
- /package/{dist → src}/commands/env.d.ts +0 -0
- /package/{dist → src}/commands/env.js +0 -0
- /package/{dist → src}/commands/exit.d.ts +0 -0
- /package/{dist → src}/commands/exit.js +0 -0
- /package/{dist → src}/commands/export.d.ts +0 -0
- /package/{dist → src}/commands/find.d.ts +0 -0
- /package/{dist → src}/commands/find.js +0 -0
- /package/{dist → src}/commands/free.d.ts +0 -0
- /package/{dist → src}/commands/free.js +0 -0
- /package/{dist → src}/commands/grep.d.ts +0 -0
- /package/{dist → src}/commands/grep.js +0 -0
- /package/{dist → src}/commands/groups.d.ts +0 -0
- /package/{dist → src}/commands/groups.js +0 -0
- /package/{dist → src}/commands/gzip.d.ts +0 -0
- /package/{dist → src}/commands/gzip.js +0 -0
- /package/{dist → src}/commands/head.d.ts +0 -0
- /package/{dist → src}/commands/head.js +0 -0
- /package/{dist → src}/commands/help.d.ts +0 -0
- /package/{dist → src}/commands/help.js +0 -0
- /package/{dist → src}/commands/helpers.d.ts +0 -0
- /package/{dist → src}/commands/history.d.ts +0 -0
- /package/{dist → src}/commands/history.js +0 -0
- /package/{dist → src}/commands/hostname.d.ts +0 -0
- /package/{dist → src}/commands/hostname.js +0 -0
- /package/{dist → src}/commands/htop.d.ts +0 -0
- /package/{dist → src}/commands/htop.js +0 -0
- /package/{dist → src}/commands/id.d.ts +0 -0
- /package/{dist → src}/commands/id.js +0 -0
- /package/{dist → src}/commands/index.d.ts +0 -0
- /package/{dist → src}/commands/index.js +0 -0
- /package/{dist → src}/commands/kill.d.ts +0 -0
- /package/{dist → src}/commands/kill.js +0 -0
- /package/{dist → src}/commands/ln.d.ts +0 -0
- /package/{dist → src}/commands/ln.js +0 -0
- /package/{dist → src}/commands/ls.d.ts +0 -0
- /package/{dist → src}/commands/lsb-release.d.ts +0 -0
- /package/{dist → src}/commands/lsb-release.js +0 -0
- /package/{dist → src}/commands/man.d.ts +0 -0
- /package/{dist → src}/commands/man.js +0 -0
- /package/{dist → src}/commands/mkdir.d.ts +0 -0
- /package/{dist → src}/commands/mkdir.js +0 -0
- /package/{dist → src}/commands/mv.d.ts +0 -0
- /package/{dist → src}/commands/mv.js +0 -0
- /package/{dist → src}/commands/nano.d.ts +0 -0
- /package/{dist → src}/commands/nano.js +0 -0
- /package/{dist → src}/commands/neofetch.d.ts +0 -0
- /package/{dist → src}/commands/neofetch.js +0 -0
- /package/{dist → src}/commands/node.d.ts +0 -0
- /package/{dist → src}/commands/node.js +0 -0
- /package/{dist → src}/commands/npm.d.ts +0 -0
- /package/{dist → src}/commands/npm.js +0 -0
- /package/{dist → src}/commands/passwd.d.ts +0 -0
- /package/{dist → src}/commands/passwd.js +0 -0
- /package/{dist → src}/commands/ping.d.ts +0 -0
- /package/{dist → src}/commands/ping.js +0 -0
- /package/{dist → src}/commands/printf.d.ts +0 -0
- /package/{dist → src}/commands/printf.js +0 -0
- /package/{dist → src}/commands/ps.d.ts +0 -0
- /package/{dist → src}/commands/ps.js +0 -0
- /package/{dist → src}/commands/pwd.d.ts +0 -0
- /package/{dist → src}/commands/pwd.js +0 -0
- /package/{dist → src}/commands/python.d.ts +0 -0
- /package/{dist → src}/commands/python.js +0 -0
- /package/{dist → src}/commands/read.d.ts +0 -0
- /package/{dist → src}/commands/read.js +0 -0
- /package/{dist → src}/commands/registry.d.ts +0 -0
- /package/{dist → src}/commands/rm.d.ts +0 -0
- /package/{dist → src}/commands/rm.js +0 -0
- /package/{dist → src}/commands/runtime.d.ts +0 -0
- /package/{dist → src}/commands/sed.d.ts +0 -0
- /package/{dist → src}/commands/sed.js +0 -0
- /package/{dist → src}/commands/set.d.ts +0 -0
- /package/{dist → src}/commands/set.js +0 -0
- /package/{dist → src}/commands/shift.d.ts +0 -0
- /package/{dist → src}/commands/shift.js +0 -0
- /package/{dist → src}/commands/sleep.d.ts +0 -0
- /package/{dist → src}/commands/sleep.js +0 -0
- /package/{dist → src}/commands/sort.d.ts +0 -0
- /package/{dist → src}/commands/sort.js +0 -0
- /package/{dist → src}/commands/source.d.ts +0 -0
- /package/{dist → src}/commands/source.js +0 -0
- /package/{dist → src}/commands/stat.d.ts +0 -0
- /package/{dist → src}/commands/stat.js +0 -0
- /package/{dist → src}/commands/su.d.ts +0 -0
- /package/{dist → src}/commands/su.js +0 -0
- /package/{dist → src}/commands/sudo.d.ts +0 -0
- /package/{dist → src}/commands/sudo.js +0 -0
- /package/{dist → src}/commands/tail.d.ts +0 -0
- /package/{dist → src}/commands/tail.js +0 -0
- /package/{dist → src}/commands/tar.d.ts +0 -0
- /package/{dist → src}/commands/tar.js +0 -0
- /package/{dist → src}/commands/tee.d.ts +0 -0
- /package/{dist → src}/commands/tee.js +0 -0
- /package/{dist → src}/commands/test.d.ts +0 -0
- /package/{dist → src}/commands/test.js +0 -0
- /package/{dist → src}/commands/touch.d.ts +0 -0
- /package/{dist → src}/commands/touch.js +0 -0
- /package/{dist → src}/commands/tr.d.ts +0 -0
- /package/{dist → src}/commands/tr.js +0 -0
- /package/{dist → src}/commands/tree.d.ts +0 -0
- /package/{dist → src}/commands/tree.js +0 -0
- /package/{dist → src}/commands/true.d.ts +0 -0
- /package/{dist → src}/commands/true.js +0 -0
- /package/{dist → src}/commands/type.d.ts +0 -0
- /package/{dist → src}/commands/type.js +0 -0
- /package/{dist → src}/commands/uname.d.ts +0 -0
- /package/{dist → src}/commands/uname.js +0 -0
- /package/{dist → src}/commands/uniq.d.ts +0 -0
- /package/{dist → src}/commands/uniq.js +0 -0
- /package/{dist → src}/commands/unset.d.ts +0 -0
- /package/{dist → src}/commands/unset.js +0 -0
- /package/{dist → src}/commands/uptime.d.ts +0 -0
- /package/{dist → src}/commands/uptime.js +0 -0
- /package/{dist → src}/commands/wc.d.ts +0 -0
- /package/{dist → src}/commands/wget.d.ts +0 -0
- /package/{dist → src}/commands/wget.js +0 -0
- /package/{dist → src}/commands/which.d.ts +0 -0
- /package/{dist → src}/commands/which.js +0 -0
- /package/{dist → src}/commands/who.d.ts +0 -0
- /package/{dist → src}/commands/who.js +0 -0
- /package/{dist → src}/commands/whoami.d.ts +0 -0
- /package/{dist → src}/commands/whoami.js +0 -0
- /package/{dist → src}/commands/xargs.d.ts +0 -0
- /package/{dist → src}/commands/xargs.js +0 -0
- /package/{dist → src}/index.d.ts +0 -0
- /package/{dist → src}/index.js +0 -0
- /package/{dist → src}/modules/neofetch.d.ts +0 -0
- /package/{dist → src}/modules/neofetch.js +0 -0
- /package/{dist → src}/modules/shellInteractive.d.ts +0 -0
- /package/{dist → src}/modules/shellInteractive.js +0 -0
- /package/{dist → src}/modules/shellRuntime.d.ts +0 -0
- /package/{dist → src}/modules/shellRuntime.js +0 -0
- /package/{dist → src}/self-standalone.d.ts +0 -0
- /package/{dist → src}/self-standalone.js +0 -0
- /package/{dist → src}/standalone-wo-sftp.d.ts +0 -0
- /package/{dist → src}/standalone-wo-sftp.js +0 -0
- /package/{dist → src}/standalone.d.ts +0 -0
- /package/{dist → src}/standalone.js +0 -0
- /package/{dist → src}/types/commands.js +0 -0
- /package/{dist → src}/types/pipeline.js +0 -0
- /package/{dist → src}/types/streams.d.ts +0 -0
- /package/{dist → src}/types/streams.js +0 -0
- /package/{dist → src}/types/vfs.js +0 -0
- /package/{dist → src}/utils/perfLogger.d.ts +0 -0
- /package/{dist → src}/utils/perfLogger.js +0 -0
- /package/{dist → src}/utils/tokenize.d.ts +0 -0
- /package/{dist → src}/utils/vfsDiff.d.ts +0 -0
- /package/{dist → src}/utils/vfsDiff.js +0 -0
- /package/{dist → src}/web-api.d.ts +0 -0
- /package/{dist → src}/web-api.js +0 -0
- /package/{dist → src}/web-full.d.ts +0 -0
- /package/{dist → src}/web-full.js +0 -0
- /package/{dist → src}/web.d.ts +0 -0
- /package/{dist → src}/web.js +0 -0
package/examples/web.min.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var k=Object.defineProperty;var O=(o,e,t)=>e in o?k(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var u=(o,e,t)=>O(o,typeof e!="symbol"?e+"":e,t);function x(o){let e=[],t="",r=!1,n="",s=0;for(;s<o.length;){let i=o[s],a=o[s+1];if((i==='"'||i==="'")&&!r){r=!0,n=i,s++;continue}if(r&&i===n){r=!1,n="",s++;continue}if(r){t+=i,s++;continue}if(i===" "){t&&(e.push(t),t=""),s++;continue}if((i===">"||i==="<")&&!r){t&&(e.push(t),t=""),i===">"&&a===">"?(e.push(">>"),s+=2):(e.push(i),s++);continue}t+=i,s++}return t&&e.push(t),e}function w(o){let e=o.trim();if(!e)return{statements:[],isValid:!0};try{return{statements:z(e),isValid:!0}}catch(t){return{statements:[],isValid:!1,error:t.message}}}function z(o){let e=A(o),t=[];for(let r of e){let s={pipeline:{commands:R(r.text.trim()),isValid:!0}};r.op&&(s.op=r.op),t.push(s)}return t}function A(o){let e=[],t="",r=0,n=!1,s="",i=0,a=c=>{t.trim()&&e.push({text:t,op:c}),t=""};for(;i<o.length;){let c=o[i],d=o.slice(i,i+2);if((c==='"'||c==="'")&&!n){n=!0,s=c,t+=c,i++;continue}if(n&&c===s){n=!1,t+=c,i++;continue}if(n){t+=c,i++;continue}if(c==="("){r++,t+=c,i++;continue}if(c===")"){r--,t+=c,i++;continue}if(r>0){t+=c,i++;continue}if(d==="&&"){a("&&"),i+=2;continue}if(d==="||"){a("||"),i+=2;continue}if(c===";"){a(";"),i++;continue}t+=c,i++}return a(),e}function R(o){return F(o).map(L)}function F(o){let e=[],t="",r=!1,n="";for(let i=0;i<o.length;i++){let a=o[i];if((a==='"'||a==="'")&&!r){r=!0,n=a,t+=a;continue}if(r&&a===n){r=!1,t+=a;continue}if(r){t+=a;continue}if(a==="|"&&o[i+1]!=="|"){if(!t.trim())throw new Error("Syntax error near unexpected token '|'");e.push(t.trim()),t=""}else t+=a}let s=t.trim();if(!s&&e.length>0)throw new Error("Syntax error near unexpected token '|'");return s&&e.push(s),e}function L(o){let e=x(o);if(e.length===0)return{name:"",args:[]};let t=[],r,n,s=!1,i=0;for(;i<e.length;){let c=e[i];if(c==="<"){if(i++,i>=e.length)throw new Error("Syntax error: expected filename after <");r=e[i],i++}else if(c===">>"){if(i++,i>=e.length)throw new Error("Syntax error: expected filename after >>");n=e[i],s=!0,i++}else if(c===">"){if(i++,i>=e.length)throw new Error("Syntax error: expected filename after >");n=e[i],s=!1,i++}else t.push(c),i++}return{name:(t[0]??"").toLowerCase(),args:t.slice(1),inputFile:r,outputFile:n,appendOutput:s}}function I(o,e){let t=o.replace(/\b([A-Za-z_][A-Za-z0-9_]*)\b/g,(r,n)=>{let s=e[n];return s!==void 0&&s!==""?s:"0"});if(!/^[\d\s+\-*/%()^!&|<>=,. ]+$/.test(t))return NaN;try{let r=Function(`"use strict"; return (${t.replace(/\*\*/g,"**")});`)();return typeof r=="number"?Math.trunc(r):NaN}catch{return NaN}}function M(o,e){let t=[],r=0;for(;r<o.length;){let n=o.indexOf("'",r);if(n===-1){t.push(e(o.slice(r)));break}t.push(e(o.slice(r,n)));let s=o.indexOf("'",n+1);if(s===-1){t.push(o.slice(n));break}t.push(o.slice(n,s+1)),r=s+1}return t.join("")}function p(o,e,t=0,r){let n=r??e.HOME??"/home/user";return M(o,s=>{let i=s;return i=i.replace(/(^|[\s:])~(\/|$)/g,(a,c,d)=>`${c}${n}${d}`),i=i.replace(/\$\?/g,String(t)),i=i.replace(/\$\$/g,"1"),i=i.replace(/\$#/g,"0"),i=i.replace(/\$\(\(([^)]+(?:\([^)]*\)[^)]*)*)\)\)/g,(a,c)=>{let d=I(c,e);return Number.isNaN(d)?"0":String(d)}),i=i.replace(/\$\{#([A-Za-z_][A-Za-z0-9_]*)\}/g,(a,c)=>String((e[c]??"").length)),i=i.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):-([^}]*)\}/g,(a,c,d)=>e[c]!==void 0&&e[c]!==""?e[c]:d),i=i.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):=([^}]*)\}/g,(a,c,d)=>((e[c]===void 0||e[c]==="")&&(e[c]=d),e[c])),i=i.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):\+([^}]*)\}/g,(a,c,d)=>e[c]!==void 0&&e[c]!==""?d:""),i=i.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(a,c)=>e[c]??""),i=i.replace(/\$([A-Za-z_][A-Za-z0-9_]*)/g,(a,c)=>e[c]??""),i})}async function C(o,e,t,r){if(o.includes("$(")){let n="",s=!1,i=0;for(;i<o.length;){let a=o[i];if(a==="'"&&!s){s=!0,n+=a,i++;continue}if(a==="'"&&s){s=!1,n+=a,i++;continue}if(!s&&a==="$"&&o[i+1]==="("){if(o[i+2]==="("){n+=a,i++;continue}let c=0,d=i+1;for(;d<o.length;){if(o[d]==="(")c++;else if(o[d]===")"&&(c--,c===0))break;d++}let g=o.slice(i+2,d).trim(),P=(await r(g)).replace(/\n$/,"");n+=P,i=d+1;continue}n+=a,i++}o=n}return p(o,e,t)}var _=new TextEncoder,B=new TextDecoder;function j(o){let e="";for(let t of o)e+=String.fromCharCode(t);return btoa(e)}function N(o){let e=atob(o),t=new Uint8Array(e.length);for(let r=0;r<e.length;r+=1)t[r]=e.charCodeAt(r);return t}function l(o,e="/"){let r=(o.startsWith("/")?o:`${e}/${o}`).split("/"),n=[];for(let s of r)if(!(!s||s===".")){if(s===".."){n.pop();continue}n.push(s)}return`/${n.join("/")}`||"/"}function h(o){let e=l(o);if(e==="/")return"/";let t=e.split("/").filter(Boolean);return t.pop(),t.length>0?`/${t.join("/")}`:"/"}function f(o){let e=l(o);return e==="/"?"/":e.split("/").filter(Boolean).at(-1)??"/"}function D(o){return o.type==="file"?{...o,contentBase64:o.contentBase64}:{...o,children:o.children.map(e=>D(e))}}function W(o,e){let t=new Date().toISOString();return{type:"directory",name:o,mode:e,createdAt:t,updatedAt:t,children:[]}}function T(o,e,t){let r=new Date().toISOString();return{type:"file",name:o,mode:t,createdAt:r,updatedAt:r,contentBase64:j(e)}}function b(o,e){return o.children.find(t=>t.name===e)}function m(o,e){let t=o.children.findIndex(r=>r.name===e.name);if(t===-1){o.children.push(e);return}o.children[t]=e}function S(o,e){o.children=o.children.filter(t=>t.name!==e)}function $(o){return l(o).split("/").filter(Boolean)}var V=globalThis;function E(o){return new Promise((e,t)=>{o.addEventListener("success",()=>e(o.result)),o.addEventListener("error",()=>t(o.error))})}var y=class{constructor(e={}){u(this,"databaseName");u(this,"storeName");u(this,"key");u(this,"root");this.databaseName=e.databaseName??"typescript-virtual-container-web",this.storeName=e.storeName??"snapshots",this.key=e.key??"current",this.root=W("",493)}async openDatabase(){return new Promise((e,t)=>{let r=V.indexedDB;if(!r){t(new Error("IndexedDB is not available in this environment"));return}let n=r.open(this.databaseName,1);n.addEventListener("upgradeneeded",()=>{let s=n.result;s.objectStoreNames.contains(this.storeName)||s.createObjectStore(this.storeName)}),n.addEventListener("success",()=>e(n.result)),n.addEventListener("error",()=>t(n.error))})}async readSnapshot(){let e=await this.openDatabase();try{let n=e.transaction(this.storeName,"readonly").objectStore(this.storeName).get(this.key),s=await E(n);return s?JSON.parse(s):null}finally{e.close()}}async writeSnapshot(e){let t=await this.openDatabase();try{let r=t.transaction(this.storeName,"readwrite"),n=r.objectStore(this.storeName);await E(n.put(JSON.stringify(e),this.key)),await new Promise((s,i)=>{r.addEventListener("complete",()=>s()),r.addEventListener("error",()=>i(r.error)),r.addEventListener("abort",()=>i(r.error))})}finally{t.close()}}serializeNode(e){return e.type==="file"?{...e}:{...e,children:e.children.map(t=>this.serializeNode(t))}}deserializeNode(e){return e.type==="file"?{...e}:{...e,children:e.children.map(t=>this.deserializeNode(t))}}getNode(e){let t=l(e);if(t==="/")return this.root;let r=$(t),n=this.root;for(let s of r){if(n.type!=="directory")throw new Error(`Not a directory: ${t}`);let i=b(n,s);if(!i)throw new Error(`No such file or directory: ${t}`);n=i}return n}ensureDirectory(e,t){let r=l(e);if(r==="/")return this.root;let n=$(r),s=this.root;for(let i of n){let a=b(s,i);if(!a){let c=W(i,t);m(s,c),s=c;continue}if(a.type!=="directory")throw new Error(`Cannot create directory '${r}': path is a file.`);s=a}return s}removeNode(e,t){let r=l(e);if(r==="/")throw new Error("Cannot remove root directory");let n=this.getNode(h(r));if(n.type!=="directory")throw new Error(`Not a directory: ${h(r)}`);let s=f(r),i=b(n,s);if(!i)throw new Error(`No such file or directory: ${r}`);if(i.type==="directory"&&i.children.length>0&&!t)throw new Error(`Cannot remove '${r}': directory not empty.`);S(n,s)}copyNode(e){return e.type==="file"?{...e,contentBase64:e.contentBase64}:{...e,children:e.children.map(t=>this.copyNode(t))}}async restoreMirror(){let e=await this.readSnapshot();e&&(this.root=this.deserializeNode(e.root))}async flushMirror(){await this.writeSnapshot({root:this.serializeNode(this.root)})}exists(e){try{return this.getNode(e),!0}catch{return!1}}list(e){let t=this.getNode(e);if(t.type!=="directory")throw new Error(`Not a directory: ${e}`);return t.children.map(r=>r.name).sort((r,n)=>r.localeCompare(n))}stat(e){let t=this.getNode(e);return t.type==="file"?{type:"file",mode:t.mode,size:N(t.contentBase64).byteLength,name:t.name}:{type:"directory",mode:t.mode,size:0,name:t.name}}readFile(e){let t=this.getNode(e);if(t.type!=="file")throw new Error(`Is a directory: ${e}`);return B.decode(N(t.contentBase64))}writeFile(e,t,r=420){let n=l(e),s=this.ensureDirectory(h(n),493),i=typeof t=="string"?_.encode(t):t,a=T(f(n),i,r);m(s,a)}mkdir(e,t=493){this.ensureDirectory(e,t)}touch(e){this.exists(e)||this.writeFile(e,"")}move(e,t){let r=this.getNode(e),n=this.getNode(h(e)),s=this.ensureDirectory(h(t),493);if(n.type!=="directory")throw new Error(`Not a directory: ${h(e)}`);S(n,f(e));let i=D(r);i.name=f(t),m(s,i)}copy(e,t){let r=this.getNode(e),n=this.ensureDirectory(h(t),493),s=this.copyNode(r);s.name=f(t),m(n,s)}remove(e,t={}){this.removeNode(e,t.recursive??!1)}exportSnapshot(){return{root:this.serializeNode(this.root)}}importSnapshot(e){this.root=this.deserializeNode(e.root)}},v=class{constructor(e,t={}){u(this,"hostname");u(this,"vfs");u(this,"env");u(this,"cwd");u(this,"commands",new Map);u(this,"initialized",!1);this.hostname=e,this.cwd=t.cwd??"/home/root",this.env={vars:{PATH:"/usr/bin:/bin",HOME:"/home/root",USER:"root",LOGNAME:"root",SHELL:"/bin/sh",HOSTNAME:e,PWD:this.cwd},lastExitCode:0},this.vfs=new y(t.vfs),this.registerBuiltins()}register(e){this.commands.set(e.name.toLowerCase(),e);for(let t of e.aliases??[])this.commands.set(t.toLowerCase(),e)}registerBuiltins(){this.register({name:"help",description:"List available web commands",params:[],run:()=>({stdout:`${this.listCommands().join(`
|
|
1
|
+
var P=Object.defineProperty;var z=(o,e,t)=>e in o?P(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var u=(o,e,t)=>z(o,typeof e!="symbol"?e+"":e,t);function w(o){let e=[],t="",i=!1,s="",n=0;for(;n<o.length;){let r=o[n],a=o[n+1];if((r==='"'||r==="'")&&!i){i=!0,s=r,n++;continue}if(i&&r===s){i=!1,s="",n++;continue}if(i){t+=r,n++;continue}if(r===" "){t&&(e.push(t),t=""),n++;continue}if(!i&&r==="2"&&a===">"){let c=o.slice(n+1);if(c.startsWith(">>&1")||c.startsWith(">> &1")){t&&(e.push(t),t=""),e.push("2>>&1"),n+=5;continue}if(c.startsWith(">&1")){t&&(e.push(t),t=""),e.push("2>&1"),n+=4;continue}if(c.startsWith(">>")){t&&(e.push(t),t=""),e.push("2>>"),n+=3;continue}if(c.startsWith(">")){t&&(e.push(t),t=""),e.push("2>"),n+=2;continue}}if((r===">"||r==="<")&&!i){t&&(e.push(t),t=""),r===">"&&a===">"?(e.push(">>"),n+=2):(e.push(r),n++);continue}t+=r,n++}return t&&e.push(t),e}function C(o){let e=o.trim();if(!e)return{statements:[],isValid:!0};try{return{statements:O(e),isValid:!0}}catch(t){return{statements:[],isValid:!1,error:t.message}}}function O(o){let e=R(o),t=[];for(let i of e){let n={pipeline:{commands:F(i.text.trim()),isValid:!0}};i.op&&(n.op=i.op),t.push(n)}return t}function R(o){let e=[],t="",i=0,s=!1,n="",r=0,a=c=>{t.trim()&&e.push({text:t,op:c}),t=""};for(;r<o.length;){let c=o[r],d=o.slice(r,r+2);if((c==='"'||c==="'")&&!s){s=!0,n=c,t+=c,r++;continue}if(s&&c===n){s=!1,t+=c,r++;continue}if(s){t+=c,r++;continue}if(c==="("){i++,t+=c,r++;continue}if(c===")"){i--,t+=c,r++;continue}if(i>0){t+=c,r++;continue}if(d==="&&"){a("&&"),r+=2;continue}if(d==="||"){a("||"),r+=2;continue}if(c===";"){a(";"),r++;continue}t+=c,r++}return a(),e}function F(o){return k(o).map(L)}function k(o){let e=[],t="",i=!1,s="";for(let r=0;r<o.length;r++){let a=o[r];if((a==='"'||a==="'")&&!i){i=!0,s=a,t+=a;continue}if(i&&a===s){i=!1,t+=a;continue}if(i){t+=a;continue}if(a==="|"&&o[r+1]!=="|"){if(!t.trim())throw new Error("Syntax error near unexpected token '|'");e.push(t.trim()),t=""}else t+=a}let n=t.trim();if(!n&&e.length>0)throw new Error("Syntax error near unexpected token '|'");return n&&e.push(n),e}function L(o){let e=w(o);if(e.length===0)return{name:"",args:[]};let t=[],i,s,n=!1,r=0,a,c=!1,d=!1;for(;r<e.length;){let f=e[r];if(f==="<"){if(r++,r>=e.length)throw new Error("Syntax error: expected filename after <");i=e[r],r++}else if(f===">>"){if(r++,r>=e.length)throw new Error("Syntax error: expected filename after >>");s=e[r],n=!0,r++}else if(f===">"){if(r++,r>=e.length)throw new Error("Syntax error: expected filename after >");s=e[r],n=!1,r++}else if(f==="2>&1")d=!0,r++;else if(f==="2>>"){if(r++,r>=e.length)throw new Error("Syntax error: expected filename after 2>>");a=e[r],c=!0,r++}else if(f==="2>"){if(r++,r>=e.length)throw new Error("Syntax error: expected filename after 2>");a=e[r],c=!1,r++}else t.push(f),r++}return{name:(t[0]??"").toLowerCase(),args:t.slice(1),inputFile:i,outputFile:s,appendOutput:n,stderrFile:a,stderrAppend:c,stderrToStdout:d}}function I(o,e){let t=o.replace(/\b([A-Za-z_][A-Za-z0-9_]*)\b/g,(i,s)=>{let n=e[s];return n!==void 0&&n!==""?n:"0"});if(!/^[\d\s+\-*/%()^!&|<>=,. ]+$/.test(t))return NaN;try{let i=Function(`"use strict"; return (${t.replace(/\*\*/g,"**")});`)();return typeof i=="number"?Math.trunc(i):NaN}catch{return NaN}}function M(o,e){let t=[],i=0;for(;i<o.length;){let s=o.indexOf("'",i);if(s===-1){t.push(e(o.slice(i)));break}t.push(e(o.slice(i,s)));let n=o.indexOf("'",s+1);if(n===-1){t.push(o.slice(s));break}t.push(o.slice(s,n+1)),i=n+1}return t.join("")}function g(o,e,t=0,i){let s=i??e.HOME??"/home/user";return M(o,n=>{let r=n;return r=r.replace(/(^|[\s:])~(\/|$)/g,(a,c,d)=>`${c}${s}${d}`),r=r.replace(/\$\?/g,String(t)),r=r.replace(/\$\$/g,"1"),r=r.replace(/\$#/g,"0"),r=r.replace(/\$\(\(([^)]+(?:\([^)]*\)[^)]*)*)\)\)/g,(a,c)=>{let d=I(c,e);return Number.isNaN(d)?"0":String(d)}),r=r.replace(/\$\{#([A-Za-z_][A-Za-z0-9_]*)\}/g,(a,c)=>String((e[c]??"").length)),r=r.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):-([^}]*)\}/g,(a,c,d)=>e[c]!==void 0&&e[c]!==""?e[c]:d),r=r.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):=([^}]*)\}/g,(a,c,d)=>((e[c]===void 0||e[c]==="")&&(e[c]=d),e[c])),r=r.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):\+([^}]*)\}/g,(a,c,d)=>e[c]!==void 0&&e[c]!==""?d:""),r=r.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(a,c)=>e[c]??""),r=r.replace(/\$([A-Za-z_][A-Za-z0-9_]*|\d+)/g,(a,c)=>e[c]??""),r})}async function N(o,e,t,i){if(o.includes("$(")){let s="",n=!1,r=0;for(;r<o.length;){let a=o[r];if(a==="'"&&!n){n=!0,s+=a,r++;continue}if(a==="'"&&n){n=!1,s+=a,r++;continue}if(!n&&a==="$"&&o[r+1]==="("){if(o[r+2]==="("){s+=a,r++;continue}let c=0,d=r+1;for(;d<o.length;){if(o[d]==="(")c++;else if(o[d]===")"&&(c--,c===0))break;d++}let m=o.slice(r+2,d).trim(),f=(await i(m)).replace(/\n$/,"");s+=f,r=d+1;continue}s+=a,r++}o=s}return g(o,e,t)}var _=new TextEncoder,B=new TextDecoder;function T(o){let e="";for(let t of o)e+=String.fromCharCode(t);return btoa(e)}function W(o){let e=atob(o),t=new Uint8Array(e.length);for(let i=0;i<e.length;i+=1)t[i]=e.charCodeAt(i);return t}function l(o,e="/"){let i=(o.startsWith("/")?o:`${e}/${o}`).split("/"),s=[];for(let n of i)if(!(!n||n===".")){if(n===".."){s.pop();continue}s.push(n)}return`/${s.join("/")}`||"/"}function h(o){let e=l(o);if(e==="/")return"/";let t=e.split("/").filter(Boolean);return t.pop(),t.length>0?`/${t.join("/")}`:"/"}function p(o){let e=l(o);return e==="/"?"/":e.split("/").filter(Boolean).at(-1)??"/"}function A(o){return o.type==="file"?{...o,contentBase64:o.contentBase64}:{...o,children:o.children.map(e=>A(e))}}function S(o,e){let t=new Date().toISOString();return{type:"directory",name:o,mode:e,createdAt:t,updatedAt:t,children:[]}}function j(o,e,t){let i=new Date().toISOString();return{type:"file",name:o,mode:t,createdAt:i,updatedAt:i,contentBase64:T(e)}}function b(o,e){return o.children.find(t=>t.name===e)}function y(o,e){let t=o.children.findIndex(i=>i.name===e.name);if(t===-1){o.children.push(e);return}o.children[t]=e}function $(o,e){o.children=o.children.filter(t=>t.name!==e)}function E(o){return l(o).split("/").filter(Boolean)}var V=globalThis;function D(o){return new Promise((e,t)=>{o.addEventListener("success",()=>e(o.result)),o.addEventListener("error",()=>t(o.error))})}var x=class{constructor(e={}){u(this,"databaseName");u(this,"storeName");u(this,"key");u(this,"root");this.databaseName=e.databaseName??"typescript-virtual-container-web",this.storeName=e.storeName??"snapshots",this.key=e.key??"current",this.root=S("",493)}async openDatabase(){return new Promise((e,t)=>{let i=V.indexedDB;if(!i){t(new Error("IndexedDB is not available in this environment"));return}let s=i.open(this.databaseName,1);s.addEventListener("upgradeneeded",()=>{let n=s.result;n.objectStoreNames.contains(this.storeName)||n.createObjectStore(this.storeName)}),s.addEventListener("success",()=>e(s.result)),s.addEventListener("error",()=>t(s.error))})}async readSnapshot(){let e=await this.openDatabase();try{let s=e.transaction(this.storeName,"readonly").objectStore(this.storeName).get(this.key),n=await D(s);return n?JSON.parse(n):null}finally{e.close()}}async writeSnapshot(e){let t=await this.openDatabase();try{let i=t.transaction(this.storeName,"readwrite"),s=i.objectStore(this.storeName);await D(s.put(JSON.stringify(e),this.key)),await new Promise((n,r)=>{i.addEventListener("complete",()=>n()),i.addEventListener("error",()=>r(i.error)),i.addEventListener("abort",()=>r(i.error))})}finally{t.close()}}serializeNode(e){return e.type==="file"?{...e}:{...e,children:e.children.map(t=>this.serializeNode(t))}}deserializeNode(e){return e.type==="file"?{...e}:{...e,children:e.children.map(t=>this.deserializeNode(t))}}getNode(e){let t=l(e);if(t==="/")return this.root;let i=E(t),s=this.root;for(let n of i){if(s.type!=="directory")throw new Error(`Not a directory: ${t}`);let r=b(s,n);if(!r)throw new Error(`No such file or directory: ${t}`);s=r}return s}ensureDirectory(e,t){let i=l(e);if(i==="/")return this.root;let s=E(i),n=this.root;for(let r of s){let a=b(n,r);if(!a){let c=S(r,t);y(n,c),n=c;continue}if(a.type!=="directory")throw new Error(`Cannot create directory '${i}': path is a file.`);n=a}return n}removeNode(e,t){let i=l(e);if(i==="/")throw new Error("Cannot remove root directory");let s=this.getNode(h(i));if(s.type!=="directory")throw new Error(`Not a directory: ${h(i)}`);let n=p(i),r=b(s,n);if(!r)throw new Error(`No such file or directory: ${i}`);if(r.type==="directory"&&r.children.length>0&&!t)throw new Error(`Cannot remove '${i}': directory not empty.`);$(s,n)}copyNode(e){return e.type==="file"?{...e,contentBase64:e.contentBase64}:{...e,children:e.children.map(t=>this.copyNode(t))}}async restoreMirror(){let e=await this.readSnapshot();e&&(this.root=this.deserializeNode(e.root))}async flushMirror(){await this.writeSnapshot({root:this.serializeNode(this.root)})}exists(e){try{return this.getNode(e),!0}catch{return!1}}list(e){let t=this.getNode(e);if(t.type!=="directory")throw new Error(`Not a directory: ${e}`);return t.children.map(i=>i.name).sort((i,s)=>i.localeCompare(s))}stat(e){let t=this.getNode(e);return t.type==="file"?{type:"file",mode:t.mode,size:W(t.contentBase64).byteLength,name:t.name}:{type:"directory",mode:t.mode,size:0,name:t.name}}readFile(e){let t=this.getNode(e);if(t.type!=="file")throw new Error(`Is a directory: ${e}`);return B.decode(W(t.contentBase64))}writeFile(e,t,i=420){let s=l(e),n=this.ensureDirectory(h(s),493),r=typeof t=="string"?_.encode(t):t,a=j(p(s),r,i);y(n,a)}mkdir(e,t=493){this.ensureDirectory(e,t)}touch(e){this.exists(e)||this.writeFile(e,"")}move(e,t){let i=this.getNode(e),s=this.getNode(h(e)),n=this.ensureDirectory(h(t),493);if(s.type!=="directory")throw new Error(`Not a directory: ${h(e)}`);$(s,p(e));let r=A(i);r.name=p(t),y(n,r)}copy(e,t){let i=this.getNode(e),s=this.ensureDirectory(h(t),493),n=this.copyNode(i);n.name=p(t),y(s,n)}remove(e,t={}){this.removeNode(e,t.recursive??!1)}exportSnapshot(){return{root:this.serializeNode(this.root)}}importSnapshot(e){this.root=this.deserializeNode(e.root)}},v=class{constructor(e,t={}){u(this,"hostname");u(this,"vfs");u(this,"env");u(this,"cwd");u(this,"commands",new Map);u(this,"initialized",!1);this.hostname=e,this.cwd=t.cwd??"/home/root",this.env={vars:{PATH:"/usr/bin:/bin",HOME:"/home/root",USER:"root",LOGNAME:"root",SHELL:"/bin/sh",HOSTNAME:e,PWD:this.cwd},lastExitCode:0},this.vfs=new x(t.vfs),this.registerBuiltins()}register(e){this.commands.set(e.name.toLowerCase(),e);for(let t of e.aliases??[])this.commands.set(t.toLowerCase(),e)}registerBuiltins(){this.register({name:"help",description:"List available web commands",params:[],run:()=>({stdout:`${this.listCommands().join(`
|
|
2
2
|
`)}
|
|
3
3
|
`,exitCode:0})}),this.register({name:"pwd",description:"Print current directory",params:[],run:()=>({stdout:`${this.cwd}
|
|
4
|
-
`,exitCode:0})}),this.register({name:"cd",description:"Change current directory",params:["[dir]"],run:({args:e})=>{let t=e[0]?l(e[0],this.cwd):"/home/root";return!this.vfs.exists(t)||this.vfs.stat(t).type!=="directory"?{stderr:`cd: no such file or directory: ${t}`,exitCode:1}:(this.cwd=t,this.env.vars.PWD=t,{exitCode:0,nextCwd:t})}}),this.register({name:"echo",description:"Display text",params:["[-n] [-e] [text...]"],run:({args:e,stdin:t})=>{let
|
|
4
|
+
`,exitCode:0})}),this.register({name:"cd",description:"Change current directory",params:["[dir]"],run:({args:e})=>{let t=e[0]?l(e[0],this.cwd):"/home/root";return!this.vfs.exists(t)||this.vfs.stat(t).type!=="directory"?{stderr:`cd: no such file or directory: ${t}`,exitCode:1}:(this.cwd=t,this.env.vars.PWD=t,{exitCode:0,nextCwd:t})}}),this.register({name:"echo",description:"Display text",params:["[-n] [-e] [text...]"],run:({args:e,stdin:t})=>{let i=e.includes("-n"),s=e.filter(a=>a!=="-n"&&a!=="-e"&&a!=="-E"),n=s.length>0?s.join(" "):t??"",r=g(n,this.env.vars,this.env.lastExitCode,this.env.vars.HOME);return{stdout:i?r:`${r}
|
|
5
5
|
`,exitCode:0}}}),this.register({name:"env",description:"Print environment variables",params:[],run:()=>({stdout:`${Object.entries(this.env.vars).map(([e,t])=>`${e}=${t}`).join(`
|
|
6
6
|
`)}
|
|
7
|
-
`,exitCode:0})}),this.register({name:"export",description:"Set environment variables",params:["KEY=VALUE..."],run:({args:e})=>{for(let t of e){let
|
|
8
|
-
`,exitCode:0}}}),this.register({name:"tee",description:"Read from stdin and write to files",params:["[-a] file..."],run:async({args:e,stdin:t})=>{let
|
|
7
|
+
`,exitCode:0})}),this.register({name:"export",description:"Set environment variables",params:["KEY=VALUE..."],run:({args:e})=>{for(let t of e){let i=t.indexOf("=");if(i===-1)continue;let s=t.slice(0,i).trim(),n=t.slice(i+1);s&&(this.env.vars[s]=n)}return{exitCode:0}}}),this.register({name:"unset",description:"Unset environment variables",params:["NAME..."],run:({args:e})=>{for(let t of e)delete this.env.vars[t];return{exitCode:0}}}),this.register({name:"mkdir",description:"Create directories",params:["[-p] dir..."],run:async({args:e})=>{let t=e.filter(i=>i!=="-p");for(let i of t)this.vfs.mkdir(l(i,this.cwd));return await this.vfs.flushMirror(),{exitCode:0}}}),this.register({name:"touch",description:"Create files",params:["file..."],run:async({args:e})=>{for(let t of e)this.vfs.touch(l(t,this.cwd));return await this.vfs.flushMirror(),{exitCode:0}}}),this.register({name:"rm",description:"Remove files or directories",params:["[-r] [-f] path..."],run:async({args:e})=>{let t=e.includes("-r"),i=e.filter(s=>s!=="-r"&&s!=="-f");for(let s of i)this.vfs.remove(l(s,this.cwd),{recursive:t});return await this.vfs.flushMirror(),{exitCode:0}}}),this.register({name:"cp",description:"Copy files or directories",params:["[-r] source destination"],run:async({args:e})=>{let t=e.includes("-r"),i=e.filter(n=>n!=="-r");if(i.length<2)return{stderr:"cp: missing destination file operand",exitCode:1};let s=l(i.at(-1),this.cwd);for(let n of i.slice(0,-1)){let r=l(n,this.cwd);if(!t&&this.vfs.stat(r).type==="directory")return{stderr:`cp: -r not specified; omitting directory '${r}'`,exitCode:1};this.vfs.copy(r,s)}return await this.vfs.flushMirror(),{exitCode:0}}}),this.register({name:"mv",description:"Move or rename files",params:["source destination"],run:async({args:e})=>{if(e.length<2)return{stderr:"mv: missing destination file operand",exitCode:1};let t=l(e[0],this.cwd),i=l(e[1],this.cwd);return this.vfs.move(t,i),await this.vfs.flushMirror(),{exitCode:0}}}),this.register({name:"cat",description:"Concatenate files",params:["[file...]"],run:({args:e,stdin:t})=>{if(e.length===0)return{stdout:t??"",exitCode:0};let i="";for(let s of e)i+=this.vfs.readFile(l(s,this.cwd));return{stdout:i,exitCode:0}}}),this.register({name:"ls",description:"List files",params:["[path]"],run:({args:e})=>{let t=l(e[0]??".",this.cwd);return{stdout:`${this.vfs.list(t).join(" ")}
|
|
8
|
+
`,exitCode:0}}}),this.register({name:"tee",description:"Read from stdin and write to files",params:["[-a] file..."],run:async({args:e,stdin:t})=>{let i=e.includes("-a"),s=e.filter(r=>r!=="-a"),n=t??"";for(let r of s){let a=l(r,this.cwd);if(i&&this.vfs.exists(a)){let c=this.vfs.readFile(a);this.vfs.writeFile(a,`${c}${n}`)}else this.vfs.writeFile(a,n)}return await this.vfs.flushMirror(),{stdout:n,exitCode:0}}}),this.register({name:"curl",description:"Fetch a URL and optionally write to a file",params:["[-o file] URL"],run:async({args:e})=>{let t=e.indexOf("-o"),i=t!==-1?e[t+1]:void 0,n=e.filter((c,d)=>c!=="-o"&&d!==t+1).at(-1);if(!n)return{stderr:"curl: missing URL",exitCode:2};let r=await fetch(n),a=await r.text();return i?(this.vfs.writeFile(l(i,this.cwd),a),await this.vfs.flushMirror(),{exitCode:r.ok?0:1}):{stdout:a,exitCode:r.ok?0:1}}}),this.register({name:"wget",description:"Fetch a URL and optionally write to a file",params:["[-O file] URL"],run:async({args:e})=>{let t=e.indexOf("-O"),i=t!==-1?e[t+1]:void 0,n=e.filter((d,m)=>d!=="-O"&&m!==t+1).at(-1);if(!n)return{stderr:"wget: missing URL",exitCode:2};let r=await fetch(n),a=await r.text(),c=i??p(new URL(n).pathname||"index.html");return this.vfs.writeFile(l(c,this.cwd),a),await this.vfs.flushMirror(),{exitCode:r.ok?0:1}}}),this.register({name:"true",description:"Return success",params:[],run:()=>({exitCode:0})}),this.register({name:"false",description:"Return failure",params:[],run:()=>({exitCode:1})})}listCommands(){let e=new Map;for(let t of this.commands.values())e.set(t.name,t);return Array.from(e.values()).sort((t,i)=>t.name.localeCompare(i.name)).map(t=>`${t.name}${t.params.length>0?` ${t.params.join(" ")}`:""}`)}resolveCommand(e){return this.commands.get(e.toLowerCase())}async ensureInitialized(){this.initialized||(await this.vfs.restoreMirror(),this.vfs.exists("/home")||this.vfs.mkdir("/home"),this.vfs.exists("/home/root")||(this.vfs.mkdir("/home/root"),this.vfs.writeFile("/home/root/README.txt",`Welcome to ${this.hostname}
|
|
9
9
|
`)),this.vfs.exists("/tmp")||this.vfs.mkdir("/tmp"),this.vfs.exists("/etc")||this.vfs.mkdir("/etc"),this.vfs.exists("/etc/hostname")||this.vfs.writeFile("/etc/hostname",`${this.hostname}
|
|
10
10
|
`),this.vfs.exists("/etc/hosts")||this.vfs.writeFile("/etc/hosts",`127.0.0.1 localhost
|
|
11
11
|
::1 localhost
|
|
12
|
-
`),this.initialized=!0)}getCurrentWorkingDirectory(){return this.cwd}async executeCommandLine(e,t=!0){await this.ensureInitialized();let
|
|
12
|
+
`),this.initialized=!0)}getCurrentWorkingDirectory(){return this.cwd}async executeCommandLine(e,t=!0){await this.ensureInitialized();let i=e.trim();if(!i)return{exitCode:0};let s=await N(i,this.env.vars,this.env.lastExitCode,a=>this.executeCommandLine(a,!1).then(c=>c.stdout??"")),n=C(s),r=await this.executeStatements(n.statements);return this.env.lastExitCode=r.exitCode??0,t&&await this.vfs.flushMirror(),r}async executeStatements(e){let t={exitCode:0},i=0;for(;i<e.length;){let s=e[i];if(t=await this.executePipeline(s.pipeline.commands),this.env.lastExitCode=t.exitCode??0,t.closeSession||t.switchUser)return t;let n=s.op;if(!(!n||n===";")){if(n==="&&"){if((t.exitCode??0)!==0)for(;i<e.length&&e[i]?.op==="&&";)i+=1}else if(n==="||"&&(t.exitCode??0)===0)for(;i<e.length&&e[i]?.op==="||";)i+=1}i+=1}return t}async executePipeline(e){return e.length===0?{exitCode:0}:e.length===1?this.executeSingleCommandWithRedirections(e[0]):this.executePipelineChain(e)}async executeSingleCommandWithRedirections(e){let t;if(e.inputFile){let s=l(e.inputFile,this.cwd);try{t=this.vfs.readFile(s)}catch{return{stderr:`${e.inputFile}: No such file or directory`,exitCode:1}}}let i=await this.executeCommand(e.name,e.args,t);if(e.outputFile){let s=l(e.outputFile,this.cwd),n=i.stdout??"";if(e.appendOutput&&this.vfs.exists(s)){let r=this.vfs.readFile(s);this.vfs.writeFile(s,`${r}${n}`)}else this.vfs.writeFile(s,n);return{...i,stdout:""}}return i}async executePipelineChain(e){let t="",i=0;for(let s=0;s<e.length;s+=1){let n=e[s];if(s===0&&n.inputFile){let a=l(n.inputFile,this.cwd);try{t=this.vfs.readFile(a)}catch{return{stderr:`${n.inputFile}: No such file or directory`,exitCode:1}}}let r=await this.executeCommand(n.name,n.args,t);t=r.stdout??"",i=r.exitCode??0}return{stdout:t,exitCode:i}}async executeCommand(e,t,i){let s=this.resolveCommand(e);if(!s)return{stderr:`${e}: command not found`,exitCode:127};let r={args:t.map(a=>g(a,this.env.vars,this.env.lastExitCode,this.env.vars.HOME)),stdin:i,cwd:this.cwd,env:this.env,rawInput:`${e} ${t.join(" ")}`.trim(),shell:this};try{let a=await s.run(r);return a.nextCwd&&(this.cwd=a.nextCwd,this.env.vars.PWD=a.nextCwd),a}catch(a){return{stderr:a instanceof Error?a.message:String(a),exitCode:1}}}};function K(o="typescript-vm",e={}){return new v(o,e)}export{x as IndexedDbMirrorVfs,v as WebShell,K as createWebShell};
|
|
13
13
|
//# sourceMappingURL=web.min.js.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "1.4.
|
|
7
|
+
"version": "1.4.4",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -24,8 +24,9 @@
|
|
|
24
24
|
"check": "bunx --bun @biomejs/biome check ./src",
|
|
25
25
|
"lint": "bunx --bun @biomejs/biome lint ./src",
|
|
26
26
|
"lint:write": "bunx --bun @biomejs/biome lint --write ./src",
|
|
27
|
-
"test": "
|
|
27
|
+
"test": "bun run test-salve",
|
|
28
28
|
"test-battery": "bun test tests/",
|
|
29
|
+
"test-salve": "for f in tests/*.test.ts; do echo \"\\n🧪 Testing $f...\"; bun test \"$f\" --timeout 10000; sleep 0.25; done",
|
|
29
30
|
"build": "tsc --project tsconfig.json",
|
|
30
31
|
"deploy:npm": "npm publish --access public",
|
|
31
32
|
"bench": "rm -rf .benchmark-shells/ && bun benchmark-virtualshell.ts",
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@biomejs/biome": "^2.4.15",
|
|
45
46
|
"@types/bun": "^1.3.13",
|
|
46
|
-
"@types/node": "^25.
|
|
47
|
+
"@types/node": "^25.7.0",
|
|
47
48
|
"@types/ssh2": "^1.15.5",
|
|
48
49
|
"typescript": "^6.0.3"
|
|
49
50
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,KAAK,iBAAiB,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;CAC1B;AAID;;;;;GAKG;AACH,qBAAa,QAAQ;IACpB,OAAO,CA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AIG;IACG,MAAM,IAAI,OAAO,CAAC,aAAa,CAAC;IAKtC;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC;IAKxC;;;;OAIG;IACG,GAAG,IAAI,OAAO,CAAC,aAAa,CAAC;CAInC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["exec.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AASpD,wBAAgB,OAAO,CACtB,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,YAAY,GACjB,IAAI,CAgCN"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["executor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,KAAK,EACX,QAAQ,EAER,SAAS,EACT,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAKpD,wBAAsB,iBAAiB,CACtC,UAAU,EAAE,SAAS,EAAE,EACvB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,YAAY,EACnB,GAAG,EAAE,QAAQ,GACX,OAAO,CAAC,aAAa,CAAC,CAsDxB;AAID,wBAAsB,eAAe,CACpC,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,YAAY,EACnB,GAAG,CAAC,EAAE,QAAQ,GACZ,OAAO,CAAC,aAAa,CAAC,CA4BxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostKey.d.ts","sourceRoot":"","sources":["hostKey.ts"],"names":[],"mappings":"AAIA,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,MAAsB,GAAG,MAAM,CAgB3E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AA+B/C,cAAM,QAAS,SAAQ,YAAY;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACzB,OAAO,CAAC,KAAK,CAAe;IAE5B,mEAAmE;IACnE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,2DAA2D;IAC3D,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqC;IAElE;;;;;;;;OAQG;gBACS,EACX,IAAI,EACJ,QAA0B,EAC1B,KAAkC,EAClC,eAAmB,EACnB,iBAA0B,GAC1B,EAAE;QACF,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,KAAK,CAAC,EAAE,YAAY,CAAC;QACrB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC3B;IAYD,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,aAAa;IAUrB,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,aAAa;IAcrB;;;;OAIG;IACU,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IA0LrC;;OAEG;IACI,IAAI,IAAI,IAAI;IAUnB;;;OAGG;IACI,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;CAGrC;AAED,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loginBanner.d.ts","sourceRoot":"","sources":["loginBanner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGvD,MAAM,WAAW,gBAAgB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACb;AAED,wBAAgB,gBAAgB,CAC/B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,eAAe,EAC3B,SAAS,EAAE,gBAAgB,GAAG,IAAI,GAChC,MAAM,CAuBR"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loginFormat.d.ts","sourceRoot":"","sources":["loginFormat.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CASlD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["prompt.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAC1B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACb,MAAM,CASR"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sftp.d.ts","sourceRoot":"","sources":["sftp.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAI3C,OAAO,KAAK,iBAAi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AAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EACX,qBAAqB,EAGrB,MAAM,iBAAiB,CAAC;AA+EzB;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,qBAAqB,GAAG,MAAM,CAM7D;AA0FD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB,CAiB5D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAErD"}
|
|
@@ -50,6 +50,10 @@ declare class VirtualFileSystem extends EventEmitter {
|
|
|
50
50
|
private root;
|
|
51
51
|
private readonly mode;
|
|
52
52
|
private readonly snapshotFile;
|
|
53
|
+
/** Active host-directory mounts: vPath → { hostPath, readOnly } */
|
|
54
|
+
private readonly mounts;
|
|
55
|
+
/** True when running in a browser environment (no host FS access). */
|
|
56
|
+
private static readonly isBrowser;
|
|
53
57
|
constructor(options?: VfsOptions);
|
|
54
58
|
private makeDir;
|
|
55
59
|
private makeFile;
|
|
@@ -75,6 +79,49 @@ declare class VirtualFileSystem extends EventEmitter {
|
|
|
75
79
|
/** Returns the snapshot file path used in `"fs"` mode, or `null`. */
|
|
76
80
|
getSnapshotPath(): string | null;
|
|
77
81
|
/** Creates a directory (and any missing parents). */
|
|
82
|
+
/**
|
|
83
|
+
* Mount a host directory into the VFS at `vPath`.
|
|
84
|
+
*
|
|
85
|
+
* Files inside `vPath` are read directly from the host filesystem via
|
|
86
|
+
* `node:fs`. All standard VFS operations (`readFile`, `writeFile`,
|
|
87
|
+
* `exists`, `stat`, `list`) are transparently delegated.
|
|
88
|
+
*
|
|
89
|
+
* In browser environments the mount is silently ignored — `vPath` remains
|
|
90
|
+
* an empty in-memory directory.
|
|
91
|
+
*
|
|
92
|
+
* @param vPath Absolute path inside the VM (e.g. `"/app"`).
|
|
93
|
+
* @param hostPath Path on the host filesystem — relative paths are
|
|
94
|
+
* resolved from `process.cwd()`.
|
|
95
|
+
* @param readOnly When `true` (default), write operations inside the
|
|
96
|
+
* mount throw `EROFS: read-only file system`.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* shell.vfs.mount("/app", "./src", { readOnly: true });
|
|
101
|
+
* // cat /app/index.ts — reads ./src/index.ts from host
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
mount(vPath: string, hostPath: string, { readOnly }?: {
|
|
105
|
+
readOnly?: boolean;
|
|
106
|
+
}): void;
|
|
107
|
+
/**
|
|
108
|
+
* Unmount a previously mounted host directory.
|
|
109
|
+
* The in-memory VFS directory at `vPath` is preserved but the host
|
|
110
|
+
* delegation is removed.
|
|
111
|
+
*/
|
|
112
|
+
unmount(vPath: string): void;
|
|
113
|
+
/** List all active mounts. */
|
|
114
|
+
getMounts(): Array<{
|
|
115
|
+
vPath: string;
|
|
116
|
+
hostPath: string;
|
|
117
|
+
readOnly: boolean;
|
|
118
|
+
}>;
|
|
119
|
+
/**
|
|
120
|
+
* If `targetPath` is inside a mount, return `{ hostPath, readOnly, relPath }`.
|
|
121
|
+
* `relPath` is the path relative to the mount's host directory.
|
|
122
|
+
* Returns `null` if the path is not under any mount.
|
|
123
|
+
*/
|
|
124
|
+
private resolveMount;
|
|
78
125
|
mkdir(targetPath: string, mode?: number): void;
|
|
79
126
|
/**
|
|
80
127
|
* Writes UTF-8 text or binary content into a file.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,OAAO,KAAK,EACX,aAAa,EAGb,YAAY,EACZ,WAAW,EAIX,gBAAgB,EAChB,MAAM,cAAc,CAAC;AAWtB;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,IAAI,CAAC;AAEjD,MAAM,WAAW,UAA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IAkCpE,+BAA+B;IACxB,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IA8BnD;;;;;OAKG;IACI,UAAU,IAAI,WAAW;IAIhC,OAAO,CAAC,YAAY;IAmBpB,OAAO,CAAC,aAAa;IAYrB;;;;;;;OAOG;WACW,YAAY,CAAC,QAAQ,EAAE,WAAW,GAAG,iBAAiB;IAMpE;;;;;;;;OAQG;IACI,cAAc,CAAC,QAAQ,EAAE,WAAW,GAAG,IAAI;IAKlD,OAAO,CAAC,cAAc;CAkCtB;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -32,6 +32,10 @@ class VirtualFileSystem extends EventEmitter {
|
|
|
32
32
|
root;
|
|
33
33
|
mode;
|
|
34
34
|
snapshotFile;
|
|
35
|
+
/** Active host-directory mounts: vPath → { hostPath, readOnly } */
|
|
36
|
+
mounts = new Map();
|
|
37
|
+
/** True when running in a browser environment (no host FS access). */
|
|
38
|
+
static isBrowser = typeof process === "undefined" || typeof process.versions?.node === "undefined";
|
|
35
39
|
constructor(options = {}) {
|
|
36
40
|
super();
|
|
37
41
|
this.mode = options.mode ?? "memory";
|
|
@@ -151,6 +155,80 @@ class VirtualFileSystem extends EventEmitter {
|
|
|
151
155
|
}
|
|
152
156
|
// ── Public filesystem API ─────────────────────────────────────────────────
|
|
153
157
|
/** Creates a directory (and any missing parents). */
|
|
158
|
+
// ── Mount API ─────────────────────────────────────────────────────────────
|
|
159
|
+
/**
|
|
160
|
+
* Mount a host directory into the VFS at `vPath`.
|
|
161
|
+
*
|
|
162
|
+
* Files inside `vPath` are read directly from the host filesystem via
|
|
163
|
+
* `node:fs`. All standard VFS operations (`readFile`, `writeFile`,
|
|
164
|
+
* `exists`, `stat`, `list`) are transparently delegated.
|
|
165
|
+
*
|
|
166
|
+
* In browser environments the mount is silently ignored — `vPath` remains
|
|
167
|
+
* an empty in-memory directory.
|
|
168
|
+
*
|
|
169
|
+
* @param vPath Absolute path inside the VM (e.g. `"/app"`).
|
|
170
|
+
* @param hostPath Path on the host filesystem — relative paths are
|
|
171
|
+
* resolved from `process.cwd()`.
|
|
172
|
+
* @param readOnly When `true` (default), write operations inside the
|
|
173
|
+
* mount throw `EROFS: read-only file system`.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* shell.vfs.mount("/app", "./src", { readOnly: true });
|
|
178
|
+
* // cat /app/index.ts — reads ./src/index.ts from host
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
mount(vPath, hostPath, { readOnly = true } = {}) {
|
|
182
|
+
if (VirtualFileSystem.isBrowser)
|
|
183
|
+
return; // silently degrade in browser
|
|
184
|
+
const normalized = normalizePath(vPath);
|
|
185
|
+
const resolved = path.resolve(hostPath);
|
|
186
|
+
if (!fsSync.existsSync(resolved)) {
|
|
187
|
+
throw new Error(`VirtualFileSystem.mount: host path does not exist: "${resolved}"`);
|
|
188
|
+
}
|
|
189
|
+
if (!fsSync.statSync(resolved).isDirectory()) {
|
|
190
|
+
throw new Error(`VirtualFileSystem.mount: host path is not a directory: "${resolved}"`);
|
|
191
|
+
}
|
|
192
|
+
// Ensure the mount point exists in the VFS tree
|
|
193
|
+
this.mkdir(normalized);
|
|
194
|
+
this.mounts.set(normalized, { hostPath: resolved, readOnly });
|
|
195
|
+
this.emit("mount", { vPath: normalized, hostPath: resolved, readOnly });
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Unmount a previously mounted host directory.
|
|
199
|
+
* The in-memory VFS directory at `vPath` is preserved but the host
|
|
200
|
+
* delegation is removed.
|
|
201
|
+
*/
|
|
202
|
+
unmount(vPath) {
|
|
203
|
+
const normalized = normalizePath(vPath);
|
|
204
|
+
if (this.mounts.delete(normalized)) {
|
|
205
|
+
this.emit("unmount", { vPath: normalized });
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/** List all active mounts. */
|
|
209
|
+
getMounts() {
|
|
210
|
+
return [...this.mounts.entries()].map(([vPath, opts]) => ({
|
|
211
|
+
vPath, ...opts,
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* If `targetPath` is inside a mount, return `{ hostPath, readOnly, relPath }`.
|
|
216
|
+
* `relPath` is the path relative to the mount's host directory.
|
|
217
|
+
* Returns `null` if the path is not under any mount.
|
|
218
|
+
*/
|
|
219
|
+
resolveMount(targetPath) {
|
|
220
|
+
const normalized = normalizePath(targetPath);
|
|
221
|
+
// Iterate mounts from most specific to least specific
|
|
222
|
+
const sorted = [...this.mounts.entries()].sort(([a], [b]) => b.length - a.length);
|
|
223
|
+
for (const [vBase, opts] of sorted) {
|
|
224
|
+
if (normalized === vBase || normalized.startsWith(`${vBase}/`)) {
|
|
225
|
+
const relPath = normalized.slice(vBase.length).replace(/^\//, "");
|
|
226
|
+
const fullHostPath = relPath ? path.join(opts.hostPath, relPath) : opts.hostPath;
|
|
227
|
+
return { hostPath: opts.hostPath, readOnly: opts.readOnly, relPath, fullHostPath };
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
154
232
|
mkdir(targetPath, mode = 0o755) {
|
|
155
233
|
const normalized = normalizePath(targetPath);
|
|
156
234
|
const existing = (() => {
|
|
@@ -171,6 +249,17 @@ class VirtualFileSystem extends EventEmitter {
|
|
|
171
249
|
* Parent directories are created when missing.
|
|
172
250
|
*/
|
|
173
251
|
writeFile(targetPath, content, options = {}) {
|
|
252
|
+
// Delegate to host FS if inside a mount
|
|
253
|
+
const m = this.resolveMount(targetPath);
|
|
254
|
+
if (m) {
|
|
255
|
+
if (m.readOnly)
|
|
256
|
+
throw new Error(`EROFS: read-only file system, open '${m.fullHostPath}'`);
|
|
257
|
+
const dir = path.dirname(m.fullHostPath);
|
|
258
|
+
if (!fsSync.existsSync(dir))
|
|
259
|
+
fsSync.mkdirSync(dir, { recursive: true });
|
|
260
|
+
fsSync.writeFileSync(m.fullHostPath, Buffer.isBuffer(content) ? content : Buffer.from(content, "utf8"));
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
174
263
|
const normalized = normalizePath(targetPath);
|
|
175
264
|
const { parent, name } = getParentDirectory(this.root, normalized, true, (p) => this.mkdirRecursive(p, 0o755));
|
|
176
265
|
const existing = parent.children.get(name);
|
|
@@ -200,6 +289,12 @@ class VirtualFileSystem extends EventEmitter {
|
|
|
200
289
|
* Gzip-compressed files are transparently decompressed.
|
|
201
290
|
*/
|
|
202
291
|
readFile(targetPath) {
|
|
292
|
+
const m = this.resolveMount(targetPath);
|
|
293
|
+
if (m) {
|
|
294
|
+
if (!fsSync.existsSync(m.fullHostPath))
|
|
295
|
+
throw new Error(`ENOENT: no such file or directory, open '${m.fullHostPath}'`);
|
|
296
|
+
return fsSync.readFileSync(m.fullHostPath, "utf8");
|
|
297
|
+
}
|
|
203
298
|
const normalized = normalizePath(targetPath);
|
|
204
299
|
const node = getNode(this.root, normalized);
|
|
205
300
|
if (node.type !== "file") {
|
|
@@ -212,6 +307,12 @@ class VirtualFileSystem extends EventEmitter {
|
|
|
212
307
|
}
|
|
213
308
|
/** Reads file content as a Buffer (decompresses if needed). */
|
|
214
309
|
readFileRaw(targetPath) {
|
|
310
|
+
const m = this.resolveMount(targetPath);
|
|
311
|
+
if (m) {
|
|
312
|
+
if (!fsSync.existsSync(m.fullHostPath))
|
|
313
|
+
throw new Error(`ENOENT: no such file or directory, open '${m.fullHostPath}'`);
|
|
314
|
+
return fsSync.readFileSync(m.fullHostPath);
|
|
315
|
+
}
|
|
215
316
|
const normalized = normalizePath(targetPath);
|
|
216
317
|
const node = getNode(this.root, normalized);
|
|
217
318
|
if (node.type !== "file") {
|
|
@@ -224,6 +325,9 @@ class VirtualFileSystem extends EventEmitter {
|
|
|
224
325
|
}
|
|
225
326
|
/** Returns true when a file or directory exists at path. */
|
|
226
327
|
exists(targetPath) {
|
|
328
|
+
const m = this.resolveMount(targetPath);
|
|
329
|
+
if (m)
|
|
330
|
+
return fsSync.existsSync(m.fullHostPath);
|
|
227
331
|
try {
|
|
228
332
|
getNode(this.root, normalizePath(targetPath));
|
|
229
333
|
return true;
|
|
@@ -238,6 +342,35 @@ class VirtualFileSystem extends EventEmitter {
|
|
|
238
342
|
}
|
|
239
343
|
/** Returns metadata for a file or directory. */
|
|
240
344
|
stat(targetPath) {
|
|
345
|
+
const m = this.resolveMount(targetPath);
|
|
346
|
+
if (m) {
|
|
347
|
+
if (!fsSync.existsSync(m.fullHostPath))
|
|
348
|
+
throw new Error(`ENOENT: stat '${m.fullHostPath}'`);
|
|
349
|
+
const hst = fsSync.statSync(m.fullHostPath);
|
|
350
|
+
const name = m.relPath.split("/").pop() ?? m.fullHostPath.split("/").pop() ?? "";
|
|
351
|
+
const now = hst.mtime;
|
|
352
|
+
if (hst.isDirectory()) {
|
|
353
|
+
return {
|
|
354
|
+
type: "directory",
|
|
355
|
+
name,
|
|
356
|
+
path: normalizePath(targetPath),
|
|
357
|
+
mode: 0o755,
|
|
358
|
+
createdAt: hst.birthtime,
|
|
359
|
+
updatedAt: now,
|
|
360
|
+
childrenCount: fsSync.readdirSync(m.fullHostPath).length,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
return {
|
|
364
|
+
type: "file",
|
|
365
|
+
name,
|
|
366
|
+
path: normalizePath(targetPath),
|
|
367
|
+
mode: m.readOnly ? 0o444 : 0o644,
|
|
368
|
+
createdAt: hst.birthtime,
|
|
369
|
+
updatedAt: now,
|
|
370
|
+
compressed: false,
|
|
371
|
+
size: hst.size,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
241
374
|
const normalized = normalizePath(targetPath);
|
|
242
375
|
const node = getNode(this.root, normalized);
|
|
243
376
|
const name = normalized === "/" ? "" : path.posix.basename(normalized);
|
|
@@ -267,6 +400,17 @@ class VirtualFileSystem extends EventEmitter {
|
|
|
267
400
|
}
|
|
268
401
|
/** Lists direct children names of a directory (sorted). */
|
|
269
402
|
list(dirPath = "/") {
|
|
403
|
+
const m = this.resolveMount(dirPath);
|
|
404
|
+
if (m) {
|
|
405
|
+
if (!fsSync.existsSync(m.fullHostPath))
|
|
406
|
+
return [];
|
|
407
|
+
try {
|
|
408
|
+
return fsSync.readdirSync(m.fullHostPath).sort();
|
|
409
|
+
}
|
|
410
|
+
catch {
|
|
411
|
+
return [];
|
|
412
|
+
}
|
|
413
|
+
}
|
|
270
414
|
const normalized = normalizePath(dirPath);
|
|
271
415
|
const node = getNode(this.root, normalized);
|
|
272
416
|
if (node.type !== "directory") {
|
|
@@ -402,6 +546,21 @@ class VirtualFileSystem extends EventEmitter {
|
|
|
402
546
|
}
|
|
403
547
|
/** Removes a file or directory node. */
|
|
404
548
|
remove(targetPath, options = {}) {
|
|
549
|
+
const m = this.resolveMount(targetPath);
|
|
550
|
+
if (m) {
|
|
551
|
+
if (m.readOnly)
|
|
552
|
+
throw new Error(`EROFS: read-only file system, unlink '${m.fullHostPath}'`);
|
|
553
|
+
if (!fsSync.existsSync(m.fullHostPath))
|
|
554
|
+
throw new Error(`ENOENT: no such file or directory, unlink '${m.fullHostPath}'`);
|
|
555
|
+
const hst = fsSync.statSync(m.fullHostPath);
|
|
556
|
+
if (hst.isDirectory()) {
|
|
557
|
+
fsSync.rmSync(m.fullHostPath, { recursive: options.recursive ?? false });
|
|
558
|
+
}
|
|
559
|
+
else {
|
|
560
|
+
fsSync.unlinkSync(m.fullHostPath);
|
|
561
|
+
}
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
405
564
|
const normalized = normalizePath(targetPath);
|
|
406
565
|
if (normalized === "/")
|
|
407
566
|
throw new Error("Cannot remove root directory.");
|