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

Investigate Yarn 2 #655

Closed
Leksat opened this issue May 26, 2021 · 6 comments
Closed

Investigate Yarn 2 #655

Leksat opened this issue May 26, 2021 · 6 comments

Comments

@Leksat
Copy link
Member

Leksat commented May 26, 2021

1. Yarn 1 has issues with focused installs, while Yarn 2 supports them. Currently it's not really possible to install dependencies just for a single workspace. The current workaround is not good. With Yarn 2 it should be easy.

2. Yarn 2 has zero-installs feature. Would be nice to try it for this monorepo. Maybe it will speed up our workflows.

@pmelab
Copy link
Contributor

pmelab commented May 27, 2021

There is one major blocker for this: Does Gatsby Cloud support Yarn 2?We have to try.

@dan2k3k4
Copy link
Member

@pmelab
Copy link
Contributor

pmelab commented May 27, 2021

Is yarn 2 backwards compatible? Can you install a yarn 2 project with yarn 1?

@Leksat
Copy link
Member Author

Leksat commented Jun 1, 2021

Looks like it is.

Yarn 2+ creates a new file in the repository, e.g. .yarn/releases/yarn-3.0.0-rc.2.cjs. This file has to be committed into the repo. And it looks like this file is Yarn itself. So the globally installed Yarn is still version 1.

$ yarn --version
1.22.10
$ cd silverback-mono # Local version which uses Yarn 3
$ yarn --version
3.0.0-rc.2

@Leksat
Copy link
Member Author

Leksat commented Jun 1, 2021

Another finding.

A project using Yarn 1 is just a set of files. With Yarn 2 it's more complicated. Tricks like the following one do not work anymore.

# Initiate a new node package.
yarn init -y
# Install the scaffold package.
yarn add ../

Yarn 2 knows that the parent dir is a workspace belonging to silverback-mono. It can't just take it out of the monorepo and errors:

Usage Error: The nearest package directory (~/work/silverback-mono/packages/npm/@amazeelabs/scaffold/test) doesn't seem to be part of the project declared in ~/work/silverback-mono.

- If the project directory is right, it might be that you forgot to list packages/npm/@amazeelabs/scaffold/test as a workspace.
- If it isn't, it's likely because you have a yarn.lock or package.json file there, confusing the project root detection.

It's solvable of course. But just something to keep in mind.

@Leksat
Copy link
Member Author

Leksat commented Jun 2, 2021

#658 uses Yarn 2 with nodeLinker: node-modules. I made it this way because the default Plug'n'Play mode requires to much of effort just to make yarn install work.

I checked yarn install time:

Yarn 1 (dd61f6f) Yarn 2 (eb3bd9c)
no caches 157s 319s
clean repo 126s 157s
re-run 56s 9s

Yarn 1 is faster 😅

Yarn 2 is faster in re-run just because it does not run prepare scripts for some reason. But it runs them on a clean repo.

Other findings:

I would stay on Yarn 1 for now. Yarn 2 with nodeLinker: node-modules gives no benefits. PNP mode has a great idea behind, but currently it's difficult to migrate to it. Let's wait for microsoft/TypeScript#35206 at least.

@Leksat Leksat closed this as completed Jun 2, 2021
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

3 participants