#yarn/corepack install

1 messages · Page 1 of 1 (latest)

harsh cape
#

OK, what's the secret here? I thought this would work:

    return dag
      .container()
      .from('node:18-slim')
      .withExec(['corepack', 'enable'])
      .withExec(['corepack', 'prepare', 'yarn@latest', '--activate'])
      .withDirectory('/src', source)

Instead, this exits with:

Stderr:
error This project's package.json defines "packageManager": "yarn@4.1.1". However the current global version of Yarn is 1.22.22.

The logs, however, seem to indicate something else is initializing first (probably the typescript SDK):

144 : 6f2066e431fd41bb:     Container.withExec(args: ["yarn", "set", "version", "stable"]): Container!
145 : 445ca20e99149742:     Container.withExec(args: ["yarn", "workspaces", "focus", "--production"]): Container!
146 : 54f90a055b200d38:     load cache: exec yarn workspaces focus --production
146 : 54f90a055b200d38:     load cache: exec yarn workspaces focus --production DONE [0.0s]
177 : a49fb438ea5de5af:     Container.withExec(args: ["yarn", "install"]): Container!
177 : a49fb438ea5de5af:   Container.withExec(args: ["yarn", "install"]): Container!
181 : 4cf4d3ff7ec5ec75:     exec yarn install
181 : 4cf4d3ff7ec5ec75:     exec yarn install ERROR [0.6s]

So, what is the right way to to upgrade yarn?

shut hound
#

👋 I'm not familiar with corepack, but reading up a bit I'm wondering why you need it 🤔
https://github.com/nodejs/corepack/blob/main/README.md

Corepack is a zero-runtime-dependency Node.js script that acts as a bridge between Node.js projects and the package managers they are intended to be used with during development. In practical terms, Corepack lets you use Yarn, npm, and pnpm without having to install them.
...
Just use your package managers as you usually would. Run yarn install in Yarn projects, pnpm install in pnpm projects, and npm in npm projects. Corepack will catch these calls, and depending on the situation...

Can't you just have Dagger functions that devs can run locally and in CI that use whatever package manager you deem best under the hood, like yarn, for instance? Usually folks will set up the cache as well for node_modules and the yarn cache.

I'd love to learn more about your ideal outcome 🙂

shut hound
#

In any case, I tried your code above and things worked for me on dagger v0.12.1.
https://github.com/jpadams/repro-drmikecrowe

I stuck a yarn/TypeScript "create react app" app in my-app/

Then I ran dagger call test --source ./my-app/ stdout (note: my function returns a Container and the stdout causes the withExecs to run)

and got this output

Preparing yarn@latest for immediate activation...

I then ran dagger call test --source ./my-app/ terminal to get an interactive terminal session.

#

Inside the container, I ran

bash
cd src
yarn install

➤ YN0000: · Yarn 4.3.1

#

I looked in package.json and see

"packageManager": "yarn@4.3.1+sha512.af78262d7d125afbfeed740602ace8c5e4405cd7f4735c08feb327286b2fd
b2390fbca01589bfd1f50b1240548b74806767f5a063c94b67e431aabd0d86f7774"
#

You can run all the same by cloning my repro module and running things from there.

harsh cape
#

Note also this (this is key):

#

Something in the typescript sdk is doing a yarn install before getting into the index.ts code. Simply run: dagger call test --source . stdout --progress plain 2>&1 | grep yarn
FWIW -- we want to control the yarn install -- i don't think this should happen under the hood (this is not respecting the lock file, so it's incorrect anyway)

harsh cape
#

As it stands right now:

  • dagger can't be used with any yarn/pnpm version that sets packageManager in package.json (the recommended best practice)
  • dagger can be used with yarn version w/o packageManager but it is doing 2x yarn install commands:
shut hound
#

@tiny sleet 👆

tiny sleet
#

It's still wip though, almost ready for a merge, but I'm actively working on this 😉

harsh cape
#

@tiny sleet --awesome, thanks. <under-his-breath>hurry...</under-his-breath> haha

#

(that's meant as a joke in case that wasn't clear)

tiny sleet
#

Yeaaah haha no worry, I'm trying to optimize some stuff and should be good

harsh cape
#

@tiny sleet - what sort of optimizations?

tiny sleet
#

I cannot use yarn import because it doesn't work as it should so I'm trying to find a workaround

harsh cape
#

Isn't a lock file required? Why would you want to operate without one?

tiny sleet
#

It's not required to install but it's better for reproductibility & it's also faster

#

Right now we don't use the lockfile by default, the PR aims to correct that by

  1. Generate a lockfile
  2. Adapt to the user's preference of package manager
harsh cape
#

@tiny sleet -- yeah, but during CI/CD, we need to use the lock file and not modify it. In the case of yarn, for v2 and above, we want yarn install --immutable. Yarn v1 has different commands

IMO, no lockfile, do nothing.