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>
This commit is contained in:
Jack 2024-07-30 22:36:19 +02:00 committed by GitHub
parent 47438fa8d1
commit 2720c07664
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 22005 additions and 37181 deletions

View file

@ -1,6 +1,7 @@
name: Monkey CI
env:
PNPM_VERSION: "9.6.0"
NODE_VERSION: "20.16.0"
RECAPTCHA_SITE_KEY: "6Lc-V8McAAAAAJ7s6LGNe7MBZnRiwbsbiWts87aj"
@ -69,34 +70,44 @@ jobs:
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'
steps:
- name: Checkout package-lock
- name: Checkout pnpm-lock
uses: actions/checkout@v4
with:
sparse-checkout: |
package-lock.json
pnpm-lock.yaml
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: ${{ env.PNPM_VERSION }}
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Cache node modules
id: cache-npm
id: cache-pnpm
uses: actions/cache@v4
env:
cache-name: node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('pnpm-lock.yaml') }}
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
- if: ${{ steps.cache-pnpm.outputs.cache-hit != 'true' }}
name: Full checkout
uses: actions/checkout@v4
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
- if: ${{ steps.cache-pnpm.outputs.cache-hit != 'true' }}
name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
- if: ${{ steps.cache-pnpm.outputs.cache-hit != 'true' }}
name: Install dependencies
run: npm install --prefer-offline --no-audit
run: pnpm install
check-pretty:
name: check-pretty
@ -105,22 +116,33 @@ jobs:
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'
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: ${{ env.PNPM_VERSION }}
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Cache node modules
id: cache-npm
id: cache-pnpm
uses: actions/cache@v4
env:
cache-name: node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('pnpm-lock.yaml') }}
- name: Install dependencies
run: npm install --prefer-offline --no-audit
run: pnpm install
- name: Check pretty (backend)
id: check-pretty-be
@ -149,22 +171,33 @@ jobs:
if: needs.pre-ci.outputs.should-build-be == 'true' || needs.pre-ci.outputs.should-build-pkg == 'true'
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: ${{ env.PNPM_VERSION }}
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Cache node modules
id: cache-npm
id: cache-pnpm
uses: actions/cache@v4
env:
cache-name: node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('pnpm-lock.yaml') }}
- name: Install dependencies
run: npm install --prefer-offline --no-audit
run: pnpm install
- name: Check lint
run: npm run lint-be
@ -181,7 +214,9 @@ jobs:
runs-on: ubuntu-latest
if: needs.pre-ci.outputs.should-build-fe == 'true' || needs.pre-ci.outputs.should-build-pkg == 'true'
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
@ -191,17 +226,27 @@ jobs:
working-directory: ./frontend/src/ts/constants
run: mv ./firebase-config-example.ts ./firebase-config.ts && cp ./firebase-config.ts ./firebase-config-live.ts
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: ${{ env.PNPM_VERSION }}
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Cache node modules
id: cache-npm
id: cache-pnpm
uses: actions/cache@v4
env:
cache-name: node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('pnpm-lock.yaml') }}
- name: Install dependencies
run: npm install --prefer-offline --no-audit
run: pnpm install
- name: Check lint
run: npm run lint-fe
@ -219,6 +264,7 @@ jobs:
if: needs.pre-ci.outputs.assets-json == 'true'
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
@ -233,22 +279,33 @@ jobs:
- 'frontend/static/themes/*.json'
- 'frontend/static/challenges/*.json'
- 'frontend/static/layouts/*.json'
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: ${{ env.PNPM_VERSION }}
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Cache node modules
id: cache-npm
id: cache-pnpm
uses: actions/cache@v4
env:
cache-name: node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('pnpm-lock.yaml') }}
- name: Install dependencies
run: npm install --prefer-offline --no-audit
run: pnpm install
- name: Lint JSON
run: npm run pr-check-lint-json
@ -271,23 +328,35 @@ jobs:
runs-on: ubuntu-latest
if: needs.pre-ci.outputs.should-build-pkg == 'true'
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: ${{ env.PNPM_VERSION }}
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Cache node modules
id: cache-npm
id: cache-pnpm
uses: actions/cache@v4
env:
cache-name: node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-build-${{ env.cache-name }}-${{ hashFiles('pnpm-lock.yaml') }}
- name: Install dependencies
run: npm install --prefer-offline --no-audit
run: pnpm install
- name: Check lint
run: npm run lint-pkg

1
.npmrc
View file

@ -1,2 +1,3 @@
engine-strict=true
save-exact=true
save-prefix=''

View file

@ -36,7 +36,8 @@ services:
- ../../:/monkeytype
entrypoint: 'bash -c "echo starting, this may take a while... \
&& cd /monkeytype \
&& npm i --prefer-offline --no-audit \
&& npm i -g pnpm \
&& pnpm i \
&& npm run dev-be"'
volumes:

View file

