Skip to content

Conversation

@erickzhao
Copy link
Member

@erickzhao erickzhao commented Dec 19, 2025

Closes #4005

I'm building upon @youaresoyoung's last PR and making a few UX tweaks and wiring the whole thing through corepack to 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, and bun.

This PR spawns corepack use <package-manager> in the template repository upon initialization. This sets the packageManager field in package.json and tells the project to use a specific version of a package manager.

Notes

  • This Corepack integration allows us to install specific versions of package managers. This makes it possible for users to choose between Yarn Classic and Yarn Berry.
  • Corepack is only included by default with Node.js up until Node 24. For Node 25 and above, users will need to npm install -g corepack. For all other versions, users will need to run corepack enable first to enable Yarn/pnpm shims.
    • Users who prefer the default npm won't run into this issue since we just fall back to npm if corepack fails at all.
  • This replaces the deprecated NODE_INSTALLER environment variable we used to use in our tests.
  • pnpm chokes up with PNPM_ERR_TARBALL_INTEGRITY when attempting to install Verdaccio tarballs if the package store already cached the equivalent packages from npm. spawn-verdaccio.ts now adds a pnpm store prune command to blow that cache away first before running any Verdaccio-based tests to avoid this error.

TODO:

  • Refactor api.init tests to use packageManager flag.
  • Remove NODE_INSTALLER environment variable logic.

@erickzhao erickzhao added the next label Dec 19, 2025
@erickzhao erickzhao force-pushed the node_installer_explicit branch from 001c77a to 09fdf0a Compare December 19, 2025 01:40
@erickzhao erickzhao changed the title feat(init): add --package-manager flag feat!(init): add --package-manager flag Dec 19, 2025
@erickzhao erickzhao changed the title feat!(init): add --package-manager flag feat(init)!: add --package-manager flag Dec 19, 2025
@erickzhao erickzhao marked this pull request as ready for review December 19, 2025 21:59
@erickzhao erickzhao requested a review from a team as a code owner December 19, 2025 21:59
task: async ({ pm }, task) => {
const pmString = `${pm.executable}@${pm.version}`;
try {
await spawn('corepack', ['use', pmString], {
Copy link
Member

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.

Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants