Skip to content

Commit 2720c07

Browse files
Miodecfehmer
andauthored
chore: switch from npm to pnpm (#5690)
* pnpm * v4, pnpm lock * checkout, node setup * cache dir * path, name * store path * name * setup pnpm, get store then check cache * unnecessary if * missing dependencies * fix docker * lock file name * remove prop * wip * fix * reduce image sizes * save exact * correct command * lock --------- Co-authored-by: Christian Fehmer <cfe@sexy-developer.com>
1 parent 47438fa commit 2720c07

15 files changed

Lines changed: 22005 additions & 37181 deletions

File tree

.github/workflows/monkey-ci.yml

Lines changed: 98 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Monkey CI
22

33
env:
4+
PNPM_VERSION: "9.6.0"
45
NODE_VERSION: "20.16.0"
56
RECAPTCHA_SITE_KEY: "6Lc-V8McAAAAAJ7s6LGNe7MBZnRiwbsbiWts87aj"
67

@@ -69,34 +70,44 @@ jobs:
6970
if: needs.pre-ci.outputs.should-build-be == 'true' || needs.pre-ci.outputs.should-build-fe == 'true' || needs.pre-ci.outputs.should-build-pkg == 'true' || needs.pre-ci.outputs.assets-json == 'true'
7071
steps:
7172

72-
- name: Checkout package-lock
73+
- name: Checkout pnpm-lock
7374
uses: actions/checkout@v4
7475
with:
7576
sparse-checkout: |
76-
package-lock.json
77+
pnpm-lock.yaml
78+
79+
- name: Setup pnpm
80+
uses: pnpm/action-setup@v4
81+
with:
82+
version: ${{ env.PNPM_VERSION }}
83+
84+
- name: Get pnpm store directory
85+
shell: bash
86+
run: |
87+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
7788
7889
- name: Cache node modules
79-
id: cache-npm
90+
id: cache-pnpm
8091
uses: actions/cache@v4
8192
env:
8293
cache-name: node-modules
8394
with:
84-
path: ~/.npm
85-
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
95+
path: ${{ env.STORE_PATH }}
96+
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('pnpm-lock.yaml') }}
8697

87-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
98+
- if: ${{ steps.cache-pnpm.outputs.cache-hit != 'true' }}
8899
name: Full checkout
89100
uses: actions/checkout@v4
90101

91-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
102+
- if: ${{ steps.cache-pnpm.outputs.cache-hit != 'true' }}
92103
name: Set up Node.js
93104
uses: actions/setup-node@v4
94105
with:
95106
node-version: ${{ env.NODE_VERSION }}
96107

97-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
108+
- if: ${{ steps.cache-pnpm.outputs.cache-hit != 'true' }}
98109
name: Install dependencies
99-
run: npm install --prefer-offline --no-audit
110+
run: pnpm install
100111

101112
check-pretty:
102113
name: check-pretty
@@ -105,22 +116,33 @@ jobs:
105116
if: needs.pre-ci.outputs.should-build-be == 'true' || needs.pre-ci.outputs.should-build-fe == 'true' || needs.pre-ci.outputs.should-build-pkg == 'true' || needs.pre-ci.outputs.assets-json == 'true'
106117
steps:
107118
- uses: actions/checkout@v4
119+
108120
- name: Set up Node.js
109121
uses: actions/setup-node@v4
110122
with:
111123
node-version: ${{ env.NODE_VERSION }}
112124

125+
- name: Setup pnpm
126+
uses: pnpm/action-setup@v4
127+
with:
128+
version: ${{ env.PNPM_VERSION }}
129+
130+
- name: Get pnpm store directory
131+
shell: bash
132+
run: |
133+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
134+
113135
- name: Cache node modules
114-
id: cache-npm
136+
id: cache-pnpm
115137
uses: actions/cache@v4
116138
env:
117139
cache-name: node-modules
118140
with:
119-
path: ~/.npm
120-
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
141+
path: ${{ env.STORE_PATH }}
142+
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('pnpm-lock.yaml') }}
121143

122144
- name: Install dependencies
123-
run: npm install --prefer-offline --no-audit
145+
run: pnpm install
124146

125147
- name: Check pretty (backend)
126148
id: check-pretty-be
@@ -149,22 +171,33 @@ jobs:
149171
if: needs.pre-ci.outputs.should-build-be == 'true' || needs.pre-ci.outputs.should-build-pkg == 'true'
150172
steps:
151173
- uses: actions/checkout@v4
174+
152175
- name: Set up Node.js
153176
uses: actions/setup-node@v4
154177
with:
155178
node-version: ${{ env.NODE_VERSION }}
156179

