-
-
Notifications
You must be signed in to change notification settings - Fork 602
feat(init)!: add --package-manager flag
#4107
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
base: next
Are you sure you want to change the base?
Conversation
…nv/lockfile fallback
001c77a to
09fdf0a
Compare
--package-manager flag--package-manager flag
--package-manager flag--package-manager flag
| task: async ({ pm }, task) => { | ||
| const pmString = `${pm.executable}@${pm.version}`; | ||
| try { | ||
| await spawn('corepack', ['use', pmString], { |
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.
It seems that corepack command is executed here regardless of whether the user passes in --package-manager or not. Would it be better to add a check here? When the user does not pass in --package-manager, the original behavior should be restored.
Also, if the --package-manager value is "npm", it can be skipped directly to avoid an unnecessary spawn call. This can also prevent the following description information from appearing when the user is using npm but has not installed corepack.
Overall, I support the changes in the current PR.
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.
Great suggestions @BlackHole1! I'm going to incorporate those into the PR this week.
Closes #4005
I'm building upon @youaresoyoung's last PR and making a few UX tweaks and wiring the whole thing through
corepackto make package manager installation more intuitive.Impetus
This makes it a lot easier to initialize a project with Yarn v4, which is kind of required to test internal builds of Forge projects now that the entire monorepo uses that package manager.
Using Corepack
Yarn Berry is only installable via Corepack, an experimental package maintained by Node.js to manage package manager versions. Corepack supports
npm,pnpm,yarn, andbun.This PR spawns
corepack use <package-manager>in the template repository upon initialization. This sets thepackageManagerfield inpackage.jsonand tells the project to use a specific version of a package manager.Notes
npm install -g corepack. For all other versions, users will need to runcorepack enablefirst to enable Yarn/pnpm shims.npmwon't run into this issue since we just fall back tonpmif corepack fails at all.NODE_INSTALLERenvironment variable we used to use in our tests.pnpmchokes up withPNPM_ERR_TARBALL_INTEGRITYwhen attempting to install Verdaccio tarballs if the package store already cached the equivalent packages from npm.spawn-verdaccio.tsnow adds apnpm store prunecommand to blow that cache away first before running any Verdaccio-based tests to avoid this error.TODO:
api.inittests to usepackageManagerflag.NODE_INSTALLERenvironment variable logic.