Skip to content

Commit e2f5c26

Browse files
Daniel15bestander
authored andcommitted
Convert "yarn" executable to a shell script that runs either "node" or "nodejs" (#1180)
Also fixes Cygwin. Closes #1142 Closes #819
1 parent 553e55f commit e2f5c26

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

bin/yarn

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,27 @@
1-
#!/usr/bin/env node
2-
require('./yarn.js');
1+
#!/bin/sh
2+
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3+
4+
case `uname` in
5+
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6+
esac
7+
8+
command_exists() {
9+
command -v "$1" >/dev/null 2>&1;
10+
}
11+
12+
if command_exists node; then
13+
node "$basedir/yarn.js" "$@"
14+
ret=$?
15+
# Debian and Ubuntu use "nodejs" as the name of the binary, not "node", so we
16+
# search for that too. See:
17+
# https://lists.debian.org/debian-devel-announce/2012/07/msg00002.html
18+
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=614907
19+
elif command_exists nodejs; then
20+
nodejs "$basedir/yarn.js" "$@"
21+
ret=$?
22+
else
23+
echo 'Yarn requires Node.js 4.0 or higher to be installed.'
24+
ret=1
25+
fi
26+
27+
exit $ret

scripts/build-deb.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -ex
44

55
# Ensure all the tools we need are available
66
ensureAvailable() {
7-
eval $1 --version >/dev/null || (echo "You need to install $1" && exit 2)
7+
command -v "$1" >/dev/null 2>&1 || (echo "You need to install $1" && exit 2)
88
}
99
ensureAvailable dpkg-deb
1010
ensureAvailable fpm
@@ -13,7 +13,7 @@ ensureAvailable lintian
1313
ensureAvailable rpmbuild
1414

1515
PACKAGE_TMPDIR=tmp/debian_pkg
16-
VERSION=`node dist/bin/yarn --version`
16+
VERSION=`dist/bin/yarn --version`
1717
TARBALL_NAME=dist/yarn-v$VERSION.tar.gz
1818
DEB_PACKAGE_NAME=yarn_$VERSION'_all.deb'
1919
OUTPUT_DIR=artifacts
@@ -50,11 +50,16 @@ find $PACKAGE_TMPDIR/usr/share/yarn \( -name '*.md' -o -name '*.md~' -o -name '
5050
# Assume everything else is junk we don't need
5151
rm -rf $PACKAGE_TMPDIR/dist
5252

53-
# Currently the "binaries" are JavaScript files that expect to be in the same
54-
# directory as the libraries, so we can't just copy them directly to /usr/bin.
55-
# Symlink them instead.
53+
# Swap out the basedir calculation code with a hard-coded path, as the default
54+
# way we do this doesn't follow symlinks.
55+
sed -i 's/basedir\=\$.*/basedir=\/usr\/share\/yarn\/bin/' $PACKAGE_TMPDIR/usr/share/yarn/bin/yarn
56+
57+
# The Yarn executable expects to be in the same directory as the libraries, so
58+
# we can't just copy it directly to /usr/bin. Symlink them instead.
5659
mkdir -p $PACKAGE_TMPDIR/usr/bin/
57-
ln -s ../share/yarn/bin/yarn.js $PACKAGE_TMPDIR/usr/bin/yarn
60+
ln -s ../share/yarn/bin/yarn $PACKAGE_TMPDIR/usr/bin/yarn
61+
# Alias as "yarnpkg" too.
62+
ln -s ../share/yarn/bin/yarn $PACKAGE_TMPDIR/usr/bin/yarnpkg
5863

5964
# Common FPM parameters for all packages we'll build using FPM
6065
FPM="fpm --input-type dir --chdir $PACKAGE_TMPDIR --name yarn --version $VERSION "`
@@ -70,9 +75,6 @@ mkdir -p $PACKAGE_TMPDIR/DEBIAN
7075
mkdir -p $PACKAGE_TMPDIR/usr/share/lintian/overrides/
7176
cp resources/debian/lintian-overrides $PACKAGE_TMPDIR/usr/share/lintian/overrides/yarn
7277

73-
# Debian/Ubuntu call the Node.js binary "nodejs", not "node".
74-
sed -i 's/env node/env nodejs/' $PACKAGE_TMPDIR/usr/share/yarn/bin/yarn.js
75-
7678
# Replace variables in Debian package control file
7779
INSTALLED_SIZE=`du -sk $PACKAGE_TMPDIR | cut -f 1`
7880
sed -e "s/\$VERSION/$VERSION/;s/\$INSTALLED_SIZE/$INSTALLED_SIZE/" < resources/debian/control.in > $PACKAGE_TMPDIR/DEBIAN/control

scripts/build-dist.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ npm install --production
1717
rm -rf node_modules/*/test node_modules/*/dist
1818
cd ..
1919

20-
tar -cvzf dist/yarn-v`node dist/bin/yarn --version`.tar.gz dist/*
20+
tar -cvzf dist/yarn-v`dist/bin/yarn --version`.tar.gz dist/*
2121
shasum -a 256 dist/yarn-*.tar.gz

0 commit comments

Comments
 (0)