Skip to content

Commit

Permalink
Convert "yarn" executable to a shell script that runs either "node" o…
Browse files Browse the repository at this point in the history
…r "nodejs" (#1180)

Also fixes Cygwin.
Closes #1142
Closes #819
  • Loading branch information
Daniel15 authored and bestander committed Oct 18, 2016
1 parent 553e55f commit e2f5c26
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
29 changes: 27 additions & 2 deletions bin/yarn
Original file line number Diff line number Diff line change
@@ -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
20 changes: 11 additions & 9 deletions scripts/build-deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 "`
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e2f5c26

Please sign in to comment.