asdf-nodejs icon indicating copy to clipboard operation
asdf-nodejs copied to clipboard

Asdf - yarn via corepack compatibility

Open Maxim-Filimonov opened this issue 2 years ago • 13 comments
trafficstars

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.

Maxim-Filimonov avatar Mar 06 '23 05:03 Maxim-Filimonov

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

augustobmoura avatar May 20 '23 17:05 augustobmoura

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

Techn1x avatar Jun 05 '23 06:06 Techn1x

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

jdx avatar Jun 05 '23 15:06 jdx

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?

Maxim-Filimonov avatar Jun 09 '23 04:06 Maxim-Filimonov

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

akkadaya avatar Jun 22 '23 00:06 akkadaya

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.

dtinth avatar Jun 27 '23 06:06 dtinth

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

Techn1x avatar Jun 28 '23 09:06 Techn1x

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

mnahkies avatar Jun 30 '23 09:06 mnahkies

@mnahkies thank you for the correction, edited.

dtinth avatar Jun 30 '23 09:06 dtinth

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!

stephenh avatar Sep 04 '23 20:09 stephenh

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.

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

katelovescode avatar Feb 26 '24 15:02 katelovescode

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 avatar Apr 16 '24 19:04 1oglop1

@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)

dtinth avatar Apr 17 '24 06:04 dtinth