Skip to content

fix: enable TypeScript plugin when a tsconfig.json is present (resolv…#1806

Open
ixexel661 wants to merge 1 commit into
webpro-nl:mainfrom
ixexel661:main
Open

fix: enable TypeScript plugin when a tsconfig.json is present (resolv…#1806
ixexel661 wants to merge 1 commit into
webpro-nl:mainfrom
ixexel661:main

Conversation

@ixexel661

Copy link
Copy Markdown

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.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant