fix: enable TypeScript plugin when a tsconfig.json is present (resolv…#1806
Open
ixexel661 wants to merge 1 commit into
Open
fix: enable TypeScript plugin when a tsconfig.json is present (resolv…#1806ixexel661 wants to merge 1 commit into
ixexel661 wants to merge 1 commit into
Conversation
…webpro-nl#1804) A tsconfig.json that extends a package is real usage of that package, even when typescript itself isn't a direct dependency. Enable the plugin on tsconfig.json presence (like the pnpm/yarn plugins do for lockfiles) so extended config packages are credited instead of being reported as unused.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a workspace's tsconfig.json extends a package by subpath (e.g. "extends": "@repo/typescript-config/base.json"), knip reports that package as an "Unused devDependency", even though the tsconfig genuinely uses it.
The TypeScript plugin is what credits the extended package as a used dependency (via resolveConfig), but it only runs when typescript (or @typescript/native-preview) is a declared dependency. If a workspace has a tsconfig.json but no direct typescript dependency, and no ancestor provides one, the plugin stays off, the extends chain is never parsed for dependencies, and the config package gets flagged. Note that knip's core already resolves the extends chain (via get-tsconfig) to merge compilerOptions, so it reads the package's file without ever crediting it.
Fix
Enable the TypeScript plugin when a tsconfig.json is present, not only when typescript is a dependency:
const isEnabled: IsPluginEnabled = ({ cwd, dependencies }) =>
hasDependency(dependencies, enablers) || isFile(cwd, 'tsconfig.json');
This follows the existing pnpm and yarn plugins, which enable on lockfile presence (isFile(cwd, 'yarn.lock')).
Test plan
Added fixture fixtures/plugins/typescript-extends-package (a consumer that extends a workspace config package by subpath, with no typescript dependency) and test/plugins/typescript-extends-package.test.ts. It fails before the fix and passes after.
Updated the moonrepo and remix plugin test expectations. With the plugin now enabled, knip correctly surfaces an extended-but-undeclared @tsconfig/node20 (unlisted) and a compilerOptions.types entry vitest/globals (unresolved).
Full smoke suite shows no new regressions.