Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Update pnpm and use corepack (#4628)

Olga Bulat9bdc32649f04
diff --git a/.github/actions/setup-env/action.yml b/.github/actions/setup-env/action.yml
index ee8034623..bdd74252f 100644
--- a/.github/actions/setup-env/action.yml
+++ b/.github/actions/setup-env/action.yml
@@ -41,11 +41,10 @@ runs:
pip install -U pip
pip install pipenv pdm
- # Node.js
- name: Setup pnpm
if: inputs.setup_nodejs == 'true'
- uses: pnpm/action-setup@v3
- # Automatically reads `packageManager` field from root `package.json`.
+ shell: bash
+ run: corepack enable pnpm
- name: Setup Node.js
if: inputs.setup_nodejs == 'true'
diff --git a/frontend/Dockerfile b/frontend/Dockerfile
index 5516ff018..592e2ef15 100644
--- a/frontend/Dockerfile
+++ b/frontend/Dockerfile
@@ -9,12 +9,9 @@ ARG FRONTEND_NODE_VERSION
FROM docker.io/node:${FRONTEND_NODE_VERSION}-alpine AS builder
-# Automatically use the right version of pnpm.
-ARG FRONTEND_PNPM_VERSION
-
# Install system packages needed to build on macOS
RUN apk add --no-cache --virtual .gyp python3 make g++ \
- && npm install -g pnpm@${FRONTEND_PNPM_VERSION}
+ && corepack enable pnpm
USER node
diff --git a/frontend/Dockerfile.playwright b/frontend/Dockerfile.playwright
index 4142abf83..2ec05a033 100644
--- a/frontend/Dockerfile.playwright
+++ b/frontend/Dockerfile.playwright
@@ -4,9 +4,10 @@ ARG PLAYWRIGHT_VERSION
FROM mcr.microsoft.com/playwright:v${PLAYWRIGHT_VERSION}-jammy
-ARG PACKAGE_MANAGER
-
COPY package.json /
+# Ensure the Playwright container's pnpm cache folder exists and is writable
+RUN mkdir -p /.cache/node/corepack/ && chmod -R 777 /.cache/node/corepack/
+
# Requires `packageManager` field to be present in `frontend/package.json`.
-RUN npm install -g $PACKAGE_MANAGER
+RUN corepack enable pnpm
diff --git a/frontend/bin/playwright.sh b/frontend/bin/playwright.sh
index c47f75ecf..8a69edda3 100755
--- a/frontend/bin/playwright.sh
+++ b/frontend/bin/playwright.sh
@@ -1,16 +1,10 @@
#! /usr/bin/env sh
set -e
-package_manager() {
- grep packageManager ../package.json | awk '{print $2}' | sed 's/[",]//g'
-}
-
version() {
pnpm ls --depth=0 | grep -e playwright | awk '{print $2}'
}
-PACKAGE_MANAGER=$(package_manager)
-export PACKAGE_MANAGER
export USER_ID="${USER_ID:-$(id -u)}"
export PLAYWRIGHT_ARGS="$*"
PLAYWRIGHT_VERSION=$(version)
@@ -19,7 +13,7 @@ export TEST_COMMAND="${TEST_COMMAND:-test:playwright:local}"
pnpm i18n:get-translations --en-only
-echo Running Playwright v"$PLAYWRIGHT_VERSION" as "$USER_ID" with Playwright arguments "$PLAYWRIGHT_ARGS" under package manager "$PACKAGE_MANAGER"
+echo Running Playwright v"$PLAYWRIGHT_VERSION" as "$USER_ID" with Playwright arguments "$PLAYWRIGHT_ARGS"
docker compose -f docker-compose.playwright.yml up --build --force-recreate --exit-code-from playwright --remove-orphans
diff --git a/frontend/docker-compose.playwright.yml b/frontend/docker-compose.playwright.yml
index e26780e12..7de7814a1 100644
--- a/frontend/docker-compose.playwright.yml
+++ b/frontend/docker-compose.playwright.yml
@@ -4,7 +4,6 @@ services:
context: .
dockerfile: Dockerfile.playwright
args:
- - PACKAGE_MANAGER=${PACKAGE_MANAGER}
- PLAYWRIGHT_VERSION=${PLAYWRIGHT_VERSION}
volumes:
- ../node_modules:/node_modules
diff --git a/frontend/package.json b/frontend/package.json
index e4af94264..bae1ab02d 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -3,6 +3,7 @@
"description": "Openverse frontend",
"private": true,
"version": "2.2.1",
+ "packageManager": "[email protected]",
"scripts": {
"predev": "pnpm install && pnpm i18n:no-get",
"dev": "run-p dev:only 'i18n:en --watch'",
diff --git a/package.json b/package.json
index 9e2c5bff3..0a5be2e66 100644
--- a/package.json
+++ b/package.json
@@ -13,7 +13,7 @@
"preeslint": "pnpm --filter '@openverse/eslint-plugin' run build",
"eslint": "eslint --ext .js,.ts,.vue,.json,.json5 --ignore-path .gitignore --ignore-path .eslintignore --max-warnings=0 frontend automations/js packages/js .pnpmfile.cjs .eslintrc.js prettier.config.js tsconfig.base.json"
},
- "packageManager": "[email protected]",
+ "packageManager": "[email protected]",
"engines": {
"node": ">= 20.0.0 <21"
},