Skip to content
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

Usage with Corepack #1200

Closed
JanJakes opened this issue Apr 11, 2022 · 2 comments
Closed

Usage with Corepack #1200

JanJakes opened this issue Apr 11, 2022 · 2 comments

Comments

@JanJakes
Copy link

JanJakes commented Apr 11, 2022

With Corepack included in NodeJS versions 14.19+, 16.19+, and 17+, some of us may want to use Volta for NodeJS version management only and leave package manager binaries to Corepack.

However, that doesn't seem to be doable at the moment as Volta doesn't expose the corepack binary, nor those it manages.

See an example and a complete reproduction below.

Corepack binary is not exposed:

$ volta install node@latest
success: installed and set [email protected] as default
   note: this version of Node includes [email protected], which is higher than your default version (8.1.4).
      To use the version included with Node, run `volta install npm@bundled`

$ node -v
v17.9.0

$ which node
/Users/<username>/.volta/bin/node

$ corepack
zsh: command not found: corepack

We can fix that by doing something along these lines:

$ echo '
DIR="$(dirname "$0")"
NODE_VERSION="$(node --version)"
"$DIR/../tools/image/node/${NODE_VERSION:1}/bin/corepack" "$@"
' > ~/.volta/bin/corepack

$ chmod +x ~/.volta/bin/corepack

Now Corepack works:

$ corepack enable

But the binaries Corepack manages are not exposed:

$ echo '{"packageManager": "[email protected]"}' > package.json

$ pnpm
zsh: command not found: pnpm

We could fix it again as with Corepack:

$ echo '
DIR="$(dirname "$0")"
NODE_VERSION="$(node --version)"
"$DIR/../tools/image/node/${NODE_VERSION:1}/bin/pnpm" "$@"
' > ~/.volta/bin/pnpm

$ chmod +x ~/.volta/bin/pnpm

Now it works:

$ pnpm -v
6.32.6

But we'd need to do that for all the binaries managed by Corepack (npm, npx, pnpm, pnpx, yarn, yarnpkg), and some of these are already taken by Volta.

Could Volta proxy to the above-mentioned commands by default? I guess it should be an easy fix.

Thanks!

@charlespierce
Copy link
Contributor

Hi @JanJakes, thanks for reporting! This is ultimately a duplicate of #987 (though as you say, the solution likely won't involve needing to install corepack directly). There's a bit of complication around the error messaging, since we want to maintain our helpful error messages and not leave something unhelpful like "Command not found" in the case where we pass-through but don't actually use the underlying corepack shim.

@JanJakes
Copy link
Author

Hi @charlespierce! Thanks for your response. It definitely looks like a related issue, although my scenario maybe adds some more context. The related pull request seems to handle this for the yarn command only but I guess passing commands through to corepack may be a more generic issue that would handle all of the corepack-managed binaries (npm, npx, pnpm, pnpx, yarn, yarnpkg).

I'm also not sure what are the plans for handling this — whether Volta wants to use corepack always when available or if it's up to us users to declare something like "useCorepack": true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants