I maintain Slashi , a VS Code extension that, among other things, offers your project's commands in a popup: run a script, install dependencies, add a package. To do that it has to answer a question every editor plugin, CI script and onboarding doc eventually runs into: which package manager does this project use?
I assumed it was a lockfile check. It mostly is. The part that bit me came later, as a bug report: a Yarn 1 project where Slashi suggested yarn dlx , which doesn't exist in Yarn 1.
This post is the detection order I ended up with, the Yarn split that matters, and the cases it still gets wrong.
Step 1: trust packageManager first
If package.json has a packageManager field, it's the most explicit statement a project can make. Corepack reads it, and so should your tool.
{ "name" : "my-app" , "packageManager" : "[email protected]" }
Enter fullscreen mode
Exit fullscreen mode
Only the prefix before @ matters for picking the tool.…