From e2f5c268862d053d15df798d683c8ad086d7f00d Mon Sep 17 00:00:00 2001 From: Daniel Lo Nigro Date: Tue, 18 Oct 2016 08:30:51 -0700 Subject: [PATCH] Convert "yarn" executable to a shell script that runs either "node" or "nodejs" (#1180) Also fixes Cygwin. Closes #1142 Closes #819 --- bin/yarn | 29 +++++++++++++++++++++++++++-- scripts/build-deb.sh | 20 +++++++++++--------- scripts/build-dist.sh | 2 +- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/bin/yarn b/bin/yarn index f6129c5829..0f5e5dd1f4 100755 --- a/bin/yarn +++ b/bin/yarn @@ -1,2 +1,27 @@ -#!/usr/bin/env node -require('./yarn.js'); +#!/bin/sh +basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") + +case `uname` in + *CYGWIN*) basedir=`cygpath -w "$basedir"`;; +esac + +command_exists() { + command -v "$1" >/dev/null 2>&1; +} + +if command_exists node; then + node "$basedir/yarn.js" "$@" + ret=$? +# Debian and Ubuntu use "nodejs" as the name of the binary, not "node", so we +# search for that too. See: +# https://lists.debian.org/debian-devel-announce/2012/07/msg00002.html +# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=614907 +elif command_exists nodejs; then + nodejs "$basedir/yarn.js" "$@" + ret=$? +else + echo 'Yarn requires Node.js 4.0 or higher to be installed.' + ret=1 +fi + +exit $ret diff --git a/scripts/build-deb.sh b/scripts/build-deb.sh index 2e5ffa6632..10f24a340c 100755 --- a/scripts/build-deb.sh +++ b/scripts/build-deb.sh @@ -4,7 +4,7 @@ set -ex # Ensure all the tools we need are available ensureAvailable() { - eval $1 --version >/dev/null || (echo "You need to install $1" && exit 2) + command -v "$1" >/dev/null 2>&1 || (echo "You need to install $1" && exit 2) } ensureAvailable dpkg-deb ensureAvailable fpm @@ -13,7 +13,7 @@ ensureAvailable lintian ensureAvailable rpmbuild PACKAGE_TMPDIR=tmp/debian_pkg -VERSION=`node dist/bin/yarn --version` +VERSION=`dist/bin/yarn --version` TARBALL_NAME=dist/yarn-v$VERSION.tar.gz DEB_PACKAGE_NAME=yarn_$VERSION'_all.deb' OUTPUT_DIR=artifacts @@ -50,11 +50,16 @@ find $PACKAGE_TMPDIR/usr/share/yarn \( -name '*.md' -o -name '*.md~' -o -name ' # Assume everything else is junk we don't need rm -rf $PACKAGE_TMPDIR/dist -# Currently the "binaries" are JavaScript files that expect to be in the same -# directory as the libraries, so we can't just copy them directly to /usr/bin. -# Symlink them instead. +# Swap out the basedir calculation code with a hard-coded path, as the default +# way we do this doesn't follow symlinks. +sed -i 's/basedir\=\$.*/basedir=\/usr\/share\/yarn\/bin/' $PACKAGE_TMPDIR/usr/share/yarn/bin/yarn + +# The Yarn executable expects to be in the same directory as the libraries, so +# we can't just copy it directly to /usr/bin. Symlink them instead. mkdir -p $PACKAGE_TMPDIR/usr/bin/ -ln -s ../share/yarn/bin/yarn.js $PACKAGE_TMPDIR/usr/bin/yarn +ln -s ../share/yarn/bin/yarn $PACKAGE_TMPDIR/usr/bin/yarn +# Alias as "yarnpkg" too. +ln -s ../share/yarn/bin/yarn $PACKAGE_TMPDIR/usr/bin/yarnpkg # Common FPM parameters for all packages we'll build using FPM FPM="fpm --input-type dir --chdir $PACKAGE_TMPDIR --name yarn --version $VERSION "` @@ -70,9 +75,6 @@ mkdir -p $PACKAGE_TMPDIR/DEBIAN mkdir -p $PACKAGE_TMPDIR/usr/share/lintian/overrides/ cp resources/debian/lintian-overrides $PACKAGE_TMPDIR/usr/share/lintian/overrides/yarn -# Debian/Ubuntu call the Node.js binary "nodejs", not "node". -sed -i 's/env node/env nodejs/' $PACKAGE_TMPDIR/usr/share/yarn/bin/yarn.js - # Replace variables in Debian package control file INSTALLED_SIZE=`du -sk $PACKAGE_TMPDIR | cut -f 1` sed -e "s/\$VERSION/$VERSION/;s/\$INSTALLED_SIZE/$INSTALLED_SIZE/" < resources/debian/control.in > $PACKAGE_TMPDIR/DEBIAN/control diff --git a/scripts/build-dist.sh b/scripts/build-dist.sh index 50eeb1d194..a811ca5bf9 100755 --- a/scripts/build-dist.sh +++ b/scripts/build-dist.sh @@ -17,5 +17,5 @@ npm install --production rm -rf node_modules/*/test node_modules/*/dist cd .. -tar -cvzf dist/yarn-v`node dist/bin/yarn --version`.tar.gz dist/* +tar -cvzf dist/yarn-v`dist/bin/yarn --version`.tar.gz dist/* shasum -a 256 dist/yarn-*.tar.gz