-
-
Notifications
You must be signed in to change notification settings - Fork 390
False positive unused files in git worktree (entry points not resolved) #1655
Description
Prerequisites
- I've read the relevant documentation
- I've searched for existing issues
- I've read the issue reproduction guide
Good version
N/A (workaround was --no-gitignore)
Bad version
6.1.1 (also 5.86.0)
Description
In a git worktree, knip reports package entry points as "unused files" that are correctly recognized in the main repo checkout. The .gitignore worktree fix in #1424 (v5.79.0) resolved gitignore traversal, but entry point resolution from package.json main/exports fields still fails in worktrees.
Environment
- Git worktree (
.gitis a file, not a directory) - pnpm monorepo with multiple workspaces
- knip 6.1.1
What happens
Running knip in a git worktree produces 18 "unused files" including:
apps/api/src/index.ts(the API entry point)packages/td/src/bin.ts(a CLI bin entry)shared/db/src/migrate.tsandshared/db/src/seed.ts(script entry points)- All
apps/api/src/routes/*/index.tsbarrel files (imported by the entry point)
Running knip in the main repo checkout (same commit, same config) correctly recognizes all of these and reports zero unused files.
Workaround
Previously we used --no-gitignore which happened to mask this issue (though it introduced other problems like scanning dist/ and coverage/ directories). There is no clean workaround that does not hide real findings.
Likely cause
The entry point resolution probably uses a path or fs.stat check on .git that assumes it is a directory. In worktrees, .git is a file containing gitdir: /path/to/main/.git/worktrees/<name>. This may affect how knip determines the repository root and resolves workspace package.json paths relative to it.
Related
- Fix gitignore ancestor detection for git worktrees #1424 (gitignore traversal fix for worktrees - merged, working correctly)
- 🐛 Knip fails in a git worktree + lefthook #990 (git hooks in worktrees - fixed)