Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(yarn): yarn 2.x support #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion compile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 19 additions & 1 deletion lib/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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
}