180+
- name: Setup pnpm
181+
uses: pnpm/action-setup@v4
182+
with:
183+
version: ${{ env.PNPM_VERSION }}
184+
185+
- name: Get pnpm store directory
186+
shell: bash
187+
run: |
188+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
189+
157190
- name: Cache node modules
158-
id: cache-npm
191+
id: cache-pnpm
159192
uses: actions/cache@v4
160193
env:
161194
cache-name: node-modules
162195
with:
163-
path: ~/.npm
164-
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
196+
path: ${{ env.STORE_PATH }}
197+
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('pnpm-lock.yaml') }}
165198

166199
- name: Install dependencies
167-
run: npm install --prefer-offline --no-audit
200+
run: pnpm install
168201

169202
- name: Check lint
170203
run: npm run lint-be
@@ -181,7 +214,9 @@ jobs:
181214
runs-on: ubuntu-latest
182215
if: needs.pre-ci.outputs.should-build-fe == 'true' || needs.pre-ci.outputs.should-build-pkg == 'true'
183216
steps:
217+
184218
- uses: actions/checkout@v4
219+
185220
- name: Set up Node.js
186221
uses: actions/setup-node@v4
187222
with:
@@ -191,17 +226,27 @@ jobs:
191226
working-directory: ./frontend/src/ts/constants
192227
run: mv ./firebase-config-example.ts ./firebase-config.ts && cp ./firebase-config.ts ./firebase-config-live.ts
193228

229+
- name: Setup pnpm
230+
uses: pnpm/action-setup@v4
231+
with:
232+
version: ${{ env.PNPM_VERSION }}
233+
234+
- name: Get pnpm store directory
235+
shell: bash
236+
run: |
237+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
238+
194239
- name: Cache node modules
195-
id: cache-npm
240+
id: cache-pnpm
196241
uses: actions/cache@v4
197242
env:
198243
cache-name: node-modules
199244
with:
200-
path: ~/.npm
201-
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
245+
path: ${{ env.STORE_PATH }}
246+
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('pnpm-lock.yaml') }}
202247

203248
- name: Install dependencies
204-
run: npm install --prefer-offline --no-audit
249+
run: pnpm install
205250

206251
- name: Check lint
207252
run: npm run lint-fe
@@ -219,6 +264,7 @@ jobs:
219264
if: needs.pre-ci.outputs.assets-json == 'true'
220265
steps:
221266
- uses: actions/checkout@v4
267+
222268
- uses: dorny/paths-filter@v3
223269
id: filter
224270
with:
@@ -233,22 +279,33 @@ jobs:
233279
- 'frontend/static/themes/*.json'
234280
- 'frontend/static/challenges/*.json'
235281
- 'frontend/static/layouts/*.json'
282+
236283
- name: Set up Node.js
237284
uses: actions/setup-node@v4
238285
with:
239286
node-version: ${{ env.NODE_VERSION }}
240287

288+
- name: Setup pnpm
289+
uses: pnpm/action-setup@v4
290+
with:
291+
version: ${{ env.PNPM_VERSION }}
292+
293+
- name: Get pnpm store directory
294+
shell: bash
295+
run: |
296+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
297+
241298
- name: Cache node modules
242-
id: cache-npm
299+
id: cache-pnpm
243300
uses: actions/cache@v4
244301
env:
245302
cache-name: node-modules
246303
with:
247-
path: ~/.npm
248-
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
304+
path: ${{ env.STORE_PATH }}
305+
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('pnpm-lock.yaml') }}
249306

250307
- name: Install dependencies
251-
run: npm install --prefer-offline --no-audit
308+
run: pnpm install
252309

253310
- name: Lint JSON
254311
run: npm run pr-check-lint-json
@@ -271,23 +328,35 @@ jobs:
271328
runs-on: ubuntu-latest
272329
if: needs.pre-ci.outputs.should-build-pkg == 'true'
273330
steps:
331+
274332
- uses: actions/checkout@v4
333+
275334
- name: Set up Node.js
276335
uses: actions/setup-node@v4
277336
with:
278337
node-version: ${{ env.NODE_VERSION }}
279338

339+
- name: Setup pnpm
340+
uses: pnpm/action-setup@v4
341+
with:
342+
version: ${{ env.PNPM_VERSION }}
343+
344+
- name: Get pnpm store directory
345+
shell: bash
346+
run: |
347+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
348+
280349
- name: Cache node modules
281-
id: cache-npm
350+
id: cache-pnpm
282351
uses: actions/cache@v4
283352
env:
284353
cache-name: node-modules
285354
with:
286-
path: ~/.npm
287-
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
355+
path: ${{ env.STORE_PATH }}
356+
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('pnpm-lock.yaml') }}
288357

