From 9bdc32649f04cccc587575dfefed7777c8d8ce02 Mon Sep 17 00:00:00 2001 From: Olga Bulat Date: Fri, 19 Jul 2024 07:07:45 +0300 Subject: [PATCH] Update pnpm and use corepack (#4628) * Update pnpm and use corepack Signed-off-by: Olga Bulat * Remove unused PACKAGE_MANAGER arg Signed-off-by: Olga Bulat * Remove comments Signed-off-by: Olga Bulat --------- Signed-off-by: Olga Bulat --- .github/actions/setup-env/action.yml | 5 ++--- frontend/Dockerfile | 5 +---- frontend/Dockerfile.playwright | 7 ++++--- frontend/bin/playwright.sh | 8 +------- frontend/docker-compose.playwright.yml | 1 - frontend/package.json | 1 + package.json | 2 +- 7 files changed, 10 insertions(+), 19 deletions(-) diff --git a/.github/actions/setup-env/action.yml b/.github/actions/setup-env/action.yml index ee803462339..bdd74252f16 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 5516ff0181d..592e2ef152e 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 4142abf833c..2ec05a03305 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 c47f75ecf49..8a69edda392 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 e26780e12fd..7de7814a1b6 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 e4af94264e7..bae1ab02dad 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -3,6 +3,7 @@ "description": "Openverse frontend", "private": true, "version": "2.2.1", + "packageManager": "pnpm@9.5.0", "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 9e2c5bff379..0a5be2e6644 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": "pnpm@9.2.0", + "packageManager": "pnpm@9.5.0", "engines": { "node": ">= 20.0.0 <21" },