@willbooster/tree-sitter-bash 2.0.1 → 2.1.1
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 +43 -6
- package/package.json +13 -8
- package/tree-sitter-bash.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/@willbooster/tree-sitter-bash)
|
|
5
5
|
[](https://github.com/WillBooster/tree-sitter-bash/actions/workflows/test.yml)
|
|
6
6
|
[](https://github.com/semantic-release/semantic-release)
|
|
7
|
-
[](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
|
|
8
8
|
|
|
9
9
|
Bash grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
|
|
10
10
|
[tree-sitter/tree-sitter-bash](https://github.com/tree-sitter/tree-sitter-bash). We are grateful to its authors and
|
|
@@ -16,11 +16,18 @@ As a result, its syntax trees differ from the original grammar's; review your qu
|
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
|
-
The npm package ships `tree-sitter-bash.wasm` for
|
|
19
|
+
The npm package ships `tree-sitter-bash.wasm` for
|
|
20
|
+
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) 1.x, a peer dependency:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
npm install @willbooster/tree-sitter-bash @willbooster/web-tree-sitter
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
In Node.js and Bun, load the grammar from its path:
|
|
20
27
|
|
|
21
28
|
```js
|
|
22
29
|
import { fileURLToPath } from 'node:url';
|
|
23
|
-
import { Language, Parser } from 'web-tree-sitter';
|
|
30
|
+
import { Language, Parser } from '@willbooster/web-tree-sitter';
|
|
24
31
|
|
|
25
32
|
await Parser.init();
|
|
26
33
|
const parser = new Parser();
|
|
@@ -29,6 +36,32 @@ parser.setLanguage(await Language.load(wasmPath));
|
|
|
29
36
|
const tree = parser.parse('cat <<EOF; echo done\n$(date)\nEOF\n');
|
|
30
37
|
```
|
|
31
38
|
|
|
39
|
+
In browsers, serve both `.wasm` files and pass their URLs; with Vite, for example:
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import { Language, Parser } from '@willbooster/web-tree-sitter';
|
|
43
|
+
import runtimeUrl from '@willbooster/web-tree-sitter/web-tree-sitter.wasm?url';
|
|
44
|
+
import bashUrl from '@willbooster/tree-sitter-bash/tree-sitter-bash.wasm?url';
|
|
45
|
+
|
|
46
|
+
await Parser.init({ locateFile: () => runtimeUrl });
|
|
47
|
+
const parser = new Parser();
|
|
48
|
+
parser.setLanguage(await Language.load(bashUrl));
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Cloudflare Workers do not allow compiling Wasm at run time, so import both `.wasm` files as modules, which Wrangler
|
|
52
|
+
precompiles, and pass them to `Parser.init` and `Language.load`. This works with and without the `nodejs_compat`
|
|
53
|
+
flag:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
import { Language, Parser } from '@willbooster/web-tree-sitter';
|
|
57
|
+
import runtime from '@willbooster/web-tree-sitter/web-tree-sitter.wasm';
|
|
58
|
+
import bash from '@willbooster/tree-sitter-bash/tree-sitter-bash.wasm';
|
|
59
|
+
|
|
60
|
+
await Parser.init({ wasmModule: runtime });
|
|
61
|
+
const parser = new Parser();
|
|
62
|
+
parser.setLanguage(await Language.load(bash));
|
|
63
|
+
```
|
|
64
|
+
|
|
32
65
|
The package also ships the queries in `queries/` and the node types in `src/node-types.json`.
|
|
33
66
|
|
|
34
67
|
## Development
|
|
@@ -36,6 +69,7 @@ The package also ships the queries in `queries/` and the node types in `src/node
|
|
|
36
69
|
```sh
|
|
37
70
|
mise install
|
|
38
71
|
bun install --frozen-lockfile
|
|
72
|
+
bun playwright install chromium
|
|
39
73
|
bun run build/ci
|
|
40
74
|
bun run test
|
|
41
75
|
script/parse-examples
|
|
@@ -56,10 +90,13 @@ script/parse-examples
|
|
|
56
90
|
scripts and runs them with the bash that `mise.toml` pins. It checks that the syntax tree shows exactly the commands
|
|
57
91
|
bash runs, with as many words and the same value for each word without expansions, and that the tree has no
|
|
58
92
|
`ERROR` or `MISSING` node for a script bash accepts. A failure prints the seed; `DIFFERENTIAL_SEED` and
|
|
59
|
-
`DIFFERENTIAL_CASES` run other or more scripts. It loads the Wasm build through web-tree-sitter, which
|
|
60
|
-
rebuilds after regenerating the parser;
|
|
93
|
+
`DIFFERENTIAL_CASES` run other or more scripts. It loads the Wasm build through @willbooster/web-tree-sitter, which
|
|
94
|
+
`bun run build/ci` rebuilds after regenerating the parser;
|
|
61
95
|
- a performance check (`test/unit/performance.test.ts`) that a 240 KB line parses in linear time, since consumers
|
|
62
|
-
parse untrusted scripts
|
|
96
|
+
parse untrusted scripts;
|
|
97
|
+
- checks that the Wasm build parses in Chromium (`test/unit/web.browser.test.ts`) and in Cloudflare Workers with and
|
|
98
|
+
without Node.js compatibility (`test/unit/workers.test.ts`, with the Worker in `test/fixtures/worker`), loading it as
|
|
99
|
+
the Usage section shows.
|
|
63
100
|
|
|
64
101
|
CI also fuzzes the parser with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
|
|
65
102
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-bash",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Bash grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"lint": "bun wb lint",
|
|
30
30
|
"lint-fix": "bun wb lint --fix",
|
|
31
31
|
"prepare": "(bun lefthook install || true) && (test ! -f .lefthook/normalize-bun-lockfile.sh || bash .lefthook/normalize-bun-lockfile.sh)",
|
|
32
|
-
"release": "
|
|
32
|
+
"release": "node script/release.mjs",
|
|
33
33
|
"prestart": "bun run build-wasm",
|
|
34
34
|
"start": "tree-sitter playground",
|
|
35
35
|
"test": "bun wb test",
|
|
@@ -42,25 +42,30 @@
|
|
|
42
42
|
"@semantic-release/exec": "7.1.0",
|
|
43
43
|
"@tsconfig/bun": "1.0.11",
|
|
44
44
|
"@types/bun": "1.4.2",
|
|
45
|
+
"@vitest/browser-playwright": "5.0.1",
|
|
45
46
|
"@willbooster/oxfmt-config": "1.2.2",
|
|
46
47
|
"@willbooster/oxlint-config": "1.4.8",
|
|
47
|
-
"@willbooster/wb": "22.
|
|
48
|
+
"@willbooster/wb": "22.11.5",
|
|
49
|
+
"@willbooster/web-tree-sitter": "1.0.0",
|
|
48
50
|
"conventional-changelog-conventionalcommits": "10.4.0",
|
|
49
51
|
"lefthook": "2.1.14",
|
|
50
|
-
"oxfmt": "0.
|
|
51
|
-
"oxlint": "1.
|
|
52
|
+
"oxfmt": "0.70.0",
|
|
53
|
+
"oxlint": "1.85.0",
|
|
52
54
|
"oxlint-tsgolint": "7.0.2002",
|
|
55
|
+
"playwright": "1.63.0",
|
|
53
56
|
"semantic-release": "25.0.9",
|
|
54
57
|
"sort-package-json": "4.0.0",
|
|
55
58
|
"tree-sitter-cli": "0.27.0",
|
|
56
59
|
"typescript": "7.0.2",
|
|
57
|
-
"
|
|
60
|
+
"vite": "8.3.0",
|
|
61
|
+
"vitest": "5.0.1",
|
|
62
|
+
"wrangler": "4.136.2"
|
|
58
63
|
},
|
|
59
64
|
"peerDependencies": {
|
|
60
|
-
"web-tree-sitter": "^0.
|
|
65
|
+
"@willbooster/web-tree-sitter": "^1.0.0"
|
|
61
66
|
},
|
|
62
67
|
"peerDependenciesMeta": {
|
|
63
|
-
"web-tree-sitter": {
|
|
68
|
+
"@willbooster/web-tree-sitter": {
|
|
64
69
|
"optional": true
|
|
65
70
|
}
|
|
66
71
|
},
|
package/tree-sitter-bash.wasm
CHANGED
|
Binary file
|