Repository navigation
build: add knip to find unused files, exports and dependencies - #142
Merged
Merged
Conversation
…ndex.js The root package isn't published and has no index.js. knip, added next, reports it as a missing entry file.
knip runs as part of npm run lint and treats configuration hints as errors. knip.jsonc marks doc-kit's config-loaded files as entries and lists the generated types, the vendored oxlint plugin and the dependencies knip can't trace, each with the reason. The CI lint job now runs plain npm ci, which installs the workspaces too, so knip can match c8 in their scripts to its package.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Draft
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.
Adds knip 6.44.1 as a pinned root devDependency, a
knipscript, and runs it at the end ofnpm run lint. 6.44.1 is from Oct 31, well past the 3-daymin-release-agegate in @lavamoat/harden's npm config (#140). The script passes--treat-config-hints-as-errors, so a stale exception inknip.jsonc(an ignored dependency that's no longer needed, say) fails lint instead of only printing a hint.Adds
knip.jsonc. Knip reads the npm workspaces itself and turns on its GitHub Actions, Node.js, oxlint, oxfmt and TypeScript plugins from what's installed, which covers most of the repo, so the config only holds what those can't see:*/types/**is ignored. These are generated bynpm run typesand published through each package'stypesfield, which knip doesn't read as an entry.tools/oxlint/anti-slop/**is ignored. It's the vendored oxlint plugin, and the same path is already excluded in.oxlintrc.jsonanddocov.jsonc.doc-kit.config.mjsanddocs/theme/Navigation.jsxare root entries.doc-kit generateloads the config by its name, and the config points doc-kit at the theme by path. Without these, knip also reported@doc-kit/generator-reactand@node-core/ui-componentsas unused, since only the theme imports them.#theme/configand#theme/Logoare ignored as unresolved imports in the root. doc-kit's React generator defines those aliases while it builds.@nodevu/*is ignored as a dependency of the root.test/types.mtsimports the published packages through the workspace links.@doc-kit/coreis ignored as a dependency of the root. It's only a JSDoc type import indoc-kit.config.mjs, and@doc-kit/cliinstalls it.luxonis ignored infetchindex. Knip saw no import and called the devDependency unused, but the tests requirecore/util/prod/optionsParser.js, which requires luxon, and the CI coverage job installs only the workspace under test (npm ci -w fetchindex). Removing it would break that job.luxonis ignored instatic.static/test/test.build.jsresolves core's own luxon on purpose, to stop the clock core reads, so it isn't a direct dependency.Every package's exports stay public: knip treats each workspace's
mainas an entry and doesn't report what an entry exports.Changes the CI lint job's install from
npm ci --workspaces=falseto plainnpm ci, which installs the root and every workspace. With only the root installed, knip can't matchc8in each workspace'scoveragescript to the c8 package, and reports c8 as both unused and an unlisted binary in all nine workspaces that use it.package-lock.jsongains knip and the 58 packages it pulls in, added withnpm i -D -E knip@6.44.1. Nothing already in the lockfile changed version.The README's development section mentions
npm run knip.Removes, in a separate commit that comes first so the knip commit passes with hints as errors:
"main": "index.js"from the rootpackage.json. There's no rootindex.js, and the root package isn't published (release.yml packs only the workspaces). Knip reported it as a missing entry file.That was the only finding that was actually unused code. Before configuration, knip reported 14 unused files, 3 unused devDependencies, 11 unlisted dependencies, 1 unused export, 7 unused exported types and 1 configuration hint. All of them were generated types, vendored code or the cases above. After both commits, knip reports nothing.
Checked with
npm run lint,npm run types(committed types unchanged),npm run coverage(100% in every package with coverage) andnpm run docs. Adding an unused export tocore/util/prod/schedule.jsand an unusedsemverdependency tooldestmade knip exit 1 with both reported. So did a staleleft-padentry in anignoreDependencieslist, reported as a configuration hint.