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

Fix support for Yarn 2 (berry) #465

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions run-build-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ run_yarn() {
fi
restore_home_cache ".yarn_cache" "yarn cache"

if [ $(which yarn) ] && [ "$(yarn --version)" != "$yarn_version" ]
# Check the version of yarn installed globally
if [ $(which yarn) ] && [ "$(YARN_IGNORE_PATH=1 yarn --version)" != "$yarn_version" ]
then
echo "Found yarn version ($(yarn --version)) that doesn't match expected ($yarn_version)"
echo "Global yarn version ($(yarn --version)) doesn't match expected ($yarn_version)"
rm -rf $NETLIFY_CACHE_DIR/yarn $HOME/.yarn
npm uninstall yarn -g
fi
Expand All @@ -98,19 +99,32 @@ run_yarn() {
export PATH=$NETLIFY_CACHE_DIR/yarn/bin:$PATH
fi

yarn_version=$(yarn --version)

echo "Installing NPM modules using Yarn version $(yarn --version)"

echo "Installing NPM modules using Yarn version $yarn_version"
run_npm_set_temp

# Remove the cache-folder flag if the user set any.
local yarn_local="$YARN_FLAGS"

# We want to control where to put the cache
# to be able to store it internally after the build.
local yarn_local="${YARN_FLAGS/--cache-folder * /}"
# The previous pattern doesn't match the end of the string.
# This removes the flag from the end of the string.
yarn_local="${yarn_local%--cache-folder *}"
if [[ "${yarn_version%%.*}" -gt "1" ]]
then
# The cache-folder flag is deprecated in Yarn 2
# Override the environment variable if the user set any.
# To use the global cache, the user should set YARN_ENABLE_GLOBAL_CACHE
export YARN_GLOBAL_FOLDER="$NETLIFY_BUILD_BASE/.yarn_cache"
else
# Remove the cache-folder flag if the user set any.
yarn_local="${yarn_local/--cache-folder * /}"
# The previous pattern doesn't match the end of the string.
# This removes the flag from the end of the string.
yarn_local="${yarn_local%--cache-folder *}"
yarn_local="--cache-folder $NETLIFY_BUILD_BASE/.yarn_cache ${yarn_local:+"$yarn_local"}"
fi

if yarn install --cache-folder $NETLIFY_BUILD_BASE/.yarn_cache ${yarn_local:+"$yarn_local"}
if yarn install ${yarn_local:+"$yarn_local"}
then
echo "NPM modules installed using Yarn"
else
Expand Down