@ -23,7 +23,8 @@
},
"dependencies": {
"@date-fns/utc": "1.2.0",
"@monkeytype/contracts": "*",
"@monkeytype/contracts": "workspace:*",
"@ts-rest/core": "3.45.2",
"@ts-rest/express": "3.45.2",
"@ts-rest/open-api": "3.45.2",
"bcrypt": "5.1.1",
@ -57,12 +58,13 @@
"swagger-ui-express": "4.3.0",
"ua-parser-js": "0.7.33",
"uuid": "9.0.1",
"winston": "3.6.0"
"winston": "3.6.0",
"zod": "3.23.8"
},
"devDependencies": {
"@monkeytype/eslint-config": "*",
"@monkeytype/shared-types": "*",
"@monkeytype/typescript-config": "*",
"@monkeytype/eslint-config": "workspace:*",
"@monkeytype/shared-types": "workspace:*",
"@monkeytype/typescript-config": "workspace:*",
"@redocly/cli": "1.18.1",
"@types/bcrypt": "5.0.2",
"@types/cors": "2.8.12",

View file

@ -1,23 +1,36 @@
FROM node:20.16.0-alpine3.19 AS builder
FROM node:20.16.0-alpine3.19
##install wget, used by the applyConfig script
RUN apk add wget
WORKDIR /app
#copy
COPY package.json package.json
COPY package-lock.json package-lock.json
COPY pnpm-lock.yaml pnpm-lock.yaml
COPY pnpm-workspace.yaml pnpm-workspace.yaml
COPY turbo.json turbo.json
COPY packages packages
COPY backend backend
#gimme pnpm
RUN npm i -g pnpm
#build
RUN npm ci
RUN pnpm i --frozen-lockfile
RUN npm run build
## remove dev dependencies
RUN npm install --install-strategy=nested --omit=dev --workspace=backend --ignore-scripts
#deploy (install all non-dev dependencies in a single node_module folder)
RUN pnpm deploy --filter backend --prod /prod/backend
## target image
FROM node:20.16.0-alpine3.19
##install wget, used by the applyConfig script
RUN apk add wget
# COPY to target
COPY --from=builder /prod/backend/node_modules /app/backend/node_modules
COPY --from=builder /prod/backend/dist /app/backend/dist
COPY --from=builder /prod/backend/email-templates /app/backend/email-templates
COPY --from=builder /prod/backend/redis-scripts /app/backend/redis-scripts
## to build directory
WORKDIR /app/backend/dist

View file

@ -7,7 +7,8 @@ ENV RECAPTCHA_SITE_KEY=###RECAPTCHA_SITE_KEY###
#COPY
COPY package.json package.json
COPY package-lock.json package-lock.json
COPY pnpm-lock.yaml pnpm-lock.yaml
COPY pnpm-workspace.yaml pnpm-workspace.yaml
COPY turbo.json turbo.json
COPY packages packages
COPY frontend frontend
@ -15,8 +16,11 @@ COPY frontend frontend
COPY docker/frontend/firebase-config-live.ts frontend/src/ts/constants/firebase-config.ts
COPY docker/frontend/firebase-config-live.ts frontend/src/ts/constants/firebase-config-live.ts
#BUILD
RUN npm ci
#gimme pnpm
RUN npm i -g pnpm
#build
RUN pnpm i --frozen-lockfile
RUN npm run build
# COPY to target

View file

@ -6,7 +6,7 @@
- [**Table of Contents**](#table-of-contents)
- [Prerequisites](#prerequisites)
- [Git](#git)
- [NodeJS and NPM](#nodejs-and-npm)
- [NodeJS and PNPM](#nodejs-and-pnpm)
- [Docker (Recommended but Optional)](#docker-recommended-but-optional)
- [Firebase (optional)](#firebase-optional)
- [Config file](#config-file)
@ -31,7 +31,7 @@ This contribution guide is for cases in which you need to test the functionality
Git is optional but we recommend you utilize it. Monkeytype uses the Git source control management (SCM) system for its version control. Assuming you don't have experience typing commands in the command line, we suggest installing [Sourcetree](https://www.sourcetreeapp.com/). You will be able to utilize the power of Git without needing to remember any cryptic commands. Using a Git client such as Sourcetree won't give you access to the full functionality of Git, but provides an easy-to-understand graphical user interface (GUI). Once you have downloaded Sourcetree, run the installer. While installing Sourcetree, keep your eyes peeled for the option to also install Git with Sourcetree. This is the option you will need to look for in order to install Git. **Make sure to click yes in the installer to install Git with Sourcetree.**
### NodeJS and NPM
### NodeJS and PNPM
Currently, the project is using version `20.16.0 LTS`.
@ -39,6 +39,8 @@ If you use `nvm` (if you use Windows, use [nvm-windows](https://github.com/corey
Alternatively, you can navigate to the NodeJS [website](https://nodejs.org/en/) to download it from there.
For package management, we use `pnpm` instead of `npm` or `yarn`. You can install it by running `npm i -g pnpm@9.6.0`. This will install `pnpm` globally on your machine.
### Docker (Recommended but Optional)
You can use docker to run the frontend and backend. This will take care of OS-specific problems but might be a bit more resource-intensive. You can download it from the [Docker website](https://www.docker.com/get-started/#h_installation).
@ -65,7 +67,7 @@ The account system will not let you create an account without a Firebase project
- Click "Generate New Private Key"
- Save as `serviceAccountKey.json` inside the `backend/src/credentials/` directory.
1. Run `npm install -g firebase-tools` to install the Firebase Command Line Interface.
1. Run `pnpm add -g firebase-tools` to install the Firebase Command Line Interface.
1. Run `firebase login` on your terminal to log in to the same Google account you just used to create the project.
1. Within the `frontend` directory, duplicate `.firebaserc_example`, rename the new file to `.firebaserc` and change the project name to the firebase project id you just created.
@ -120,7 +122,7 @@ Its time to run Monkeytype. Just like with the databases, you can run the fronte
### Dependencies (if running manually)
Run `npm i` in the project root to install all dependencies.
Run `pnpm i` in the project root to install all dependencies.
### Both Frontend and Backend

View file

@ -14,7 +14,8 @@ services:
- ../../:/monkeytype
entrypoint: 'bash -c "echo starting, this may take a while... \
&& cd /monkeytype \
&& npm i --prefer-offline --no-audit \
&& npm i -g pnpm \
&& pnpm i \
&& export SERVER_OPEN=false \
&& npm run dev-fe"'

View file

@ -30,9 +30,9 @@
],
"devDependencies": {
"@fortawesome/fontawesome-free": "5.15.4",
"@monkeytype/eslint-config": "*",
"@monkeytype/shared-types": "*",
"@monkeytype/typescript-config": "*",
"@monkeytype/eslint-config": "workspace:*",
"@monkeytype/shared-types": "workspace:*",
"@monkeytype/typescript-config": "workspace:*",
"@types/canvas-confetti": "1.4.3",
"@types/chartjs-plugin-trendline": "1.0.1",
"@types/damerau-levenshtein": "1.0.0",
@ -70,7 +70,8 @@
},
"dependencies": {
"@date-fns/utc": "1.2.0",
"@monkeytype/contracts": "*",
"@monkeytype/contracts": "workspace:*",
"@ts-rest/core": "3.45.2",
"axios": "1.6.4",
"canvas-confetti": "1.5.1",
"chart.js": "3.7.1",
@ -91,8 +92,9 @@
"lz-ts": "1.1.2",
"object-hash": "3.0.0",
"slim-select": "2.8.1",
"stemmer": "2.0.1",
"throttle-debounce": "5.0.2",
"stemmer": "2.0.1"
"zod": "3.23.8"
},
"overrides": {
"madge": {

37114
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -4,6 +4,7 @@
"private": true,
"type": "module",
"scripts": {
"preinstall": "npx only-allow pnpm",
"full-check": "turbo lint ts-check build test validate-json",
"prepare": "husky install",
"pre-commit": "lint-staged",
@ -66,6 +67,7 @@
"husky": "8.0.1",
"knip": "2.19.2",
"lint-staged": "13.2.3",
"only-allow": "1.2.1",
"prettier": "2.5.1",
"release-it": "16.1.4",
"turbo": "2.0.9",
@ -81,11 +83,6 @@
"eslint"
]
},
"workspaces": [
"frontend",
"backend",
"packages/*"
],
"version": "24.31.0",
"packageManager": "npm@10.2.4"
"packageManager": "pnpm@9.6.0"
}

View file

@ -13,8 +13,8 @@
"zod": "3.23.8"
},
"devDependencies": {
"@monkeytype/eslint-config": "*",
"@monkeytype/typescript-config": "*",
"@monkeytype/eslint-config": "workspace:*",
"@monkeytype/typescript-config": "workspace:*",
"chokidar": "3.6.0",
"esbuild": "0.23.0",
"eslint": "8.57.0",

View file

@ -8,11 +8,11 @@
"lint": "eslint \"./**/*.ts\""
},
"dependencies": {
"@monkeytype/contracts": "*"
"@monkeytype/contracts": "workspace:*"
},
"devDependencies": {
"@monkeytype/eslint-config": "*",
"@monkeytype/typescript-config": "*",
"@monkeytype/eslint-config": "workspace:*",
"@monkeytype/typescript-config": "workspace:*",
"rimraf": "5.0.9",
"typescript": "5.5.3",
"eslint": "8.57.0"

21842
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load diff

4
pnpm-workspace.yaml Normal file
View file

@ -0,0 +1,4 @@
packages:
- "frontend"
- "backend"
- "packages/*"