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

Use Yarn 2 #11167

Merged
merged 2 commits into from Jun 21, 2020
Merged

Use Yarn 2 #11167

merged 2 commits into from Jun 21, 2020

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Feb 24, 2020

Q                       A
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes? 👍
License MIT

Prev: #11142


NOTE to whoever rebases this PR

To solve conflicts related to the workspace: protocol in package.jsons, use this script:

const cp = require("child_process");
const fs = require("fs");

cp.execSync("git checkout --ours .");

const allPkgs = ["codemods", "eslint", "packages"].flatMap(
  dir => fs.readdirSync(dir).map(d => `${dir}/${d}/package.json`)
).filter(p => {
  try {
    fs.readFileSync(p);
    return true;
  } catch {
    return false;
  }
});

const allNames = allPkgs.map(p => require(process.cwd() + "/" + p).name);

for (const pkg of allPkgs) {
  const p = JSON.parse(fs.readFileSync(pkg, "utf8"));
  let updated = false;

  for (const d of ["dependencies", "devDependencies"]) {
    if (!p[d]) continue;

    for (const [name, version] of Object.entries(p[d])) {
      if (allNames.includes(name) &&!version.startsWith("workspace:")) {
        p[d][name] = `workspace:${version}`;
        updated = true;
      }
    }
  }

  console.log(pkg, updated);
  if (updated) fs.writeFileSync(pkg, JSON.stringify(p, null, 2) + "\n");
}

- &save-yarn-cache
paths:
- .yarn/cache
key: v2-yarn-cache

- &save-node-modules-cache
# Cache big node_modules folders
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(😢We are cursed by not using PnP)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, after yarnpkg/berry#955 we don't need to cache it anymore!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That PR is merged, guess we can get rid of the cache?

@nicolo-ribaudo nicolo-ribaudo force-pushed the yarn-2-compat branch 2 times, most recently from 66070cd to 5788ad5 Compare February 27, 2020 21:28
@nicolo-ribaudo nicolo-ribaudo marked this pull request as ready for review February 27, 2020 21:46
@nicolo-ribaudo
Copy link
Member Author

Ready!

Thanks @arcanis and @larixer for the help ❤️

@nicolo-ribaudo
Copy link
Member Author

New failure which wasn't there before the rebase 🙃

@arcanis
Copy link
Contributor

arcanis commented Feb 28, 2020

Interesting, I tried locally but can't repro it 🤔 Can you try pushing an empty commit to run the test again while preserving the logs for future reference? I wonder if it's consistent. Printing the n_m content might also help shed some light.

@nicolo-ribaudo
Copy link
Member Author

nicolo-ribaudo commented Mar 3, 2020

@arcanis The problem was caused by accidentally caching node_modules on Windows. No, it's still not working.

Currently, Travis CI automatically caches it for JavaScript projects: it might be good to reach out to them asking to automatically cache .yarn/cache (and not node_modules) when using Yarn 2.

@larixer
Copy link

larixer commented Mar 3, 2020

@nicolo-ribaudo Please note, that I'm sure that node-modules linker in berry's master is broken at the moment (I have missed the results of require and peer dependency guarantees checks on installed packages), but it will be fixed via this PR:
yarnpkg/berry#1015
Also, I think that caching node_modules should work and actually speed up linking. I think both .yarn/cache and node_modules caching should be beneficial in case of n_m linker

@nicolo-ribaudo
Copy link
Member Author

Yeah, I'm using that PR (not master).

@larixer
Copy link

larixer commented Mar 3, 2020

@nicolo-ribaudo I'm hesitant about if it is right to reuse the cached node_modules from the broken version of node-modules plugin?

@nicolo-ribaudo
Copy link
Member Author

So far I have disabled node_modules cache so it's not what is causing problems. I will enable it again when CI is green. (Maybe, because the additional cache size might not be worth 5s of saved linking time)

@nicolo-ribaudo nicolo-ribaudo force-pushed the yarn-2-compat branch 8 times, most recently from 36fb287 to e177dbd Compare March 4, 2020 00:07
@nicolo-ribaudo
Copy link
Member Author

nicolo-ribaudo commented Mar 4, 2020

The windows build is failing because of a permission problem. The node_modules/@babel/helpers symlink created by Yarn in the root of the monorepo throws EPERM when accessed.

Ctrl+F for realpathSync in https://api.travis-ci.com/v3/job/293683500/log.txt

@nicolo-ribaudo
Copy link
Member Author

It works 🎉 🎉 🎉

@nicolo-ribaudo nicolo-ribaudo marked this pull request as ready for review June 4, 2020 23:06
@babel-bot
Copy link
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/24241/

Copy link
Contributor

@arcanis arcanis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm - for what it's worth, we also use the Babel repo as part of our E2E tests for the n-m linker, so that should help ensure that this setup will always work.

