feat: Track B Phase 1 — Node 化(better-sqlite3 + vitest + esbuild bundle)
让 cxs 不依赖 Bun runtime 也能跑,完成"双发布"双轨的另一条腿。
用户 npm i -g cxs 装 ~13 MB(better-sqlite3 prebuild + chalk + commander),
对比 standalone binary 60-117 MB 体积优势明显。Bun 仍是主开发 runtime
(bun:sqlite 路径已弃用,因为 Bun 不支持 better-sqlite3 N-API,见
oven-sh/bun#4290)。
DB 层:bun:sqlite → better-sqlite3
- db.ts / query.ts:Database 改 better-sqlite3 default import,
Database.setCustomSQLite 删除(不需要 homebrew dylib 优化),
db.query<RowType, ParamType> 改 db.prepare<ParamType, RowType>(类型参
数顺序倒置),db.run 带参数版本改 db.prepare(sql).run(...args),
db.run 不带参的 DDL 改 db.exec
- 测试文件同步改 import + db.exec/db.prepare
- query.test.ts 子进程内嵌 eval script 也从 bun:sqlite 改 better-sqlite3
测试框架:bun:test → vitest
- 7 个 .test.ts import 切到 vitest(API 完全兼容 BDD 风格)
- @types/bun + bun-types 删除
- import.meta.dir → import.meta.dirname(Node 22+ 内置标准 API)
子进程 spawn:Bun.spawn → child_process.spawn
- cli.test.ts runCli + runExecutable 重写为 promise 风格
- cli.test.ts 子进程跑 cli.ts 改用 node --import tsx 路径
- query.test.ts runReadChild 内嵌 script 也加 --import tsx
- eval/perf-bench.ts + eval/run-manual-eval.ts 同样
- eval 内 ./bin/cxs 改成 process.execPath + tsx + cli.ts
- 删除 cli.test.ts "bin/cxs symlink" 测试(bin/cxs 不存在了)
Build pipeline:
- bin/cxs bash shim 删除;package.json bin 字段直指 dist/cli.js
- esbuild 把 cli.ts bundle 成 dist/cli.js 单文件 57 KB
(better-sqlite3 / chalk / commander external 走 npm 解析)
- scripts/post-build.mjs 给 dist/cli.js 加 #!/usr/bin/env node shebang
+ chmod 0755
- npm run build 跑完整 pipeline,prepublishOnly 自动触发
- package.json files 字段改 ["dist/", "README.md", "LICENSE"];
engines 从 bun>=1.3 改 node>=22(JSON import + with type 需要)
- tsconfig.json 加 resolveJsonModule + dist/ 到 exclude
Dev runtime:
- "cxs" / "eval:manual" / "eval:perf" 全改 tsx 跑(放弃 bun run cli.ts)
- README "CLI Install Guide" 重组为三档:standalone binary / npm i -g
/ 源码开发,各档体积与依赖说明清晰
实测全过:
- bun run check:tsc + 42 vitest tests 全绿
- npm run build:dist/cli.js 57 KB single file
- node dist/cli.js 全套 (--version / current bad / sync empty / stats /
find) 完整跑通
- npm pack 19.4 KB,4 文件 tarball;npm i -g 装上 12.8 MB,跑通
- bun build --compile darwin-arm64 仍 work(无回归)
- npm run eval:perf 子进程链路通
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Entire-Checkpoint: 160b6a90ffb6