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

[Question]: autoswitch for .npmrc? #370

Closed
kwonoj opened this issue Jan 20, 2021 · 11 comments
Closed

[Question]: autoswitch for .npmrc? #370

kwonoj opened this issue Jan 20, 2021 · 11 comments

Comments

@kwonoj
Copy link

kwonoj commented Jan 20, 2021

Sorry if this is already supported and I may miss obvious documentation.

Is there way to enable / config sort of automatic switching, i.e if change path and if those repos have corresponding .npmrc automatically call fnm use? I'm trying to our work's setup to utilize fnm and curious if it's supported out of the box instead of trying to wrap those behaviors in our script.

Also, thanks for the great work. 👍

@Schniz
Copy link
Owner

Schniz commented Jan 20, 2021

Hi, and no worries. This is not supported right now. The real question is — how would you "switch" between different npm versions? npm is practically a global package installed, so you can either install a new (or old) version, but not replace them. I mean, don't get me wrong, we can hack something that allows switching npm versions, but I'm not sure it is worth the hustle.

What is your use-case? You want to install a Node version with a specific npm version?

😃

@kwonoj
Copy link
Author

kwonoj commented Jan 20, 2021

That's valid question and I do agree it's bit tricky to handle indeed. afaik some version mgr such as nvm for windows (https://github.com/coreybutler/nvm-windows) puts npm side-by-side to version of node.js installed, so it is possible switching node.js version actually changes npm as well.

Primary usecase is let work repo enforces to use specific version automatically without manually changing. Supporting change node / npm at once would be best, but curious if it's possible to support switching node.js at least. This is a good-to-have feature in my mind, totally ok if this seems too complex to be included in fnm.

@ljharb
Copy link

ljharb commented Jan 20, 2021

npmrc doesn’t specify the version of anything. did you mean a different file?

npm comes with node, so you’d switch it as part of switching the node version. an npm version manager would be an entirely different beast, and would conflict heavily with a node version manager.

@kwonoj
Copy link
Author

kwonoj commented Jan 20, 2021

Huh, why I wrote npmrc - I meant nvmrc.

@kwonoj
Copy link
Author

kwonoj commented Jan 20, 2021

I think I wrote my q too broad could cause overcomplex flows. What I was originally thinking is calling fnm use per .nvmrc - npm was good to have but didn't think deeply about those.

@Schniz
Copy link
Owner

Schniz commented Jan 20, 2021

So if I understand you correctly, we do support .nvmrc!
I used nvm before I used fnm, and most of our projects at work have .nvmrc files. 😄

So: .nvmrc (and .node-version) works for fnm use, and will allow you to change node versions. fnm can also automatically switch your Node versions based on .nvmrc when you change directories with fnm env --use-on-cd 😃

@kwonoj
Copy link
Author

kwonoj commented Jan 20, 2021

Thanks for the quick update, I'll give it a go. When I write this q I guess I am dumb and missing some obvious and indeed it looks like it. 😅

@Schniz
Copy link
Owner

Schniz commented Jan 20, 2021

All questions are good questions. I'm closing the issue but please open a new one or reopen if you have any issues. I'm here for any assistance! 😃

@Schniz Schniz closed this as completed Jan 20, 2021
@idkjs
Copy link
Contributor

idkjs commented Mar 3, 2021

What would you fish.config look like in this case?

fnm env --fnm-dir=$SSD/.fnm | source
fnm env --use-on-cd

?

@Schniz
Copy link
Owner

Schniz commented Mar 3, 2021

In what case?

probably

fnm env --fnm-dir=$SSD/.fnm --use-on-cd | source

@redeemefy
Copy link

I'm not sure if I understand correctly. I have a file in .oh-my-zsh/custom/fnm.zsh with eval "$(fnm env --use-on-cd)". That seems to work when I cd into the project directory. However, it doesn't work when I cd out of the project directory, as you can see 👇 .

Another thing that is strange to me is that when I run fnm list all versions are prefixed with *. I could be wrong about this UX but I would expect only the current version to have the * letting the developer know that's the version in used.

Assuming that the * are just bullets, then that's fine. That means that the * has no meaning in the UX. I guess the confusion is coming on how nvm list shows *. But if that is not the purpose in fnm, then that's fine.

However, the feature of reverting the node --version when cd out of a project that has .node-version/.nvmrc file, it could cause problems when running npm i ... and installing a 📦 in the wrong node version.

Screen Shot 2021-12-07 at 10 16 40 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants