Fix package manager detection in non-monorepos #907
Merged
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.
For reasons unknown,
@manypkg/find-root
only returns a tool (package manager) if it detects that you're in a monorepo. If you're not, it returns aRoot
tool, which is absolutely useless.This was causing
yarn
(via the fallback logic) to be incorrectly detected as the package manager in apnpm
repo, causingsku pre-commit
to run the wrong command (yarn --check-files
).I've kept the root directory detection from
@manypkg/find-root
, but leveraged@antfu/ni
's API for detecting the package manager in the case where a non-supported tool is detected. This involves looking for lockfiles, which is what thedetect
API from@antfu/ni
does, but it's async only, so I've made a synchronous version because package manager detection in sku can't be made async right now.Finally, I made the
lintStaged
call use config defined as an object rather than resolving to a file because it's simpler IMO. I did this initially as I thought maybe the lint staged config was the issue.