fix: add a fallback to seach for lock file at cwd if its missing at the root level - #2020
Merged
webpro merged 1 commit intoSep 7, 2026
Merged
Conversation
Member
|
Thank you! Looks all good to me, happy to merge. |
Contributor
Author
|
cool, let me know. If i need to do anything else 👍 |
Member
|
🚀 This pull request is included in v6.35.0. See Release 6.35.0 for release notes. Using Knip in a commercial project? Please consider becoming a sponsor. |
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.
Hey — small one. Ran into this setting knip up in a repo where the JS project isn't at the git root.
Description
npm create @knip/configpicks the wrong package manager when the git root isn't the JS project root. In ayarnproject it runsnpm add -D knip ..., which leaves apackage-lock.jsonsitting next to thepnpm-lock.yaml.I was able to find it, because my package.json's setup has issues with
npm--legacy-peer-deps. And it started to throw errors.Steps to reproduce
Runs
npm add -D knip typescript @types/node. Should bepnpm add.What's happening
knip/packages/create-config/index.js
Lines 29 to 36 in aaab35a
That's right for the common case, for monorepos — npm, pnpm, yarn and bun workspaces all keep a single lockfile at the workspace root, so a workspace package has none of its own. Looking in cwd would come up empty for every monorepo package.
The problem is it assumes
git root == workspace root. When that's not true nothing matches, we fall through to return 'npm', and then install in cwd —execSync(cmd, { stdio: 'inherit' })passes no cwd, so the child inherits ours. Detection reads one directory, the install happens in another.