Skip to content

feat: add --reinstall-packages-from= argument for fnm install#510

Closed
libook wants to merge 1 commit into
Schniz:masterfrom
libook:feat-reinstall-packages-from
Closed

feat: add --reinstall-packages-from= argument for fnm install#510
libook wants to merge 1 commit into
Schniz:masterfrom
libook:feat-reinstall-packages-from

Conversation

@libook

@libook libook commented Aug 9, 2021

Copy link
Copy Markdown

I am a noob in Rust.
My code may not be good enough. Please feel free to left your comments.

@vercel

vercel Bot commented Aug 9, 2021

Copy link
Copy Markdown

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/schniz/fnm/FVX9uLJzzvvQ3eZ1Cq26FGeFTony
✅ Preview: https://fnm-git-fork-libook-feat-reinstall-packages-from-schniz.vercel.app

@Schniz Schniz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @libook! THANK YOU for the contribution!

As I already mentioned in the thread, I am pretty torn about this feature: it really feels out of fnm's scope. You can even see that it is very third party in the code you just wrote here, and can be easily migrated to be a script like:

#!/bin/sh

fnm install $1
PACKAGES=$(fnm exec --using=$2 npm list -g --depth=0 2>/dev/null | ...)
fnm exec --using=$1 npm install -g $PACKAGES

So I'm not entirely sold in favor of maintaining this. What do you think? What are the pros (and if you can, the cons) of adding this?


Also, since fnm supports Windows, we should support this feature for Windows users too. Taking all of this code to another Rust module that is properly tested using unit/e2e tests will allow CI to run the code on Linux/Mac and Windows machines.


thanks again for your contribution and I'm really sorry if I'm a serious downer.

Comment thread src/commands/install.rs
Comment on lines +113 to +128
let output = std::process::Command::new("sh")
.arg("-c")
.arg(format!(
concat!(
"fnm use \"{}\" >/dev/null ",
"&& npm list -g --depth=0 2>/dev/null ",
"| command sed 1,1d ",
"| command sed ",
"-e '/ -> / d' ",
"-e '/\\(empty\\)/ d' ",
"-e 's/^.* \\(.*@[^ ]*\\).*/\\1/' ",
"-e '/^npm@[^ ]*.*$/ d'",
),
user_version,
))
.output().expect("Failed to get package list.");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work on Windows-based shells (wincmd).
Maybe we can try adding a new command, fnm reinstall-packages-from, and we can add unit/e2e tests for it.

Comment thread src/commands/install.rs
Comment on lines +230 to +233
#[snafu(display("Execute command failed:\n{}", stderr))]
CommandExecutionFailed {
stderr: String,
},

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be more specific. InstallingPackagesFromOtherVersionFailed

@libook

libook commented Aug 9, 2021

Copy link
Copy Markdown
Author

@Schniz You are right.

I am an nvm user for many years. I use MacOs, Linux and WSL as developing environment. And have forgotten that nvm doesn't support windows.

I am learning Rust. I found fnm in some Rust news. It is a real "fast node manager" as the name said.
I use nvm in many automatic scripts. So I wish that I can replace nvm to fnm. Fnm doesn't have features like --reinstall-packages-from=. I was wondering if I can add the feature for fnm.

That is why I did this.


it is very third party in the code

I agree with you. This feature requires both npm and node version manager. Npm can't do this by itself. Extra script is the only way, if a node version manager doesn't do this either.
It may still be a common requirement while using a node version manager (at least for developers who is maintaining multiple node projects like me).

Maybe there will be a better way for cross platform supporting and even for multiple node package managers too(e.g. yarn and pnpm) in the future.

I am happy with learning and hacking Rust in this work. And I have learned a lot. I am ok if you think that it is not the time for this feature.

@libook libook closed this Aug 9, 2021
@ljharb

ljharb commented Aug 9, 2021

Copy link
Copy Markdown

@libook the next version of nvm does in fact support windows, the current one has supported WSL for years.

@libook

libook commented Aug 10, 2021

Copy link
Copy Markdown
Author

@ljharb Wow, a familiar avatar. I always see you in ECMA works.

Yes, I have been using nvm for years. Nvm has powerful functions. I have a zsh tool box which requires nvm as an optional dependency for scripts.
Will nvm support Windows PowerShell? I know nvm-windows. But POSIX environment (sure, include WSL) is enough for me. Just in case for native library requirements you know.

Thank you guys for maintaining cool things.

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

Successfully merging this pull request may close these issues.

3 participants