-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add @yarnpkg/tools
package with detectPackageManager
function
#3408
base: master
Are you sure you want to change the base?
Conversation
Thanks for this. As for more context on why this is going to be super useful, here are two frameworks that try to detect the package manager but don't handle all the edge cases (particularly they can't detect when used inside workspaces): Angular: https://github.com/angular/angular-cli/blob/c1512e42742c17ace82e783e8e9c919ae925d269/packages/angular/cli/utilities/package-manager.ts#L34-L58 An opinion on the name I'm not sure what a good name would be, going to list some random names for possible inspiration:
I think a good name would be self describing, so just by glancing at it inside a |
The name really depends on what we want this package to do, @paul-soporan do you have any plans of adding To add to the examples @andreialecu provided,
You can use https://github.com/loganfsmyth/gensync to write it once while supporting both sync, async, and callback based functions. |
return { | ||
name: PackageManager.YARN, | ||
reason: `Found "${field}" in npm_config_user_agent`, | ||
isClassic: value.startsWith(`0`) || value.startsWith(`1`), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be a problem with Yarn 10 😆
What's the problem this PR addresses?
There's currently no standardized way for third-party tools to detect which package manager should be used inside the project, which leads to each tool implementing a different set of heuristics that don't handle all of the edge cases.
How did you fix it?
I created a new
@yarnpkg/tools
package containing adetectPackageManager
function to be used by any tools needing to pick a package manager to use either inside a project or when init-ing a new project.TODO:
corepack elect
at the end (Implements "corepack elect" nodejs/corepack#26)detectPackageManager
fromscriptUtils
(in@yarnpkg/core
) withdetectPackageManagerFromProject
Checklist