From 4e36794db3afc42484ee2d5d7617faec33761cbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Antunes?= Date: Wed, 26 Oct 2022 17:19:03 +0100 Subject: [PATCH] fix(yarn): setup a fallback strategy for workspace detection and non-corepack logic (#862) --- Dockerfile | 3 +++ run-build-functions.sh | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 903ea887..4578fd31 100644 --- a/Dockerfile +++ b/Dockerfile @@ -291,10 +291,13 @@ ENV PNPM_VERSION=7.13.4 ENV NETLIFY_NODE_VERSION="16" +# We install an "internal" yarn v1 executable to be used only for workspace detection. We can remove it once we have a better +# strategy in place RUN /bin/bash -c ". ~/.nvm/nvm.sh && \ nvm install --no-progress $NETLIFY_NODE_VERSION && \ npm install -g grunt-cli bower && \ nvm alias default node && \ + bash /usr/local/bin/yarn-installer.sh --version $YARN_VERSION && \ nvm cache clear && \ corepack enable && \ corepack prepare yarn@$YARN_VERSION --activate && \ diff --git a/run-build-functions.sh b/run-build-functions.sh index 43e8d77f..9a8944d5 100755 --- a/run-build-functions.sh +++ b/run-build-functions.sh @@ -25,6 +25,10 @@ DEFAULT_SWIFT_VERSION="5.4" # PHP version DEFAULT_PHP_VERSION="8.0" +# Internal yarn config +# We use an "internal" yarn v1 executable as to not be impacted by corepack yarn selection +INTERNAL_YARN_PATH="$HOME/.yarn/bin" + # Pipenv configuration export PIPENV_RUNTIME=3.8 export PIPENV_VENV_IN_PROJECT=1 @@ -107,7 +111,7 @@ restore_node_modules() { # YARN_IGNORE_PATH will ignore the presence of a local yarn executable (i.e. yarn 2) and default # to using the global one (which, for now, is always yarn 1.x). See https://yarnpkg.com/configuration/yarnrc#ignorePath # we can actually use this command for npm workspaces as well - workspace_output="$(YARN_IGNORE_PATH=1 yarn workspaces --json info 2>/dev/null)" + workspace_output="$(YARN_IGNORE_PATH=1 "$INTERNAL_YARN_PATH/yarn" workspaces --json info 2>/dev/null)" workspace_exit_code=$? if [ $workspace_exit_code -eq 0 ] then @@ -137,6 +141,10 @@ run_yarn() { restore_home_cache ".yarn_cache" "yarn cache" if ! [ $(which corepack) ] || has_feature_flag "$featureFlags" "build-image-disable-node-corepack"; then + + # We manually add our internal yarn version to our path as a fallback, as this means the customer won't have a default + # yarn version installed + export PATH=$INTERNAL_YARN_PATH:$PATH if [ -d $NETLIFY_CACHE_DIR/yarn ] then export PATH=$NETLIFY_CACHE_DIR/yarn/bin:$PATH