Skip to content

Commit 7cc4ad4

Browse files
authored
chore: migrate to pnpm (#139)
1 parent c78f84b commit 7cc4ad4

8 files changed

Lines changed: 7200 additions & 11699 deletions

File tree

.github/workflows/checks.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,26 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515

16+
- name: Install pnpm
17+
uses: pnpm/action-setup@v4
18+
1619
- name: Setup Node.js
1720
uses: actions/setup-node@v4
1821
with:
1922
node-version: 22
20-
cache: 'npm'
23+
cache: 'pnpm'
2124

2225
- name: Install dependencies
23-
run: npm ci
26+
run: pnpm install --frozen-lockfile
2427

2528
- name: Build
26-
run: npm run build
29+
run: pnpm run build
2730

2831
- name: Lint
29-
run: npm run lint
32+
run: pnpm run lint
3033

3134
- name: Install Playwright
32-
run: npx playwright install firefox --with-deps
35+
run: pnpm exec playwright install firefox --with-deps
3336

3437
- name: Test
35-
run: npm run test
38+
run: pnpm run test

Dockerfile

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,61 @@ FROM apify/actor-node:22 AS builder
66
# override the default working directory set in the base image
77
WORKDIR /home/myuser
88

9-
# Copy just package.json and package-lock.json
9+
# Enable pnpm through Corepack. The base image runs as the non-root `myuser`, and the default
10+
# Corepack shim location (/usr/local/bin) is root-owned, so install the shims into a
11+
# user-writable directory and put it on PATH. The exact pnpm version comes from the
12+
# "packageManager" field in package.json.
13+
ENV PATH=/home/myuser/bin:$PATH
14+
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
15+
RUN mkdir -p /home/myuser/bin && corepack enable --install-directory /home/myuser/bin pnpm
16+
17+
# Copy just package.json, the lockfile, the workspace config and patches
1018
# to speed up the build using Docker layer cache.
11-
COPY --chown=myuser package*.json ./
19+
COPY --chown=myuser package.json pnpm-lock.yaml pnpm-workspace.yaml ./
20+
COPY --chown=myuser patches ./patches
1221

13-
# Install all dependencies. Don't audit to speed up the installation.
14-
RUN npm install --include=dev --audit=false
22+
# The base image ships a preinstalled node_modules. Remove it first so pnpm's isolated layout
23+
# doesn't get confused by a preexisting non-pnpm node_modules. `npm install` used to overwrite it
24+
# implicitly; pnpm does not.
25+
RUN rm -rf node_modules && pnpm install --frozen-lockfile
1526

1627
# Next, copy the source files using the user set
1728
# in the base image.
1829
COPY --chown=myuser . ./
1930

20-
# Install all dependencies and build the project.
21-
# Don't audit to speed up the installation.
22-
RUN npm run build
31+
# Build the project.
32+
RUN pnpm run build
2333

2434
# Build Ghostery blockers for content filtering
25-
RUN npm run build:playwright-blockers
35+
RUN pnpm run build:playwright-blockers
2636

2737
# Create final image
2838
FROM apify/actor-node-playwright-firefox:22-1.55.1
2939

30-
# Copy just package.json and package-lock.json
40+
# Enable pnpm through Corepack (see the builder stage for why we use a custom install directory).
41+
ENV PATH=/home/myuser/bin:$PATH
42+
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
43+
RUN mkdir -p /home/myuser/bin && corepack enable --install-directory /home/myuser/bin pnpm
44+
45+
# Copy just package.json, the lockfile, the workspace config and patches
3146
# to speed up the build using Docker layer cache.
32-
COPY --chown=myuser package*.json ./
47+
COPY --chown=myuser package.json pnpm-lock.yaml pnpm-workspace.yaml ./
3348
COPY --chown=myuser policies.json ./
3449
COPY --chown=myuser patches ./patches
3550

36-
# Install NPM packages, skip development dependencies to keep the image small. Avoid logging too
51+
# Install packages, skip development dependencies to keep the image small. Avoid logging too
3752
# much and print the dependency tree for debugging. Optional dependencies are needed - `impit`
38-
# ships its native bindings as one.
39-
RUN npm --quiet set progress=false \
40-
&& npm install --omit=dev \
41-
&& echo "Installed NPM packages:" \
42-
&& (npm list --omit=dev --all || true) \
53+
# ships its native bindings as one. Remove the base image's preinstalled node_modules first
54+
# (see builder stage).
55+
RUN rm -rf node_modules \
56+
&& pnpm install --prod --frozen-lockfile \
57+
&& echo "Installed packages:" \
58+
&& (pnpm list --prod --depth Infinity || true) \
4359
&& echo "Node.js version:" \
4460
&& node --version \
45-
&& echo "NPM version:" \
46-
&& npm --version \
47-
&& rm -r ~/.npm
61+
&& echo "pnpm version:" \
62+
&& pnpm --version \
63+
&& pnpm store prune
4864

4965
# Copy built JS files from builder image
5066
COPY --from=builder --chown=myuser /home/myuser/dist ./dist
@@ -53,7 +69,7 @@ COPY --from=builder --chown=myuser /home/myuser/dist ./dist
5369
COPY --from=builder --chown=myuser /home/myuser/blockers ./blockers
5470

5571
# Next, copy the remaining files and directories with the source code.
56-
# Since we do this after NPM install, quick build will be really fast
72+
# Since we do this after pnpm install, quick build will be really fast
5773
# for most source file changes.
5874
COPY --chown=myuser . ./
5975

@@ -69,4 +85,4 @@ ENV PLAYWRIGHT_FIREFOX_POLICIES_JSON="/home/myuser/policies.json"
6985
ENV NODE_NO_WARNINGS=1
7086

7187
# Run the image.
72-
CMD ["npm", "run", "start:prod", "--silent"]
88+
CMD ["pnpm", "run", "start:prod", "--silent"]

0 commit comments

Comments
 (0)