From 79a0453fb12da06130c9e770552a4542790883c5 Mon Sep 17 00:00:00 2001 From: Matt Yeh Date: Tue, 23 Mar 2021 22:39:14 -0400 Subject: [PATCH] feat(yarn): support yarn 2.x --- bin/compile | 2 +- compile | 2 +- lib/build.sh | 20 +++++++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/bin/compile b/bin/compile index 89f13f5..fc571ab 100644 --- a/bin/compile +++ b/bin/compile @@ -36,7 +36,7 @@ cleanup_cache download_node install_node install_npm -if [ -f "$assets_dir/yarn.lock" ]; then +if [ -f "$assets_dir/yarn.lock" ] || [ -d "$assets_dir/.yarn" ] || [ -f "$assets_dir/.pnp.*" ]; then install_yarn "$heroku_dir/yarn" fi diff --git a/compile b/compile index efc96b0..0eefdfd 100644 --- a/compile +++ b/compile @@ -1,4 +1,4 @@ -if [ -f "$assets_dir/yarn.lock" ]; then +if [ -f "$assets_dir/yarn.lock" ] || [ -d "$assets_dir/.yarn" ] || [ -f "$assets_dir/.pnp.*" ]; then yarn deploy else npm run deploy diff --git a/lib/build.sh b/lib/build.sh index 50e9815..ea14ce8 100644 --- a/lib/build.sh +++ b/lib/build.sh @@ -89,7 +89,7 @@ install_npm() { install_yarn() { local dir="$1" - if [ ! $yarn_version ]; then + if [ ! $yarn_version ] || is_yarn2_configured; then echo "Downloading and installing yarn lastest..." local download_url="https://yarnpkg.com/latest.tar.gz" else @@ -112,6 +112,10 @@ install_yarn() { chmod +x $dir/bin/* PATH=$dir/bin:$PATH echo "Installed yarn $(yarn --version)" + + if is_yarn2_configured; then + yarn set version berry + fi } install_and_cache_deps() { @@ -231,3 +235,17 @@ remove_node() { rm -rf $assets_dir/node_modules rm -rf $heroku_dir/node } + +is_yarn2_configured() { + if [ ! $yarn_version ]; then + return $(false) + else + local regex='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)' + local major_version=`echo $yarn_version | sed -e "s#$regex#\1#"` + if [ $major_version -ge 2 ]; then + return $(true) + else + return $(false) + fi + fi +}