From baa599d0a0657b01d106535ac5ee750ea1fa404b Mon Sep 17 00:00:00 2001 From: Young Min Kin Date: Mon, 3 Aug 2020 20:48:20 +0900 Subject: [PATCH 1/4] Add support for Yarn 2 (berry) --- run-build-functions.sh | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/run-build-functions.sh b/run-build-functions.sh index 55c58973..74399cb4 100755 --- a/run-build-functions.sh +++ b/run-build-functions.sh @@ -82,7 +82,8 @@ 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)" rm -rf $NETLIFY_CACHE_DIR/yarn $HOME/.yarn @@ -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. + export YARN_GLOBAL_FOLDER="$NETLIFY_BUILD_BASE/.yarn_cache" + export YARN_ENABLE_GLOBAL_CACHE=1 + 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 From de778da0a9db2a85127aefe16e85d6e8bb386dea Mon Sep 17 00:00:00 2001 From: ylemkimon Date: Wed, 5 Aug 2020 19:34:58 +0900 Subject: [PATCH 2/4] Update run-build-functions.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Maƫl Nison --- run-build-functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-build-functions.sh b/run-build-functions.sh index 74399cb4..4b2e598f 100755 --- a/run-build-functions.sh +++ b/run-build-functions.sh @@ -85,7 +85,7 @@ run_yarn() { # 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)) that doesn't match expected ($yarn_version)" rm -rf $NETLIFY_CACHE_DIR/yarn $HOME/.yarn npm uninstall yarn -g fi From 021e8cdd7e756ab96c186543d35864cab14e35b5 Mon Sep 17 00:00:00 2001 From: ylemkimon Date: Thu, 6 Aug 2020 03:04:34 +0900 Subject: [PATCH 3/4] Do not set YARN_ENABLE_GLOBAL_CACHE by default --- run-build-functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-build-functions.sh b/run-build-functions.sh index 4b2e598f..e149ade8 100755 --- a/run-build-functions.sh +++ b/run-build-functions.sh @@ -113,8 +113,8 @@ run_yarn() { 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" - export YARN_ENABLE_GLOBAL_CACHE=1 else # Remove the cache-folder flag if the user set any. yarn_local="${yarn_local/--cache-folder * /}" From ec6e2ce61d6f3d4111d1a6dbeff7342189901cc1 Mon Sep 17 00:00:00 2001 From: ylemkimon Date: Thu, 6 Aug 2020 03:19:58 +0900 Subject: [PATCH 4/4] Fix grammar --- run-build-functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-build-functions.sh b/run-build-functions.sh index e149ade8..0a99d76a 100755 --- a/run-build-functions.sh +++ b/run-build-functions.sh @@ -85,7 +85,7 @@ run_yarn() { # Check the version of yarn installed globally if [ $(which yarn) ] && [ "$(YARN_IGNORE_PATH=1 yarn --version)" != "$yarn_version" ] then - echo "Global 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