From 87871bc430da828b49386645756c1724d2ed617d Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 2 Sep 2024 20:55:57 +0100 Subject: [PATCH] Make compatible with pnpm (#854) Switches behavior based on the presence of `yarn.lock` See https://github.com/discourse/discourse/pull/28671 --- image/base/release.Dockerfile | 3 +-- image/discourse_dev/Dockerfile | 2 +- image/discourse_test/Dockerfile | 3 +-- launcher_go/v2/test/templates/web.template.yml | 7 ++++++- templates/web.template.yml | 8 ++++++-- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/image/base/release.Dockerfile b/image/base/release.Dockerfile index ebea1ca..612f4a5 100644 --- a/image/base/release.Dockerfile +++ b/image/base/release.Dockerfile @@ -10,7 +10,6 @@ RUN cd /var/www/discourse &&\ sudo -u discourse bundle config --local path ./vendor/bundle &&\ sudo -u discourse bundle config --local without test development &&\ sudo -u discourse bundle install --jobs $(($(nproc) - 1)) &&\ - sudo -u discourse yarn install --frozen-lockfile &&\ - sudo -u discourse yarn cache clean &&\ + sudo -u discourse /bin/bash -c 'if [ -f yarn.lock ]; then yarn install --frozen-lockfile && yarn cache clean; else pnpm install --frozen-lockfile; fi' &&\ find /var/www/discourse/vendor/bundle -name cache -not -path '*/gems/*' -type d -exec rm -rf {} + &&\ find /var/www/discourse/vendor/bundle -name tmp -type d -exec rm -rf {} + diff --git a/image/discourse_dev/Dockerfile b/image/discourse_dev/Dockerfile index 8643473..eeb0698 100644 --- a/image/discourse_dev/Dockerfile +++ b/image/discourse_dev/Dockerfile @@ -73,6 +73,6 @@ RUN --mount=type=bind,src=/repo,from=repo-fetcher,target=/tmp/discourse-clone,re # Warm global yarn cache RUN --mount=type=bind,src=/repo,from=repo-fetcher,target=/tmp/discourse-clone,readwrite \ cd /tmp/discourse-clone \ - && yarn install + && (if [ -f yarn.lock ]; then yarn install; else pnpm install; fi) USER root diff --git a/image/discourse_test/Dockerfile b/image/discourse_test/Dockerfile index bbfcd4e..843d92b 100644 --- a/image/discourse_test/Dockerfile +++ b/image/discourse_test/Dockerfile @@ -30,8 +30,7 @@ FROM with_browsers AS release RUN cd /var/www/discourse &&\ sudo -u discourse bundle install --jobs $(($(nproc) - 1)) &&\ - sudo -E -u discourse -H yarn install &&\ - sudo -u discourse yarn cache clean + sudo -E -u discourse -H /bin/bash -c 'if [ -f yarn.lock ]; then (yarn install && yarn cache clean); else pnpm install; fi' RUN cd /var/www/discourse && sudo -E -u discourse -H bundle exec rake plugin:install_all_official &&\ LOAD_PLUGINS=1 sudo -E -u discourse -H bundle exec rake plugin:install_all_gems &&\ diff --git a/launcher_go/v2/test/templates/web.template.yml b/launcher_go/v2/test/templates/web.template.yml index d3d992b..1106204 100644 --- a/launcher_go/v2/test/templates/web.template.yml +++ b/launcher_go/v2/test/templates/web.template.yml @@ -184,7 +184,12 @@ run: if [ "$version" != "tests-passed" ]; then rm -rf app/assets/javascripts/node_modules fi - - su discourse -c 'yarn install --frozen-lockfile && yarn cache clean' + - |- + if [ -f yarn.lock ]; then + su discourse -c 'yarn install --frozen-lockfile && yarn cache clean' + else + su discourse -c 'pnpm install --frozen-lockfile' + fi - exec: cd: $home diff --git a/templates/web.template.yml b/templates/web.template.yml index 7762339..01dc69c 100644 --- a/templates/web.template.yml +++ b/templates/web.template.yml @@ -185,8 +185,12 @@ run: if [ "$version" != "tests-passed" ]; then rm -rf app/assets/javascripts/node_modules fi - - su discourse -c 'yarn config set network-timeout 60000 -g' - - su discourse -c 'yarn install --frozen-lockfile && yarn cache clean' + - |- + if [ -f yarn.lock ]; then + su discourse -c 'yarn install --frozen-lockfile && yarn cache clean' + else + su discourse -c 'pnpm install --frozen-lockfile' + fi - exec: cd: $home -- 2.25.1