@nicolo-ribaudo
Copy link
Member Author

⚠️ Use "rebase and merge", it will make it easier to fix conflicts

NOTE: When rebasing, this commit can cause a lot of conflicts.
You can run this script (choose the correct one) in the monorepo
root to automatically fix them.
nicolo-ribaudo added a commit to nicolo-ribaudo/babel that referenced this pull request Jun 21, 2020
* Update husky
* Update Makefile
* Update CI config
* Update e2e and utils bash scripts
* Patch lerna
* Directly spawn node. This won't work with PnP
* Don't make lerna ignore codemods and eslint packages
* Add yarn.lock
* Use process.execPath
* Updates the e2e upgrade
* Updates build
* Update e2e old babel
* Fix e2e babel old
* Simplify e2e old babel script
* Update lockfile
* Update preset-env fixtures
* Remove nested lock files
* Fix codesandbox
* Update husky
* Update Makefile
* Update CI config
* Update e2e and utils bash scripts
* Patch lerna
* Directly spawn node. This won't work with PnP
* Don't make lerna ignore codemods and eslint packages
* Add yarn.lock
* Use process.execPath
* Updates the e2e upgrade
* Updates build
* Update e2e old babel
* Fix e2e babel old
* Simplify e2e old babel script
* Update lockfile
* Update preset-env fixtures
* Remove nested lock files
* Fix codesandbox
@babel babel deleted a comment from babel-bot Jun 21, 2020
@babel babel deleted a comment from babel-bot Jun 21, 2020
@babel babel deleted a comment from babel-bot Jun 21, 2020
@nicolo-ribaudo
Copy link
Member Author

I'm counting @arcanis's review for our two-:white_check_mark: policy, since as a Yarn maintainer he is one of the most qualified people out there to review this PR!

@nicolo-ribaudo nicolo-ribaudo merged commit e4604da into babel:next-8-dev Jun 21, 2020
nicolo-ribaudo added a commit that referenced this pull request Jun 21, 2020
NOTE: When rebasing, this commit can cause a lot of conflicts.
You can run this script (choose the correct one) in the monorepo
root to automatically fix them.
@nicolo-ribaudo nicolo-ribaudo deleted the yarn-2-compat branch June 21, 2020 20:22
nicolo-ribaudo added a commit that referenced this pull request Jun 21, 2020
NOTE: When rebasing, this commit can cause a lot of conflicts.
You can run this script (choose the correct one) in the monorepo
root to automatically fix them.
nicolo-ribaudo added a commit that referenced this pull request Jun 21, 2020
* Update husky
* Update Makefile
* Update CI config
* Update e2e and utils bash scripts
* Patch lerna
* Directly spawn node. This won't work with PnP
* Don't make lerna ignore codemods and eslint packages
* Add yarn.lock
* Use process.execPath
* Updates the e2e upgrade
* Updates build
* Update e2e old babel
* Fix e2e babel old
* Simplify e2e old babel script
* Update lockfile
* Update preset-env fixtures
* Remove nested lock files
* Fix codesandbox
@kachkaev
Copy link

As of now, CONTRIBUTING.md on next-8-dev and next-8-rebased still says:

Yarn: Make sure that Yarn 1 is installed with version >= 1.19.0.

Should the instructions be changed in a follow-up PR? The doc should probably include tips on how to use yarn2 without uninstalling yarn1 because this is what most devs are still using.

@merceyz
Copy link
Contributor

merceyz commented Jun 21, 2020

how to use yarn2 without uninstalling yarn1 because this is what most devs are still using.

Yarn will shell out to the local version in the repository so that isn't an issue.

@arcanis
Copy link
Contributor

arcanis commented Jun 21, 2020

The documentation is still up to date - as of this PR the Yarn version is stored within the repository, external contributors only need a global Yarn, regardless of its version.

nicolo-ribaudo added a commit that referenced this pull request Jul 5, 2020
NOTE: When rebasing, this commit can cause a lot of conflicts.
You can run this script (choose the correct one) in the monorepo
root to automatically fix them.
nicolo-ribaudo added a commit that referenced this pull request Jul 5, 2020
* Update husky
* Update Makefile
* Update CI config
* Update e2e and utils bash scripts
* Patch lerna
* Directly spawn node. This won't work with PnP
* Don't make lerna ignore codemods and eslint packages
* Add yarn.lock
* Use process.execPath
* Updates the e2e upgrade
* Updates build
* Update e2e old babel
* Fix e2e babel old
* Simplify e2e old babel script
* Update lockfile
* Update preset-env fixtures
* Remove nested lock files
* Fix codesandbox
@JLHwung JLHwung mentioned this pull request Aug 14, 2020
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Sep 21, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Dependency ⬆️
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants