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

nvm use should write a .nvmrc file by default #2849

Open
colearendt opened this issue Jul 27, 2022 · 7 comments
Open

nvm use should write a .nvmrc file by default #2849

colearendt opened this issue Jul 27, 2022 · 7 comments
Labels
feature requests I want a new feature in nvm! pull request wanted This is a great way to contribute! Help us out :-D

Comments

@colearendt
Copy link

Thanks for the great work on this!

I am most familiar with a lot of the semantics of the pyenv project. One of the nice features that keeps things consistent is that when pyenv uses the following logic:

  • if there is a .python_version file in the current directory use that
  • if there is a .python_version in a parent directory, use that
  • if there is no .python_version in this or a parent directory, use the default
  • you can change the version by selecting pyenv local
  • when pyenv local is called, a .python_version file is written to the current directory

I just learned that nvm supports the same via the .nvmrc file. However, it is opt-in behavior (which I found surprising). I also found it hard to discover, because there was no command-line option related to writing a file / etc.

And to the main thrust of this issue, the last bullet is different - I must write a .nvmrc file myself. I would expect that if I went to the trouble of nvm use in the current, then I am expecting other shells in this directory to do the same.

Perhaps there is another use case I am not thinking of. However, at a minimum I would expect a flag to "write a .nvmrc file for me" as an opt-in. And the opt-out of writing such a file feels like the better interface.

@ljharb
Copy link
Member

ljharb commented Jul 30, 2022

I definitely don't think this should be done by default; just because someone is nvm useing does not mean that's the version other developers should be expected to use - and just because one developer is using nvm doesn't mean that a project's git repo should get an .nvmrc file unless every other developer is also expected to use it.

I think some kind of option on nvm use/nvm install that created/updated an $PWD/.nvmrc file would be reasonable, tho.

@ljharb ljharb added feature requests I want a new feature in nvm! pull request wanted This is a great way to contribute! Help us out :-D labels Jul 30, 2022
@colearendt
Copy link
Author

colearendt commented Jul 30, 2022

That makes sense. For the record, I think the way we generally work around that in .python-version is by either .gitignoreing it, or committing it and people can either choose to use it or not. I will say, after digging into #2850, that this may be related to python-virtualenv and another "overstepping reasonable bounds."

This is the help docs on nvm use for reference:

  nvm use [<version>]                         Modify PATH to use <version>. Uses .nvmrc if available and version is omitted.
   The following optional arguments, if provided, must appear directly after `nvm use`:
    --silent                                  Silences stdout/stderr output
    --lts                                     Uses automatic LTS (long-term support) alias `lts/*`, if available.
    --lts=<LTS name>                          Uses automatic alias for provided LTS line, if available.

Does nvm use -w v16 seem like a reasonable interface? (-w for "write"). It saves the hassle of nvm use v16 && echo 'v16' > .nvmrc.

@mouday
Copy link

mouday commented Aug 17, 2022

this good a idea!

maartin0 added a commit to maartin0/nvm that referenced this issue Aug 29, 2022
ljharb added a commit to maartin0/nvm that referenced this issue Oct 8, 2022
FIxes nvm-sh#2849.

Co-authored-by: Martin <16228305+maartin0@users.noreply.github.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
ljharb added a commit to maartin0/nvm that referenced this issue Oct 8, 2022
FIxes nvm-sh#2849.

Co-authored-by: Martin <16228305+maartin0@users.noreply.github.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
ljharb added a commit to maartin0/nvm that referenced this issue Oct 8, 2022
FIxes nvm-sh#2849.

Co-authored-by: Martin <16228305+maartin0@users.noreply.github.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
ljharb added a commit to maartin0/nvm that referenced this issue Oct 8, 2022
FIxes nvm-sh#2849.

Co-authored-by: Martin <16228305+maartin0@users.noreply.github.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
@ryenus
Copy link
Contributor

ryenus commented Nov 2, 2022

I second that --save can exist but it should NOT be the default. I want to be able to change the current node version regardless which directory I'm currently in.

maartin0 added a commit to maartin0/nvm that referenced this issue Nov 8, 2022
FIxes nvm-sh#2849.

Co-authored-by: Martin <16228305+maartin0@users.noreply.github.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
ljharb added a commit to maartin0/nvm that referenced this issue Dec 28, 2022
FIxes nvm-sh#2849.

Co-authored-by: Martin <16228305+maartin0@users.noreply.github.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
@katcaola
Copy link

katcaola commented Mar 20, 2023

As a heads up, the windows version of nvm does not support certain version strings the way that nvm-sh does. I'm trying to script an automatic repository setup for both windows and unix users, and

  • you can't use vX.Y.Z as a version string in the windows version (it must be X.Y.Z)
  • you can't have lts version name strings like lts/hydrogen in the windows version (it must be ltsX such as lts18).

Making it default might not work for users who use nvm for windows.

@ryenus
Copy link
Contributor

ryenus commented Mar 20, 2023

BTW, there's direnv, here's a related issue: direnv/direnv#335

@ljharb
Copy link
Member

ljharb commented Mar 20, 2023

@katcaola you mean nvm-windows? That's a completely different project. nvm itself (which works on windows in some shells) supports the same strings as on non-windows.

joaonunomota pushed a commit to joaonunomota/nvm that referenced this issue Jul 29, 2023
FIxes nvm-sh#2849.

Co-authored-by: Martin <16228305+maartin0@users.noreply.github.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Feb 21, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <16228305+maartin0@users.noreply.github.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Feb 21, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Feb 21, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Feb 21, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Feb 22, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Feb 22, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Feb 22, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Feb 22, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Feb 24, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Feb 29, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Feb 29, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Feb 29, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Feb 29, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Feb 29, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Feb 29, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Mar 1, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Mar 1, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Mar 16, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Mar 17, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
maartin0 added a commit to maartin0/nvm that referenced this issue Mar 17, 2024
Fixes nvm-sh#2849.

Co-authored-by: Martin <maartin00000@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature requests I want a new feature in nvm! pull request wanted This is a great way to contribute! Help us out :-D
Projects
None yet
Development

No branches or pull requests

5 participants