Prerequisites
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 (
.git is 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.ts and shared/db/src/seed.ts (script entry points)
- All
apps/api/src/routes/*/index.ts barrel 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
Prerequisites
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
.gitignoreworktree fix in #1424 (v5.79.0) resolved gitignore traversal, but entry point resolution frompackage.jsonmain/exportsfields still fails in worktrees.Environment
.gitis a file, not a directory)What happens
Running
knipin 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)apps/api/src/routes/*/index.tsbarrel files (imported by the entry point)Running
knipin the main repo checkout (same commit, same config) correctly recognizes all of these and reports zero unused files.Workaround
Previously we used
--no-gitignorewhich happened to mask this issue (though it introduced other problems like scanningdist/andcoverage/directories). There is no clean workaround that does not hide real findings.Likely cause
The entry point resolution probably uses a path or
fs.statcheck on.gitthat assumes it is a directory. In worktrees,.gitis a file containinggitdir: /path/to/main/.git/worktrees/<name>. This may affect how knip determines the repository root and resolves workspacepackage.jsonpaths relative to it.Related