From ab60a8e51feae53ee14b023c7759d071bac7835c Mon Sep 17 00:00:00 2001 From: Lukas Holzer Date: Tue, 25 Oct 2022 16:32:53 +0200 Subject: [PATCH] fix: feature flag node corepack usage (#860) * fix: feature flag node corepack usage * chore: PR feedback --- run-build-functions.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/run-build-functions.sh b/run-build-functions.sh index 6eec85d1..43e8d77f 100755 --- a/run-build-functions.sh +++ b/run-build-functions.sh @@ -133,9 +133,10 @@ restore_node_modules() { run_yarn() { yarn_version=$1 + featureFlags=$2 restore_home_cache ".yarn_cache" "yarn cache" - if ! [ $(which corepack) ]; then + if ! [ $(which corepack) ] || has_feature_flag "$featureFlags" "build-image-disable-node-corepack"; then if [ -d $NETLIFY_CACHE_DIR/yarn ] then export PATH=$NETLIFY_CACHE_DIR/yarn/bin:$PATH @@ -187,9 +188,10 @@ run_yarn() { run_pnpm() { pnpm_version=$1 + featureFlags=$2 restore_home_cache ".pnpm-store" "pnpm cache" - if ! [ $(which corepack) ]; then + if ! [ $(which corepack) ] || has_feature_flag "$featureFlags" "build-image-disable-node-corepack"; then echo "Error while installing PNPM $pnpm_version" echo "We cannot install the expected version of PNPM ($pnpm_version) as your required Node.js version $NODE_VERSION does not allow that" echo "Please ensure that you use at least Node Version 14.19.0 or greater than 16.9.0" @@ -266,12 +268,13 @@ run_npm() { echo "$(shasum package.json)-$NODE_VERSION" > "$NETLIFY_CACHE_DIR/package-sha" fi fi - + export PATH=$(npm bin):$PATH } install_node() { local defaultNodeVersion=$1 + local featureFlags=$2 source $NVM_DIR/nvm.sh : ${NODE_VERSION="$defaultNodeVersion"} @@ -311,7 +314,7 @@ install_node() { fi # if Node.js Corepack is available enable it - if [ $(which corepack) ]; then + if [ $(which corepack) ] && ! has_feature_flag "$featureFlags" "build-image-disable-node-corepack"; then echo "Enabling node corepack" corepack enable fi @@ -366,7 +369,7 @@ install_dependencies() { fi # Node version - install_node $defaultNodeVersion + install_node "$defaultNodeVersion" "$featureFlags" # Automatically installed Build plugins if [ ! -d "$PWD/.netlify" ] @@ -604,9 +607,9 @@ install_dependencies() { restore_home_cache ".node/corepack" "corepack dependencies" if [ "$NETLIFY_USE_YARN" = "true" ] || ([ "$NETLIFY_USE_YARN" != "false" ] && [ -f yarn.lock ]); then - run_yarn $YARN_VERSION + run_yarn $YARN_VERSION "$featureFlags" elif [ "$NETLIFY_USE_PNPM" = "true" ] || ([ "$NETLIFY_USE_PNPM" != "false" ] && [ -f pnpm-lock.yaml ]); then - run_pnpm $PNPM_VERSION + run_pnpm $PNPM_VERSION "$featureFlags" else run_npm "$featureFlags" fi