Yarn: readlink: illegal option -- f on Mac OS

Created on 20 Jan 2017  路  6Comments  路  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?
bug
What is the current behavior?

Introduced in https://github.com/yarnpkg/yarn/pull/2441
related http://biercoff.com/fixing-readlink-illegal-option-f-error-on-a-mac/

yarn --version
readlink: illegal option -- f
usage: readlink [-n] [file ...]
0.20.0-0

Please mention your node.js, yarn and operating system version.

Yarn 0.20.0-0
Mac OS X

Most helpful comment

@bestander please try the following on your Mac. Replace https://github.com/yarnpkg/yarn/blob/master/bin/yarn#L2 with:

if [ "$(uname -s)" = 'Linux' ]; then
basedir=$(dirname "$(readlink -f "$0" || echo "$(echo "$0" | sed -e 's,\\,/,g')")")
else
basedir=$(dirname "$(readlink "$0" || echo "$(echo "$0" | sed -e 's,\\,/,g')")")
fi

All 6 comments

@bestander please try the following on your Mac. Replace https://github.com/yarnpkg/yarn/blob/master/bin/yarn#L2 with:

if [ "$(uname -s)" = 'Linux' ]; then
basedir=$(dirname "$(readlink -f "$0" || echo "$(echo "$0" | sed -e 's,\\,/,g')")")
else
basedir=$(dirname "$(readlink "$0" || echo "$(echo "$0" | sed -e 's,\\,/,g')")")
fi

@philtay, yeah I think it would work.
What about this change as well https://github.com/yarnpkg/yarn/pull/2455?

@bestander the deb builder script will continue to work without problems (i.e. no need for the sed hack). anyway i just noticed that you already have a case on uname. let's use it. a more elegant solution:

argv0=$(echo "$0" | sed -e 's,\\,/,g')
basedir=$(dirname "$(readlink "$0" || echo "$argv0")")

use_winpty=0

case "$(uname -s)" in
  *CYGWIN*) basedir=$(cygpath -w "$basedir");;
  MSYS*|MINGW*) use_winpty=1;;
  Linux) basedir=$(dirname "$(readlink -f "$0" || echo "$argv0")");;
esac

the snippet above will replace https://github.com/yarnpkg/yarn/blob/master/bin/yarn#L2-L9

@philtay, would you send a PR please?

@bestander please test it on your mac. just to be 100% sure. as soon as you give me the ok i'll open a pr

@philtay, tested on Mac, no error, works fine.

Was this page helpful?
0 / 5 - 0 ratings