Skip to content
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

Option to disable adding yarn global scripts to $PATH #10641

Closed
SimenB opened this issue Feb 1, 2022 · 5 comments · Fixed by #10642
Closed

Option to disable adding yarn global scripts to $PATH #10641

SimenB opened this issue Feb 1, 2022 · 5 comments · Fixed by #10642
Labels
Feature New feature or request

Comments

@SimenB
Copy link
Contributor

SimenB commented Feb 1, 2022

If the feature request is for a plugin or theme, specify it here.

yarn plugin

If the feature solves a problem you have, specify it here.

See #10290 (comment)

Tl;dr: yarn global bin takes a long time (yarn global bin 0.15s user 0.05s system 83% cpu 0.241 total on my system), adding significant overhead to new sessions.

Additionally, Yarn v2 and later doesn't support the command, so in projects using the modern versions of Yarn the command always fails. Using hyperfine, calling zsh -i -c exit takes 1.568 s ± 0.063 s with the yarn plugin and 298.8 ms ± 6.6 ms with it removed.

Also of note is that the global yarn will probably remain on v1 forever (see e.g. nodejs/docker-node#1180 (comment) for some discussion about which version to ship in the office node Docker images)

Describe the proposed feature.

Add some way of disabling the feature added in #9410. Probably some environment variable?

Describe alternatives you've considered

Disabling the plugin entirely. But I dearly love the aliases and completions, so that would be a shame 🙂

Additional context

No response

Related Issues

#10290, #10396

@carlosala
Copy link
Member

carlosala commented Feb 1, 2022

I think it's reasonable add an environment variable. Maybe ZSH_YARN_DISABLE_GLOBAL?

@SimenB
Copy link
Contributor Author

SimenB commented Feb 1, 2022

With the edit, I agree! 😃 Sounds good to me 👍

@mcornella
Copy link
Member

mcornella commented Feb 1, 2022

I'd prefer the setting to be zstyle-based so we don't pollute the global variable namespace. Something like

zstyle ':omz:plugins:yarn' global-path false

In the code, we can test for that setting with

zstyle -T ':omz:plugins:yarn' global-path

Here -T returns true if the setting is not defined, but in the future we can reverse that to -t which will by default be interpreted as false.

This can be tested or chained with the normal true/false semantics:

if zstyle -T ':omz:plugins:yarn' global-path; then

# or

zstyle -T ':omz:plugins:yarn' global-path && ...

@carlosala
Copy link
Member

Looks great. I'll update the PR then

carlosala added a commit to carlosala/ohmyzsh that referenced this issue Feb 1, 2022
@SimenB
Copy link
Contributor Author

SimenB commented Feb 3, 2022

Awesome, thank you!

Before (in yarn v2 repo)

$ hyperfine -w 2 'zsh -i -c exit'
Benchmark 1: zsh -i -c exit
  Time (mean ± σ):      1.618 s ±  0.136 s    [User: 1.833 s, System: 0.312 s]
  Range (min … max):    1.490 s …  1.934 s    10 runs

After

$ hyperfine -w 2 'zsh -i -c exit'
Benchmark 1: zsh -i -c exit
  Time (mean ± σ):     299.1 ms ±  10.7 ms    [User: 201.1 ms, System: 140.3 ms]
  Range (min … max):   272.6 ms … 311.6 ms    10 runs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants