Skip to content

Commit

Permalink
Update to Yarn 4 (#16069)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolò Ribaudo <hello@nicr.dev>
  • Loading branch information
JLHwung and nicolo-ribaudo committed Nov 14, 2023
1 parent 5e1c5f0 commit 76d2dcd
Show file tree
Hide file tree
Showing 16 changed files with 5,101 additions and 5,072 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
cache: "yarn"
- name: 'Check or update Yarn cache (fix w/ "yarn install")'
env:
YARN_ENABLE_HARDENED_MODE: true # enable hardened mode as CI may run on untrusted repos
YARN_ENABLE_SCRIPTS: false # disable post-install scripts
YARN_NODE_LINKER: pnp # use pnp linker for better linking performance: it's meant to update yarn cache only
run: |
Expand Down Expand Up @@ -307,6 +308,8 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
env:
YARN_IGNORE_NODE: 1
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/e2e-tests-breaking-esm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: "*"
- name: Get yarn3 cache directory path
id: yarn3-cache-dir-path
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Use yarn1 cache
uses: actions/cache@v3
Expand All @@ -79,17 +79,17 @@ jobs:
path: ${{ steps.yarn1-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn1-e2e-breaking-${{ matrix.project }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn1-e2e-breaking-${{ matrix.project }}-
- name: Use yarn3 cache
- name: Use yarn cache
uses: actions/cache@v3
id: yarn3-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn3-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn3-e2e-breaking-${{ matrix.project }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn3-e2e-breaking-${{ matrix.project }}-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-e2e-breaking-${{ matrix.project }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn-e2e-breaking-${{ matrix.project }}-
- name: Clean babel cache
run: |
rm -rf ${{ steps.yarn1-cache-dir-path.outputs.dir }}/*babel*
rm -rf ${{ steps.yarn3-cache-dir-path.outputs.dir }}/*babel*
rm -rf ${{ steps.yarn-cache-dir-path.outputs.dir }}/*babel*
- uses: actions/download-artifact@v3
with:
name: verdaccio-workspace
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: "*"
- name: Get yarn3 cache directory path
id: yarn3-cache-dir-path
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Use yarn1 cache
uses: actions/cache@v3
Expand All @@ -72,17 +72,17 @@ jobs:
path: ${{ steps.yarn1-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn1-e2e-${{ matrix.project }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn1-e2e-${{ matrix.project }}-
- name: Use yarn3 cache
- name: Use yarn cache
uses: actions/cache@v3
id: yarn3-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn3-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn3-e2e-${{ matrix.project }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn3-e2e-${{ matrix.project }}-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-e2e-${{ matrix.project }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn-e2e-${{ matrix.project }}-
- name: Clean babel cache
run: |
rm -rf ${{ steps.yarn1-cache-dir-path.outputs.dir }}/*babel*
rm -rf ${{ steps.yarn3-cache-dir-path.outputs.dir }}/*babel*
rm -rf ${{ steps.yarn-cache-dir-path.outputs.dir }}/*babel*
- uses: actions/download-artifact@v3
with:
name: verdaccio-workspace
Expand Down
78 changes: 39 additions & 39 deletions .yarn/plugins/@yarnpkg/plugin-babel-release-tool.cjs

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions .yarn/plugins/@yarnpkg/plugin-conditions.cjs

Large diffs are not rendered by default.

52 changes: 0 additions & 52 deletions .yarn/plugins/@yarnpkg/plugin-constraints.cjs

This file was deleted.

874 changes: 0 additions & 874 deletions .yarn/releases/yarn-3.6.2.cjs

This file was deleted.

893 changes: 893 additions & 0 deletions .yarn/releases/yarn-4.0.2.cjs

Large diffs are not rendered by default.

114 changes: 68 additions & 46 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
compressionLevel: mixed

conditions:
BABEL_8_BREAKING:
default: false
Expand All @@ -6,78 +8,98 @@ conditions:

enableGlobalCache: true

enableTransparentWorkspaces: false
# Disable hardened mode. The Hardened mode will be run in the prepare-yarn-cache CI job.
enableHardenedMode: false

# Disable postinstall scripts.
enableScripts: false

nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-babel-release-tool.cjs
spec: "https://raw.githubusercontent.com/nicolo-ribaudo/yarn-plugin-babel-release-tool/main/bundles/%40yarnpkg/plugin-babel-release-tool.js"
- path: .yarn/plugins/@yarnpkg/plugin-conditions.cjs
spec: "https://raw.githubusercontent.com/nicolo-ribaudo/yarn-plugin-conditions/main/bundles/%40yarnpkg/plugin-conditions.js"
- path: .yarn/plugins/@yarnpkg/plugin-constraints.cjs
spec: "@yarnpkg/plugin-constraints"

releaseTool:
ignoreChanges:
- "*.md"
- "*.txt"
- test/**
- "**/test/**"
- codemods/**
- "@(!(native-modules|built-ins|plugins|package|corejs2-built-ins|corejs3-shipped-proposals|plugins-bugfixes)).json"
implicitDependencies:
"@babel/runtime":
- "@babel/helpers"
"@babel/runtime-corejs2":
- "@babel/helpers"
"@babel/runtime-corejs3":
- "@babel/helpers"
enableTransparentWorkspaces: false

unsafeHttpWhitelist:
- localhost
nodeLinker: node-modules

packageExtensions:
# @babel/preset-env depends on all these packages using the condition:
# protocol, which does not properly propagate peer dependency requirements.
# We know that we have the correct Babel version in the monorepo, so let's
# just remove the peerDependency requirement to silence the warning.
"@babel/plugin-proposal-private-property-in-object@*":
peerDependencies: { "@babel/core": null }
peerDependencies:
"@babel/core": null
"@babel/plugin-syntax-async-generators@*":
peerDependencies: { "@babel/core": null }
peerDependencies:
"@babel/core": null
"@babel/plugin-syntax-class-properties@*":
peerDependencies: { "@babel/core": null }
peerDependencies:
"@babel/core": null
"@babel/plugin-syntax-class-static-block@*":
peerDependencies: { "@babel/core": null }
peerDependencies:
"@babel/core": null
"@babel/plugin-syntax-dynamic-import@*":
peerDependencies: { "@babel/core": null }
peerDependencies:
"@babel/core": null
"@babel/plugin-syntax-export-namespace-from@*":
peerDependencies: { "@babel/core": null }
peerDependencies:
"@babel/core": null
"@babel/plugin-syntax-import-meta@*":
peerDependencies: { "@babel/core": null }
peerDependencies:
"@babel/core": null
"@babel/plugin-syntax-json-strings@*":
peerDependencies: { "@babel/core": null }
peerDependencies:
"@babel/core": null
"@babel/plugin-syntax-logical-assignment-operators@*":
peerDependencies: { "@babel/core": null }
peerDependencies:
"@babel/core": null
"@babel/plugin-syntax-nullish-coalescing-operator@*":
peerDependencies: { "@babel/core": null }
peerDependencies:
"@babel/core": null
"@babel/plugin-syntax-numeric-separator@*":
peerDependencies: { "@babel/core": null }
peerDependencies:
"@babel/core": null
"@babel/plugin-syntax-object-rest-spread@*":
peerDependencies: { "@babel/core": null }
peerDependencies:
"@babel/core": null
"@babel/plugin-syntax-optional-catch-binding@*":
peerDependencies: { "@babel/core": null }
peerDependencies:
"@babel/core": null
"@babel/plugin-syntax-optional-chaining@*":
peerDependencies: { "@babel/core": null }
peerDependencies:
"@babel/core": null
"@babel/plugin-syntax-private-property-in-object@*":
peerDependencies: { "@babel/core": null }
peerDependencies:
"@babel/core": null
"@babel/plugin-syntax-top-level-await@*":
peerDependencies: { "@babel/core": null }
peerDependencies:
"@babel/core": null
"@babel/plugin-syntax-unicode-sets-regex@*":
peerDependencies: { "@babel/core": null }
peerDependencies:
"@babel/core": null

plugins:
- checksum: 0f9f9afc8fdd7275b8c61b00ae8e74f7c23ac91533bacd242cc9478f6d20792335145d9b68abe8d01b6e50844bbb6a777097cc85973990fe4badf2c9a2b6ae11
path: .yarn/plugins/@yarnpkg/plugin-babel-release-tool.cjs
spec: "https://raw.githubusercontent.com/nicolo-ribaudo/yarn-plugin-babel-release-tool/main/bundles/%40yarnpkg/plugin-babel-release-tool.js"
- checksum: 6cf6890a3e6d1f062f554975b176684bc580b2e8b2f708dc29b80a7f6c9ba28f6df205348fa9e0b007cb2f50c447aadbead1374385e302c0ac5d728b1de0de92
path: .yarn/plugins/@yarnpkg/plugin-conditions.cjs
spec: "https://raw.githubusercontent.com/nicolo-ribaudo/yarn-plugin-conditions/main/bundles/%40yarnpkg/plugin-conditions.js"

releaseTool:
ignoreChanges:
- "*.md"
- "*.txt"
- test/**
- "**/test/**"
- codemods/**
- "@(!(native-modules|built-ins|plugins|package|corejs2-built-ins|corejs3-shipped-proposals|plugins-bugfixes)).json"
implicitDependencies:
"@babel/runtime":
- "@babel/helpers"
"@babel/runtime-corejs2":
- "@babel/helpers"
"@babel/runtime-corejs3":
- "@babel/helpers"

unsafeHttpWhitelist:
- localhost

yarnPath: .yarn/releases/yarn-3.6.2.cjs
yarnPath: .yarn/releases/yarn-4.0.2.cjs
15 changes: 0 additions & 15 deletions constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,6 @@ gen_enforced_dependency(WorkspaceCwd, DependencyIdent, null, 'devDependencies')
workspace_has_dependency(WorkspaceCwd, DependencyIdent, _, 'devDependencies'),
workspace_has_dependency(WorkspaceCwd, DependencyIdent, _, 'dependencies').

% Enforces `exports` to be consistent
gen_enforced_field(WorkspaceCwd, 'exports', '{ ".": "./lib/index.js", "./package.json": "./package.json" }') :-
\+ workspace_field(WorkspaceCwd, 'private', true),
% Exclude packages with more complex `exports`
workspace_ident(WorkspaceCwd, WorkspaceIdent),
WorkspaceIdent \= '@babel/compat-data',
WorkspaceIdent \= '@babel/helper-plugin-test-runner', % TODO: Remove in Babel 8
WorkspaceIdent \= '@babel/core', % TODO: Remove in Babel 8
WorkspaceIdent \= '@babel/parser',
WorkspaceIdent \= '@babel/plugin-transform-react-jsx', % TODO: Remove in Babel 8
WorkspaceIdent \= '@babel/standalone',
WorkspaceIdent \= '@babel/types', % @babel/types has types exports
\+ atom_concat('@babel/eslint-', _, WorkspaceIdent),
\+ atom_concat('@babel/runtime', _, WorkspaceIdent).

% Enforces the type field to be set
gen_enforced_field(WorkspaceCwd, 'type', 'commonjs') :-
\+ workspace_field(WorkspaceCwd, 'type', 'module').
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"test:runtime:bundlers": "node test/runtime-integration/bundlers.cjs",
"test:runtime:node": "node test/runtime-integration/node.cjs"
},
"packageManager": "yarn@3.6.2",
"packageManager": "yarn@4.0.2",
"devDependencies": {
"$repo-utils": "link:./scripts/repo-utils",
"@babel/cli": "8.0.0-alpha.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-code-frame/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"main": "./lib/index.js",
"dependencies": {
"@babel/highlight": "workspace:^",
"chalk": "condition:BABEL_8_BREAKING ? ^5.3.0 : ^2.4.2 (esm:default,Chalk)"
"chalk": "condition:BABEL_8_BREAKING ? ^5.3.0 : ^2.4.2 (esm:default|Chalk)"
},
"devDependencies": {
"import-meta-resolve": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-highlight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"main": "./lib/index.js",
"dependencies": {
"@babel/helper-validator-identifier": "workspace:^",
"chalk": "condition:BABEL_8_BREAKING ? ^5.3.0 : ^2.4.2 (esm:default,Chalk)",
"chalk": "condition:BABEL_8_BREAKING ? ^5.3.0 : ^2.4.2 (esm:default|Chalk)",
"js-tokens": "condition:BABEL_8_BREAKING ? ^8.0.0 : ^4.0.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions scripts/integration-tests/e2e-prettier.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ source utils/cleanup.sh
set -x

# Clone prettier
git clone --depth=1 https://github.com/prettier/prettier tmp/prettier
cd tmp/prettier || exit
git clone --depth=1 https://github.com/prettier/prettier /tmp/prettier
cd /tmp/prettier || exit

# Update @babel/* dependencies
node "$root/utils/bump-babel-dependencies.js"
Expand Down
52 changes: 52 additions & 0 deletions yarn.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
% Enforces `exports` to be consistent
gen_enforced_field(WorkspaceCwd, 'exports', '{ ".": "./lib/index.js", "./package.json": "./package.json" }') :-
\+ workspace_field(WorkspaceCwd, 'private', true),
% Exclude packages with more complex `exports`
workspace_ident(WorkspaceCwd, WorkspaceIdent),
WorkspaceIdent \= '@babel/compat-data',
WorkspaceIdent \= '@babel/helper-plugin-test-runner', % TODO: Remove in Babel 8
WorkspaceIdent \= '@babel/core', % TODO: Remove in Babel 8
WorkspaceIdent \= '@babel/parser',
WorkspaceIdent \= '@babel/plugin-transform-react-jsx', % TODO: Remove in Babel 8
WorkspaceIdent \= '@babel/standalone',
WorkspaceIdent \= '@babel/types', % @babel/types has types exports
\+ atom_concat('@babel/eslint-', _, WorkspaceIdent),
\+ atom_concat('@babel/runtime', _, WorkspaceIdent).
*/

function enforcePackageExports({ Yarn }) {
for (const workspace of Yarn.workspaces()) {
if (workspace.manifest.private) continue;
// Exclude packages with more complex `exports`
const packageName = workspace.pkg.ident;
if (
[
"@babel/compat-data",
"@babel/helper-plugin-test-runner", // TODO: Remove in Babel 8
"@babel/core", // TODO: Remove in Babel 8
"@babel/parser",
"@babel/plugin-transform-react-jsx", // TODO: Remove in Babel 8
"@babel/standalone",
"@babel/types", // @babel/types has types exports
].includes(packageName) ||
packageName.startsWith("@babel/eslint-") ||
packageName.startsWith("@babel/runtime")
) {
continue;
}

const desiredExports = {
".": "./lib/index.js",
"./package.json": "./package.json",
};

workspace.set("exports", desiredExports);
}
}

module.exports = {
constraints: async ctx => {
enforcePackageExports(ctx);
},
};

0 comments on commit 76d2dcd

Please sign in to comment.