just-bash 2.12.7 → 2.13.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 +89 -3
- package/dist/AGENTS.md +1 -1
- package/dist/Bash.d.ts +17 -0
- package/dist/bin/chunks/{awk2-EB5SCHVW.js → awk2-VTJMI54B.js} +1 -1
- package/dist/bin/chunks/chunk-3YMCKZTY.js +14 -0
- package/dist/bin/chunks/{chunk-O5B6WWQQ.js → chunk-A3HQTYHR.js} +1 -1
- package/dist/bin/chunks/chunk-AAW7UMPO.js +9 -0
- package/dist/bin/chunks/{chunk-ROMKUVHI.js → chunk-AXWFPG37.js} +1 -1
- package/dist/bin/chunks/{chunk-BBRVF6XE.js → chunk-B3RU2PUI.js} +27 -27
- package/dist/bin/chunks/chunk-CQG2HEAL.js +5 -0
- package/dist/bin/chunks/chunk-DOXYBGNA.js +12 -0
- package/dist/bin/chunks/{chunk-PIBXJ3VX.js → chunk-GR23MPTT.js} +1 -1
- package/dist/bin/chunks/{chunk-35JD7YEM.js → chunk-HJEHIH4P.js} +13 -13
- package/dist/bin/chunks/{chunk-ZNPXCE5B.js → chunk-LGF54XJQ.js} +1 -1
- package/dist/bin/{shell/chunks/chunk-5MUD3WB2.js → chunks/chunk-MO4RPBN2.js} +1 -1
- package/dist/bin/chunks/chunk-N6KA6G3Q.js +11 -0
- package/dist/bin/{shell/chunks/chunk-JX6YLHDX.js → chunks/chunk-OOJCYVYF.js} +1 -1
- package/dist/bin/{shell/chunks/chunk-2BC3N3L2.js → chunks/chunk-ORUYSLP4.js} +4 -4
- package/dist/bin/{shell/chunks/chunk-OLN6BSO3.js → chunks/chunk-SDLWFYVT.js} +2 -2
- package/dist/bin/chunks/{chunk-STOAUD75.js → chunk-THNL3XFF.js} +8 -8
- package/dist/bin/chunks/{chunk-DHFZMFUW.js → chunk-UPUMZYZE.js} +1 -1
- package/dist/bin/chunks/{chunk-ZJGIBTWD.js → chunk-V7ZOPVQS.js} +1 -1
- package/dist/bin/chunks/{chunk-IRCLOW32.js → chunk-VVFGRIJZ.js} +1 -1
- package/dist/bin/chunks/{chunk-QTII62YM.js → chunk-WS6P4H4S.js} +1 -1
- package/dist/bin/{shell/chunks/chunk-NTKUVXEL.js → chunks/chunk-YU6OGPZR.js} +2 -2
- package/dist/bin/{shell/chunks/chunk-PLKGKTIS.js → chunks/chunk-ZO5PSLKR.js} +2 -2
- package/dist/bin/{shell/chunks/curl-3GMIPMCI.js → chunks/curl-B64SIJOD.js} +1 -1
- package/dist/bin/chunks/env-NTPN5QYM.js +2 -0
- package/dist/bin/{shell/chunks/expansion-JBCP2CHQ.js → chunks/expansion-2RO5M3QC.js} +1 -1
- package/dist/bin/chunks/{find-MTLF23HX.js → find-GAYRV4IF.js} +1 -1
- package/dist/bin/chunks/flag-coverage-IRM4GISL.js +2 -0
- package/dist/bin/{shell/chunks/help-4H52JYYC.js → chunks/help-DVG4AAGE.js} +1 -1
- package/dist/bin/chunks/{jq-P457LMHU.js → jq-V7FYGIKO.js} +1 -1
- package/dist/bin/chunks/js-exec-YGYYZEEQ.js +97 -0
- package/dist/bin/chunks/js-exec-worker.js +4368 -0
- package/dist/bin/chunks/python3-EIXZW3LO.js +12 -0
- package/dist/bin/chunks/rg-C6KMBFNG.js +2 -0
- package/dist/bin/{shell/chunks/sed-UV2LTNVK.js → chunks/sed-3C6IBX5L.js} +1 -1
- package/dist/bin/chunks/sleep-ND6FZRZ4.js +2 -0
- package/dist/bin/chunks/{sqlite3-B3P3OMPI.js → sqlite3-TZEE4O7U.js} +1 -1
- package/dist/bin/chunks/tar-TOWX2TDU.js +2 -0
- package/dist/bin/{shell/chunks/time-GZSHCM77.js → chunks/time-VSKBXRQH.js} +1 -1
- package/dist/bin/chunks/timeout-Z24MNWOP.js +2 -0
- package/dist/bin/chunks/worker.js +168 -33
- package/dist/bin/chunks/xan-MOZFJGMY.js +2 -0
- package/dist/bin/chunks/xargs-SCYIFXOW.js +2 -0
- package/dist/bin/chunks/yq-JJLSDDST.js +2 -0
- package/dist/bin/just-bash.js +211 -210
- package/dist/bin/shell/chunks/{awk2-EB5SCHVW.js → awk2-VTJMI54B.js} +1 -1
- package/dist/bin/shell/chunks/chunk-3YMCKZTY.js +14 -0
- package/dist/bin/shell/chunks/{chunk-O5B6WWQQ.js → chunk-A3HQTYHR.js} +1 -1
- package/dist/bin/shell/chunks/chunk-AAW7UMPO.js +9 -0
- package/dist/bin/shell/chunks/{chunk-ROMKUVHI.js → chunk-AXWFPG37.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-BBRVF6XE.js → chunk-B3RU2PUI.js} +27 -27
- package/dist/bin/shell/chunks/chunk-CQG2HEAL.js +5 -0
- package/dist/bin/shell/chunks/chunk-DOXYBGNA.js +12 -0
- package/dist/bin/shell/chunks/{chunk-PIBXJ3VX.js → chunk-GR23MPTT.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-35JD7YEM.js → chunk-HJEHIH4P.js} +13 -13
- package/dist/bin/shell/chunks/{chunk-ZNPXCE5B.js → chunk-LGF54XJQ.js} +1 -1
- package/dist/bin/{chunks/chunk-5MUD3WB2.js → shell/chunks/chunk-MO4RPBN2.js} +1 -1
- package/dist/bin/shell/chunks/chunk-N6KA6G3Q.js +11 -0
- package/dist/bin/{chunks/chunk-JX6YLHDX.js → shell/chunks/chunk-OOJCYVYF.js} +1 -1
- package/dist/bin/{chunks/chunk-2BC3N3L2.js → shell/chunks/chunk-ORUYSLP4.js} +4 -4
- package/dist/bin/{chunks/chunk-OLN6BSO3.js → shell/chunks/chunk-SDLWFYVT.js} +2 -2
- package/dist/bin/shell/chunks/{chunk-STOAUD75.js → chunk-THNL3XFF.js} +8 -8
- package/dist/bin/shell/chunks/{chunk-DHFZMFUW.js → chunk-UPUMZYZE.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-ZJGIBTWD.js → chunk-V7ZOPVQS.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-IRCLOW32.js → chunk-VVFGRIJZ.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-QTII62YM.js → chunk-WS6P4H4S.js} +1 -1
- package/dist/bin/{chunks/chunk-NTKUVXEL.js → shell/chunks/chunk-YU6OGPZR.js} +2 -2
- package/dist/bin/{chunks/chunk-PLKGKTIS.js → shell/chunks/chunk-ZO5PSLKR.js} +2 -2
- package/dist/bin/{chunks/curl-3GMIPMCI.js → shell/chunks/curl-B64SIJOD.js} +1 -1
- package/dist/bin/shell/chunks/env-NTPN5QYM.js +2 -0
- package/dist/bin/{chunks/expansion-JBCP2CHQ.js → shell/chunks/expansion-2RO5M3QC.js} +1 -1
- package/dist/bin/shell/chunks/{find-MTLF23HX.js → find-GAYRV4IF.js} +1 -1
- package/dist/bin/shell/chunks/flag-coverage-IRM4GISL.js +2 -0
- package/dist/bin/{chunks/help-4H52JYYC.js → shell/chunks/help-DVG4AAGE.js} +1 -1
- package/dist/bin/shell/chunks/{jq-P457LMHU.js → jq-V7FYGIKO.js} +1 -1
- package/dist/bin/shell/chunks/js-exec-VYG74FQ3.js +97 -0
- package/dist/bin/shell/chunks/python3-WO3WFGMS.js +12 -0
- package/dist/bin/shell/chunks/rg-C6KMBFNG.js +2 -0
- package/dist/bin/{chunks/sed-UV2LTNVK.js → shell/chunks/sed-3C6IBX5L.js} +1 -1
- package/dist/bin/shell/chunks/sleep-ND6FZRZ4.js +2 -0
- package/dist/bin/shell/chunks/{sqlite3-B3P3OMPI.js → sqlite3-TZEE4O7U.js} +1 -1
- package/dist/bin/shell/chunks/tar-TOWX2TDU.js +2 -0
- package/dist/bin/{chunks/time-GZSHCM77.js → shell/chunks/time-VSKBXRQH.js} +1 -1
- package/dist/bin/shell/chunks/timeout-Z24MNWOP.js +2 -0
- package/dist/bin/shell/chunks/xan-MOZFJGMY.js +2 -0
- package/dist/bin/shell/chunks/xargs-SCYIFXOW.js +2 -0
- package/dist/bin/shell/chunks/yq-JJLSDDST.js +2 -0
- package/dist/bin/shell/shell.js +208 -208
- package/dist/bundle/browser.js +594 -594
- package/dist/bundle/chunks/{awk2-VPBKDCSO.js → awk2-POPGKRAI.js} +1 -1
- package/dist/bundle/chunks/{chunk-X36DXRVC.js → chunk-24IMIIXA.js} +1 -1
- package/dist/bundle/chunks/{chunk-72EQZSVH.js → chunk-5QMZ5MUS.js} +2 -2
- package/dist/bundle/chunks/{chunk-DZZS6SJP.js → chunk-7TSDKFEO.js} +1 -1
- package/dist/bundle/chunks/{chunk-7YDOWJ75.js → chunk-A5O5YHGN.js} +1 -1
- package/dist/bundle/chunks/{chunk-KZ7BI7TV.js → chunk-BBXLRYSX.js} +2 -2
- package/dist/bundle/chunks/{chunk-TRD56HID.js → chunk-FEIOJCZD.js} +1 -1
- package/dist/bundle/chunks/{chunk-X3CVFNQZ.js → chunk-GOV5EKKI.js} +1 -1
- package/dist/bundle/chunks/{chunk-AUD37QB3.js → chunk-IUWCBQII.js} +1 -1
- package/dist/bundle/chunks/chunk-JCMONG3T.js +13 -0
- package/dist/bundle/chunks/{chunk-D2FZX7A2.js → chunk-LPQPILI2.js} +8 -8
- package/dist/bundle/chunks/chunk-MJWMXCEJ.js +10 -0
- package/dist/bundle/chunks/{chunk-2GOYXRRP.js → chunk-MLXIYONF.js} +4 -4
- package/dist/bundle/chunks/chunk-NAERJDUW.js +8 -0
- package/dist/bundle/chunks/{chunk-OKEHYWBE.js → chunk-NYQYO467.js} +13 -13
- package/dist/bundle/chunks/{chunk-C7ZTXK5C.js → chunk-O2DBFL6Z.js} +1 -1
- package/dist/bundle/chunks/{chunk-VSWTMNI3.js → chunk-OARHFVLG.js} +2 -2
- package/dist/bundle/chunks/{chunk-U5FWK6IA.js → chunk-RUF7WQ7U.js} +1 -1
- package/dist/bundle/chunks/chunk-TOMNU26N.js +4 -0
- package/dist/bundle/chunks/{chunk-4YPFHVJJ.js → chunk-UNYNJIFU.js} +27 -27
- package/dist/bundle/chunks/{chunk-VBF2GWEM.js → chunk-V3IEYMEA.js} +1 -1
- package/dist/bundle/chunks/chunk-YTNYSM6T.js +11 -0
- package/dist/bundle/chunks/{chunk-BED5HSP2.js → chunk-ZXL7TQLN.js} +1 -1
- package/dist/bundle/chunks/{curl-KM2ZAUR6.js → curl-FCIO57JJ.js} +1 -1
- package/dist/bundle/chunks/env-5EPCWSXR.js +1 -0
- package/dist/bundle/chunks/{expansion-XG7G47TX.js → expansion-ENLSRCXJ.js} +1 -1
- package/dist/bundle/chunks/{find-DOIVMX6X.js → find-TPUOAIUQ.js} +1 -1
- package/dist/bundle/chunks/flag-coverage-SPT2DN2I.js +1 -0
- package/dist/bundle/chunks/{help-IA5CMGR4.js → help-VVWX7SA5.js} +1 -1
- package/dist/bundle/chunks/{jq-NLRWI2Q6.js → jq-DIRZBOTX.js} +1 -1
- package/dist/bundle/chunks/js-exec-R2LSP7M4.js +96 -0
- package/dist/bundle/chunks/js-exec-worker.js +4368 -0
- package/dist/bundle/chunks/python3-DH2SBOI3.js +11 -0
- package/dist/bundle/chunks/rg-FOQSCCX3.js +1 -0
- package/dist/bundle/chunks/{sed-2BILOGNL.js → sed-DISNI47D.js} +1 -1
- package/dist/bundle/chunks/sleep-VZFPZFWA.js +1 -0
- package/dist/bundle/chunks/{sqlite3-VEDNWJL6.js → sqlite3-7F22DOIP.js} +1 -1
- package/dist/bundle/chunks/tar-232RCEFK.js +1 -0
- package/dist/bundle/chunks/{time-XL42Z4U5.js → time-FABCOJJU.js} +1 -1
- package/dist/bundle/chunks/timeout-VRKMCG72.js +1 -0
- package/dist/bundle/chunks/worker.js +168 -33
- package/dist/bundle/chunks/xan-BXDXYEIB.js +1 -0
- package/dist/bundle/chunks/xargs-I6EZUCYF.js +1 -0
- package/dist/bundle/chunks/yq-XMVSIL6Z.js +1 -0
- package/dist/bundle/index.cjs +976 -877
- package/dist/bundle/index.js +245 -245
- package/dist/commands/js-exec/fetch-polyfill.d.ts +6 -0
- package/dist/commands/js-exec/js-exec.d.ts +11 -0
- package/dist/commands/js-exec/module-shims.d.ts +29 -0
- package/dist/commands/js-exec/path-polyfill.d.ts +6 -0
- package/dist/commands/js-exec/worker.d.ts +30 -0
- package/dist/commands/python3/worker.d.ts +1 -0
- package/dist/commands/query-engine/safe-object.d.ts +11 -0
- package/dist/commands/registry.d.ts +13 -2
- package/dist/commands/{python3/fs-bridge-handler.d.ts → worker-bridge/bridge-handler.d.ts} +25 -8
- package/dist/commands/{python3 → worker-bridge}/protocol.d.ts +6 -3
- package/dist/commands/{python3/sync-fs-backend.d.ts → worker-bridge/sync-backend.d.ts} +25 -4
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/interpreter/interpreter.d.ts +3 -0
- package/dist/interpreter/types.d.ts +8 -0
- package/dist/limits.d.ts +3 -1
- package/dist/network/allow-list/shared.d.ts +8 -0
- package/dist/network/types.d.ts +15 -1
- package/dist/types.d.ts +12 -0
- package/package.json +12 -11
- package/dist/bin/chunks/chunk-47HZU3SY.js +0 -5
- package/dist/bin/chunks/chunk-N4EU64Y4.js +0 -9
- package/dist/bin/chunks/chunk-VCKKRS7V.js +0 -12
- package/dist/bin/chunks/chunk-VIYJJTN2.js +0 -14
- package/dist/bin/chunks/env-HOVBNLUR.js +0 -2
- package/dist/bin/chunks/flag-coverage-7GOZYXJT.js +0 -2
- package/dist/bin/chunks/python3-45TMCI4M.js +0 -17
- package/dist/bin/chunks/rg-34GE6REQ.js +0 -2
- package/dist/bin/chunks/sleep-3WHM7JMW.js +0 -2
- package/dist/bin/chunks/tar-SO3XDDIW.js +0 -2
- package/dist/bin/chunks/timeout-BYB3L2JA.js +0 -2
- package/dist/bin/chunks/xan-FZB7FHX3.js +0 -2
- package/dist/bin/chunks/xargs-GBL6PZ2K.js +0 -2
- package/dist/bin/chunks/yq-H7D2U3HS.js +0 -2
- package/dist/bin/shell/chunks/chunk-47HZU3SY.js +0 -5
- package/dist/bin/shell/chunks/chunk-N4EU64Y4.js +0 -9
- package/dist/bin/shell/chunks/chunk-VCKKRS7V.js +0 -12
- package/dist/bin/shell/chunks/chunk-VIYJJTN2.js +0 -14
- package/dist/bin/shell/chunks/env-HOVBNLUR.js +0 -2
- package/dist/bin/shell/chunks/flag-coverage-7GOZYXJT.js +0 -2
- package/dist/bin/shell/chunks/python3-IV3DBMHM.js +0 -17
- package/dist/bin/shell/chunks/rg-34GE6REQ.js +0 -2
- package/dist/bin/shell/chunks/sleep-3WHM7JMW.js +0 -2
- package/dist/bin/shell/chunks/tar-SO3XDDIW.js +0 -2
- package/dist/bin/shell/chunks/timeout-BYB3L2JA.js +0 -2
- package/dist/bin/shell/chunks/xan-FZB7FHX3.js +0 -2
- package/dist/bin/shell/chunks/xargs-GBL6PZ2K.js +0 -2
- package/dist/bin/shell/chunks/yq-H7D2U3HS.js +0 -2
- package/dist/bundle/chunks/chunk-3RA5L262.js +0 -8
- package/dist/bundle/chunks/chunk-6HBBXB3L.js +0 -11
- package/dist/bundle/chunks/chunk-EX62JIX3.js +0 -13
- package/dist/bundle/chunks/chunk-ZSJYNBAF.js +0 -4
- package/dist/bundle/chunks/env-XZY4LKEO.js +0 -1
- package/dist/bundle/chunks/flag-coverage-NT32EG6Q.js +0 -1
- package/dist/bundle/chunks/python3-G2ZUJAQL.js +0 -16
- package/dist/bundle/chunks/rg-RAICUFGG.js +0 -1
- package/dist/bundle/chunks/sleep-IUBP5GMH.js +0 -1
- package/dist/bundle/chunks/tar-LKO7DKAK.js +0 -1
- package/dist/bundle/chunks/timeout-TL4Q5YKZ.js +0 -1
- package/dist/bundle/chunks/xan-KSDYKKEK.js +0 -1
- package/dist/bundle/chunks/xargs-2BBAQDTC.js +0 -1
- package/dist/bundle/chunks/yq-HIQ4WMDY.js +0 -1
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ Supports optional network access via `curl` with secure-by-default URL filtering
|
|
|
25
25
|
- [Shell Features](#shell-features)
|
|
26
26
|
- [Default Layout](#default-layout)
|
|
27
27
|
- [Network Access](#network-access)
|
|
28
|
+
- [JavaScript Support](#javascript-support)
|
|
28
29
|
- [Execution Protection](#execution-protection)
|
|
29
30
|
- [AST Transform Plugins](#ast-transform-plugins)
|
|
30
31
|
- [Development](#development)
|
|
@@ -35,7 +36,8 @@ Supports optional network access via `curl` with secure-by-default URL filtering
|
|
|
35
36
|
- Execution is protected against infinite loops or recursion. However, Bash is not fully robust against DOS from input. If you need to be robust against this, use process isolation at the OS level.
|
|
36
37
|
- Binaries or even WASM are inherently unsupported (Use [Vercel Sandbox](https://vercel.com/docs/vercel-sandbox) or a similar product if a full VM is needed).
|
|
37
38
|
- There is no network access by default.
|
|
38
|
-
- Network access can be enabled, but requests are checked against URL prefix allow-lists and HTTP-method allow-lists. See [network access](#network-access) for details
|
|
39
|
+
- Network access can be enabled, but requests are checked against URL prefix allow-lists and HTTP-method allow-lists. See [network access](#network-access) for details.
|
|
40
|
+
- Python and JS execution are off by default as they may represent additional security surface.
|
|
39
41
|
|
|
40
42
|
## Installation
|
|
41
43
|
|
|
@@ -68,12 +70,44 @@ const env = new Bash({
|
|
|
68
70
|
env: { MY_VAR: "value" }, // Initial environment
|
|
69
71
|
cwd: "/app", // Starting directory (default: /home/user)
|
|
70
72
|
executionLimits: { maxCallDepth: 50 }, // See "Execution Protection"
|
|
73
|
+
python: true, // Enable python3/python commands
|
|
74
|
+
javascript: true, // Enable js-exec command
|
|
75
|
+
// Or with bootstrap: javascript: { bootstrap: "globalThis.X = 1;" }
|
|
71
76
|
});
|
|
72
77
|
|
|
73
78
|
// Per-exec overrides
|
|
74
79
|
await env.exec("echo $TEMP", { env: { TEMP: "value" }, cwd: "/tmp" });
|
|
80
|
+
|
|
81
|
+
// Pass stdin to the script
|
|
82
|
+
await env.exec("cat", { stdin: "hello from stdin\n" });
|
|
83
|
+
|
|
84
|
+
// Start with a clean environment
|
|
85
|
+
await env.exec("env", { replaceEnv: true, env: { ONLY: "this" } });
|
|
86
|
+
|
|
87
|
+
// Pass arguments without shell escaping (like spawnSync)
|
|
88
|
+
await env.exec("grep", { args: ["-r", "TODO", "src/"] });
|
|
89
|
+
|
|
90
|
+
// Cancel long-running scripts
|
|
91
|
+
const controller = new AbortController();
|
|
92
|
+
setTimeout(() => controller.abort(), 5000);
|
|
93
|
+
await env.exec("while true; do sleep 1; done", { signal: controller.signal });
|
|
94
|
+
|
|
95
|
+
// Preserve leading whitespace (e.g., for heredocs)
|
|
96
|
+
await env.exec("cat <<EOF\n indented\nEOF", { rawScript: true });
|
|
75
97
|
```
|
|
76
98
|
|
|
99
|
+
`exec()` options:
|
|
100
|
+
|
|
101
|
+
| Option | Type | Description |
|
|
102
|
+
|---|---|---|
|
|
103
|
+
| `env` | `Record<string, string>` | Environment variables for this execution only |
|
|
104
|
+
| `cwd` | `string` | Working directory for this execution only |
|
|
105
|
+
| `stdin` | `string` | Standard input passed to the script |
|
|
106
|
+
| `args` | `string[]` | Additional argv passed directly to the first command (bypasses shell parsing; does not change `$1`, `$2`, ...) |
|
|
107
|
+
| `replaceEnv` | `boolean` | Start with empty env instead of merging (default: `false`) |
|
|
108
|
+
| `signal` | `AbortSignal` | Cooperative cancellation; stops at next statement boundary |
|
|
109
|
+
| `rawScript` | `boolean` | Skip leading-whitespace normalization (default: `false`) |
|
|
110
|
+
|
|
77
111
|
#### Lazy Files
|
|
78
112
|
|
|
79
113
|
File values can be functions (sync or async). The function is called on first read and the result is cached — if the file is written to before being read, the function is never called:
|
|
@@ -300,7 +334,7 @@ pnpm shell --no-network
|
|
|
300
334
|
|
|
301
335
|
### Data Processing
|
|
302
336
|
|
|
303
|
-
`jq` (JSON), `python3`/`python` (Python via
|
|
337
|
+
`jq` (JSON), `js-exec` (JavaScript/TypeScript via QuickJS; requires opt-in), `python3`/`python` (Python via WASM/CPython; requires opt-in), `sqlite3` (SQLite), `xan` (CSV), `yq` (YAML/XML/TOML/CSV)
|
|
304
338
|
|
|
305
339
|
### Compression & Archives
|
|
306
340
|
|
|
@@ -379,7 +413,7 @@ const env = new Bash({
|
|
|
379
413
|
|
|
380
414
|
## Python Support
|
|
381
415
|
|
|
382
|
-
Python support via
|
|
416
|
+
Python support via WASM/CPython is opt-in due to additional security surface. Enable it explicitly, but be aware of the risk:
|
|
383
417
|
|
|
384
418
|
```typescript
|
|
385
419
|
const env = new Bash({
|
|
@@ -395,6 +429,58 @@ await env.exec('python3 script.py');
|
|
|
395
429
|
|
|
396
430
|
**Note:** The `python3` and `python` commands only exist when `python: true` is configured. Python is not available in browser environments.
|
|
397
431
|
|
|
432
|
+
## JavaScript Support
|
|
433
|
+
|
|
434
|
+
JavaScript and TypeScript execution via QuickJS is opt-in due to additional security surface. Enable it with the `javascript` option:
|
|
435
|
+
|
|
436
|
+
```typescript
|
|
437
|
+
const env = new Bash({
|
|
438
|
+
javascript: true,
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
// Execute JavaScript code
|
|
442
|
+
await env.exec('js-exec -c "console.log(1 + 2)"');
|
|
443
|
+
|
|
444
|
+
// Run script files (.js, .mjs, .ts, .mts)
|
|
445
|
+
await env.exec('js-exec script.js');
|
|
446
|
+
|
|
447
|
+
// ES module mode with imports
|
|
448
|
+
await env.exec('js-exec -m -c "import fs from \'fs\'; console.log(fs.readFileSync(\'/data/file.txt\', \'utf8\'))"');
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
### Bootstrap Code
|
|
452
|
+
|
|
453
|
+
You can run setup code before every `js-exec` invocation using the `bootstrap` option. This is useful for injecting polyfills, global utilities, or environment setup:
|
|
454
|
+
|
|
455
|
+
```typescript
|
|
456
|
+
const env = new Bash({
|
|
457
|
+
javascript: {
|
|
458
|
+
bootstrap: `
|
|
459
|
+
globalThis.API_BASE = "https://api.example.com";
|
|
460
|
+
globalThis.formatDate = (d) => new Date(d).toISOString();
|
|
461
|
+
`,
|
|
462
|
+
},
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
await env.exec('js-exec -c "console.log(API_BASE)"');
|
|
466
|
+
// Output: https://api.example.com
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
### Node.js Compatibility
|
|
470
|
+
|
|
471
|
+
`js-exec` provides broad Node.js compatibility. Both `require()` and `import` are supported:
|
|
472
|
+
|
|
473
|
+
- **fs**: `readFileSync`, `writeFileSync`, `readdirSync`, `statSync`, `existsSync`, `mkdirSync`, `rmSync`, `fs.promises.*`
|
|
474
|
+
- **path**: `join`, `resolve`, `dirname`, `basename`, `extname`, `relative`, `normalize`
|
|
475
|
+
- **child_process**: `execSync`, `spawnSync`
|
|
476
|
+
- **process**: `argv`, `cwd()`, `exit()`, `env`, `platform`, `version`
|
|
477
|
+
- **Other modules**: `os`, `url`, `assert`, `util`, `events`, `buffer`, `stream`, `string_decoder`, `querystring`
|
|
478
|
+
- **Globals**: `console`, `fetch`, `Buffer`, `URL`, `URLSearchParams`
|
|
479
|
+
|
|
480
|
+
`fs.readFileSync()` returns a `Buffer` by default (matching Node.js). Pass an encoding like `'utf8'` to get a string.
|
|
481
|
+
|
|
482
|
+
**Note:** The `js-exec` command only exists when `javascript` is configured. It is not available in browser environments. Execution runs in a QuickJS WASM sandbox with a 64 MB memory limit and configurable timeout (default: 10s, 60s with network). Requires Node.js >= 22.6 (uses `stripTypeScriptTypes` from `node:module`).
|
|
483
|
+
|
|
398
484
|
## SQLite Support
|
|
399
485
|
|
|
400
486
|
The `sqlite3` command uses sql.js (WASM-based SQLite) which is fully sandboxed and cannot access the real filesystem:
|
package/dist/AGENTS.md
CHANGED
|
@@ -66,7 +66,7 @@ const result = await bash.exec("cat input.txt | grep pattern");
|
|
|
66
66
|
|
|
67
67
|
**Text processing**: `awk`, `cat`, `column`, `comm`, `cut`, `egrep`, `expand`, `fgrep`, `fold`, `grep`, `head`, `join`, `nl`, `paste`, `rev`, `rg`, `sed`, `sort`, `strings`, `tac`, `tail`, `tr`, `unexpand`, `uniq`, `wc`, `xargs`
|
|
68
68
|
|
|
69
|
-
**Data processing**: `jq` (JSON), `python3`/`python` (Python via
|
|
69
|
+
**Data processing**: `jq` (JSON), `js-exec` (JavaScript/TypeScript via QuickJS), `python3`/`python` (Python via WASM/CPython), `sqlite3` (SQLite), `xan` (CSV), `yq` (YAML/XML/TOML/CSV)
|
|
70
70
|
|
|
71
71
|
**File operations**: `basename`, `chmod`, `cp`, `dirname`, `du`, `file`, `find`, `ln`, `ls`, `mkdir`, `mv`, `od`, `pwd`, `readlink`, `rm`, `rmdir`, `split`, `stat`, `touch`, `tree`
|
|
72
72
|
|
package/dist/Bash.d.ts
CHANGED
|
@@ -27,6 +27,10 @@ export interface BashLogger {
|
|
|
27
27
|
/** Log debug messages (stdout output) */
|
|
28
28
|
debug(message: string, data?: Record<string, unknown>): void;
|
|
29
29
|
}
|
|
30
|
+
export interface JavaScriptConfig {
|
|
31
|
+
/** Bootstrap JavaScript code to run before user scripts */
|
|
32
|
+
bootstrap?: string;
|
|
33
|
+
}
|
|
30
34
|
export interface BashOptions {
|
|
31
35
|
files?: InitialFiles;
|
|
32
36
|
env?: Record<string, string>;
|
|
@@ -67,6 +71,11 @@ export interface BashOptions {
|
|
|
67
71
|
* (arbitrary code execution via CPython Emscripten).
|
|
68
72
|
*/
|
|
69
73
|
python?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Enable js-exec command for sandboxed JavaScript execution via QuickJS.
|
|
76
|
+
* Disabled by default. Can be a boolean or a config object with bootstrap code.
|
|
77
|
+
*/
|
|
78
|
+
javascript?: boolean | JavaScriptConfig;
|
|
70
79
|
/**
|
|
71
80
|
* Optional list of command names to register.
|
|
72
81
|
* If not provided, all built-in commands are available.
|
|
@@ -185,6 +194,13 @@ export interface ExecOptions {
|
|
|
185
194
|
* When aborted, the interpreter stops executing at the next statement boundary.
|
|
186
195
|
*/
|
|
187
196
|
signal?: AbortSignal;
|
|
197
|
+
/**
|
|
198
|
+
* Additional argv entries appended to the first executed command at the interpreter level.
|
|
199
|
+
* Values bypass shell parsing entirely — no escaping, splitting, or globbing.
|
|
200
|
+
* Like child_process.spawnSync(cmd, args). These do not set or modify the shell's
|
|
201
|
+
* positional parameters ($1, $2, "$@", etc.).
|
|
202
|
+
*/
|
|
203
|
+
args?: string[];
|
|
188
204
|
}
|
|
189
205
|
export declare class Bash {
|
|
190
206
|
readonly fs: IFileSystem;
|
|
@@ -197,6 +213,7 @@ export declare class Bash {
|
|
|
197
213
|
private logger?;
|
|
198
214
|
private defenseInDepthConfig?;
|
|
199
215
|
private coverageWriter?;
|
|
216
|
+
private jsBootstrapCode?;
|
|
200
217
|
private transformPlugins;
|
|
201
218
|
private state;
|
|
202
219
|
constructor(options?: BashOptions);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a,b}from"./chunk-
|
|
2
|
+
import{a,b}from"./chunk-SDLWFYVT.js";import"./chunk-4PRVMER6.js";import"./chunk-MO4RPBN2.js";import"./chunk-YU6OGPZR.js";import"./chunk-SE4C7FJY.js";import"./chunk-6KZRLMG3.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";export{a as awkCommand2,b as flagsForFuzzing};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as g}from"./chunk-4OALHZXB.js";import{c as u}from"./chunk-QZNF3Y3J.js";import{a as h}from"./chunk-4PRVMER6.js";import{a as f}from"./chunk-SYG3IW7P.js";var v={name:"time",async execute(r,s){let a="%e %M",o=null,p=!1,c=!1,t=0;for(;t<r.length;){let e=r[t];if(e==="-f"||e==="--format"){if(t++,t>=r.length)return{stdout:"",stderr:`time: missing argument to '-f'
|
|
3
|
+
`,exitCode:1};a=r[t],t++}else if(e==="-o"||e==="--output"){if(t++,t>=r.length)return{stdout:"",stderr:`time: missing argument to '-o'
|
|
4
|
+
`,exitCode:1};o=r[t],t++}else if(e==="-a"||e==="--append")p=!0,t++;else if(e==="-v"||e==="--verbose")a=`Command being timed: %C
|
|
5
|
+
Elapsed (wall clock) time: %e seconds
|
|
6
|
+
Maximum resident set size (kbytes): %M`,t++;else if(e==="-p"||e==="--portability")c=!0,t++;else if(e==="--"){t++;break}else if(e.startsWith("-"))t++;else break}let l=r.slice(t);if(l.length===0)return{stdout:"",stderr:"",exitCode:0};let w=u(),C=l.join(" "),i;try{if(!s.exec)return{stdout:"",stderr:`time: exec not available
|
|
7
|
+
`,exitCode:1};i=await s.exec(g([l[0]]),{env:h(s.env),cwd:s.cwd,stdin:s.stdin,signal:s.signal,args:l.slice(1)})}catch(e){i={stdout:"",stderr:`time: ${f(e.message)}
|
|
8
|
+
`,exitCode:127}}let m=(u()-w)/1e3,n;if(c?n=`real ${m.toFixed(2)}
|
|
9
|
+
user 0.00
|
|
10
|
+
sys 0.00
|
|
11
|
+
`:(n=a.replace(/%e/g,m.toFixed(2)).replace(/%E/g,F(m)).replace(/%M/g,"0").replace(/%S/g,"0.00").replace(/%U/g,"0.00").replace(/%P/g,"0%").replace(/%C/g,C),n.endsWith(`
|
|
12
|
+
`)||(n+=`
|
|
13
|
+
`)),o)try{let e=s.fs.resolvePath(s.cwd,o);if(p&&await s.fs.exists(e)){let d=await s.fs.readFile(e);await s.fs.writeFile(e,d+n)}else await s.fs.writeFile(e,n)}catch(e){let d=f(e.message);return{stdout:i.stdout,stderr:i.stderr+`time: cannot write to '${o}': ${d}
|
|
14
|
+
`,exitCode:i.exitCode}}else i={...i,stderr:i.stderr+n};return i}};function F(r){let s=Math.floor(r/3600),a=Math.floor(r%3600/60),o=r%60;return s>0?`${s}:${a.toString().padStart(2,"0")}:${o.toFixed(2).padStart(5,"0")}`:`${a}:${o.toFixed(2).padStart(5,"0")}`}var S={name:"time",flags:[{flag:"-p",type:"boolean"}],needsArgs:!0};export{v as a,S as b};
|
|
@@ -43,7 +43,7 @@ import{a as O}from"./chunk-SE4C7FJY.js";import{e as j,f as K,g as C,h as re,i as
|
|
|
43
43
|
`);)f=!0,u++;if(f&&u<s&&r[u]===")")return!0}if(a===0)return!1;n++;continue}if(a===1&&(o==="|"&&n+1<s&&r[n+1]==="|"||o==="&"&&n+1<s&&r[n+1]==="&"||o==="|"&&n+1<s&&r[n+1]!=="|"))return!0;n++}return!1}};var Qe=1e6,Ze=1e5,Qt=1e6,Ue=200,Zt=new Set([p.LESS,p.GREAT,p.DLESS,p.DGREAT,p.LESSAND,p.GREATAND,p.LESSGREAT,p.DLESSDASH,p.CLOBBER,p.TLESS,p.AND_GREAT,p.AND_DGREAT]),Ut=new Set([p.LESS,p.GREAT,p.DLESS,p.DGREAT,p.LESSAND,p.GREATAND,p.LESSGREAT,p.DLESSDASH,p.CLOBBER,p.TLESS]),Ht=new Set([p.LESS,p.GREAT,p.DLESS,p.DGREAT,p.LESSAND,p.GREATAND,p.LESSGREAT,p.DLESSDASH,p.CLOBBER,p.TLESS,p.AND_GREAT,p.AND_DGREAT]),G=class extends Error{line;column;token;constructor(t,r,s,n=void 0){super(`Parse error at ${r}:${s}: ${t}`),this.line=r,this.column=s,this.token=n,this.name="ParseException"}};function Cr(e){let t="",r=0;for(;r<e.length;){let s=e[r];if(s<128){t+=String.fromCharCode(s),r++;continue}if((s&224)===192){if(r+1<e.length&&(e[r+1]&192)===128&&s>=194){let n=(s&31)<<6|e[r+1]&63;t+=String.fromCharCode(n),r+=2;continue}t+=String.fromCharCode(s),r++;continue}if((s&240)===224){if(r+2<e.length&&(e[r+1]&192)===128&&(e[r+2]&192)===128){if(s===224&&e[r+1]<160){t+=String.fromCharCode(s),r++;continue}let n=(s&15)<<12|(e[r+1]&63)<<6|e[r+2]&63;if(n>=55296&&n<=57343){t+=String.fromCharCode(s),r++;continue}t+=String.fromCharCode(n),r+=3;continue}t+=String.fromCharCode(s),r++;continue}if((s&248)===240&&s<=244){if(r+3<e.length&&(e[r+1]&192)===128&&(e[r+2]&192)===128&&(e[r+3]&192)===128){if(s===240&&e[r+1]<144){t+=String.fromCharCode(s),r++;continue}let n=(s&7)<<18|(e[r+1]&63)<<12|(e[r+2]&63)<<6|e[r+3]&63;if(n>1114111){t+=String.fromCharCode(s),r++;continue}t+=String.fromCodePoint(n),r+=4;continue}t+=String.fromCharCode(s),r++;continue}t+=String.fromCharCode(s),r++}return t}function Kt(e,t,r){let s=r+1;for(;s<t.length&&/[a-zA-Z0-9_-]/.test(t[s]);)s++;return s}function He(e,t,r,s,n){let a=1,i=r+1;for(;i<t.length&&a>0;)t[i]===s?a++:t[i]===n&&a--,a>0&&i++;return a===0?i:-1}function fe(e,t,r){let s=r,n=1;for(;s<t.length&&n>0;){let a=t[s];if(a==="\\"&&s+1<t.length){s+=2;continue}if(a==="'"){let i=t.indexOf("'",s+1);if(i!==-1){s=i+1;continue}}if(a==='"'){for(s++;s<t.length&&t[s]!=='"';)t[s]==="\\"&&s+1<t.length?s+=2:s++;s<t.length&&s++;continue}a==="{"?n++:a==="}"&&n--,n>0&&s++}return s}function Xt(e,t,r){let s=r,n=!1;for(;s<t.length;){let a=t[s];if(a==="/"&&n||a==="}")break;if(a==="'"){let i=t.indexOf("'",s+1);if(i!==-1){s=i+1,n=!0;continue}}if(a==='"'){for(s++;s<t.length&&t[s]!=='"';)t[s]==="\\"&&s+1<t.length?s+=2:s++;s<t.length&&s++,n=!0;continue}a==="\\"?(s+=2,n=!0):(s++,n=!0)}return s}function Jt(e,t,r){let s=r,n="";for(;s<t.length;){let a=t[s];if(a==="*"||a==="?")n+=a,s++;else if(a==="["){let i=Or(t,s);i===-1?(n+=a,s++):(n+=t.slice(s,i+1),s=i+1)}else break}return{pattern:n,endIndex:s}}function Or(e,t){let r=t+1;for(r<e.length&&e[r]==="^"&&r++,r<e.length&&e[r]==="]"&&r++;r<e.length;){let s=e[r];if(s==="\\"&&r+1<e.length){let n=e[r+1];if(n==='"'||n==="'")return-1;r+=2;continue}if(s==="]")return r;if(s==='"'||s==="$"||s==="`")return-1;if(s==="'"){let n=e.indexOf("'",r+1);if(n!==-1){r=n+1;continue}}if(s==="["&&r+1<e.length&&e[r+1]===":"){let n=e.indexOf(":]",r+2);if(n!==-1){r=n+2;continue}}if(s==="["&&r+1<e.length&&(e[r+1]==="."||e[r+1]==="=")){let a=`${e[r+1]}]`,i=e.indexOf(a,r+2);if(i!==-1){r=i+2;continue}}r++}return-1}function Yt(e,t,r){let s="",n=r;for(;n<t.length&&t[n]!=="'";){let a=t[n];if(a==="\\"&&n+1<t.length)switch(t[n+1]){case"n":s+=`
|
|
44
44
|
`,n+=2;break;case"t":s+=" ",n+=2;break;case"r":s+="\r",n+=2;break;case"\\":s+="\\",n+=2;break;case"'":s+="'",n+=2;break;case'"':s+='"',n+=2;break;case"a":s+="\x07",n+=2;break;case"b":s+="\b",n+=2;break;case"e":case"E":s+="\x1B",n+=2;break;case"f":s+="\f",n+=2;break;case"v":s+="\v",n+=2;break;case"x":{let l=[],o=n;for(;o+1<t.length&&t[o]==="\\"&&t[o+1]==="x";){let c=t.slice(o+2,o+4),u=parseInt(c,16);if(!Number.isNaN(u)&&c.length>0)l.push(u),o+=2+c.length;else break}l.length>0?(s+=Cr(l),n=o):(s+="\\x",n+=2);break}case"u":{let l=t.slice(n+2,n+6),o=parseInt(l,16);Number.isNaN(o)?(s+="\\u",n+=2):(s+=String.fromCharCode(o),n+=6);break}case"c":{if(n+2<t.length){let o=t[n+2].charCodeAt(0)&31;s+=String.fromCharCode(o),n+=3}else s+="\\c",n+=2;break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let l="",o=n+1;for(;o<t.length&&o<n+4&&/[0-7]/.test(t[o]);)l+=t[o],o++;let c=parseInt(l,8);s+=String.fromCharCode(c),n=o;break}default:s+=a,n++}else s+=a,n++}return n<t.length&&t[n]==="'"&&n++,{part:w.literal(s),endIndex:n}}function je(e,t){let r=t.trim();return r===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:M(e,r)}function jt(e){let t=[],r="",s=0;for(let n=0;n<e.length;n++){let a=e[n];a==="{"?(s++,r+=a):a==="}"?(s--,r+=a):a===","&&s===0?(t.push(r),r=""):r+=a}return t.push(r),t}function en(e,t,r,s){let n=He(e,t,r,"{","}");if(n===-1)return null;let a=t.slice(r+1,n),i=a.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(i)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(i[1],10),end:Number.parseInt(i[2],10),step:i[3]?Number.parseInt(i[3],10):void 0,startStr:i[1],endStr:i[2]}]},endIndex:n+1};let l=a.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return l?{part:{type:"BraceExpansion",items:[{type:"Range",start:l[1],end:l[2],step:l[3]?Number.parseInt(l[3],10):void 0}]},endIndex:n+1}:a.includes(",")&&s?{part:{type:"BraceExpansion",items:jt(a).map(u=>({type:"Word",word:w.word(s(e,u,!1,!1,!1))}))},endIndex:n+1}:a.includes(",")?{part:{type:"BraceExpansion",items:jt(a).map(u=>({type:"Word",word:w.word([w.literal(u)])}))},endIndex:n+1}:null}function Ke(e,t){let r="";for(let s of t.parts)switch(s.type){case"Literal":r+=s.value;break;case"SingleQuoted":r+=`'${s.value}'`;break;case"Escaped":r+=s.value;break;case"DoubleQuoted":r+='"';for(let n of s.parts)n.type==="Literal"||n.type==="Escaped"?r+=n.value:n.type==="ParameterExpansion"&&(r+=`\${${n.parameter}}`);r+='"';break;case"ParameterExpansion":r+=`\${${s.parameter}}`;break;case"Glob":r+=s.pattern;break;case"TildeExpansion":r+="~",s.user&&(r+=s.user);break;case"BraceExpansion":{r+="{";let n=[];for(let a of s.items)if(a.type==="Range"){let i=a.startStr??String(a.start),l=a.endStr??String(a.end);a.step!==void 0?n.push(`${i}..${l}..${a.step}`):n.push(`${i}..${l}`)}else n.push(Ke(e,a.word));n.length===1&&s.items[0].type==="Range"?r+=n[0]:r+=n.join(","),r+="}";break}default:r+=s.type}return r}function tn(e,t){return{[p.LESS]:"<",[p.GREAT]:">",[p.DGREAT]:">>",[p.LESSAND]:"<&",[p.GREATAND]:">&",[p.LESSGREAT]:"<>",[p.CLOBBER]:">|",[p.TLESS]:"<<<",[p.AND_GREAT]:"&>",[p.AND_DGREAT]:"&>>",[p.DLESS]:"<",[p.DLESSDASH]:"<"}[t]||">"}function De(e){let t=e.current(),r=t.type;if(r===p.NUMBER){let s=e.peek(1);return t.end!==s.start?!1:Ut.has(s.type)}if(r===p.FD_VARIABLE){let s=e.peek(1);return Ht.has(s.type)}return Zt.has(r)}function xe(e){let t=null,r;e.check(p.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(p.FD_VARIABLE)&&(r=e.advance().value);let s=e.advance(),n=tn(e,s.type);if(s.type===p.DLESS||s.type===p.DLESSDASH)return Lr(e,n,t,s.type===p.DLESSDASH);e.isWord()||e.error("Expected redirection target");let a=e.parseWord();return w.redirection(n,a,t,r)}function Lr(e,t,r,s){e.isWord()||e.error("Expected here-document delimiter");let n=e.advance(),a=n.value,i=n.quoted||!1;(a.startsWith("'")&&a.endsWith("'")||a.startsWith('"')&&a.endsWith('"'))&&(a=a.slice(1,-1));let l=w.redirection(s?"<<-":"<<",w.hereDoc(a,w.word([]),s,i),r);return e.addPendingHeredoc(l,a,s,i),l}function rn(e){let t=e.current().line,r=[],s=null,n=[],a=[];for(;e.check(p.ASSIGNMENT_WORD)||De(e);)e.checkIterationLimit(),e.check(p.ASSIGNMENT_WORD)?r.push(Wr(e)):a.push(xe(e));if(e.isWord())s=e.parseWord();else if(r.length>0&&(e.check(p.DBRACK_START)||e.check(p.DPAREN_START))){let l=e.advance();s=w.word([w.literal(l.value)])}for(;(!e.isStatementEnd()||e.check(p.RBRACE))&&!e.check(p.PIPE,p.PIPE_AMP);)if(e.checkIterationLimit(),De(e))a.push(xe(e));else if(e.check(p.RBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(p.LBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(p.DBRACK_END)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.isWord())n.push(e.parseWord());else if(e.check(p.ASSIGNMENT_WORD)){let l=e.advance(),o=l.value,c=o.endsWith("="),u=o.endsWith("=(");if((c||u)&&(u||e.check(p.LPAREN))){let f=u?o.slice(0,-2):o.slice(0,-1);u||e.expect(p.LPAREN);let h=Xe(e);e.expect(p.RPAREN);let d=h.map(g=>Ke(e,g)),m=`${f}=(${d.join(" ")})`;n.push(e.parseWordFromString(m,!1,!1))}else n.push(e.parseWordFromString(o,l.quoted,l.singleQuoted))}else if(e.check(p.LPAREN))e.error("syntax error near unexpected token `('");else break;let i=w.simpleCommand(s,n,r,a);return i.line=t,i}function Wr(e){let t=e.expect(p.ASSIGNMENT_WORD),r=t.value,s=r.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);s||e.error(`Invalid assignment: ${r}`);let n=s[0],a,i=n.length;if(r[i]==="["){let f=0,h=i+1;for(;i<r.length;i++)if(r[i]==="[")f++;else if(r[i]==="]"&&(f--,f===0))break;f!==0&&e.error(`Invalid assignment: ${r}`),a=r.slice(h,i),i++}let l=r[i]==="+";l&&i++,r[i]!=="="&&e.error(`Invalid assignment: ${r}`),i++;let o=r.slice(i);if(o==="("){let f=Xe(e);e.expect(p.RPAREN);let h=a!==void 0?`${n}[${a}]`:n;return w.assignment(h,null,l,f)}if(o===""&&e.check(p.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let h=Xe(e);e.expect(p.RPAREN);let d=a!==void 0?`${n}[${a}]`:n;return w.assignment(d,null,l,h)}}let c=o?e.parseWordFromString(o,t.quoted,t.singleQuoted,!0):null,u=a!==void 0?`${n}[${a}]`:n;return w.assignment(u,c,l,null)}var Tr=new Set([p.AMP,p.PIPE,p.PIPE_AMP,p.SEMICOLON,p.AND_AND,p.OR_OR,p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND]);function Xe(e){let t=[];for(e.skipNewlines();!e.check(p.RPAREN,p.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):Tr.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function Je(e,t){e.expect(p.IF);let r=[],s=e.parseCompoundList();e.expect(p.THEN);let n=e.parseCompoundList();if(n.length===0){let l=e.check(p.FI)?"fi":e.check(p.ELSE)?"else":e.check(p.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${l}'`)}for(r.push({condition:s,body:n});e.check(p.ELIF);){e.advance();let l=e.parseCompoundList();e.expect(p.THEN);let o=e.parseCompoundList();if(o.length===0){let c=e.check(p.FI)?"fi":e.check(p.ELSE)?"else":e.check(p.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${c}'`)}r.push({condition:l,body:o})}let a=null;e.check(p.ELSE)&&(e.advance(),a=e.parseCompoundList(),a.length===0&&e.error("syntax error near unexpected token `fi'")),e.expect(p.FI);let i=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.ifNode(r,a,i)}function Ye(e,t){let r=e.expect(p.FOR);if(e.check(p.DPAREN_START))return Vr(e,t,r.line);e.isWord()||e.error("Expected variable name in for loop");let n=e.advance().value,a=null;if(e.skipNewlines(),e.check(p.IN))for(e.advance(),a=[];!e.check(p.SEMICOLON,p.NEWLINE,p.DO,p.EOF)&&e.isWord();)a.push(e.parseWord());e.check(p.SEMICOLON)&&e.advance(),e.skipNewlines(),e.expect(p.DO);let i=e.parseCompoundList();e.expect(p.DONE);let l=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.forNode(n,a,i,l)}function Vr(e,t,r){e.expect(p.DPAREN_START);let s=null,n=null,a=null,i=["","",""],l=0,o=0;for(;!e.check(p.DPAREN_END,p.EOF);){let f=e.advance();if(f.type===p.SEMICOLON&&o===0){if(l++,l>2)break}else f.value==="("&&o++,f.value===")"&&o--,i[l]+=f.value}e.expect(p.DPAREN_END),i[0].trim()&&(s=M(e,i[0].trim())),i[1].trim()&&(n=M(e,i[1].trim())),i[2].trim()&&(a=M(e,i[2].trim())),e.skipNewlines(),e.check(p.SEMICOLON)&&e.advance(),e.skipNewlines();let c;e.check(p.LBRACE)?(e.advance(),c=e.parseCompoundList(),e.expect(p.RBRACE)):(e.expect(p.DO),c=e.parseCompoundList(),e.expect(p.DONE));let u=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:s,condition:n,update:a,body:c,redirections:u,line:r}}function et(e,t){e.expect(p.WHILE);let r=e.parseCompoundList();e.expect(p.DO);let s=e.parseCompoundList();s.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(p.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.whileNode(r,s,n)}function tt(e,t){e.expect(p.UNTIL);let r=e.parseCompoundList();e.expect(p.DO);let s=e.parseCompoundList();s.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(p.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.untilNode(r,s,n)}function nt(e,t){e.expect(p.CASE),e.isWord()||e.error("Expected word after 'case'");let r=e.parseWord();e.skipNewlines(),e.expect(p.IN),e.skipNewlines();let s=[];for(;!e.check(p.ESAC,p.EOF);){e.checkIterationLimit();let a=e.getPos(),i=qr(e);if(i&&s.push(i),e.skipNewlines(),e.getPos()===a&&!i)break}e.expect(p.ESAC);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.caseNode(r,s,n)}function qr(e){e.check(p.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(p.PIPE));)e.advance();if(t.length===0)return null;e.expect(p.RPAREN),e.skipNewlines();let r=[];for(;!e.check(p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND,p.ESAC,p.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===p.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(p.LPAREN)&&e.peek(1).type===p.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let n=e.getPos(),a=e.parseStatement();if(a&&r.push(a),e.skipSeparators(!1),e.getPos()===n&&!a)break}let s=";;";return e.check(p.DSEMI)?(e.advance(),s=";;"):e.check(p.SEMI_AND)?(e.advance(),s=";&"):e.check(p.SEMI_SEMI_AND)&&(e.advance(),s=";;&"),w.caseItem(t,r,s)}function rt(e,t){e.expect(p.LPAREN);let r=e.parseCompoundList();e.expect(p.RPAREN);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.subshell(r,s)}function st(e,t){e.expect(p.LBRACE);let r=e.parseCompoundList();e.expect(p.RBRACE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.group(r,s)}var Fr=["-a","-b","-c","-d","-e","-f","-g","-h","-k","-p","-r","-s","-t","-u","-w","-x","-G","-L","-N","-O","-S","-z","-n","-o","-v","-R"],zr=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function sn(e){return e.isWord()||e.check(p.LBRACE)||e.check(p.RBRACE)||e.check(p.ASSIGNMENT_WORD)}function an(e){if(e.check(p.BANG)&&e.peek(1).type===p.LPAREN){e.advance(),e.advance();let t=1,r="!(";for(;t>0&&!e.check(p.EOF);)if(e.check(p.LPAREN))t++,r+="(",e.advance();else if(e.check(p.RPAREN))t--,t>0&&(r+=")"),e.advance();else if(e.isWord())r+=e.advance().value;else if(e.check(p.PIPE))r+="|",e.advance();else break;return r+=")",e.parseWordFromString(r,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function at(e){return e.skipNewlines(),Gr(e)}function Gr(e){let t=on(e);for(e.skipNewlines();e.check(p.OR_OR);){e.advance(),e.skipNewlines();let r=on(e);t={type:"CondOr",left:t,right:r},e.skipNewlines()}return t}function on(e){let t=it(e);for(e.skipNewlines();e.check(p.AND_AND);){e.advance(),e.skipNewlines();let r=it(e);t={type:"CondAnd",left:t,right:r},e.skipNewlines()}return t}function it(e){return e.skipNewlines(),e.check(p.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:it(e)}):Qr(e)}function Qr(e){if(e.check(p.LPAREN)){e.advance();let t=at(e);return e.expect(p.RPAREN),{type:"CondGroup",expression:t}}if(sn(e)){let t=e.current(),r=t.value;if(Fr.includes(r)&&!t.quoted){if(e.advance(),e.check(p.DBRACK_END)&&e.error(`Expected operand after ${r}`),sn(e)){let a=e.parseWordNoBraceExpansion();return{type:"CondUnary",operator:r,operand:a}}let n=e.current();e.error(`unexpected argument \`${n.value}' to conditional unary operator`)}let s=e.parseWordNoBraceExpansion();if(e.isWord()&&zr.includes(e.current().value)){let n=e.advance().value,a;return n==="=~"?a=Zr(e):n==="=="||n==="!="?a=an(e):a=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:n,left:s,right:a}}if(e.check(p.LESS)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:s,right:n}}if(e.check(p.GREAT)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:">",left:s,right:n}}if(e.isWord()&&e.current().value==="="){e.advance();let n=an(e);return{type:"CondBinary",operator:"==",left:s,right:n}}return{type:"CondWord",word:s}}e.error("Expected conditional expression")}function Zr(e){let t=[],r=0,s=-1,n=e.getInput(),a=()=>e.check(p.DBRACK_END)||e.check(p.AND_AND)||e.check(p.OR_OR)||e.check(p.NEWLINE)||e.check(p.EOF);for(;!a();){let i=e.current(),l=s>=0&&i.start>s;if(r===0&&l)break;if(r>0&&l){let o=n.slice(s,i.start);t.push({type:"Literal",value:o})}if(e.isWord()||e.check(p.ASSIGNMENT_WORD)){let o=e.parseWordForRegex();t.push(...o.parts),s=e.peek(-1).end}else if(e.check(p.LPAREN)){let o=e.advance();t.push({type:"Literal",value:"("}),r++,s=o.end}else if(e.check(p.DPAREN_START)){let o=e.advance();t.push({type:"Literal",value:"(("}),r+=2,s=o.end}else if(e.check(p.DPAREN_END))if(r>=2){let o=e.advance();t.push({type:"Literal",value:"))"}),r-=2,s=o.end}else{if(r===1)break;break}else if(e.check(p.RPAREN))if(r>0){let o=e.advance();t.push({type:"Literal",value:")"}),r--,s=o.end}else break;else if(e.check(p.PIPE)){let o=e.advance();t.push({type:"Literal",value:"|"}),s=o.end}else if(e.check(p.SEMICOLON))if(r>0){let o=e.advance();t.push({type:"Literal",value:";"}),s=o.end}else break;else if(r>0&&e.check(p.LESS)){let o=e.advance();t.push({type:"Literal",value:"<"}),s=o.end}else if(r>0&&e.check(p.GREAT)){let o=e.advance();t.push({type:"Literal",value:">"}),s=o.end}else if(r>0&&e.check(p.DGREAT)){let o=e.advance();t.push({type:"Literal",value:">>"}),s=o.end}else if(r>0&&e.check(p.DLESS)){let o=e.advance();t.push({type:"Literal",value:"<<"}),s=o.end}else if(r>0&&e.check(p.LESSAND)){let o=e.advance();t.push({type:"Literal",value:"<&"}),s=o.end}else if(r>0&&e.check(p.GREATAND)){let o=e.advance();t.push({type:"Literal",value:">&"}),s=o.end}else if(r>0&&e.check(p.LESSGREAT)){let o=e.advance();t.push({type:"Literal",value:"<>"}),s=o.end}else if(r>0&&e.check(p.CLOBBER)){let o=e.advance();t.push({type:"Literal",value:">|"}),s=o.end}else if(r>0&&e.check(p.TLESS)){let o=e.advance();t.push({type:"Literal",value:"<<<"}),s=o.end}else if(r>0&&e.check(p.AMP)){let o=e.advance();t.push({type:"Literal",value:"&"}),s=o.end}else if(r>0&&e.check(p.LBRACE)){let o=e.advance();t.push({type:"Literal",value:"{"}),s=o.end}else if(r>0&&e.check(p.RBRACE)){let o=e.advance();t.push({type:"Literal",value:"}"}),s=o.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function Ee(e){return e.length>0?e:[w.literal("")]}function Hr(e,t){let r=1,s=t+1;for(;s<e.length&&r>0;){let n=e[s];if(n==="\\"){s+=2;continue}if("@*+?!".includes(n)&&s+1<e.length&&e[s+1]==="("){s++,r++,s++;continue}if(n==="(")r++;else if(n===")"&&(r--,r===0))return s;s++}return-1}function jr(e,t,r){let s=r+1,n=t[s];if("@*#?$!-0123456789".includes(n))return{part:w.parameterExpansion(n),endIndex:s+1};let a="";for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)a+=t[s],s++;return{part:w.parameterExpansion(a),endIndex:s}}function Kr(e,t,r,s=!1){let n=r+2,a=!1;t[n]==="!"&&(a=!0,n++);let i=!1;t[n]==="#"&&!/[}:#%/^,]/.test(t[n+1]||"}")&&(i=!0,n++);let l="",o=t[n];if(/[@*#?$!-]/.test(o)&&!/[a-zA-Z0-9_]/.test(t[n+1]||""))l=o,n++;else for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)l+=t[n],n++;if(t[n]==="["){let u=He(e,t,n,"[","]");if(l+=t.slice(n,u+1),n=u+1,t[n]==="["){let f=1,h=n;for(;h<t.length&&f>0;)t[h]==="{"?f++:t[h]==="}"&&f--,f>0&&h++;let d=t.slice(r+2,h);return{part:w.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:h+1}}}if(l===""&&!a&&!i&&t[n]!=="}"){let u=1,f=n;for(;f<t.length&&u>0;)t[f]==="{"?u++:t[f]==="}"&&u--,u>0&&f++;if(u>0)throw new G("unexpected EOF while looking for matching '}'",0,0);let h=t.slice(r+2,f);return{part:w.parameterExpansion("",{type:"BadSubstitution",text:h}),endIndex:f+1}}let c=null;if(a){let u=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(u)if(n<t.length&&t[n]!=="}"&&/[:=\-+?#%/^,@]/.test(t[n])){let f=ot(e,t,n,l,s);f.operation?(c={type:"Indirection",innerOp:f.operation},n=f.endIndex):(c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},l="")}else c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},l="";else if(t[n]==="*"||t[n]==="@"&&!/[QPaAEKkuUL]/.test(t[n+1]||"")){let f=t[n];n++,c={type:"VarNamePrefix",prefix:l,star:f==="*"},l=""}else if(n<t.length&&t[n]!=="}"&&/[:=\-+?#%/^,@]/.test(t[n])){let f=ot(e,t,n,l,s);f.operation?(c={type:"Indirection",innerOp:f.operation},n=f.endIndex):c={type:"Indirection"}}else c={type:"Indirection"}}else if(i)if(t[n]===":")for(c={type:"LengthSliceError"};n<t.length&&t[n]!=="}";)n++;else t[n]!=="}"&&/[-+=?]/.test(t[n])?e.error(`\${#${l}${t.slice(n,t.indexOf("}",n))}}: bad substitution`):t[n]==="/"?e.error(`\${#${l}${t.slice(n,t.indexOf("}",n))}}: bad substitution`):c={type:"Length"};if(!c&&n<t.length&&t[n]!=="}"){let u=ot(e,t,n,l,s);c=u.operation,n=u.endIndex}if(n<t.length&&t[n]!=="}"){let u=t[n];if(!/[:\-+=?#%/^,@[]/.test(u)){let f=n;for(;f<t.length&&t[f]!=="}";)f++;let h=t.slice(r,f+1);e.error(`\${${h.slice(2,-1)}}: bad substitution`)}}for(;n<t.length&&t[n]!=="}";)n++;if(n>=t.length)throw new G("unexpected EOF while looking for matching '}'",0,0);return{part:w.parameterExpansion(l,c),endIndex:n+1}}function ot(e,t,r,s,n=!1){let a=r,i=t[a],l=t[a+1]||"";if(i===":"){let o=l;if("-=?+".includes(o)){a+=2;let A=fe(e,t,a),S=t.slice(a,A),y=ae(e,S,!1,!1,!0,!1,n,!1,!1,!0),b=w.word(Ee(y));if(o==="-")return{operation:{type:"DefaultValue",word:b,checkEmpty:!0},endIndex:A};if(o==="=")return{operation:{type:"AssignDefault",word:b,checkEmpty:!0},endIndex:A};if(o==="?")return{operation:{type:"ErrorIfUnset",word:b,checkEmpty:!0},endIndex:A};if(o==="+")return{operation:{type:"UseAlternative",word:b,checkEmpty:!0},endIndex:A}}a++;let c=fe(e,t,a),u=t.slice(a,c),f=-1,h=0,d=0;for(let E=0;E<u.length;E++){let A=u[E];if(A==="("||A==="[")h++;else if(A===")"||A==="]")h--;else if(A==="?"&&h===0)d++;else if(A===":"&&h===0)if(d>0)d--;else{f=E;break}}let m=f>=0?u.slice(0,f):u,g=f>=0?u.slice(f+1):null;return{operation:{type:"Substring",offset:je(e,m),length:g!==null?je(e,g):null},endIndex:c}}if("-=?+".includes(i)){a++;let o=fe(e,t,a),c=t.slice(a,o),u=ae(e,c,!1,!1,!0,!1,n,!1,!1,!0),f=w.word(Ee(u));if(i==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:o};if(i==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:o};if(i==="?")return{operation:{type:"ErrorIfUnset",word:c?f:null,checkEmpty:!1},endIndex:o};if(i==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:o}}if(i==="#"||i==="%"){let o=l===i,c=i==="#"?"prefix":"suffix";a+=o?2:1;let u=fe(e,t,a),f=t.slice(a,u),h=ae(e,f,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:w.word(Ee(h)),side:c,greedy:o},endIndex:u}}if(i==="/"){let o=l==="/";a+=o?2:1;let c=null;t[a]==="#"?(c="start",a++):t[a]==="%"&&(c="end",a++);let u;c!==null&&(t[a]==="/"||t[a]==="}")?u=a:u=Xt(e,t,a);let f=t.slice(a,u),h=ae(e,f,!1,!1,!1),d=w.word(Ee(h)),m=null,g=u;if(t[u]==="/"){let E=u+1,A=fe(e,t,E),S=t.slice(E,A),y=ae(e,S,!1,!1,!1);m=w.word(Ee(y)),g=A}return{operation:{type:"PatternReplacement",pattern:d,replacement:m,all:o,anchor:c},endIndex:g}}if(i==="^"||i===","){let o=l===i,c=i==="^"?"upper":"lower";a+=o?2:1;let u=fe(e,t,a),f=t.slice(a,u),h=f?w.word([w.literal(f)]):null;return{operation:{type:"CaseModification",direction:c,all:o,pattern:h},endIndex:u}}return i==="@"&&/[QPaAEKkuUL]/.test(l)?{operation:{type:"Transform",operator:l},endIndex:a+2}:{operation:null,endIndex:a}}function lt(e,t,r,s=!1){let n=r+1;if(n>=t.length)return{part:w.literal("$"),endIndex:n};let a=t[n];if(a==="("&&t[n+1]==="(")return e.isDollarDparenSubshell(t,r)?e.parseCommandSubstitution(t,r):e.parseArithmeticExpansion(t,r);if(a==="["){let i=1,l=n+1;for(;l<t.length&&i>0;)t[l]==="["?i++:t[l]==="]"&&i--,i>0&&l++;if(i===0){let o=t.slice(n+1,l),c=M(e,o);return{part:w.arithmeticExpansion(c),endIndex:l+1}}}return a==="("?e.parseCommandSubstitution(t,r):a==="{"?Kr(e,t,r,s):/[a-zA-Z_0-9@*#?$!-]/.test(a)?jr(e,t,r):{part:w.literal("$"),endIndex:n}}function ln(e,t){let r=[],s=0,n="",a=()=>{n&&(r.push(w.literal(n)),n="")};for(;s<t.length;){let i=t[s];if(i==="\\"&&s+1<t.length){let l=t[s+1];if(l==="$"||l==="`"||l==='"'||l==="\\"){n+=l,s+=2;continue}n+=i,s++;continue}if(i==="$"){a();let{part:l,endIndex:o}=lt(e,t,s,!0);l&&r.push(l),s=o;continue}if(i==="`"){a();let{part:l,endIndex:o}=e.parseBacktickSubstitution(t,s,!0);r.push(l),s=o;continue}n+=i,s++}return a(),r}function Xr(e,t,r){let s=[],n=r,a="",i=()=>{a&&(s.push(w.literal(a)),a="")};for(;n<t.length&&t[n]!=='"';){let l=t[n];if(l==="\\"&&n+1<t.length){let o=t[n+1];if('"\\$`\n'.includes(o)){a+=o,n+=2;continue}a+=l,n++;continue}if(l==="$"){i();let{part:o,endIndex:c}=lt(e,t,n,!0);o&&s.push(o),n=c;continue}if(l==="`"){i();let{part:o,endIndex:c}=e.parseBacktickSubstitution(t,n,!0);s.push(o),n=c;continue}a+=l,n++}return i(),{part:w.doubleQuoted(s),endIndex:n}}function ae(e,t,r=!1,s=!1,n=!1,a=!1,i=!1,l=!1,o=!1,c=!1){if(s)return[w.singleQuoted(t)];if(r){let m=ln(e,t);return[w.doubleQuoted(m)]}if(t.length>=2&&t[0]==='"'&&t[t.length-1]==='"'){let m=t.slice(1,-1),g=!1;for(let E=0;E<m.length;E++){if(m[E]==='"'){g=!0;break}m[E]==="\\"&&E+1<m.length&&E++}if(!g){let E=ln(e,m);return[w.doubleQuoted(E)]}}let u=[],f=0,h="",d=()=>{h&&(u.push(w.literal(h)),h="")};for(;f<t.length;){let m=t[f];if(m==="\\"&&f+1<t.length){let g=t[f+1];if(o){d(),u.push(w.escaped(g)),f+=2;continue}let E=a?g==="$"||g==="`"||g===`
|
|
45
45
|
`:g==="$"||g==="`"||g==='"'||g==="'"||g===`
|
|
46
|
-
`||c&&g==="}",A=i?"*?[]\\".includes(g):"*?[]\\(){}.^+".includes(g);E?h+=g:A?(d(),u.push(w.escaped(g))):h+=`\\${g}`,f+=2;continue}if(m==="'"&&!i&&!a){d();let g=t.indexOf("'",f+1);if(g===-1){h+=t.slice(f);break}u.push(w.singleQuoted(t.slice(f+1,g))),f=g+1;continue}if(m==='"'&&!a){d();let{part:g,endIndex:E}=Xr(e,t,f+1);u.push(g),f=E+1;continue}if(m==="$"&&t[f+1]==="'"){d();let{part:g,endIndex:E}=Yt(e,t,f+2);u.push(g),f=E;continue}if(m==="$"){d();let{part:g,endIndex:E}=lt(e,t,f);g&&u.push(g),f=E;continue}if(m==="`"){d();let{part:g,endIndex:E}=e.parseBacktickSubstitution(t,f);u.push(g),f=E;continue}if(m==="~"){let g=f>0?t[f-1]:"";if(f===0||g==="="||n&&g===":"){let A=Kt(e,t,f),S=t[A];if(S===void 0||S==="/"||S===":"){d();let y=t.slice(f+1,A)||null;u.push({type:"TildeExpansion",user:y}),f=A;continue}}}if("@*+?!".includes(m)&&f+1<t.length&&t[f+1]==="("){let g=Hr(t,f+1);if(g!==-1){d();let E=t.slice(f,g+1);u.push({type:"Glob",pattern:E}),f=g+1;continue}}if(m==="*"||m==="?"||m==="["){d();let{pattern:g,endIndex:E}=Jt(e,t,f);u.push({type:"Glob",pattern:g}),f=E;continue}if(m==="{"&&!n&&!l){let g=en(e,t,f,ae);if(g){d(),u.push(g.part),f=g.endIndex;continue}}h+=m,f++}return d(),u}function un(e,t){let r=e.length,s=t+3,n=2,a=!1,i=!1;for(;s<r&&n>0;){let l=e[s];if(a){l==="'"&&(a=!1),s++;continue}if(i){if(l==="\\"){s+=2;continue}l==='"'&&(i=!1),s++;continue}if(l==="'"){a=!0,s++;continue}if(l==='"'){i=!0,s++;continue}if(l==="\\"){s+=2;continue}if(l==="("){n++,s++;continue}if(l===")"){if(n--,n===1){let o=s+1;return!(o<r&&e[o]===")")}if(n===0)return!1;s++;continue}if(n===1&&(l==="|"&&s+1<r&&e[s+1]==="|"||l==="&"&&s+1<r&&e[s+1]==="&"||l==="|"&&s+1<r&&e[s+1]!=="|"))return!0;s++}return!1}function cn(e,t,r,s){let n=t+2,a=1,i=n,l=!1,o=!1,c=0,u=!1,f="";for(;i<e.length&&a>0;){let g=e[i];l?g==="'"&&(l=!1):o?g==="\\"&&i+1<e.length?i++:g==='"'&&(o=!1):g==="'"?(l=!0,f=""):g==='"'?(o=!0,f=""):g==="\\"&&i+1<e.length?(i++,f=""):/[a-zA-Z_]/.test(g)?f+=g:(f==="case"?(c++,u=!1):f==="in"&&c>0?u=!0:f==="esac"&&c>0&&(c--,u=!1),f="",g==="("?i>0&&e[i-1]==="$"?a++:u||a++:g===")"?u?u=!1:a--:g===";"&&c>0&&i+1<e.length&&e[i+1]===";"&&(u=!0)),a>0&&i++}a>0&&s("unexpected EOF while looking for matching `)'");let h=e.slice(n,i),m=r().parse(h);return{part:w.commandSubstitution(m,!1),endIndex:i+1}}function fn(e,t,r,s,n){let i=t+1,l="";for(;i<e.length&&e[i]!=="`";)if(e[i]==="\\"){let u=e[i+1];u==="$"||u==="`"||u==="\\"||u===`
|
|
46
|
+
`||c&&g==="}",A=i?"*?[]\\".includes(g):"*?[]\\(){}.^+".includes(g);E?h+=g:A?(d(),u.push(w.escaped(g))):h+=`\\${g}`,f+=2;continue}if(m==="'"&&!i&&!a){d();let g=t.indexOf("'",f+1);if(g===-1){h+=t.slice(f);break}u.push(w.singleQuoted(t.slice(f+1,g))),f=g+1;continue}if(m==='"'&&!a){d();let{part:g,endIndex:E}=Xr(e,t,f+1);u.push(g),f=E+1;continue}if(m==="$"&&t[f+1]==="'"){d();let{part:g,endIndex:E}=Yt(e,t,f+2);u.push(g),f=E;continue}if(m==="$"){d();let{part:g,endIndex:E}=lt(e,t,f);g&&u.push(g),f=E;continue}if(m==="`"){d();let{part:g,endIndex:E}=e.parseBacktickSubstitution(t,f);u.push(g),f=E;continue}if(m==="~"){let g=f>0?t[f-1]:"";if(f===0||g==="="||n&&g===":"){let A=Kt(e,t,f),S=t[A];if(S===void 0||S==="/"||S===":"){d();let y=t.slice(f+1,A)||null;u.push({type:"TildeExpansion",user:y}),f=A;continue}}}if("@*+?!".includes(m)&&f+1<t.length&&t[f+1]==="("){let g=Hr(t,f+1);if(g!==-1){d();let E=t.slice(f,g+1);u.push({type:"Glob",pattern:E}),f=g+1;continue}}if(m==="*"||m==="?"||m==="["){d();let{pattern:g,endIndex:E}=Jt(e,t,f);u.push({type:"Glob",pattern:g}),f=E;continue}if(m==="{"&&!n&&!l&&!a){let g=en(e,t,f,ae);if(g){d(),u.push(g.part),f=g.endIndex;continue}}h+=m,f++}return d(),u}function un(e,t){let r=e.length,s=t+3,n=2,a=!1,i=!1;for(;s<r&&n>0;){let l=e[s];if(a){l==="'"&&(a=!1),s++;continue}if(i){if(l==="\\"){s+=2;continue}l==='"'&&(i=!1),s++;continue}if(l==="'"){a=!0,s++;continue}if(l==='"'){i=!0,s++;continue}if(l==="\\"){s+=2;continue}if(l==="("){n++,s++;continue}if(l===")"){if(n--,n===1){let o=s+1;return!(o<r&&e[o]===")")}if(n===0)return!1;s++;continue}if(n===1&&(l==="|"&&s+1<r&&e[s+1]==="|"||l==="&"&&s+1<r&&e[s+1]==="&"||l==="|"&&s+1<r&&e[s+1]!=="|"))return!0;s++}return!1}function cn(e,t,r,s){let n=t+2,a=1,i=n,l=!1,o=!1,c=0,u=!1,f="";for(;i<e.length&&a>0;){let g=e[i];l?g==="'"&&(l=!1):o?g==="\\"&&i+1<e.length?i++:g==='"'&&(o=!1):g==="'"?(l=!0,f=""):g==='"'?(o=!0,f=""):g==="\\"&&i+1<e.length?(i++,f=""):/[a-zA-Z_]/.test(g)?f+=g:(f==="case"?(c++,u=!1):f==="in"&&c>0?u=!0:f==="esac"&&c>0&&(c--,u=!1),f="",g==="("?i>0&&e[i-1]==="$"?a++:u||a++:g===")"?u?u=!1:a--:g===";"&&c>0&&i+1<e.length&&e[i+1]===";"&&(u=!0)),a>0&&i++}a>0&&s("unexpected EOF while looking for matching `)'");let h=e.slice(n,i),m=r().parse(h);return{part:w.commandSubstitution(m,!1),endIndex:i+1}}function fn(e,t,r,s,n){let i=t+1,l="";for(;i<e.length&&e[i]!=="`";)if(e[i]==="\\"){let u=e[i+1];u==="$"||u==="`"||u==="\\"||u===`
|
|
47
47
|
`||r&&u==='"'?(u!==`
|
|
48
48
|
`&&(l+=u),i+=2):(l+=e[i],i++)}else l+=e[i],i++;i>=e.length&&n("unexpected EOF while looking for matching ``'");let c=s().parse(l);return{part:w.commandSubstitution(c,!0),endIndex:i+1}}var V=class e{tokens=[];pos=0;pendingHeredocs=[];parseIterations=0;parseDepth=0;_input="";getInput(){return this._input}checkIterationLimit(){if(this.parseIterations++,this.parseIterations>Qt)throw new G("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}enterDepth(){if(this.parseDepth++,this.parseDepth>Ue)throw new G(`Maximum parser nesting depth exceeded (${Ue})`,this.current().line,this.current().column);return()=>{this.parseDepth--}}parse(t,r){if(t.length>Qe)throw new G(`Input too large: ${t.length} bytes exceeds limit of ${Qe}`,1,1);this._input=t;let s=new ve(t,r);if(this.tokens=s.tokenize(),this.tokens.length>Ze)throw new G(`Too many tokens: ${this.tokens.length} exceeds limit of ${Ze}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}parseTokens(t){return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(t=0){return this.tokens[this.pos+t]||this.tokens[this.tokens.length-1]}advance(){let t=this.current();return this.pos<this.tokens.length-1&&this.pos++,t}getPos(){return this.pos}check(t,r,s,n,...a){let i=this.tokens[this.pos]?.type;return i===t||r!==void 0&&i===r||s!==void 0&&i===s||n!==void 0&&i===n?!0:a.length>0?a.includes(i):!1}expect(t,r){if(this.check(t))return this.advance();let s=this.current();throw new G(r||`Expected ${t}, got ${s.type}`,s.line,s.column,s)}error(t){let r=this.current();throw new G(t,r.line,r.column,r)}skipNewlines(){for(;this.check(p.NEWLINE,p.COMMENT);)this.check(p.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(p.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(p.SEMICOLON,p.COMMENT)){this.advance();continue}if(t&&this.check(p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,r,s,n){this.pendingHeredocs.push({redirect:t,delimiter:r,stripTabs:s,quoted:n})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(p.HEREDOC_CONTENT)){let r=this.advance(),s;t.quoted?s=w.word([w.literal(r.value)]):s=this.parseWordFromString(r.value,!1,!1,!1,!0),t.redirect.target=w.hereDoc(t.delimiter,s,t.stripTabs,t.quoted)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(p.EOF,p.NEWLINE,p.SEMICOLON,p.AMP,p.AND_AND,p.OR_OR,p.RPAREN,p.RBRACE,p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return t===p.WORD||t===p.NAME||t===p.NUMBER||t===p.ASSIGNMENT_WORD||t===p.IF||t===p.FOR||t===p.WHILE||t===p.UNTIL||t===p.CASE||t===p.LPAREN||t===p.LBRACE||t===p.DPAREN_START||t===p.DBRACK_START||t===p.FUNCTION||t===p.BANG||t===p.TIME||t===p.IN||t===p.LESS||t===p.GREAT||t===p.DLESS||t===p.DGREAT||t===p.LESSAND||t===p.GREATAND||t===p.LESSGREAT||t===p.DLESSDASH||t===p.CLOBBER||t===p.TLESS||t===p.AND_GREAT||t===p.AND_DGREAT}parseScript(){let t=[],s=0;for(this.skipNewlines();!this.check(p.EOF);){s++,s>1e4&&this.error("Parser stuck: too many iterations (>10000)");let n=this.checkUnexpectedToken();if(n){t.push(n),this.skipSeparators(!1);continue}let a=this.pos,i=this.parseStatement();i&&t.push(i),this.skipSeparators(!1),this.check(p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===a&&!this.check(p.EOF)&&this.advance()}return w.script(t)}checkUnexpectedToken(){let t=this.current().type,r=this.current().value;if((t===p.DO||t===p.DONE||t===p.THEN||t===p.ELSE||t===p.ELIF||t===p.FI||t===p.ESAC)&&this.error(`syntax error near unexpected token \`${r}'`),t===p.RBRACE||t===p.RPAREN){let s=`syntax error near unexpected token \`${r}'`;return this.advance(),w.statement([w.pipeline([w.simpleCommand(null,[],[],[])])],[],!1,{message:s,token:r})}return(t===p.DSEMI||t===p.SEMI_AND||t===p.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${r}'`),t===p.SEMICOLON&&this.error(`syntax error near unexpected token \`${r}'`),(t===p.PIPE||t===p.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${r}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,r=[],s=[],n=!1,a=this.parsePipeline();for(r.push(a);this.check(p.AND_AND,p.OR_OR);){let o=this.advance();s.push(o.type===p.AND_AND?"&&":"||"),this.skipNewlines();let c=this.parsePipeline();r.push(c)}this.check(p.AMP)&&(this.advance(),n=!0);let i=this.pos>0?this.tokens[this.pos-1].end:t,l=this._input.slice(t,i);return w.statement(r,s,n,void 0,l)}parsePipeline(){let t=!1,r=!1;this.check(p.TIME)&&(this.advance(),t=!0,this.check(p.WORD,p.NAME)&&this.current().value==="-p"&&(this.advance(),r=!0));let s=0;for(;this.check(p.BANG);)this.advance(),s++;let n=s%2===1,a=[],i=[],l=this.parseCommand();for(a.push(l);this.check(p.PIPE,p.PIPE_AMP);){let o=this.advance();this.skipNewlines(),i.push(o.type===p.PIPE_AMP);let c=this.parseCommand();a.push(c)}return w.pipeline(a,n,t,r,i.length>0?i:void 0)}parseCommand(){return this.check(p.IF)?Je(this):this.check(p.FOR)?Ye(this):this.check(p.WHILE)?et(this):this.check(p.UNTIL)?tt(this):this.check(p.CASE)?nt(this):this.check(p.LPAREN)?rt(this):this.check(p.LBRACE)?st(this):this.check(p.DPAREN_START)?this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand():this.check(p.DBRACK_START)?this.parseConditionalCommand():this.check(p.FUNCTION)?this.parseFunctionDef():this.check(p.NAME,p.WORD)&&this.peek(1).type===p.LPAREN&&this.peek(2).type===p.RPAREN?this.parseFunctionDef():rn(this)}dparenClosesWithSpacedParens(){let t=1,r=1;for(;r<this.tokens.length-this.pos;){let s=this.peek(r);if(s.type===p.EOF)return!1;if(s.type===p.DPAREN_START||s.type===p.LPAREN)t++;else if(s.type===p.DPAREN_END){if(t-=2,t<=0)return!1}else if(s.type===p.RPAREN&&(t--,t===0&&this.peek(r+1).type===p.RPAREN))return!0;r++}return!1}parseNestedSubshellsFromDparen(){this.advance();let t=this.parseCompoundList();this.expect(p.RPAREN),this.expect(p.RPAREN);let r=this.parseOptionalRedirections(),s=w.subshell(t,[]);return w.subshell([w.statement([w.pipeline([s],!1,!1,!1)])],r)}isWord(){let t=this.current().type;return t===p.WORD||t===p.NAME||t===p.NUMBER||t===p.IF||t===p.FOR||t===p.WHILE||t===p.UNTIL||t===p.CASE||t===p.FUNCTION||t===p.ELSE||t===p.ELIF||t===p.FI||t===p.THEN||t===p.DO||t===p.DONE||t===p.ESAC||t===p.IN||t===p.SELECT||t===p.TIME||t===p.COPROC||t===p.BANG}parseWord(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted)}parseWordNoBraceExpansion(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted,!1,!1,!0)}parseWordForRegex(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted,!1,!1,!0,!0)}parseWordFromString(t,r=!1,s=!1,n=!1,a=!1,i=!1,l=!1){let o=ae(this,t,r,s,n,a,!1,i,l);return w.word(o)}parseCommandSubstitution(t,r){return cn(t,r,()=>new e,s=>this.error(s))}parseBacktickSubstitution(t,r,s=!1){return fn(t,r,s,()=>new e,n=>this.error(n))}isDollarDparenSubshell(t,r){return un(t,r)}parseArithmeticExpansion(t,r){let s=r+3,n=1,a=0,i=s;for(;i<t.length-1&&n>0;)t[i]==="$"&&t[i+1]==="("?t[i+2]==="("?(n++,i+=3):(a++,i+=2):t[i]==="("&&t[i+1]==="("?(n++,i+=2):t[i]===")"&&t[i+1]===")"?a>0?(a--,i++):(n--,n>0&&(i+=2)):t[i]==="("?(a++,i++):(t[i]===")"&&a>0&&a--,i++);let l=t.slice(s,i),o=this.parseArithmeticExpression(l);return{part:w.arithmeticExpansion(o),endIndex:i+2}}parseArithmeticCommand(){let t=this.expect(p.DPAREN_START),r="",s=1,n=0,a=!1,i=!1;for(;s>0&&!this.check(p.EOF);){if(a){if(a=!1,n>0){n--,r+=")";continue}if(this.check(p.RPAREN)){s--,i=!0,this.advance();continue}if(this.check(p.DPAREN_END)){s--,i=!0;continue}r+=")";continue}if(this.check(p.DPAREN_START))s++,r+="((",this.advance();else if(this.check(p.DPAREN_END))n>=2?(n-=2,r+="))",this.advance()):n===1?(n--,r+=")",a=!0,this.advance()):(s--,i=!0,s>0&&(r+="))"),this.advance());else if(this.check(p.LPAREN))n++,r+="(",this.advance();else if(this.check(p.RPAREN))n>0&&n--,r+=")",this.advance();else{let c=this.current().value,u=r.length>0?r[r.length-1]:"";r.length>0&&!r.endsWith(" ")&&!(c==="="&&/[|&^+\-*/%<>]$/.test(r))&&!(c==="<"&&u==="<")&&!(c===">"&&u===">")&&(r+=" "),r+=c,this.advance()}}i||this.expect(p.DPAREN_END);let l=this.parseArithmeticExpression(r.trim()),o=this.parseOptionalRedirections();return w.arithmeticCommand(l,o,t.line)}parseConditionalCommand(){let t=this.expect(p.DBRACK_START),r=at(this);this.expect(p.DBRACK_END);let s=this.parseOptionalRedirections();return w.conditionalCommand(r,s,t.line)}parseFunctionDef(){let t;if(this.check(p.FUNCTION)){if(this.advance(),this.check(p.NAME)||this.check(p.WORD))t=this.advance().value;else{let n=this.current();throw new G("Expected function name",n.line,n.column,n)}this.check(p.LPAREN)&&(this.advance(),this.expect(p.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(p.LPAREN),this.expect(p.RPAREN);this.skipNewlines();let r=this.parseCompoundCommandBody({forFunctionBody:!0}),s=this.parseOptionalRedirections();return w.functionDef(t,r,s)}parseCompoundCommandBody(t){let r=t?.forFunctionBody;if(this.check(p.LBRACE))return st(this,{skipRedirections:r});if(this.check(p.LPAREN))return rt(this,{skipRedirections:r});if(this.check(p.IF))return Je(this,{skipRedirections:r});if(this.check(p.FOR))return Ye(this,{skipRedirections:r});if(this.check(p.WHILE))return et(this,{skipRedirections:r});if(this.check(p.UNTIL))return tt(this,{skipRedirections:r});if(this.check(p.CASE))return nt(this,{skipRedirections:r});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth(),r=[];for(this.skipNewlines();!this.check(p.EOF,p.FI,p.ELSE,p.ELIF,p.THEN,p.DO,p.DONE,p.ESAC,p.RPAREN,p.RBRACE,p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)&&this.isCommandStart();){this.checkIterationLimit();let s=this.pos,n=this.parseStatement();if(n&&r.push(n),this.skipSeparators(),this.pos===s&&!n)break}return t(),r}parseOptionalRedirections(){let t=[];for(;De(this);){this.checkIterationLimit();let r=this.pos;if(t.push(xe(this)),this.pos===r)break}return t}parseArithmeticExpression(t){return M(this,t)}};function di(e,t){return new V().parse(e,t)}var Yr=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9a-fA-F"]]);function ut(e){return Yr.get(e)??""}function hn(e){let t=[],r="",s=0;for(;s<e.length;){let n=e[s];if(n==="["){for(r+=n,s++,s<e.length&&(e[s]==="!"||e[s]==="^")&&(r+=e[s],s++),s<e.length&&e[s]==="]"&&(r+=e[s],s++);s<e.length&&e[s]!=="]";){if(e[s]==="["&&s+1<e.length&&e[s+1]===":"){let a=e.indexOf(":]",s+2);if(a!==-1){r+=e.slice(s,a+2),s=a+2;continue}}if(e[s]==="\\"&&s+1<e.length){r+=e[s]+e[s+1],s+=2;continue}r+=e[s],s++}s<e.length&&e[s]==="]"&&(r+=e[s],s++)}else n===":"?(r!==""&&t.push(r),r="",s++):n==="\\"&&s+1<e.length?(r+=n+e[s+1],s+=2):(r+=n,s++)}return r!==""&&t.push(r),t}function pn(e){let t="^";for(let r=0;r<e.length;r++){let s=e[r];if(s==="*")t+="[^/]*";else if(s==="?")t+="[^/]";else if(s==="["){let n=r+1,a="[";n<e.length&&(e[n]==="^"||e[n]==="!")&&(a+="^",n++),n<e.length&&e[n]==="]"&&(a+="\\]",n++);let i=n;for(;i<e.length;){if(e[i]==="\\"&&i+1<e.length){i+=2;continue}if(e[i]==="["&&i+1<e.length&&e[i+1]===":"){let o=e.indexOf(":]",i+2);if(o!==-1){i=o+2;continue}}if(e[i]==="]")break;i++}let l=n;for(;n<e.length&&e[n]!=="]";){if(e[n]==="["&&n+1<e.length&&e[n+1]===":"){let o=e.indexOf(":]",n+2);if(o!==-1){let c=e.slice(n+2,o),u=ut(c);a+=u,n=o+2;continue}}if(e[n]==="\\"&&n+1<e.length){a+=`\\${e[n+1]}`,n+=2;continue}if(e[n]==="-"){let o=n===l,c=n+1===i;o||c?a+="\\-":a+="-"}else a+=e[n];n++}a+="]",t+=a,r=n}else if(s==="\\"&&r+1<e.length){let n=e[r+1];/[.+^${}()|\\*?[\]]/.test(n)?t+=`\\${n}`:t+=n,r++}else/[.+^${}()|]/.test(s)?t+=`\\${s}`:t+=s}return t+="$",O(t)}function ct(e,t){let r=1,s=t+1;for(;s<e.length&&r>0;){let n=e[s];if(n==="\\"){s+=2;continue}if(n==="(")r++;else if(n===")"&&(r--,r===0))return s;s++}return-1}function ft(e){let t=[],r="",s=0,n=!1,a=0;for(;a<e.length;){let i=e[a];if(i==="'"&&!n){n=!0,r+="\0QUOTE_START\0",a++;continue}if(i==="'"&&n){n=!1,r+="\0QUOTE_END\0",a++;continue}if(n){r+=i,a++;continue}if(i==="\\"){r+=i,a+1<e.length?(r+=e[a+1],a+=2):a++;continue}i==="("?(s++,r+=i):i===")"?(s--,r+=i):i==="|"&&s===0?(t.push(r),r=""):r+=i,a++}return t.push(r),t}var dn=5,oe=class{fs;cwd;globignorePatterns=[];hasGlobignore=!1;globstar=!1;nullglob=!1;failglob=!1;dotglob=!1;extglob=!1;globskipdots=!0;ops={count:0};maxOps;constructor(t,r,s,n){this.fs=t,this.cwd=r,typeof n=="boolean"?(this.globstar=n,this.maxOps=1e5):n?(this.globstar=n.globstar??!1,this.nullglob=n.nullglob??!1,this.failglob=n.failglob??!1,this.dotglob=n.dotglob??!1,this.extglob=n.extglob??!1,this.globskipdots=n.globskipdots??!0,this.maxOps=n.maxGlobOperations??1e5):this.maxOps=1e5;let a=s?.get("GLOBIGNORE");a!==void 0&&a!==""&&(this.hasGlobignore=!0,this.globignorePatterns=hn(a))}checkOpsLimit(){if(++this.ops.count>this.maxOps)throw new L(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations")}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(r=>{let s=r.split("/").pop()||r;if((this.hasGlobignore||this.globskipdots)&&(s==="."||s===".."))return!1;if(this.hasGlobignore){for(let n of this.globignorePatterns)if(this.matchGlobignorePattern(r,n))return!1}return!0})}matchGlobignorePattern(t,r){return pn(r).test(t)}isGlobPattern(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandArgs(t,r){let s=t.map((i,l)=>(r?.[l]??!1)||!this.isGlobPattern(i)?null:this.expand(i)),n=await Promise.all(s.map(i=>i||Promise.resolve(null))),a=[];for(let i=0;i<t.length;i++){let l=n[i];l===null?a.push(t[i]):l.length>0?a.push(...l):a.push(t[i])}return a}async expand(t){if(this.globstar){let s=t.split("/"),n=0;for(let a of s)if(a==="**"&&(n++,n>dn))throw new L(`Glob pattern has too many ** segments (max ${dn})`,"glob_operations")}let r;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))r=await this.expandRecursive(t);else{let s=t.replace(/\*\*+/g,"*");r=await this.expandSimple(s)}return this.filterGlobignore(r)}isGlobstarValid(t){let r=t.split("/");for(let s of r)if(s.includes("**")&&s!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let r=t.startsWith("/"),s=t.split("/").filter(c=>c!==""),n=-1;for(let c=0;c<s.length;c++)if(this.hasGlobChars(s[c])){n=c;break}if(n===-1)return[t];let a,i;if(n===0)r?(a="/",i="/"):(a=this.cwd,i="");else{let c=s.slice(0,n);r?(a=`/${c.join("/")}`,i=`/${c.join("/")}`):(a=this.fs.resolvePath(this.cwd,c.join("/")),i=c.join("/"))}let l=s.slice(n);return(await this.expandSegments(a,i,l)).sort()}async expandSegments(t,r,s){if(this.checkOpsLimit(),s.length===0)return[r];let[n,...a]=s,i=[];try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let l=await this.fs.readdirWithFileTypes(t),o=[],c=[...l],u=this.dotglob||this.hasGlobignore;if(n.startsWith(".")||this.dotglob){let h=l.some(m=>m.name==="."),d=l.some(m=>m.name==="..");h||c.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),d||c.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let h of c)if(!(h.name.startsWith(".")&&!n.startsWith(".")&&!u)&&this.matchPattern(h.name,n)){let d=t==="/"?`/${h.name}`:`${t}/${h.name}`,m;r===""?m=h.name:r==="/"?m=`/${h.name}`:m=`${r}/${h.name}`,a.length===0?o.push(Promise.resolve([m])):h.isDirectory&&o.push(this.expandSegments(d,m,a))}let f=await Promise.all(o);for(let h of f)i.push(...h)}else{this.checkOpsLimit();let l=await this.fs.readdir(t),o=[],c=[...l],u=this.dotglob||this.hasGlobignore;(n.startsWith(".")||this.dotglob)&&(l.includes(".")||c.push("."),l.includes("..")||c.push(".."));for(let h of c)if(!(h.startsWith(".")&&!n.startsWith(".")&&!u)&&this.matchPattern(h,n)){let d=t==="/"?`/${h}`:`${t}/${h}`,m;r===""?m=h:r==="/"?m=`/${h}`:m=`${r}/${h}`,a.length===0?o.push(Promise.resolve([m])):o.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory)return this.expandSegments(d,m,a)}catch(g){if(g instanceof L)throw g}return[]})())}let f=await Promise.all(o);for(let h of f)i.push(...h)}}catch(l){if(l instanceof L)throw l}return i}async expandRecursive(t){let r=[],s=t.indexOf("**"),n=t.slice(0,s).replace(/\/$/,"")||".",i=t.slice(s+2).replace(/^\//,"");return i.includes("**")&&this.isGlobstarValid(i)?(await this.walkDirectoryMultiGlobstar(n,i,r),[...new Set(r)].sort()):(await this.walkDirectory(n,i,r),r.sort())}async walkDirectoryMultiGlobstar(t,r,s){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let a=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(n):null;if(a){let i=[];for(let c of a){let u=t==="."?c.name:`${t}/${c.name}`;c.isDirectory&&i.push(u)}let l=t==="."?r:`${t}/${r}`,o=await this.expandRecursive(l);s.push(...o);for(let c=0;c<i.length;c+=100){let u=i.slice(c,c+100);await Promise.all(u.map(f=>this.walkDirectoryMultiGlobstar(f,r,s)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(n),l=[];for(let u of i){let f=t==="."?u:`${t}/${u}`,h=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(h)).isDirectory&&l.push(f)}catch(d){if(d instanceof L)throw d}}let o=t==="."?r:`${t}/${r}`,c=await this.expandRecursive(o);s.push(...c);for(let u=0;u<l.length;u+=100){let f=l.slice(u,u+100);await Promise.all(f.map(h=>this.walkDirectoryMultiGlobstar(h,r,s)))}}}catch(a){if(a instanceof L)throw a}}async walkDirectory(t,r,s){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let a=await this.fs.readdirWithFileTypes(n),i=[],l=[];for(let o of a){let c=t==="."?o.name:`${t}/${o.name}`;o.isDirectory?l.push(c):r&&this.matchPattern(o.name,r)&&i.push(c)}s.push(...i);for(let o=0;o<l.length;o+=100){let c=l.slice(o,o+100);await Promise.all(c.map(u=>this.walkDirectory(u,r,s)))}}else{this.checkOpsLimit();let a=await this.fs.readdir(n),i=[];for(let o=0;o<a.length;o+=100){let c=a.slice(o,o+100),u=await Promise.all(c.map(async f=>{let h=t==="."?f:`${t}/${f}`,d=this.fs.resolvePath(this.cwd,h);try{this.checkOpsLimit();let m=await this.fs.stat(d);return{name:f,path:h,isDirectory:m.isDirectory}}catch(m){if(m instanceof L)throw m;return null}}));i.push(...u.filter(f=>f!==null))}for(let o of i)!o.isDirectory&&r&&this.matchPattern(o.name,r)&&s.push(o.path);let l=i.filter(o=>o.isDirectory);for(let o=0;o<l.length;o+=100){let c=l.slice(o,o+100);await Promise.all(c.map(u=>this.walkDirectory(u.path,r,s)))}}}catch(a){if(a instanceof L)throw a}}matchPattern(t,r){return this.patternToRegex(r).test(t)}patternToRegex(t){let r=this.patternToRegexStr(t);return O(`^${r}$`)}patternToRegexStr(t){let r="",s=!1;for(let n=0;n<t.length;n++){if(t.slice(n,n+13)==="\0QUOTE_START\0"){s=!0,n+=12;continue}if(t.slice(n,n+11)==="\0QUOTE_END\0"){s=!1,n+=10;continue}let a=t[n];if(s){/[.+^${}()|\\*?[\]]/.test(a)?r+=`\\${a}`:r+=a;continue}if(this.extglob&&(a==="@"||a==="*"||a==="+"||a==="?"||a==="!")&&n+1<t.length&&t[n+1]==="("){let i=ct(t,n+1);if(i!==-1){let l=t.slice(n+2,i),o=ft(l),c=o.map(f=>this.patternToRegexStr(f)),u=c.length>0?c.join("|"):"(?:)";if(a==="@")r+=`(?:${u})`;else if(a==="*")r+=`(?:${u})*`;else if(a==="+")r+=`(?:${u})+`;else if(a==="?")r+=`(?:${u})?`;else if(a==="!")if(i<t.length-1){let h=o.map(m=>this.computePatternLength(m));if(h.every(m=>m!==null)&&h.every(m=>m===h[0])&&h[0]!==null){let m=h[0];if(m===0)r+="(?:.+)";else{let g=[];m>0&&g.push(`.{0,${m-1}}`),g.push(`.{${m+1},}`),g.push(`(?!(?:${u})).{${m}}`),r+=`(?:${g.join("|")})`}}else r+=`(?:(?!(?:${u})).)*?`}else r+=`(?!(?:${u})$).*`;n=i;continue}}if(a==="*")r+=".*";else if(a==="?")r+=".";else if(a==="["){let i=n+1,l="[";i<t.length&&(t[i]==="^"||t[i]==="!")&&(l+="^",i++),i<t.length&&t[i]==="]"&&(l+="\\]",i++);let o=i;for(;o<t.length;){if(t[o]==="\\"&&o+1<t.length){o+=2;continue}if(t[o]==="["&&o+1<t.length&&t[o+1]===":"){let u=t.indexOf(":]",o+2);if(u!==-1){o=u+2;continue}}if(t[o]==="]")break;o++}let c=i;for(;i<t.length&&t[i]!=="]";){if(t[i]==="["&&i+1<t.length&&t[i+1]===":"){let u=t.indexOf(":]",i+2);if(u!==-1){let f=t.slice(i+2,u),h=ut(f);l+=h,i=u+2;continue}}if(t[i]==="\\"&&i+1<t.length){l+=`\\${t[i+1]}`,i+=2;continue}if(t[i]==="-"){let u=i===c,f=i+1===o;u||f?l+="\\-":l+="-"}else l+=t[i];i++}l+="]",r+=l,n=i}else if(a==="\\"&&n+1<t.length){let i=t[n+1];/[.+^${}()|\\*?[\]]/.test(i)?r+=`\\${i}`:r+=i,n++}else/[.+^${}()|]/.test(a)?r+=`\\${a}`:r+=a}return r}computePatternLength(t){let r=0,s=0,n=!1;for(;s<t.length;){if(t.slice(s,s+13)==="\0QUOTE_START\0"){n=!0,s+=13;continue}if(t.slice(s,s+11)==="\0QUOTE_END\0"){n=!1,s+=11;continue}let a=t[s];if(n){r+=1,s++;continue}if((a==="@"||a==="*"||a==="+"||a==="?"||a==="!")&&s+1<t.length&&t[s+1]==="("){let i=ct(t,s+1);if(i!==-1){if(a==="@"){let l=t.slice(s+2,i),c=ft(l).map(u=>this.computePatternLength(u));if(c.every(u=>u!==null)&&c.every(u=>u===c[0])){r+=c[0],s=i+1;continue}return null}return null}}if(a==="*")return null;if(a==="?"){r+=1,s++;continue}if(a==="["){let i=t.indexOf("]",s+1);if(i!==-1){r+=1,s=i+1;continue}r+=1,s++;continue}if(a==="\\"){r+=1,s+=2;continue}r+=1,s++}return r}};function es(e,t,r){switch(r){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new C("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new C("division by 0");return e%t;case"**":if(t<0)throw new C("exponent less than 0");return e**t;case"<<":return e<<t;case">>":return e>>t;case"<":return e<t?1:0;case"<=":return e<=t?1:0;case">":return e>t?1:0;case">=":return e>=t?1:0;case"==":return e===t?1:0;case"!=":return e!==t?1:0;case"&":return e&t;case"|":return e|t;case"^":return e^t;case",":return t;default:return 0}}function mn(e,t,r){switch(r){case"=":return t;case"+=":return e+t;case"-=":return e-t;case"*=":return e*t;case"/=":return t!==0?Math.trunc(e/t):0;case"%=":return t!==0?e%t:0;case"<<=":return e<<t;case">>=":return e>>t;case"&=":return e&t;case"|=":return e|t;case"^=":return e^t;default:return t}}function ts(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function ns(e,t){let r=e.state.env.get(t);if(r!==void 0)return r;let s=e.state.env.get(`${t}_0`);return s!==void 0?s:await v(e,t)}function rs(e){if(!e)return 0;let t=Number.parseInt(e,10);if(!Number.isNaN(t)&&/^-?\d+$/.test(e.trim()))return t;let r=e.trim();if(!r)return 0;try{let s=new V,{expr:n,pos:a}=Z(s,r,0);if(a<r.length){let i=r.slice(a).trim().split(/\s+/)[0];throw new C(`${r}: syntax error in expression (error token is "${i}")`)}return n.type==="ArithNumber"?n.value:t||0}catch(s){if(s instanceof C)throw s;let n=r.split(/\s+/).slice(1)[0]||r;throw new C(`${r}: syntax error in expression (error token is "${n}")`)}}async function ht(e,t){if(!t)return 0;let r=Number.parseInt(t,10);if(!Number.isNaN(r)&&/^-?\d+$/.test(t.trim()))return r;let s=t.trim();if(!s)return 0;let n=new V,{expr:a,pos:i}=Z(n,s,0);if(i<s.length){let l=s.slice(i).trim(),o=l.split(/\s+/)[0]||l;throw new C(`syntax error in expression (error token is "${o}")`,"","")}return await R(e,a)}async function pt(e,t,r=new Set,s=0){if(s>100)throw new C("maximum variable indirection depth exceeded");if(r.has(t))return 0;r.add(t);let n=await ns(e,t);if(!n)return 0;let a=Number.parseInt(n,10);if(!Number.isNaN(a)&&/^-?\d+$/.test(n.trim()))return a;let i=n.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return await pt(e,i,r,s+1);let l=new V,{expr:o,pos:c}=Z(l,i,0);if(c<i.length){let u=i.slice(c).trim(),f=u.split(/\s+/)[0]||u;throw new C(`${i}: syntax error in expression (error token is "${f}")`)}return await R(e,o)}async function _e(e,t){if(t.startsWith("#")){let f=t.slice(1),h=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(h){let m=h[1],g=P(e,m);return String(g.length)}let d=e.state.env.get(f)||"";return String(d.length)}if(t.startsWith("!")){let f=t.slice(1),h=e.state.env.get(f)||"";return e.state.env.get(h)||""}let r=[":-",":=",":?",":+","-","=","?","+"],s=-1,n="";for(let f of r){let h=t.indexOf(f);h>0&&(s===-1||h<s)&&(s=h,n=f)}if(s===-1)return await v(e,t);let a=t.slice(0,s),i=t.slice(s+n.length),l=e.state.env.get(a),o=l===void 0,c=l==="",u=n.startsWith(":");switch(n){case":-":case"-":return o||u&&c?i:l||"";case":=":case"=":return o||u&&c?(e.state.env.set(a,i),i):l||"";case":+":case"+":return!(o||u&&c)?i:"";case":?":case"?":{if(o||u&&c)throw new Error(i||`${a}: parameter null or not set`);return l||""}default:return l||""}}async function R(e,t,r=!1){switch(t.type){case"ArithNumber":if(Number.isNaN(t.value))throw new C("value too great for base");return t.value;case"ArithVariable":return await pt(e,t.name);case"ArithSpecialVar":{let n=(await v(e,t.name)).trim();if(!n)return 0;let a=Number.parseInt(n,10);if(!Number.isNaN(a)&&/^-?\d+$/.test(n))return a;let i=new V,{expr:l}=Z(i,n,0);return await R(e,l)}case"ArithNested":return await R(e,t.expression);case"ArithCommandSubst":{if(e.execFn){let s=await e.execFn(t.command,{signal:e.state.signal});s.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+s.stderr);let n=s.stdout.trim();return Number.parseInt(n,10)||0}return 0}case"ArithBracedExpansion":{let s=await _e(e,t.content);return Number.parseInt(s,10)||0}case"ArithDynamicBase":{let s=await _e(e,t.baseExpr),n=Number.parseInt(s,10);if(n<2||n>64)return 0;let a=`${n}#${t.value}`;return ge(a)}case"ArithDynamicNumber":{let n=await _e(e,t.prefix)+t.suffix;return ge(n)}case"ArithArrayElement":{let s=e.state.associativeArrays?.has(t.array),n=async a=>{let i=e.state.env.get(a);return i!==void 0?await ht(e,i):0};if(t.stringKey!==void 0)return await n(`${t.array}_${t.stringKey}`);if(s&&t.index?.type==="ArithVariable"&&!t.index.hasDollarPrefix)return await n(`${t.array}_${t.index.name}`);if(s&&t.index?.type==="ArithVariable"&&t.index.hasDollarPrefix){let a=await v(e,t.index.name);return await n(`${t.array}_${a}`)}if(t.index){let a=await R(e,t.index,r);if(a<0){let o=P(e,t.array),c=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${c}: ${t.array}: bad array subscript
|
|
49
49
|
`,0;let f=Math.max(...o.map(([h])=>typeof h=="number"?h:0))+1+a;if(f<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${c}: ${t.array}: bad array subscript
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as v}from"./chunk-4PRVMER6.js";import{a as c,b as f,c as m}from"./chunk-GTNBSMZR.js";var g={name:"env",summary:"run a program in a modified environment",usage:"env [OPTION]... [NAME=VALUE]... [COMMAND [ARG]...]",options:["-i, --ignore-environment start with an empty environment","-u NAME, --unset=NAME remove NAME from the environment"," --help display this help and exit"]},w={name:"env",async execute(o,i){if(f(o))return c(g);let a=!1,r=[],u=new Map,t=-1;for(let n=0;n<o.length;n++){let e=o[n];if(e==="-i"||e==="--ignore-environment")a=!0;else if(e==="-u"&&n+1<o.length)r.push(o[++n]);else if(e.startsWith("-u"))r.push(e.slice(2));else if(e.startsWith("--unset="))r.push(e.slice(8));else{if(e.startsWith("--")&&e!=="--")return m("env",e);if(e.startsWith("-")&&e!=="-"){for(let l of e.slice(1))if(l!=="i"&&l!=="u")return m("env",`-${l}`);e.includes("i")&&(a=!0)}else if(e.includes("=")&&t===-1){let l=e.indexOf("="),d=e.slice(0,l),h=e.slice(l+1);u.set(d,h)}else{t=n;break}}}let s;if(a)s=new Map(u);else{s=new Map(i.env);for(let n of r)s.delete(n);for(let[n,e]of u)s.set(n,e)}if(t===-1){let n=[];for(let[e,l]of s)n.push(`${e}=${l}`);return{stdout:n.join(`
|
|
3
|
+
`)+(n.length>0?`
|
|
4
|
+
`:""),stderr:"",exitCode:0}}if(!i.exec)return{stdout:"",stderr:`env: command execution not supported in this context
|
|
5
|
+
`,exitCode:1};let p=o.slice(t);return i.exec("command",{cwd:i.cwd,env:v(s),replaceEnv:!0,stdin:i.stdin,signal:i.signal,args:p})}},x={name:"printenv",summary:"print all or part of environment",usage:"printenv [OPTION]... [VARIABLE]...",options:[" --help display this help and exit"]},E={name:"printenv",async execute(o,i){if(f(o))return c(x);let a=o.filter(t=>!t.startsWith("-"));if(a.length===0){let t=[];for(let[s,p]of i.env)t.push(`${s}=${p}`);return{stdout:t.join(`
|
|
6
|
+
`)+(t.length>0?`
|
|
7
|
+
`:""),stderr:"",exitCode:0}}let r=[],u=0;for(let t of a){let s=i.env.get(t);s!==void 0?r.push(s):u=1}return{stdout:r.join(`
|
|
8
|
+
`)+(r.length>0?`
|
|
9
|
+
`:""),stderr:"",exitCode:u}}},M={name:"env",flags:[{flag:"-i",type:"boolean"},{flag:"-u",type:"value",valueHint:"string"}]},N={name:"printenv",flags:[]};export{w as a,E as b,M as c,N as d};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as d}from"./chunk-YTIURC67.js";import{a as n,b as i}from"./chunk-
|
|
2
|
+
import{a as d}from"./chunk-YTIURC67.js";import{a as n,b as i}from"./chunk-OOJCYVYF.js";import{a,b as l}from"./chunk-GTNBSMZR.js";var u={name:"sleep",summary:"delay for a specified amount of time",usage:"sleep NUMBER[SUFFIX]",description:`Pause for NUMBER seconds. SUFFIX may be:
|
|
3
3
|
s - seconds (default)
|
|
4
4
|
m - minutes
|
|
5
5
|
h - hours
|