-
-
Notifications
You must be signed in to change notification settings - Fork 292
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
Prefer locally installed version, fall back to global. #32
Prefer locally installed version, fall back to global. #32
Conversation
Do you really need this feature despite npm scripts automatically run locally installed binaries? https://docs.npmjs.com/misc/scripts#path |
Yes. |
I am working on fallback-cli, which will do basically the same thing in a generic way. It's almost ready (just need to ad a couple more tests and some docs). |
Switched PR to use fallback-cli. |
I simple solution to this is prepending |
@joakimbeng Huh, I guess I had always just assumed Unfortunately, it doesn't work for me. I use |
Not a big fan of this tbh. This way every tool has to change instead of you once. This will also break when global and local CLI differ, which will definitely happen at some point. It also makes it ambigious when the local/global one is used and makes it a lot harder to debug issues coming up. I've just aliased it in my dotfiles:
I would rather see this solved for all tools through For reference, relevant ESLint discussion → eslint/eslint#3993. |
That entirely depends on what you mean by "break". If you are saying that version X won't handle the same options as version Y, then yeah, obviously. The fallback mechanism won't fail, but the options you can use with each version of the CLI will obviously change over time. This solution remains backwards/forwards compatible as long as you never change the relative path to
To the contrary, it disambiguates things. If local is present, it is always what is used. Currently, you have a confusing scenario where two identical commands produce different results depending on if they are executed from an npm script or the command line.
I do not see how it is any harder than the current situation. Currently if a user submits an issue reporting that "
That is all fine and good when it actually happens. Still, code within a given project is intended to be linted/styled against a specific version of a specific linter.
Not sure what to make of that. |
@vdemedes @floatdrop @SamVerschueren @kevva Could really use your thoughts on this. If I decide to use it here, I'm gonna use it in AVA too. |
Isn't it possible to do this a little bit cleaner? It adds quite some overhead to your modules imo. But not sure if can be done otherwise. Why the shim? Can't the Not sure if possible, hard to figure out on mobile :). |
@SamVerschueren The shim is necessary. Here's the default process:
The important thing to note is that when you call the global As for parsing Not a concern here, but for The only real downside is that your global cli changes behavior depending on directory. In a sense, that is unexpected and potentially confusing. "Why is I have been burned repeatedly by the other situation. With |
Not have much time at the moment, will have a closer look soon. Thanks for explaining! |
I feel strongly against this, because it introduces a lot of confusion. There should be a clear differentiation of what's local and what's global, as it is now. I wouldn't mess with this just to save a few characters. As @sindresorhus and @shinnn pointed out, you can use npm scripts or bash aliases for that. |
People keep saying that, but I still do not buy it. If I run the command |
@jamestalmage Here's absolutely common scenario (at least for me), which I always use when developing CLI tools. Say I implemented some new stuff in xo CLI and I want to test it. I run |
Ok, so we change "bin": {
"xo": "cli-shim.js",
"_xo": "cli.js"
} And then you can just Alternatively we could add a Or... What if I can detect that it is globally linked and automagically ignore the local version? Not sure if it's possible, but I think it probably is. Might be difficult. But if that's what it takes I'll try it. |
And all these hacks are just to avoid typing a few more characters? |
No. To avoid confusing scenarios for users. |
I think it will only avoid confusing scenarios for beginners, but introduce confusion among experienced developers. |
Can you describe a scenario where it might confuse a developer (outside someone who is hacking on |
Because this PR breaks standard behavior. If I execute This just introduces black magic under the hood, which will confuse experienced Node.js developers and they'll wonder "why the hell does this command uses a locally installed version", "I am not using npm scripts, why is it using a local version", "I am not using relative path, why is it using a local version". To sum up, there is only one reason for it and many reasons against. People participating in this discussion pointed out good solutions on how to save characters and use local xo versions. They are standard, they are straightforward and they don't require tweaking the |
@vdemedes I've read and given careful consideration to every response. I'm not here to stir up trouble, but to have a healthy debate. I hope you are not taking it that way. Speaking frankly, IMO you have only provided one good example of a scenario where someone would actually NOT want the behavior proposed (yourself as you hack on This whole section of your response:
... is unconvincing unless there are scenarios where people actually want that. If I have a codebase that is currently linted against |
To sum up and make this as clear as possible one more time, my concerns are related only to not altering standard behavior. |
Alright, we eventually came to the conclusion in AVA that this can actually be useful. @jamestalmage Can you update to use the same method as used in AVA? |
closing in favor of #57 |
Use whatever version of
xo
is installed locally innode_modules
, before using the globally installed version.Fairly naive implementation, but it works and is backward compatible as far back as I checked (0.7.x).
I disable
update-notifier
if a local version is found. That could maybe be improved upon by still notifying if local is out of date.update-notifier
seems to always recommend installation with the-g
flag though.