Skip to content

Commit a9c72e9

Browse files
authored
Merge pull request #690 from vintasoftware/migrate-npm-to-pnpm
Migrate from npm to pnpm
2 parents a8e10c2 + 9818580 commit a9c72e9

File tree

10 files changed

+11122
-90
lines changed

10 files changed

+11122
-90
lines changed

.github/workflows/shared-build/action.yml

Lines changed: 90 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,57 @@
11
name: "Shared Build Steps"
22
description: "Shared build steps for main and nightly"
33

4+
outputs:
5+
branch:
6+
description: "Branch name"
7+
sha_short:
8+
description: "Short SHA of HEAD"
9+
SECRET_KEY:
10+
description: "Generated Django secret key"
11+
412
runs:
513
using: "composite"
614
steps:
715
- name: Store branch and latest SHA
816
id: vars
917
shell: bash
1018
run: |
11-
echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
12-
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
19+
echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT
20+
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
21+
1322
- name: Setup Python
1423
uses: actions/setup-python@v5
1524
with:
1625
python-version: "3.12"
17-
- name: Setup Node
26+
27+
- name: Install pnpm
28+
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
29+
with:
30+
run_install: false
31+
32+
- name: Verify pnpm is available
33+
shell: bash
34+
run: |
35+
which pnpm
36+
pnpm --version
37+
38+
- name: Setup Node (with pnpm cache)
1839
uses: actions/setup-node@v4
1940
with:
2041
node-version: "20.13"
21-
- name: Cache node modules
42+
cache: "pnpm"
43+
44+
- name: Cache pnpm store
2245
uses: actions/cache@v4
2346
env:
24-
cache-name: node-modules-cache
47+
cache-name: pnpm-store-cache
2548
with:
26-
path: ~/.npm
49+
path: ~/.pnpm-store
2750
key: build-${{ env.cache-name }}-${{ steps.vars.outputs.branch }}-${{ steps.vars.outputs.sha_short }}
2851
restore-keys: |
29-
build-${{ env.cache-name }}-${{ steps.vars.outputs.branch }}-${{ steps.vars.outputs.sha_short }}
3052
build-${{ env.cache-name }}-${{ steps.vars.outputs.branch }}
3153
build-${{ env.cache-name }}
54+
3255
- name: Cache pip
3356
uses: actions/cache@v4
3457
env:
@@ -37,89 +60,123 @@ runs:
3760
path: ~/.cache/pip
3861
key: build-${{ env.cache-name }}-${{ steps.vars.outputs.branch }}-${{ steps.vars.outputs.sha_short }}
3962
restore-keys: |
40-
build-${{ env.cache-name }}-${{ steps.vars.outputs.branch }}-${{ steps.vars.outputs.sha_short }}
4163
build-${{ env.cache-name }}-${{ steps.vars.outputs.branch }}
4264
build-${{ env.cache-name }}
65+
4366
- run: python -m pip install --upgrade pip
4467
shell: bash
68+
4569
- name: Install Django
46-
run: pip install "django>=4,<5"
70+
run: pip install "django>=5,<6"
4771
shell: bash
72+
4873
- name: Setup testproject
49-
run: django-admin startproject testproject --extension py,json,yml,yaml,toml --name Dockerfile,README.md,.env.example,.gitignore,Makefile --template=.
50-
shell: bash
51-
- run: |
52-
npm update --save
53-
npm update --save-dev
74+
run: django-admin startproject testproject --extension py,json,yml,yaml,toml --name Dockerfile,README.md,.env.example,.gitignore,Makefile,.npmrc --template=.
5475
shell: bash
55-
working-directory: testproject
56-
- run: npm install --no-optional
76+
77+
- name: Install JS dependencies
78+
run: pnpm install --frozen-lockfile
5779
working-directory: testproject
5880
shell: bash
59-
- run: npm dedupe
81+
82+
- name: Deduplicate JS dependencies
83+
run: pnpm dedupe
6084
working-directory: testproject
6185
shell: bash
62-
- run: pip install poetry==2.0.1 --upgrade
86+
87+
- name: Install Poetry
88+
run: pip install poetry==2.0.1 --upgrade
6389
working-directory: testproject
6490
shell: bash
65-
- run: poetry install --with dev --no-root --no-interaction --no-ansi
91+
92+
- name: Poetry install (backend)
93+
run: poetry install --with dev --no-root --no-interaction --no-ansi
6694
working-directory: testproject
6795
shell: bash
68-
- run: cp testproject/settings/local.py.example testproject/settings/local.py
96+
97+
- name: Copy local settings template
98+
run: cp testproject/settings/local.py.example testproject/settings/local.py
6999
working-directory: testproject/backend
70100
shell: bash
71-
- run: cp .env.example .env
101+
102+
- name: Copy .env example
103+
run: cp .env.example .env
72104
working-directory: testproject/backend
73105
shell: bash
74-
- run: poetry run python manage.py makemigrations
106+
107+
- name: Django makemigrations
108+
run: poetry run python manage.py makemigrations
75109
working-directory: testproject/backend
76110
env:
77111
DATABASE_URL: "sqlite:///"
78112
shell: bash
79-
- run: poetry run python manage.py migrate
113+
114+
- name: Django migrate
115+
run: poetry run python manage.py migrate
80116
working-directory: testproject/backend
81117
env:
82118
DATABASE_URL: "sqlite:///"
83119
shell: bash
120+
84121
- name: Generate backend schema
85122
run: poetry run python manage.py spectacular --color --file schema.yml
86123
working-directory: testproject/backend
87124
env:
88125
DATABASE_URL: "sqlite:///"
89126
shell: bash
127+
90128
- name: Generate frontend API client
91-
run: npm run openapi-ts
129+
run: pnpm run openapi-ts
92130
working-directory: testproject
93131
shell: bash
94-
- run: npm run lint
132+
133+
- name: Lint frontend
134+
run: pnpm run lint
95135
working-directory: testproject
96136
shell: bash
97-
- run: npm run build
137+
138+
- name: Build frontend
139+
run: pnpm run build
98140
working-directory: testproject
99141
shell: bash
100-
- run: npm run test
142+
143+
- name: Test frontend
144+
run: pnpm run test
101145
working-directory: testproject
102146
shell: bash
103-
- run: poetry run python manage.py test
147+
148+
- name: Test backend
149+
run: poetry run python manage.py test
104150
working-directory: testproject/backend
105151
env:
106152
DATABASE_URL: "sqlite:///"
107153
shell: bash
154+
108155
- name: Generate secret key
109-
run: echo '::set-output name=SECRET_KEY::`python -c "import uuid; print(uuid.uuid4().hex + uuid.uuid4().hex)"`'
110156
id: secret-id-generator
111157
shell: bash
112-
- run: rm .gitignore # prevents conflict with ruff
158+
run: |
159+
secret=$(python -c "import uuid; print(uuid.uuid4().hex + uuid.uuid4().hex)")
160+
echo "SECRET_KEY=$secret" >> $GITHUB_OUTPUT
161+
162+
- name: Remove .gitignore to prevent ruff conflict
163+
run: rm .gitignore
113164
shell: bash
114-
- run: poetry run ruff check .
165+
166+
- name: Lint backend with ruff
167+
run: poetry run ruff check .
115168
working-directory: testproject/backend
116169
shell: bash
117-
- run: poetry run python manage.py makemigrations --check --dry-run
170+
171+
- name: Check migrations (dry run)
172+
run: poetry run python manage.py makemigrations --check --dry-run
118173
working-directory: testproject/backend
119174
env:
120175
DATABASE_URL: "sqlite:///"
121176
shell: bash
122-
- run: poetry run python manage.py check --deploy --fail-level WARNING
177+
178+
- name: Django deploy checks
179+
run: poetry run python manage.py check --deploy --fail-level WARNING
123180
working-directory: testproject/backend
124181
env:
125182
SECRET_KEY: ${{ steps.secret-id-generator.outputs.SECRET_KEY }}

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shamefully-hoist=true

Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ backend_format:
1717
# Commands for Docker version
1818
docker_setup:
1919
docker volume create {{project_name}}_dbdata
20-
docker compose build --no-cache backend
20+
docker compose build --no-cache backend frontend
2121
docker compose run --rm backend python manage.py spectacular --color --file schema.yml
22-
docker compose run --rm frontend npm install
23-
docker compose run --rm frontend npm run openapi-ts
22+
docker compose run --rm frontend pnpm run openapi-ts
2423

