Prerequisites
Reproduction url
https://stackblitz.com/edit/github-z7snogip?file=README.md
Reproduction access
Description of the issue
If tsconfig.json rootDir is set to ".", and outDir to "dist", Knip fails to reverse-map package.json exports.
Reproduction steps:
npm install
npm run knip - see false unused files reports
- If I move those same files into src/ and update the tsconfig.json rootDir to be src/, the false error goes away
The issue might come from here from the !isUnderSrcDir(absSpecifier, srcDir) && check:
|
const rewritePattern = (sourceMaps: SourceMap[], absSpecifier: string, extensions: string) => { |
|
for (const { srcDir, outDir } of sourceMaps) { |
|
if (!isUnderSrcDir(absSpecifier, srcDir) && isUnderOutDir(absSpecifier, outDir)) { |
|
return srcDir + absSpecifier.slice(outDir.length).replace(matchExt, extensions); |
|
} |
|
} |
|
}; |
Use case:
- I wish root-level .ts files, like
vite.config.ts and support scripts to be type checked as part of build, so rootDir is set to . rather than src/. This also helps typescript-eslint as it can use the same typescript program instance for the entire package.
A workaround:
- Do not specify a "rootDir" in tsconfig.json - typescript still automatically infers it as ".", where as knip infers it as "src". Fragile 🙂
Prerequisites
Reproduction url
https://stackblitz.com/edit/github-z7snogip?file=README.md
Reproduction access
Description of the issue
If tsconfig.json rootDir is set to ".", and outDir to "dist", Knip fails to reverse-map package.json exports.
Reproduction steps:
npm installnpm run knip- see false unused files reportsThe issue might come from here from the
!isUnderSrcDir(absSpecifier, srcDir) &&check:knip/packages/knip/src/util/to-source-path.ts
Lines 38 to 44 in cfb9ac4
Use case:
vite.config.tsand support scripts to be type checked as part of build, so rootDir is set to . rather than src/. This also helps typescript-eslint as it can use the same typescript program instance for the entire package.A workaround: