Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Commit

Permalink
fix: feature flag node corepack usage (#860)
Browse files Browse the repository at this point in the history
* fix: feature flag node corepack usage

* chore: PR feedback
  • Loading branch information
lukasholzer authored Oct 25, 2022
1 parent 5a7cdf3 commit ab60a8e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions run-build-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -366,7 +369,7 @@ install_dependencies() {
fi

# Node version
install_node $defaultNodeVersion
install_node "$defaultNodeVersion" "$featureFlags"

# Automatically installed Build plugins
if [ ! -d "$PWD/.netlify" ]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ab60a8e

Please sign in to comment.