2524
docker_test:
2625
docker compose run --rm backend python manage.py test $(ARG) --parallel --keepdb
@@ -53,5 +52,8 @@ docker_backend_shell:
5352
docker_backend_update_schema:
5453
docker compose run --rm backend python manage.py spectacular --color --file schema.yml
5554

55+
docker_frontend_shell:
56+
docker compose run --rm frontend sh
57+
5658
docker_frontend_update_api:
57-
docker compose run --rm frontend npm run openapi-ts
59+
docker compose run --rm frontend pnpm run openapi-ts

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ Send us an email at contact@vintasoftware.com telling us a bit more about how ou
7676
- [ ] Open the command line and go to the directory you want to start your project in
7777
- [ ] Start your project using (replace `project_name` with your project name and remove the curly braces):
7878
```
79-
django-admin startproject {{project_name}} --extension py,json,yml,yaml,toml --name Dockerfile,README.md,.env.example,.gitignore,Makefile --template=https://github.com/vintasoftware/django-react-boilerplate/archive/refs/heads/main.zip
79+
django-admin startproject {{project_name}} --extension py,json,yml,yaml,toml --name Dockerfile,README.md,.env.example,.gitignore,Makefile,.npmrc --template=https://github.com/vintasoftware/django-react-boilerplate/archive/refs/heads/main.zip
8080
```
8181
Alternatively, you may start the project in the current directory by placing a `.` right after the project name, using the following command:
8282
```
83-
django-admin startproject {{project_name}} . --extension py,json,yml,yaml,toml --name Dockerfile,README.md,.env.example,.gitignore,Makefile --template=https://github.com/vintasoftware/django-react-boilerplate/archive/refs/heads/main.zip
83+
django-admin startproject {{project_name}} . --extension py,json,yml,yaml,toml --name Dockerfile,README.md,.env.example,.gitignore,Makefile,.npmrc --template=https://github.com/vintasoftware/django-react-boilerplate/archive/refs/heads/main.zip
8484
```
8585
In the next steps, always remember to replace {{project_name}} with your project's name (in case it isn't yet):
8686
- [ ] Above: don't forget the `--extension` and `--name` params!
@@ -130,8 +130,8 @@ After completing ALL of the above, remove this `Project bootstrap` section from
130130
131131
- Open a new command line window and go to the project's directory
132132
- Update the dependencies management files by performing any number of the following steps:
133-
- To add a new **frontend** dependency, run `npm install <package name> --save`
134-
> The above command will update your `package.json`, but won't make the change effective inside the container yet
133+
- To add a new **frontend** dependency, run `pnpm add <package name>`
134+
> The above command will update your `package.json` and `pnpm-lock.yaml`, but won't make the change effective inside the container yet
135135
- To add a new **backend** dependency, run `docker compose run --rm backend bash` to open an interactive shell and then run `poetry add {dependency}` to add the dependency. If the dependency should be only available for development user append `-G dev` to the command.
136136
- After updating the desired file(s), run `make docker_update_dependencies` to update the containers with the new dependencies
137137
> The above command will stop and re-build the containers in order to make the new dependencies effective
@@ -164,10 +164,10 @@ After completing ALL of the above, remove this `Project bootstrap` section from
164164
#### Setup and run the frontend app
165165
166166
- Open a new command line window and go to the project's directory
167-
- `npm install`
168-
- `npm run openapi-ts`
167+
- `pnpm install`
168+
- `pnpm run openapi-ts`
169169
- This is used to generate the TypeScript client API code from the backend OpenAPI schema
170-
- `npm run dev`
170+
- `pnpm run dev`
171171
- This is used to serve the frontend assets to be consumed by [django-webpack-loader](https://github.com/django-webpack/django-webpack-loader) and not to run the React application as usual, so don't worry if you try to check what's running on port 3000 and see an error on your browser
172172
- Open a browser and go to `http://localhost:8000` to see the project running
173173
@@ -221,7 +221,7 @@ We use the [`openapi-ts`](https://heyapi.vercel.app/openapi-ts/get-started.html)
221221
>
222222
> To update the client code, run:
223223
> - If you are using Docker: `make docker_frontend_update_api`
224-
> - If you are not using Docker: `npm run openapi-ts`
224+
> - If you are not using Docker: `pnpm run openapi-ts`
225225
226226
> [!NOTE]
227227
> If `pre-commit` is properly enabled, it will automatically update both schema and client before each commit whenever necessary.
@@ -329,7 +329,7 @@ After enabling dyno metadata and setting the environment variables, your next Re
329329
## Linting
330330

331331
- At pre-commit time (see below)
332-
- Manually with `poetry run ruff` and `npm run lint` on project root.
332+
- Manually with `poetry run ruff` and `pnpm run lint` on project root.
333333
- During development with an editor compatible with ruff and ESLint.
334334

335335
## Pre-commit hooks

frontend/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
FROM node:20-alpine
22

33
WORKDIR /app/
4-
ADD package.json /app/package.json
5-
RUN npm install
4+
ADD package.json pnpm-lock.yaml* /app/
5+
RUN corepack enable && corepack prepare pnpm@10 --activate
6+
RUN pnpm install --frozen-lockfile=false
67
ADD . /app/
78

8-
CMD ["npm", "run", "dev"]
9+
CMD ["pnpm", "run", "dev"]

0 commit comments

Comments
 (0)