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

Asdf - yarn via corepack compatibility #342

Open
Maxim-Filimonov opened this issue Mar 6, 2023 · 13 comments
Open

Asdf - yarn via corepack compatibility #342

Maxim-Filimonov opened this issue Mar 6, 2023 · 13 comments

Comments

@Maxim-Filimonov
Copy link

Maxim-Filimonov commented Mar 6, 2023

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.

@augustobmoura
Copy link
Member

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

@Techn1x
Copy link

Techn1x commented Jun 5, 2023

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

@jdx
Copy link

jdx commented Jun 5, 2023

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

@Maxim-Filimonov
Copy link
Author

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?

@akkadaya
Copy link

Does this help?

It will let you install Yarn in the project or lock the version

@dtinth
Copy link

dtinth commented Jun 27, 2023

Thanks to this:

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.

@Techn1x
Copy link

Techn1x commented Jun 28, 2023

Unfortunately some repos in my organisation will likely continue using yarn/pnpm plugins, so I don't think that will work for us.

@mnahkies
Copy link

@dtinth I think you meant to write asdf reshim nodejs but otherwise this solution worked for me

@dtinth
Copy link

dtinth commented Jun 30, 2023

@mnahkies thank you for the correction, edited.

@stephenh
Copy link

stephenh commented Sep 4, 2023

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!

@katelovescode
Copy link

Thanks to this:

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.

Thanks so much, this is what I needed to do.

@1oglop1
Copy link

1oglop1 commented Apr 16, 2024

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": "pnpm@9.0.1"
then after corepack use pnpm@9.0.1
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!

@dtinth
Copy link

dtinth commented Apr 17, 2024

@1oglop1 With Corepack, when you run pnpm

  • Case 1: In a folder with package.json containing "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 pnpm in this case — that is, in your project — run corepack use pnpm. This updates package.json file.
  • Case 2: In a folder with package.json containing "packageManager": "yarn@…" (something other than pnpm)

    • Corepack will refuse to let you run pnpm and will say “Usage Error: This project is configured to use yarn” instead.
  • Case 3: In other cases — for instance, when you are not in a project with a package.json file

    • Corepack will use the globally-installed version of pnpm.
    • To upgrade the globally-installed version, run corepack install --global pnpm

To summarize

  • To keep your globally-installed version updated, run corepack install --global pnpm
  • To keep the pnpm version in your project up-to-date, run corepack use pnpm (or use renovate)

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

No branches or pull requests

10 participants