289358
- name: Install dependencies
290-
run: npm install --prefer-offline --no-audit
359+
run: pnpm install
291360

292361
- name: Check lint
293362
run: npm run lint-pkg

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
engine-strict=true
22
save-exact=true
3+
save-prefix=''

backend/docker/compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ services:
3636
- ../../:/monkeytype
3737
entrypoint: 'bash -c "echo starting, this may take a while... \
3838
&& cd /monkeytype \
39-
&& npm i --prefer-offline --no-audit \
39+
&& npm i -g pnpm \
40+
&& pnpm i \
4041
&& npm run dev-be"'
4142

4243
volumes:

backend/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
},
2424
"dependencies": {
2525
"@date-fns/utc": "1.2.0",
26-
"@monkeytype/contracts": "*",
26+
"@monkeytype/contracts": "workspace:*",
27+
"@ts-rest/core": "3.45.2",
2728
"@ts-rest/express": "3.45.2",
2829
"@ts-rest/open-api": "3.45.2",
2930
"bcrypt": "5.1.1",
@@ -57,12 +58,13 @@
5758
"swagger-ui-express": "4.3.0",
5859
"ua-parser-js": "0.7.33",
5960
"uuid": "9.0.1",
60-
"winston": "3.6.0"
61+
"winston": "3.6.0",
62+
"zod": "3.23.8"
6163
},
6264
"devDependencies": {
63-
"@monkeytype/eslint-config": "*",
64-
"@monkeytype/shared-types": "*",
65-
"@monkeytype/typescript-config": "*",
65+
"@monkeytype/eslint-config": "workspace:*",
66+
"@monkeytype/shared-types": "workspace:*",
67+
"@monkeytype/typescript-config": "workspace:*",
6668
"@redocly/cli": "1.18.1",
6769
"@types/bcrypt": "5.0.2",
6870
"@types/cors": "2.8.12",

docker/backend/Dockerfile

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
1+
FROM node:20.16.0-alpine3.19 AS builder
12

2-
FROM node:20.16.0-alpine3.19
3-
4-
##install wget, used by the applyConfig script
5-
RUN apk add wget
63
WORKDIR /app
74

85
#copy
96
COPY package.json package.json
10-
COPY package-lock.json package-lock.json
7+
COPY pnpm-lock.yaml pnpm-lock.yaml
8+
COPY pnpm-workspace.yaml pnpm-workspace.yaml
119
COPY turbo.json turbo.json
1210
COPY packages packages
1311
COPY backend backend
1412

13+
#gimme pnpm
14+
RUN npm i -g pnpm
15+
1516
#build
16-
RUN npm ci
17+
RUN pnpm i --frozen-lockfile
1718
RUN npm run build
1819

19-
## remove dev dependencies
20-
RUN npm install --install-strategy=nested --omit=dev --workspace=backend --ignore-scripts
20+
#deploy (install all non-dev dependencies in a single node_module folder)
21+
RUN pnpm deploy --filter backend --prod /prod/backend
22+
23+
## target image
24+
FROM node:20.16.0-alpine3.19
25+
26+
##install wget, used by the applyConfig script
27+
RUN apk add wget
28+
29+
# COPY to target
30+
COPY --from=builder /prod/backend/node_modules /app/backend/node_modules
31+
COPY --from=builder /prod/backend/dist /app/backend/dist
32+
COPY --from=builder /prod/backend/email-templates /app/backend/email-templates
33+
COPY --from=builder /prod/backend/redis-scripts /app/backend/redis-scripts
2134

2235
## to build directory
2336
WORKDIR /app/backend/dist

docker/frontend/Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@ ENV RECAPTCHA_SITE_KEY=###RECAPTCHA_SITE_KEY###
77

88
#COPY
99
COPY package.json package.json
10-
COPY package-lock.json package-lock.json
10+
COPY pnpm-lock.yaml pnpm-lock.yaml
11+
COPY pnpm-workspace.yaml pnpm-workspace.yaml
1112
COPY turbo.json turbo.json
1213
COPY packages packages
1314
COPY frontend frontend
1415

1516
COPY docker/frontend/firebase-config-live.ts frontend/src/ts/constants/firebase-config.ts
1617
COPY docker/frontend/firebase-config-live.ts frontend/src/ts/constants/firebase-config-live.ts
1718

18-
#BUILD
19-
RUN npm ci
19+
#gimme pnpm
20+
RUN npm i -g pnpm
21+
22+
#build
23+
RUN pnpm i --frozen-lockfile
2024
RUN npm run build
2125

2226
# COPY to target

0 commit comments

Comments
 (0)