Skip to content

Commit 8710923

Browse files
authored
chore(yarn) : migrated yarn to modern yarn berry (#842)
* chore(yarn): migrated yarn to modern yarn: version:[email protected] * chore(package.json): add missing peer deps for cypress/coverage * chore(github-actions): updated workflow with corepack to use modern yarn * chore(ci.yml): update workflow to run on push & unauthorised file job to run on pull only * chore(docs): Add docs for corepack for modern yarn * Add corepack in deploy-preview
1 parent b4daf0e commit 8710923

File tree

9 files changed

+10430
-5942
lines changed

9 files changed

+10430
-5942
lines changed

.github/workflows/build-preview.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ jobs:
1818
uses: actions/checkout@v4
1919
with:
2020
submodules: 'recursive'
21+
22+
- name: Corepack enable
23+
run: corepack enable
2124

2225
- name: Get yarn cache directory path
2326
id: yarn-cache-dir-path
24-
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
27+
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
2528

2629
- name: Cache Node dependencies
2730
uses: actions/cache@v4
@@ -48,7 +51,7 @@ jobs:
4851
node-version: 20
4952

5053
- name: Install dependencies
51-
run: yarn install --frozen-lockfile
54+
run: yarn install --immutable
5255

5356
- name: Build Site
5457
run: yarn run build

.github/workflows/ci.yml

+45-54
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: CI
22
on:
33
pull_request:
44
types: [opened, reopened, synchronize]
5+
push:
6+
branches:
7+
- main
58

69
env:
710
CODECOV_UNIQUE_NAME: CODECOV_UNIQUE_NAME-${{ github.run_id }}-${{ github.run_number }}
@@ -13,43 +16,64 @@ jobs:
1316
steps:
1417
- name: Checkout repository
1518
uses: actions/checkout@v4
16-
17-
- name: Get yarn cache directory path
18-
id: yarn-cache-dir-path
19-
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
20-
21-
- name: Cache Node dependencies
22-
uses: actions/cache@v4
23-
id: yarn-cache
24-
with:
25-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
26-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
27-
restore-keys: |
28-
${{ runner.os }}-yarn-
29-
30-
- if: ${{ steps.yarn-cache.outputs.cache-hit != 'true' }}
31-
name: List the state of node modules
32-
continue-on-error: true
33-
run: yarn list
3419

20+
- name: Corepack enable
21+
run: corepack enable
22+
3523
- name: Setup Node.js
3624
uses: actions/setup-node@v4
3725
with:
3826
node-version: 20
27+
cache: 'yarn'
3928

4029
- name: Install dependencies
41-
run: yarn install --frozen-lockfile
42-
30+
run: yarn install --immutable
4331

4432
- name: Linting and Formatting checks
4533
run: yarn run lint
4634

4735
- name: Type checking
4836
run: yarn run typecheck
4937

38+
testing-and-coverage:
39+
name: Testing and Coverage
40+
needs: [code-quality-checks]
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Checkout repository
44+
uses: actions/checkout@v4
45+
with:
46+
submodules: recursive
47+
48+
- name: Corepack enable
49+
run: corepack enable
50+
51+
- name: Setup Node.js
52+
uses: actions/setup-node@v4
53+
with:
54+
node-version: 20
55+
cache: 'yarn'
56+
57+
- name: Install dependencies
58+
run: yarn install --immutable
59+
60+
- name: Run development server
61+
run: yarn run dev &
62+
63+
- name: Run tests and generate coverage report
64+
run: yarn run test:coverage:all
65+
66+
- name: Upload coverage report to Codecov
67+
uses: codecov/[email protected]
68+
with:
69+
token: ${{ secrets.CODECOV_TOKEN }}
70+
name: ${{ env.CODECOV_UNIQUE_NAME }}
71+
verbose: true
72+
fail_ci_if_error: true
73+
5074
check-unauthorized-file-changes:
5175
name: Check Unauthorized File Changes
52-
if: ${{github.actor != 'dependabot[bot]'}}
76+
if: ${{github.actor != 'dependabot[bot]'}} && ${{github.event_name == 'pull_request'}}
5377
runs-on: ubuntu-latest
5478
steps:
5579
- name: Checkout code
@@ -94,36 +118,3 @@ jobs:
94118
echo "$file is unauthorized to change/delete"
95119
done
96120
exit 1
97-
98-
testing-and-coverage:
99-
name: Testing and Coverage
100-
needs: [code-quality-checks]
101-
runs-on: ubuntu-latest
102-
steps:
103-
- name: Checkout repository
104-
uses: actions/checkout@v4
105-
with:
106-
submodules: recursive
107-
108-
- name: Setup Node.js
109-
uses: actions/setup-node@v4
110-
with:
111-
node-version: 20
112-
cache: 'yarn'
113-
114-
- name: Install dependencies
115-
run: yarn install --frozen-lockfile
116-
117-
- name: Run development server
118-
run: yarn run dev &
119-
120-
- name: Run tests and generate coverage report
121-
run: yarn run test:coverage:all
122-
123-
- name: Upload coverage report to Codecov
124-
uses: codecov/codecov-action@v4
125-
with:
126-
token: ${{ secrets.CODECOV_TOKEN }}
127-
name: ${{ env.CODECOV_UNIQUE_NAME }}
128-
verbose: true
129-
fail_ci_if_error: true

.github/workflows/link-checker.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ jobs:
1313
steps:
1414
- name: Checkout Repository
1515
uses: actions/checkout@v4
16+
with:
17+
submodules: 'recursive'
1618

17-
- name: Submodule
18-
run: git submodule update --init --recursive
19+
- name: Corepack enable
20+
run: corepack enable
1921

2022
- name: Set up Node.js
2123
uses: actions/setup-node@v4
@@ -30,8 +32,8 @@ jobs:
3032
private-key: ${{ secrets.PRIVATE_KEY }}
3133

3234
- name: Install Dependencies
33-
run: yarn install --frozen-lockfile
34-
35+
run: yarn install --immutable
36+
3537
- name: Serve App Locally
3638
run: yarn run dev &
3739

.github/workflows/production-deployment.yml

+6-11
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,13 @@ jobs:
1818
uses: actions/checkout@v4
1919
with:
2020
submodules: 'recursive'
21+
22+
- name: Corepack enable
23+
run: corepack enable
2124

2225
- name: Get yarn cache directory path
2326
id: yarn-cache-dir-path
24-
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
25-
26-
- name: Cache Node dependencies
27-
uses: actions/cache@v4
28-
id: yarn-cache
29-
with:
30-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
31-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
32-
restore-keys: |
33-
${{ runner.os }}-yarn-
27+
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
3428

3529
- name: Cache Next Build
3630
uses: actions/cache@v4
@@ -46,9 +40,10 @@ jobs:
4640
uses: actions/setup-node@v4
4741
with:
4842
node-version: 20
43+
cache: 'yarn'
4944

5045
- name: Install dependencies
51-
run: yarn install --frozen-lockfile
46+
run: yarn install --immutable
5247

5348
- name: Build Site
5449
run: yarn run build

.gitignore

+11-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,14 @@ yarn-error.log*
4949
.vscode/*
5050
!.vscode/launch.json
5151

52-
.idea/*
52+
.idea/*
53+
54+
# yarn
55+
.pnp.*
56+
.yarn/*
57+
!.yarn/patches
58+
!.yarn/plugins
59+
!.yarn/releases
60+
!.yarn/sdks
61+
!.yarn/versions
62+

.yarnrc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

README.md

+62
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,68 @@ cp .env.example .env
5252

5353
4. Ensure .env is in your .gitignore.
5454

55+
### Setup Corepack
56+
57+
This project uses modern Yarn ([email protected]), which requires Corepack for proper setup and management of package managers. Corepack is a tool that comes with Node.js 14.19.0 and later, allowing for consistent package manager versions across your project.
58+
59+
#### What is Corepack?
60+
61+
Corepack is an experimental tool to help with managing versions of your package managers. It exposes binary proxies for each supported package manager that, when called, will identify whatever package manager is configured for the current project, download it if needed, and finally run it.
62+
63+
64+
#### Installing Corepack
65+
66+
If you're using Node.js version 14.19.0 or later, Corepack is included but might need to be enabled. For Node.js 16.10 or later, Corepack is available by default but might still need to be enabled.
67+
68+
To enable Corepack, run:
69+
70+
```bash
71+
corepack enable
72+
```
73+
74+
If you're using an older version of Node.js or if the above command doesn't work, you can install Corepack globally using npm:
75+
76+
```bash
77+
npm install -g corepack
78+
```
79+
80+
#### Using Corepack with This Project
81+
82+
Once Corepack is enabled or installed, it will automatically use the correct version of Yarn specified in the project's `package.json` file. You don't need to manually install Yarn.
83+
84+
To use Yarn commands, simply run them as usual:
85+
86+
```bash
87+
yarn install
88+
yarn run build
89+
yarn run dev
90+
```
91+
92+
Corepack will ensure that the correct version of Yarn is used for these commands.
93+
94+
#### Updating Yarn Version
95+
96+
If you need to update the Yarn version used in the project:
97+
98+
1. Update the `packageManager` field in `package.json`:
99+
```json
100+
{
101+
"packageManager": "[email protected]"
102+
}
103+
```
104+
2. Run `yarn set version x.y.z` to update the local Yarn version.
105+
106+
#### Troubleshooting
107+
108+
If you encounter any issues with Yarn commands, try running:
109+
110+
```bash
111+
corepack prepare
112+
```
113+
114+
This will ensure that the correct version of Yarn is downloaded and prepared for use.
115+
116+
For more information about Corepack, refer to the [official Node.js documentation](https://nodejs.org/api/corepack.html).
55117

56118
#### Install dependencies
57119

package.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@
5454
"zustand": "^4.0.0-rc.1"
5555
},
5656
"devDependencies": {
57+
"@babel/core": "^7.25.2",
58+
"@babel/preset-env": "^7.25.3",
5759
"@cypress/code-coverage": "^3.12.44",
5860
"@next/eslint-plugin-next": "^14.0.1",
61+
"@types/babel__core": "^7",
62+
"@types/babel__preset-env": "^7",
5963
"@types/file-saver": "^2.0.7",
6064
"@types/js-yaml": "^4.0.5",
6165
"@types/node": "^20.14.10",
@@ -84,7 +88,8 @@
8488
"postcss": "^8.4.40",
8589
"prettier": "3.3.3",
8690
"tailwindcss": "^3.3.5",
87-
"typescript": "5.2.2"
91+
"typescript": "5.2.2",
92+
"webpack": "^5.93.0"
8893
},
8994
"babel": {
9095
"presets": [
@@ -93,5 +98,6 @@
9398
"plugins": [
9499
"istanbul"
95100
]
96-
}
101+
},
102+
"packageManager": "[email protected]+sha512.91d93b445d9284e7ed52931369bc89a663414e5582d00eea45c67ddc459a2582919eece27c412d6ffd1bd0793ff35399381cb229326b961798ce4f4cc60ddfdb"
97103
}

0 commit comments

Comments
 (0)