-
Notifications
You must be signed in to change notification settings - Fork 143
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
yarn global installs don't get shimmed #42
Comments
In light of npm5, this is less of an issue for me. If you think it's worth the effort to build in yarn support, let me know and I'm willing to contribute a PR. Otherwise maybe this should be a note in the readme to indicate yarn global installs are not supported. |
FWIW I'd definitely appreciate yarn support. |
http://blog.scottlogic.com/2017/06/06/does-npm5-deprecate-yarn.html |
I think this issue is not only about e.g.) $ npm install -g npm-check-updates
$ which npm-check-updates
$ npm-check-updates -u
bash: npm-check-updates: command not found So, this issue should be fixed. |
@gipcompany I think that's slightly different. If you run |
You can fix this by configuring yarn to use a custom global prefix path. You can run
Then, just add # Yarn bin
export PATH="$PATH:$HOME/.yarn/bin" See yarnpkg/yarn#630 for some more info. Working example to show that installing global binary packages with yarn works as expected: $ which yarn # yarn is installed via `npm` managed by `asdf`
/home/maddy/.asdf/shims/yarn
$ which grunt # grunt isn't installed yet
grunt not found
$ yarn global add grunt # globally install grunt with yarn
yarn global v1.6.0
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "[email protected]" with binaries:
- grunt
Done in 2.28s.
$ which grunt # grunt should now be installed and available in your `PATH`
/home/maddy/.yarn/bin/grunt
$ grunt --version # verify that we can successfully call grunt
grunt-cli v1.2.0 |
|
is this issue still present? |
Ya, I believe it's still present. Even though I opened the issue, I don't think this should be fixed. Yarn doesn't recommend If you're on a mac and install it via brew, or another system packager, you don't need asdf to shim packages that're installed via yarn since yarn is installed somewhere else on your system, and caches in different locations, and works independently of the nodejs version. asdf-nodejs only needs to worry about the nodejs version at this point, which in my book is 👍 Or, you could use npm which asdf-nodejs does shim bins for. Sometimes you have to run Maybe there are compelling reasons for asdf-nodejs to support shimming yarn global installs, but I haven't found any yet. Let me know if you know of any. |
@dbernheisel Yes, I installed yarn via apt and this was solved. Also other issues have been resolved by |
@dbernheisel The reshim tip worked for me, great! TIL about yarn not recommending |
@squarism https://yarnpkg.com/en/docs/install#mac-stable |
AFAIK the best way you can install yarn is via apt-get, that way you can configure to install node as a dependency or use your system's node. Read the docs there is a flag for it.
Maybe the OP or one of the mods can close this issue.
…On Dec 6, 2018, 6:31 AM, at 6:31 AM, David Bernheisel ***@***.***> wrote:
@squarism https://yarnpkg.com/en/docs/install#mac-stable
`brew install yarn --without-node` might be what you're looking for
--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#42 (comment)
|
asdf v0.7.0 (installed via homebrew) $ brew install yarn --ignore-dependencies
🍺 /usr/local/Cellar/yarn/1.13.0: 14 files, 4.7MB, built in 8 seconds
$ yarn global bin
/Users/username/.asdf/installs/nodejs/10.15.3/.npm/bin
$ yarn global add grunt
yarn global v1.13.0
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
[4/4] 🔨 Building fresh packages...
success Installed "[email protected]" with binaries:
- grunt
✨ Done in 4.92s.
$ which grunt
$ asdf reshim
$ which grunt
/Users/username/.asdf/shims/grunt
$ grunt --version
grunt-cli v1.2.0 I found the below behavior a little strange. I think I'd rather just have the shim not exist if not installed for a given version. Due to one unfortunate nature of Yarn (one global install for all), after performing a This can seem a bit odd. If you switch to another node version, and are expecting this behavior, you'll need to run It might be best to have yarn use a private bin folder -- often defaulted to /usr/local/bin for MacOS, for example as occurs naturally when using nvm (nvm is not compatible with npm's prefix config, and screams loudly about it if it is set). $ asdf global nodejs 8.10.0
$ which grunt
/Users/username/.asdf/shims/grunt
$ grunt --version
asdf: No version set for command grunt
you might want to add one of the following in your .tool-versions file:
nodejs 10.15.3
# yarn hasn't yet symlinked bins for this version in my case, so naturally this won't work.
$ asdf reshim
$ which grunt
/Users/username/.asdf/shims/grunt
$ grunt --version
asdf: No version set for command grunt
you might want to add one of the following in your .tool-versions file:
nodejs 10.15.3
$ asdf global nodejs 10.15.3
$ which grunt
/Users/username/.asdf/shims/grunt
$ grunt --version
grunt-cli v1.2.0 It certainly would be nice if shims could be recreated after I'm coming to the conclusion that it may be best to manage global packages using NPM. I've had some trouble in the past with global packages that require node-gyp when installing with yarn, using a version manager, and needing those packages to be available for multiple versions of node. |
until a solution is added to asdf-nodejs, i wrote a script to handle this. when you initialize a shell session, it adds the bin path of the current version of node to your PATH. drop this in your i did some basic smoke tests, but let me know if something isn't acting right on_change_dir() {
# -> asdf-nodejs
local nodejs_current
if nodejs_current=$(asdf current nodejs); then
# add current path the first time
if [ ! $nodejs_current_version ]; then
local nodejs_current_path=$(asdf where nodejs)
export PATH=$nodejs_current_path/.npm/bin:$PATH
fi
# set next version to extracted current semantic version
local nodejs_next_version=$(echo $nodejs_current | cut -d '(' -f 1 | xargs)
# set current version to next version if it has not been set yet
nodejs_current_version=${nodejs_current_version-$nodejs_next_version}
# check if version has changed
if [ $nodejs_current_version != $nodejs_next_version ]; then
local nodejs_current_path=$(asdf where nodejs $nodejs_current_version)
local nodejs_next_path=$(asdf where nodejs)
# update path with new path
PATH=${PATH/$nodejs_current_path/$nodejs_next_path}
# update current version
nodejs_current_version=$nodejs_next_version
fi
else
echo "No nodejs version set. Type `asdf list-all nodejs` for all versions."
fi
}
function chpwd { on_change_dir }
on_change_dir |
Couldn't |
Things have changed with yarn 2. They now recommend to install yarn globally with npm and then spawn a per-project installation with the globally installed version. If I understand correctly, this means that there is no need for multiple yarn installations anymore and installation via <your OS-specific tool> is more suitable. |
@dbernheisel: @cbows is correct above. Yarn 2 behaves differently now. If I have to I will uninstall my (I don't mind either way; this is just my personal preference.) |
My comments above about Yarn are 2+ yrs old and about Yarn 1. I haven't used Yarn 2 yet, but looks like it should be treated differently so perhaps this can be fixed now? I'm not familiar with Yarn 2, but I'm sure the maintainers will accept PRs to make asdf-nodejs better. Since I don't use Yarn 2 I'm not well-suited to contribute at this point. |
For me, this works. The prefix doesn't work and I do not know why. By the way, I think that is a better way to fix this issue. |
In 2021 @b0o solution worked for me. Must admit a bit of a pain in the 🍑 when simply trying to add global packages like expo etc via yarn |
You can do like this: export PATH="$(yarn global bin):$PATH"
|
Unfortunelly the problem persists. In fact, it becomes more problematic due to changes on yarn installation instructions. As @dbernheisel mentioned, using Using the command Well, this new method doesn't work with 'asdf' too. You need to manually And, of course, any subsequent call of About change yarn configurations (like |
I don't see why this would be a worse problem in yarn v2 as system-wide installations have been removed. Apparently, since its inception (more on this github issue). And I agree with this direction. The best recommendation for using commands from packages is by using either If you are sure about installing global commands (there are some fair points to do it), the recommended way would be not to run As this was a decision made by the yarn team itself, I'm marking this issue as yarn() {
command yarn "$@"
if [ "$1" = global ]; then
asdf reshim nodejs
fi
} |
Steps to reproduce:
Looking at the source, it seems that npm is the only package manager that's managed in this plugin for postinstall hooks for shimming.
The text was updated successfully, but these errors were encountered: