Skip to content

Commit 0b61791

Browse files
KemingHewei
andauthored
πŸ”§ Migration from yarn to pnpm (#433)
* πŸ”§ Full migration from yarn to pnpm as packageManager Updated all GitHub Action scripts, husky hooks, package.json, Playwright config, Dockerfile, and README.md * πŸ’š Added pnpm setup to actions workflow per official docs * πŸ‘· Update pnpm usage in CI * πŸ‘· Update pnpm usage in docker * πŸ“ Update changeset --------- Co-authored-by: Wei He <[email protected]>
1 parent 29f583d commit 0b61791

File tree

12 files changed

+5261
-4317
lines changed

12 files changed

+5261
-4317
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"socialify": patch
3+
---
4+
5+
Migrated from yarn to pnpm package manager
6+
Updated scripts, hooks, and README.md
7+
Update Dockerfile

β€Ž.github/dependabot.ymlβ€Ž

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
# To get started with Dependabot version updates, you'll need to specify which
2-
# package ecosystems to update and where the package manifests are located.
3-
# Please see the documentation for all configuration options:
4-
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5-
61
version: 2
72
updates:
8-
- package-ecosystem: "npm" # See documentation for possible values
9-
directory: "/" # Location of package manifests
3+
- package-ecosystem: "npm"
4+
directory: "/"
105
schedule:
11-
interval: "weekly"
6+
interval: "daily"
127
commit-message:
138
prefix: "⬆️"
149
- package-ecosystem: "github-actions"
1510
directory: "/"
1611
schedule:
1712
interval: "weekly"
13+
- package-ecosystem: "docker"
14+
directory: "/"
15+
schedule:
16+
interval: "weekly"

β€Ž.github/workflows/build.ymlβ€Ž

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,23 @@ jobs:
1818
- name: Checkout repo
1919
uses: actions/checkout@v4
2020

21+
- name: Setup pnpm
22+
uses: pnpm/action-setup@v4
23+
2124
- name: Setup node
2225
uses: actions/setup-node@v4
2326
with:
24-
node-version: 22.x
25-
cache: 'yarn'
27+
node-version-file: .nvmrc
28+
cache: 'pnpm'
2629

2730
- name: Install dependencies
28-
run: yarn install --frozen-lockfile
31+
run: pnpm install
2932

3033
- name: Lint
31-
run: yarn lint
34+
run: pnpm lint
3235

3336
- name: Unit Test
34-
run: yarn test:unit
37+
run: pnpm test:unit
3538

3639
- name: Build
37-
run: yarn build
40+
run: pnpm build

β€Ž.github/workflows/e2e.ymlβ€Ž

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ jobs:
2222
- name: Checkout repo
2323
uses: actions/checkout@v4
2424

25+
- name: Setup pnpm
26+
uses: pnpm/action-setup@v4
27+
2528
- name: Setup node
2629
uses: actions/setup-node@v4
2730
with:
28-
node-version: 22.x
29-
cache: 'yarn'
31+
node-version-file: .nvmrc
32+
cache: 'pnpm'
3033

3134
- name: Install dependencies
32-
run: yarn install --frozen-lockfile
35+
run: pnpm install
3336

3437
- name: Get Playwright's Version
3538
shell: bash # necessary for it to work on Windows, which uses powershell by default
@@ -45,11 +48,11 @@ jobs:
4548
key: ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.PLAYWRIGHT_VERSION }}
4649

4750
- name: Install Playwrigtht dependencies
48-
run: yarn playwright install --with-deps chromium
51+
run: pnpm playwright install --with-deps chromium
4952
if: steps.playwright-cache.outputs.cache-hit != 'true'
5053

5154
- name: E2E Test
52-
run: yarn test:e2e
55+
run: pnpm test:e2e
5356
env:
5457
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5558
PROJECT_URL: http://127.0.0.1:3000

β€Ž.github/workflows/release.ymlβ€Ž

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ jobs:
1515
- name: Checkout Repo
1616
uses: actions/checkout@v4
1717

18+
- name: Setup pnpm
19+
uses: pnpm/action-setup@v4
20+
1821
- name: Setup Node.js
1922
uses: actions/setup-node@v4
2023
with:
21-
node-version: 22.x
24+
node-version-file: .nvmrc
25+
cache: 'pnpm'
2226

2327
- name: Install Dependencies
24-
run: yarn
28+
run: pnpm install
2529

2630
- name: Create Release Pull Request
2731
uses: changesets/action@v1

β€Ž.husky/pre-commitβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
yarn verify
1+
pnpm verify

β€ŽDockerfileβ€Ž

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
1-
FROM node:22-alpine AS base
2-
31
# Stage 1: Install dependencies
4-
FROM base AS deps
5-
WORKDIR /app
6-
COPY package.json yarn.lock ./
7-
# postinstall script requires a public directory
8-
RUN mkdir -p /app/public && \
9-
yarn install --frozen-lockfile
10-
11-
# Stage 2: Build the application
12-
FROM base AS builder
2+
FROM node:22-alpine AS deps
133

4+
ENV PNPM_HOME="/pnpm"
5+
ENV PATH="$PNPM_HOME:$PATH"
146
ENV NODE_ENV=production
157
ENV CI=true
16-
ENV NEXT_TELEMETRY_DISABLED=1
178

189
WORKDIR /app
1910

20-
COPY --from=deps /app/node_modules ./node_modules
11+
COPY package.json pnpm-lock.yaml ./
12+
RUN corepack enable && \
13+
pnpm fetch --prod && \
14+
pnpm install -r --offline --prod
15+
16+
17+
# Stage 2: Build the application
18+
FROM deps AS builder
19+
20+
ENV NEXT_TELEMETRY_DISABLED=1
21+
22+
RUN pnpm fetch --dev && \
23+
pnpm install -r --offline --dev --prod
2124
COPY . .
22-
COPY --from=deps /app/public ./public
25+
RUN pnpm build
2326

24-
RUN yarn build
2527

2628
# Stage 3: Prepare the production image
27-
FROM base AS runner
29+
FROM gcr.io/distroless/nodejs22-debian12 AS runner
2830

2931
ENV GITHUB_TOKEN=
3032
ENV PROJECT_URL=http://localhost:3000
@@ -37,16 +39,12 @@ ENV NEXT_TELEMETRY_DISABLED=1
3739

3840
WORKDIR /app
3941

40-
# Copy only the necessary files and install production dependencies
41-
COPY package.json yarn.lock ./
42-
RUN mkdir -p /app/public && \
43-
yarn install --production --frozen-lockfile && \
44-
yarn cache clean
45-
42+
COPY package.json ./
43+
COPY --from=deps /app/node_modules ./node_modules
4644
COPY --from=builder /app/.next ./.next
4745
COPY --from=builder /app/public ./public
4846
COPY --from=builder /app/next.config.js /app/custom-rewrites.js ./
4947

5048
EXPOSE 3000
5149

52-
CMD ["yarn", "start"]
50+
CMD ["./node_modules/next/dist/bin/next", "start"]

β€ŽREADME.mdβ€Ž

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,38 +70,38 @@ git clone https://github.com/wei/socialify.git && cd $_
7070
cp .env.example .env
7171

7272
# Install dependencies
73-
yarn install
73+
pnpm install
7474

7575
# Start local development server
76-
yarn dev
76+
pnpm dev
7777
```
7878

7979
### Testing and Committing
8080

81-
Socialify uses [`biomejs`](https://biomejs.dev/) as linter/formatter, [`Jest`](https://jestjs.io/) for unit testing, and [`Playwright`](https://playwright.dev/) for end-to-end testing.
81+
Socialify uses [`biomejs`](https://biomejs.dev/) as linter/formatter, [`Jest`](https://jestjs.io/) for unit testing, and [`Playwright`](https://playwright.dev/) for end-to-end testing.
8282

8383
Make sure to run and pass the linter, unit and end-to-end tests locally before committing your code. Please let us know in case you need to update the test snapshots. More in `"scripts"` section in your `package.json` file.
8484

8585
```shell
8686
# Run linter/formatter
87-
yarn lint # yarn lint:fix
87+
pnpm lint
8888

8989
# Fix linter/formatter errors
90-
# yarn lint:fix
90+
# pnpm lint:fix
9191

9292
# Run unit tests
93-
yarn test:unit
93+
pnpm test:unit
9494

9595
# Install Playwright dependencies (first-time)
96-
# yarn playwright install --with-deps chrome
96+
# pnpm playwright install --with-deps chrome
9797

9898
# Run e2e tests
99-
yarn test:e2e
99+
pnpm test:e2e
100100
```
101101

102102
**One** changeset file is required per each PR.
103103

104-
1. Run `yarn changeset` and select the appropriate senmantic versioning type (major, minor, patch) based on the scope of the change, together with an concise message.
104+
1. Run `pnpm changeset` and select the appropriate senmantic versioning type (major, minor, patch) based on the scope of the change, together with an concise message.
105105
2. You will see a new markdown file with a silly name like `milk-honey-eggs.md` in the `.changeset` directory.
106106
3. Test, commit, and push your code **WITH** this changeset file when submitting a new PR.
107107
4. You can manually edit it to include more information. For example:

β€Žpackage.jsonβ€Ž

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
"test:unit:update-snapshot": "jest -u",
1515
"test:e2e": "playwright test",
1616
"test:e2e:update-snapshot": "playwright test --update-snapshots",
17-
"test": "yarn test:unit && yarn test:e2e",
17+
"test": "pnpm test:unit && pnpm test:e2e",
1818
"start": "next start",
1919
"lint": "biome ci --max-diagnostics=999 .",
2020
"lint:fix": "biome check --write --verbose --max-diagnostics=999 .",
2121
"lint:fix-unsafe": "biome check --write-unsafe --verbose --max-diagnostics=999 .",
2222
"ncu": "npx npm-check-updates -u",
23-
"verify": "yarn lint && yarn test && yarn build",
23+
"verify": "pnpm lint && pnpm test && pnpm build",
2424
"download-font": "./fonts/download-font.sh",
25-
"postinstall": "cp ./node_modules/yoga-wasm-web/dist/yoga.wasm ./public/yoga.wasm; cp ./node_modules/@resvg/resvg-wasm/index_bg.wasm ./public/resvg_bg.wasm",
25+
"postinstall": "mkdir -p ./public && cp ./node_modules/yoga-wasm-web/dist/yoga.wasm ./public/yoga.wasm && cp ./node_modules/@resvg/resvg-wasm/index_bg.wasm ./public/resvg_bg.wasm",
2626
"prepare": "is-ci || husky"
2727
},
2828
"engines": {
@@ -51,6 +51,7 @@
5151
"devDependencies": {
5252
"@biomejs/biome": "^1.9.4",
5353
"@changesets/cli": "^2.27.10",
54+
"@jest/types": "^29.6.3",
5455
"@playwright/test": "^1.49.0",
5556
"@testing-library/dom": "^10.4.0",
5657
"@testing-library/jest-dom": "^6.6.3",
@@ -82,5 +83,6 @@
8283
"last 1 firefox version",
8384
"last 1 safari version"
8485
]
85-
}
86+
},
87+
"packageManager": "[email protected]+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c"
8688
}

β€Žplaywright.config.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export default defineConfig({
110110

111111
// Init a new production build and start a local server before running the e2e tests.
112112
webServer: {
113-
command: 'yarn build && yarn start',
113+
command: 'pnpm build && pnpm start',
114114
url: 'http://127.0.0.1:3000',
115115
reuseExistingServer: !process.env.CI,
116116
},

0 commit comments

Comments
Β (0)