@willbooster/tree-sitter-bash 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![license](https://img.shields.io/npm/l/@willbooster/tree-sitter-bash.svg)](https://www.npmjs.com/package/@willbooster/tree-sitter-bash)
5
5
  [![Test](https://github.com/WillBooster/tree-sitter-bash/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-bash/actions/workflows/test.yml)
6
6
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
7
- [![wbfy](https://img.shields.io/badge/wbfy-20.23.2-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
7
+ [![wbfy](https://img.shields.io/badge/wbfy-20.26.0-1e90ff.svg)](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 [web-tree-sitter](https://www.npmjs.com/package/web-tree-sitter):
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
@@ -46,7 +80,8 @@ script/parse-examples
46
80
  - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
47
81
  - an incremental-parsing check (`test/unit/incremental.test.ts`): `tree-sitter fuzz` edits each corpus case at random,
48
82
  reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and
49
- `TREE_SITTER_EDITS` run other or more edits;
83
+ `TREE_SITTER_EDITS` run other or more edits. It also applies edits that random ones rarely reach and compares each
84
+ incremental reparse with a fresh parse;
50
85
  - a check that real-world scripts cloned into `examples/` fail to parse exactly as listed in
51
86
  `script/known-failures.txt`. The first run clones them, which takes a few minutes. The example repositories are
52
87
  pinned to commits in `script/parse-examples`. After a grammar change or a moved pin alters that list,
@@ -55,13 +90,15 @@ script/parse-examples
55
90
  scripts and runs them with the bash that `mise.toml` pins. It checks that the syntax tree shows exactly the commands
56
91
  bash runs, with as many words and the same value for each word without expansions, and that the tree has no
57
92
  `ERROR` or `MISSING` node for a script bash accepts. A failure prints the seed; `DIFFERENTIAL_SEED` and
58
- `DIFFERENTIAL_CASES` run other or more scripts. It loads the Wasm build through web-tree-sitter, which `bun run build/ci`
59
- 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;
60
95
  - a performance check (`test/unit/performance.test.ts`) that a 240 KB line parses in linear time, since consumers
61
- 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.
62
100
 
63
- CI also runs these tests on Linux arm64 and macOS, and fuzzes the parser with libFuzzer and sanitizers
64
- (`.github/workflows/robustness.yml`).
101
+ CI also fuzzes the parser with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
65
102
 
66
103
  ### References
67
104
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-bash",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Bash grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -18,7 +18,7 @@
18
18
  "grammar.js",
19
19
  "tree-sitter.json",
20
20
  "queries/*",
21
- "src/**",
21
+ "src/node-types.json",
22
22
  "*.wasm"
23
23
  ],
24
24
  "scripts": {
@@ -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.8.0",
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.68.0",
51
- "oxlint": "1.83.0",
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
- "web-tree-sitter": "0.27.0"
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.27.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
  },
Binary file
package/tree-sitter.json CHANGED
@@ -18,7 +18,7 @@
18
18
  }
19
19
  ],
20
20
  "metadata": {
21
- "version": "2.0.0",
21
+ "version": "2.1.0",
22
22
  "license": "MIT",
23
23
  "description": "Bash grammar for tree-sitter",
24
24
  "authors": [
@@ -29,13 +29,5 @@
29
29
  "links": {
30
30
  "repository": "https://github.com/WillBooster/tree-sitter-bash"
31
31
  }
32
- },
33
- "bindings": {
34
- "c": true,
35
- "go": true,
36
- "node": false,
37
- "python": true,
38
- "rust": false,
39
- "swift": true
40
32
  }
41
33
  }