Commit 2a62159
authored
refactor: replace bun run with tsx/pnpm across scripts and CI (#999)
## Phase 4: Replace `bun run` with `tsx`/`pnpm run`
Part of the Bun → Node.js migration. Removes Bun as the TypeScript
runner for scripts and CI, replacing with `tsx` and `pnpm run`.
### Changes
**Script files (14 converted):**
- Replaced `Bun.file().text()` → `readFile()` from `node:fs/promises`
- Replaced `Bun.write()` → `writeFile()`
- Replaced `Bun.file().exists()` → `access()`
- Replaced `Bun.file().json()` → `JSON.parse(readFile())`
- Replaced `new Bun.Glob()` → `tinyglobby`
- Updated shebangs: `#!/usr/bin/env bun` → `#!/usr/bin/env tsx`
- `generate-api-schema.ts`: replaced
`require.resolve("@sentry/api/package.json")` with `import.meta.resolve`
+ `fileURLToPath` (avoids `ERR_PACKAGE_PATH_NOT_EXPORTED` and
`ERR_AMBIGUOUS_MODULE_SYNTAX`)
**ESM require shim (`script/require-shim.mjs`):**
- Source code uses bare `require()` for lazy loading (circular dep
breaking, optional features). This works natively in Bun and CJS
bundles, but fails under tsx/Node ESM (since `"type": "module"` is set).
- The shim provides `globalThis.require` via `createRequire`, anchored
at the project root (`package.json`).
- All relative `require()` calls in `src/` are behind runtime-only code
paths (DB init, telemetry) that do not execute during tsx script runs.
**Worker source refactor (`src/lib/scan/grep-worker-source.ts`):**
- Replaced `import ... with { type: "text" }` (Bun-specific) with a
wrapper module that uses `readFileSync` at dev time.
- At build time, esbuild's `text-import-plugin` intercepts the module
and inlines `grep-worker.js` as a string constant.
- Removed the now-dead `textImportPlugin` from `vitest.config.ts`.
**package.json:**
- Added `"tsx"` script alias: `tsx --import ./script/require-shim.mjs`
- All scripts use `pnpm tsx` (which invokes the alias)
- Only `build`/`build:all` retain `bun run` (needs `Bun.build()`
compiler)
**CI (`.github/workflows/ci.yml`):**
- Removed `setup-bun` from all jobs except `build-binary`
- All `bun run` → `pnpm run` in non-build steps
**Documentation:**
- Updated `README.md`, `DEVELOPMENT.md`, `contributing.md` to use `pnpm
run` instead of `bun run`
- Updated script JSDoc usage examples in `bench.ts`, `bench-sweep.ts`
- Added `docs/pnpm-lock.yaml` for docs site build (was using `bun.lock`)
**Tests:**
- Fixed `bundle.test.ts` and `library.test.ts` E2E tests: `spawn("bun",
...)` → `spawn("pnpm", ...)`
- Fixed `concurrent-worker.ts` shebang and usage comments
### Intentionally kept on Bun
- `script/build.ts` — uses `Bun.build()` (compiler) which has no Node
equivalent
- `build-binary` CI job retains `setup-bun`
### Testing
- All CI checks pass (lint, typecheck, unit tests, E2E, build binary,
build npm, build docs)
- tsx confirmed working on Node v22 and v241 parent 20c1e0d commit 2a62159
31 files changed
Lines changed: 6261 additions & 283 deletions
File tree
- .github/workflows
- docs
- src/content/docs
- script
- src/lib
- scan
- test
- e2e
- lib/db
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
| 141 | + | |
142 | 142 | | |
143 | | - | |
| 143 | + | |
144 | 144 | | |
145 | | - | |
| 145 | + | |
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
| 174 | + | |
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| |||
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | 214 | | |
218 | 215 | | |
219 | 216 | | |
| |||
226 | 223 | | |
227 | 224 | | |
228 | 225 | | |
229 | | - | |
| 226 | + | |
230 | 227 | | |
231 | | - | |
| 228 | + | |
232 | 229 | | |
233 | 230 | | |
234 | 231 | | |
| |||
253 | 250 | | |
254 | 251 | | |
255 | 252 | | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
| |||
637 | 637 | | |
638 | 638 | | |
639 | 639 | | |
640 | | - | |
641 | | - | |
642 | | - | |
643 | 640 | | |
644 | 641 | | |
645 | 642 | | |
| |||
659 | 656 | | |
660 | 657 | | |
661 | 658 | | |
662 | | - | |
| 659 | + | |
663 | 660 | | |
664 | 661 | | |
665 | 662 | | |
666 | 663 | | |
667 | 664 | | |
668 | 665 | | |
669 | | - | |
| 666 | + | |
670 | 667 | | |
671 | 668 | | |
672 | 669 | | |
| |||
679 | 676 | | |
680 | 677 | | |
681 | 678 | | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | 679 | | |
686 | 680 | | |
687 | 681 | | |
| |||
697 | 691 | | |
698 | 692 | | |
699 | 693 | | |
700 | | - | |
| 694 | + | |
701 | 695 | | |
702 | 696 | | |
703 | 697 | | |
| |||
723 | 717 | | |
724 | 718 | | |
725 | 719 | | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | 720 | | |
730 | 721 | | |
731 | 722 | | |
| |||
750 | 741 | | |
751 | 742 | | |
752 | 743 | | |
753 | | - | |
| 744 | + | |
754 | 745 | | |
755 | 746 | | |
756 | 747 | | |
757 | 748 | | |
758 | 749 | | |
759 | 750 | | |
760 | 751 | | |
761 | | - | |
762 | | - | |
| 752 | + | |
| 753 | + | |
763 | 754 | | |
764 | 755 | | |
765 | 756 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 56 | + | |
| 57 | + | |
61 | 58 | | |
62 | 59 | | |
63 | 60 | | |
| |||
68 | 65 | | |
69 | 66 | | |
70 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
| 88 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
28 | 30 | | |
29 | | - | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
37 | | - | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
86 | 88 | | |
87 | 89 | | |
88 | 90 | | |
| 91 | + | |
| 92 | + | |
89 | 93 | | |
90 | | - | |
| 94 | + | |
91 | 95 | | |
92 | 96 | | |
93 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
| 136 | + | |
137 | 137 | | |
138 | | - | |
139 | | - | |
| 138 | + | |
| 139 | + | |
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| |||
0 commit comments