🐛 TBD
Sorry for not providing a reproduction, I tried one here that best resembles my project setup with minimum complexity.
Workspace
bis using only a subset of workspacea. In the current state,packages/a/src/utils/unused.tsshould be flagged as an unused file/all of its exports should be flagged as unused, and inpackages/a/src/utils/used.ts, only theaFoovariable is being used, so theaBarexport/variable should be flagged as unused.The repo uses TS project references and workspaces (here npm, although mine is Yarn, but I don't believe it makes a huge difference), so the dependency between workspaces is seen both through the project references' setup (
packages/b/tsconfig.jsoncontains a project reference topackages/a/tsconfig.json) and through the regular dependencies (packages/b/package.jsonhas a"@internal/a": "*"dev dependency). You can make sure that everything works properly by runningnpm run b(I've made this script readily available in the root), it should simply displayaFoo.Both workspaces define a
"exports": { "./*": "./src/*.ts" }subpath export, which basically makes every file available from the outside. So technically, I guess this warrants anentry: ['./src/**']config in Knip as every file could be accessed, so that's what I've done here. But despite that, we still want to know whether some of those files (and the exported variables inside) are unused, hence addingincludeEntryExports: trueto Knip's config.Despite all this, if you run
npm run knip(which I've setup to just target thepackages/aworkspace), the current result is the following, which isn't what I expected:Unused exports (3) unusedVar unknown packages/a/src/utils/unused.ts:1:14 aFoo unknown packages/a/src/utils/used.ts:1:14 aBar unknown packages/a/src/utils/used.ts:2:14Do you reckon my usage makes sense for Knip to analyze? Am I misconfiguring or misunderstanding something? Can you confirm the current configuration is correct (or not) and would work if this current issue were to be tackled?
Originally posted by @acidoxee in #853
There was an error when running Knip because of "references": ["../a"] (no "path" prop):
❯ npx knip
Analyzing workspace packages/b...
TypeError: Cannot read properties of undefined (reading 'endsWith')
at eval (file:///home/projects/stackblitz-starters-tml4esvn/node_modules/knip/dist/plugins/typescript/index.js:30:46)
at _0x5f388d._evaluate (https://stackblitzstarterstml4esvn-3ik3.w-credentialless-staticblitz.com/blitz.7f809d15.js:40:796928)
Node.js v18.20.3
And after I fixed that, the result was:
❯ npx knip
Unused exports (2)
unusedVar unknown packages/a/src/utils/unused.ts:1:14
aBar unknown packages/a/src/utils/used.ts:2:14
@acidoxee not sure what is actionable here, can you please elaborate?
Closing due to inactivity, not sure what to could be done here.