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

chore(yarn) : migrated yarn to modern yarn berry #842

Merged
merged 7 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/build-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ jobs:
uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Corepack enable
run: corepack enable

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT

- name: Cache Node dependencies
uses: actions/cache@v4
Expand All @@ -48,7 +51,7 @@ jobs:
node-version: 20

- name: Install dependencies
run: yarn install --frozen-lockfile
run: yarn install --immutable

- name: Build Site
run: yarn run build
Expand Down
99 changes: 45 additions & 54 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: CI
on:
pull_request:
types: [opened, reopened, synchronize]
push:
branches:
- main

env:
CODECOV_UNIQUE_NAME: CODECOV_UNIQUE_NAME-${{ github.run_id }}-${{ github.run_number }}
Expand All @@ -13,43 +16,64 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- name: Cache Node dependencies
uses: actions/cache@v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- if: ${{ steps.yarn-cache.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: yarn list

- name: Corepack enable
run: corepack enable

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'

- name: Install dependencies
run: yarn install --frozen-lockfile

run: yarn install --immutable

- name: Linting and Formatting checks
run: yarn run lint

- name: Type checking
run: yarn run typecheck

testing-and-coverage:
name: Testing and Coverage
needs: [code-quality-checks]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Corepack enable
run: corepack enable

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'

- name: Install dependencies
run: yarn install --immutable

- name: Run development server
run: yarn run dev &

- name: Run tests and generate coverage report
run: yarn run test:coverage:all

- name: Upload coverage report to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: ${{ env.CODECOV_UNIQUE_NAME }}
verbose: true
fail_ci_if_error: true

check-unauthorized-file-changes:
name: Check Unauthorized File Changes
if: ${{github.actor != 'dependabot[bot]'}}
if: ${{github.actor != 'dependabot[bot]'}} && ${{github.event_name == 'pull_request'}}
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand Down Expand Up @@ -94,36 +118,3 @@ jobs:
echo "$file is unauthorized to change/delete"
done
exit 1

testing-and-coverage:
name: Testing and Coverage
needs: [code-quality-checks]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Run development server
run: yarn run dev &

- name: Run tests and generate coverage report
run: yarn run test:coverage:all

- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: ${{ env.CODECOV_UNIQUE_NAME }}
verbose: true
fail_ci_if_error: true
10 changes: 6 additions & 4 deletions .github/workflows/link-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ jobs:
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Submodule
run: git submodule update --init --recursive
- name: Corepack enable
run: corepack enable

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

- name: Install Dependencies
run: yarn install --frozen-lockfile

run: yarn install --immutable
- name: Serve App Locally
run: yarn run dev &

Expand Down
17 changes: 6 additions & 11 deletions .github/workflows/production-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@ jobs:
uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Corepack enable
run: corepack enable

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- name: Cache Node dependencies
uses: actions/cache@v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT

- name: Cache Next Build
uses: actions/cache@v4
Expand All @@ -46,9 +40,10 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'

- name: Install dependencies
run: yarn install --frozen-lockfile
run: yarn install --immutable

- name: Build Site
run: yarn run build
Expand Down
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,14 @@ yarn-error.log*
.vscode/*
!.vscode/launch.json

.idea/*
.idea/*

# yarn
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,68 @@ cp .env.example .env

4. Ensure .env is in your .gitignore.

### Setup Corepack

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.

#### What is Corepack?

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.


#### Installing Corepack

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.

To enable Corepack, run:

```bash
corepack enable
```

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:

```bash
npm install -g corepack
```

#### Using Corepack with This Project

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.

To use Yarn commands, simply run them as usual:

```bash
yarn install
yarn run build
yarn run dev
```

Corepack will ensure that the correct version of Yarn is used for these commands.

#### Updating Yarn Version

If you need to update the Yarn version used in the project:

1. Update the `packageManager` field in `package.json`:
```json
{
"packageManager": "[email protected]"
}
```
2. Run `yarn set version x.y.z` to update the local Yarn version.

#### Troubleshooting

If you encounter any issues with Yarn commands, try running:

```bash
corepack prepare
```

This will ensure that the correct version of Yarn is downloaded and prepared for use.

For more information about Corepack, refer to the [official Node.js documentation](https://nodejs.org/api/corepack.html).

#### Install dependencies

Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@
"zustand": "^4.0.0-rc.1"
},
"devDependencies": {
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.3",
"@cypress/code-coverage": "^3.12.44",
"@next/eslint-plugin-next": "^14.0.1",
"@types/babel__core": "^7",
"@types/babel__preset-env": "^7",
"@types/file-saver": "^2.0.7",
"@types/js-yaml": "^4.0.5",
"@types/node": "^20.14.10",
Expand Down Expand Up @@ -84,7 +88,8 @@
"postcss": "^8.4.40",
"prettier": "3.3.3",
"tailwindcss": "^3.3.5",
"typescript": "5.2.2"
"typescript": "5.2.2",
"webpack": "^5.93.0"
},
"babel": {
"presets": [
Expand All @@ -93,5 +98,6 @@
"plugins": [
"istanbul"
]
}
},
"packageManager": "[email protected]+sha512.91d93b445d9284e7ed52931369bc89a663414e5582d00eea45c67ddc459a2582919eece27c412d6ffd1bd0793ff35399381cb229326b961798ce4f4cc60ddfdb"
}
Loading
Loading