asdf-nodejs
asdf-nodejs copied to clipboard
Asdf - yarn via corepack compatibility
I'm wondering with upcoming corepack feature stabilization are there any ways to integrate it with asdf?
Right now, it seem when we do corepack enable in one repo it enables it for all the repos which share the same version of node.
We have decided to opt out of corepack for now to avoid upgrading yarn across repos.
What I envision integration would allow is to separate yarn version for each repo like we do with asdf now but able to enable corepact without affecting other repos.
I still need to understand how corepack works behind the scenes, but we are probably willing to offer a better integration. Contributions are also welcome
Right now, it seem when we do corepack enable in one repo it enables it for all the repos which share the same version of node.
I'm using pnpm though but otherwise I'm seeing the same thing.
Since corepack just dumps the shims in the same dir as node https://github.com/nodejs/corepack#corepack-enable--name I worry that asdf plugins like yarn and pnpm would cause issues here too (though I don't know for sure)
Like for a different repo, if I have nodejs and pnpm plugins, which would also create a pnpm shim in the shims folder - would that interfere with some other repo that gets pnpm via corepack, or vice versa
I believe you that asdf-yarn/asdf-pnpm would need to be specified before node in .tool-versions in order for the corepack shims from asdf-nodejs to not be used
I believe you that asdf-yarn/asdf-pnpm would need to be specified before node in .tool-versions in order for the corepack shims from asdf-nodejs to not be used
we did exactly that for asdf-yarn and it worked. However, if any dev enables corepack on other repo it will break this one i believe. Or will it not?
Does this help?
- Yarn 1 https://classic.yarnpkg.com/lang/en/docs/cli/version
- Yarn >2 https://yarnpkg.com/cli/version
It will let you install Yarn in the project or lock the version
Thanks to this:
- https://github.com/asdf-vm/asdf-nodejs/pull/349/files
The solution I took was:
corepack enable
asdf reshim nodejs
So now, I use corepack to manage yarn/pnpm version and do not use asdf plugins for that.
Unfortunately some repos in my organisation will likely continue using yarn/pnpm plugins, so I don't think that will work for us.
@dtinth I think you meant to write asdf reshim nodejs but otherwise this solution worked for me
@mnahkies thank you for the correction, edited.
I don't 100% know if this is best practice, but currently I'm using asdf-nodejs to manage Node versions across repos via .nvmrc (as usual), and then for each repo that needs a new version of node, just doing corepack enable && asdf reshim nodejs, to get the right version of yarn.
This is working really well, so thanks! Just naively it seems nice to ideally avoid re-running corepack enable && asdf reshim nodejs and somehow having asdf-nodejs know it should do that for me.
I get there is probably not a good indicator for when this should happen; maybe a new config flag/env variable, or looking for a packageManager key in package.json (seems neat?), but just mentioning it as an idea. Thanks!
Thanks to this:
- https://github.com/asdf-vm/asdf-nodejs/pull/349/files
The solution I took was:
corepack enable asdf reshim nodejsSo now, I use
corepackto manageyarn/pnpmversion and do not use asdf plugins for that.
Thanks so much, this is what I needed to do.
Sorry for being blunt but I am not very well-versed in what is going on with corepack.
It would be great if someone could explain this simply or point me to the right resources.
I've been using ASDF just for nodejs and pnpm up until version 18
nodejs 18.20.2
pnpm 9.0.1
Then this corepack change came and ruined my entire setup 🙀 and I had to adopt it unwillingly for one of the projects.
I've been using renovate to keep .tool-versions up to date and everything worked great, all environments had tools synchronized.
After I enabled corepack
corepack enable
asdf reshim nodejs
it keep using whatever version from .asdf/installs/nodejs/20.8.0/bin/pnpm which I found was the version I did not want to use.
After some digging, I learned that I can set the version in package.json -> "packageManager": "[email protected]"
then after corepack use [email protected]
Renovate should keep the version up to date according to: https://docs.renovatebot.com/modules/manager/npm/#additional-information
my question is what other do I need to make to ensure the pnpm version is what I expect across all projects I work with?
Thank you!
@1oglop1 With Corepack, when you run pnpm…
-
Case 1: In a folder with
package.jsoncontaining"packageManager": "pnpm@…"- Corepack will use the specified version of
pnpm. - If the specified version has not yet been installed, Corepack will download and install it automatically.
- To upgrade the version of
pnpmin this case — that is, in your project — runcorepack use pnpm. This updatespackage.jsonfile.
- Corepack will use the specified version of
-
Case 2: In a folder with
package.jsoncontaining"packageManager": "yarn@…"(something other thanpnpm)- Corepack will refuse to let you run
pnpmand will say “Usage Error: This project is configured to use yarn” instead.
- Corepack will refuse to let you run
-
Case 3: In other cases — for instance, when you are not in a project with a
package.jsonfile- Corepack will use the globally-installed version of
pnpm. - To upgrade the globally-installed version, run
corepack install --global pnpm
- Corepack will use the globally-installed version of
To summarize
- To keep your globally-installed version updated, run
corepack install --global pnpm - To keep the
pnpmversion in your project up-to-date, runcorepack use pnpm(or use renovate)