Skip to content

ci: 引入 knip 死代码 dry-run(仅报告,不删除代码) - #207

Open
xingwangzhe wants to merge 1 commit into
hikariming:mainfrom
xingwangzhe:codex/ci/knip-dry-run
Open

ci: 引入 knip 死代码 dry-run(仅报告,不删除代码)#207
xingwangzhe wants to merge 1 commit into
hikariming:mainfrom
xingwangzhe:codex/ci/knip-dry-run

Conversation

@xingwangzhe

@xingwangzhe xingwangzhe commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

关联 issue

背景

引入 knip 死代码 / 未用依赖静态检测(纯 dry-run,只读,未删除任何代码),并把当前发现的冗余项列出来,交由管理员决策;同时建议把 knip dry-run 纳入 CI。完整发现清单见 #208

改动

  • package.json:新增 knip@^6.32.2 devDependency 与 "knip": "knip" script。
  • knip.json(新增):基础配置,并处理两个 knip 默认行为:
    • Vitest 插件:项目 vitest.config.ts 没有 test 段,导致插件默认不把测试文件当 entry、100+ 测试文件被误报为 unused;这里显式声明 src/**/*.test.{ts,tsx}packages/**/*.test.{ts,tsx} 为 Vitest entry。
    • packages/ghfind-js 是独立发布的 SDK(不在 pnpm workspace 内),其入口文件/导出被误报,已 ignore;后续可单独扫描。
  • .github/workflows/ci.yml:在 lint 之后新增 Knip (dead code dry-run) 步骤,continue-on-error: true 非阻塞——只展示报告、不挡合并;注释里说明等冗余清理完毕后去掉该开关即可强制。

说明 / 局限

  • 本 PR 不删除任何代码,所有冗余项需要管理员决策(见 chore: 引入 knip 死代码 dry-run,列出冗余项供决策 #208):
    • 未用依赖 2 个:@radix-ui/react-separator(仅被无引用的 separator.tsx 使用)、@vercel/speed-insights(全仓库无引用)。
    • 未声明依赖 1 个:server-only 在 7 个文件被 import 但不在 package.json/lock(构建能过是 Next.js 对它有内置特判,建议补声明)。
    • 未引用源文件 8 个 + scripts 一次性脚本 21 个 + 未用导出 91/类型 38(多为 shadcn/ui 风格重导出,低优先级)。
    • scripts/blog-aggregates.mts 硬编码了他人机器绝对路径 /Users/rqq/github-roast/...,本机/CI 无法运行,建议修复或删除。
  • knip 需要 Node ≥ 20.19,CI 用 Node 22 满足。

本地验证

🤖 Generated with Codex

@vercel

vercel Bot commented Aug 18, 2026

Copy link
Copy Markdown

@xingwangzhe is attempting to deploy a commit to the hikariming's projects Team on Vercel.

A member of the Team first needs to authorize it.

Add knip as a devDependency with a `knip` script and a knip.json
configured to scan the app (Vitest test files as entries, and the
standalone `packages/ghfind-js` SDK excluded from the root scan).

The dry-run currently reports findings (unused deps/files, undeclared
`server-only`, etc.) — intentionally no code is deleted here so the
maintainer can decide. A non-blocking `continue-on-error` step is added
to CI so the report is visible without blocking merges.

Signed-off-by: 王兴家 <xingwangzhe@outlook.com>
@xingwangzhe
xingwangzhe force-pushed the codex/ci/knip-dry-run branch from e0439ad to 2b40e11 Compare August 18, 2026 10:54
@xingwangzhe
xingwangzhe marked this pull request as ready for review August 18, 2026 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant