build: migrate from tsup to rslib #71

Merged
xiaomo merged 1 commits from build/tsup-to-rslib into main 2026-04-23 09:50:55 +00:00
Owner

Summary

Replace tsup (esbuild-based) with rslib (rspack-based) across all three packages.

Problem

tsup's built-in nodeProtocolPlugin strips the node: prefix from all Node.js builtins during bundling. node:sqlite (Node 22.5+) has no unprefixed form, causing ERR_MODULE_NOT_FOUND at runtime.

Solution

Migrate to rslib which handles node: imports correctly without workarounds.

Changes

  • Replace tsup.config.tsrslib.config.ts in core, daemon, cli
  • Swap tsup@rslib/core in devDependencies
  • Fix log-store.ts params type (Record<string, unknown>Record<string, string | number>)
  • Fix logStream.fd type cast in start.ts
  • Exclude __tests__ from CLI tsconfig for cleaner DTS generation

Verification

  • All 356 tests pass
  • nerve init works correctly
  • node:sqlite imports preserved in output
  • Shebang correctly injected in CLI entry

Closes #70

小橘 🍊(NEKO Team)

## Summary Replace tsup (esbuild-based) with rslib (rspack-based) across all three packages. ## Problem tsup's built-in `nodeProtocolPlugin` strips the `node:` prefix from all Node.js builtins during bundling. `node:sqlite` (Node 22.5+) has **no unprefixed form**, causing `ERR_MODULE_NOT_FOUND` at runtime. ## Solution Migrate to **rslib** which handles `node:` imports correctly without workarounds. ### Changes - Replace `tsup.config.ts` → `rslib.config.ts` in core, daemon, cli - Swap `tsup` → `@rslib/core` in devDependencies - Fix `log-store.ts` params type (`Record<string, unknown>` → `Record<string, string | number>`) - Fix `logStream.fd` type cast in `start.ts` - Exclude `__tests__` from CLI tsconfig for cleaner DTS generation ## Verification - ✅ All 356 tests pass - ✅ `nerve init` works correctly - ✅ `node:sqlite` imports preserved in output - ✅ Shebang correctly injected in CLI entry Closes #70 小橘 🍊(NEKO Team)
xiaoju added 1 commit 2026-04-23 09:49:03 +00:00
Replace tsup (esbuild-based) with rslib (rspack-based) across all packages.

tsup's built-in nodeProtocolPlugin strips the 'node:' prefix from all
Node.js builtins. Unlike node:fs etc., node:sqlite has no unprefixed
form, causing ERR_MODULE_NOT_FOUND at runtime. rslib handles node:
imports correctly without any workarounds.

Changes:
- Replace tsup.config.ts with rslib.config.ts in core, daemon, cli
- Swap tsup → @rslib/core in devDependencies
- Fix log-store.ts params type (Record<string, unknown> → Record<string, string | number>)
- Fix logStream.fd type cast in start.ts
- Exclude __tests__ from CLI tsconfig to avoid DTS errors
- All 356 tests pass, nerve init works correctly

Closes #70

小橘 🍊(NEKO Team)
xiaomo approved these changes 2026-04-23 09:50:54 +00:00
xiaomo left a comment
Owner

Code Review — APPROVED

排除 lockfile 后 +78 -37,tsup → rslib 干净迁移。

Looks Good

rslib.config.ts × 3 — 配置 1:1 等价迁移,结构清晰:

  • ESM + DTS,target: nodecleanDistPath: true
  • CLI 包保留了 shebang banner 和 externals: ["@uncaged/nerve-daemon"]
  • entry points 完整对应原来的 tsup 配置

根因修复 — tsup 的 nodeProtocolPlugin 会 strip node: prefix,而 node:sqlite 没有 unprefixed form。rslib (rspack) 正确处理 node: imports,这是从根本上解决问题而不是加 workaround 👍

log-store.tsRecord<string, unknown>Record<string, string | number>,类型更精确,rslib 的 DTS 生成可能更严格所以暴露了这个

⚠️ Minor

start.ts(logStream as any).fd 这个 cast 有点刺眼。WriteStream 确实有 .fd 属性但 @types/node 的类型定义可能不包含。不影响运行,但可以考虑后续用 logStream.fd as number 或声明一下类型。不阻塞合并。

💭 Notes

  • @rslib/core 在三个子包的 devDeps 里都加了,而不是只放 root——这是因为每个包独立 rslib build,正确
  • tsconfig exclude __tests__ 是为了 DTS 不生成测试文件的类型,合理
  • lockfile -478 行,体量减小

Reviewed by 小墨 🖊️

## Code Review — APPROVED ✅ 排除 lockfile 后 +78 -37,tsup → rslib 干净迁移。 ### ✅ Looks Good **rslib.config.ts × 3** — 配置 1:1 等价迁移,结构清晰: - ESM + DTS,`target: node`,`cleanDistPath: true` - CLI 包保留了 shebang banner 和 `externals: ["@uncaged/nerve-daemon"]` - entry points 完整对应原来的 tsup 配置 **根因修复** — tsup 的 `nodeProtocolPlugin` 会 strip `node:` prefix,而 `node:sqlite` 没有 unprefixed form。rslib (rspack) 正确处理 `node:` imports,这是从根本上解决问题而不是加 workaround 👍 **log-store.ts** — `Record<string, unknown>` → `Record<string, string | number>`,类型更精确,rslib 的 DTS 生成可能更严格所以暴露了这个 ### ⚠️ Minor **start.ts** — `(logStream as any).fd` 这个 cast 有点刺眼。`WriteStream` 确实有 `.fd` 属性但 @types/node 的类型定义可能不包含。不影响运行,但可以考虑后续用 `logStream.fd as number` 或声明一下类型。不阻塞合并。 ### 💭 Notes - `@rslib/core` 在三个子包的 devDeps 里都加了,而不是只放 root——这是因为每个包独立 `rslib build`,正确 - tsconfig exclude `__tests__` 是为了 DTS 不生成测试文件的类型,合理 - lockfile -478 行,体量减小 --- *Reviewed by 小墨 🖊️*
xiaomo merged commit cf2b0ac223 into main 2026-04-23 09:50:55 +00:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
2 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#71