Skip to content

Make volta-migrate regenerate shims and add --no-create option to it - #938

Merged
charlespierce merged 5 commits into
volta-cli:mainfrom
uasi:regenerate-shims
Feb 15, 2021
Merged

charlespierce merged 5 commits into
volta-cli:mainfrom
uasi:regenerate-shims

Conversation

@uasi

@uasi uasi commented Feb 13, 2021

Copy link
Copy Markdown
Contributor

Addresses #927

Background

Shims are symbolic links to /path/to/volta-shim. If a package manager installs a new version of Volta to a different location and removes the current version, shims will be broken.

Changes

  • Make volta-migrate regenerate shims even if the layout is up-to-date.
  • Add --no-create option to volta-migrate. When specified, volta-migrate runs migration only if the Volta directory already exists.

@uasi

uasi commented Feb 14, 2021

Copy link
Copy Markdown
Contributor Author

There's something wrong with the macOS (ARM) build.

@charlespierce charlespierce left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this @uasi! I have one question about the added flag to volta-migrate.

Also, if you're willing, would you also remove the call to regenerate_shims_for_dir in https://github.com/volta-cli/volta/blob/main/src/common.rs#L22 ? That is always called right after calling volta-migrate, and since we're now doing that same thing within volta-migrate, we don't need to duplicate it.

Comment thread src/volta-migrate.rs Outdated
raw(global_setting = "structopt::clap::AppSettings::DeriveDisplayOrder"),
raw(global_setting = "structopt::clap::AppSettings::DisableVersion")
)]
struct VoltaMigrate {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you expand a bit on the use-case behind this option? The migration is designed to be idempotent, so running it multiple times shouldn't be a concern. Additionally, Volta will absolutely not work without the directory set up (and will force it to be set up when it's run), so I'm not clear what the benefits would of calling volta-migrate and having it no-op would be.

Finally, while I agree that calling volta-migrate from the Homebrew installer makes sense, I think that volta-migrate (similar to volta-shim) is primarily intended to be an implementation detail, so I'm a little wary of adding StructOpt to it as that involves a lot of extra compilation baggage and makes it seem more like a CLI that people should think about.

@uasi uasi Feb 15, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think brew intall volta alone should not modify anything under the home directory, so volta-migrate have to be no-op unless ~/.volta exists. Not creating ~/.volta in advance is not a problem as a first-time user will probably run volta install node afterwards anyway.

On the other hand, brew upgrade volta should take care of existing shims so that the user doesn't have to run volta setup themselves again.

As for option parsing, how about just doing std::env::args().nth(1) == Some("--no-create".to_owned()) without StructOpt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

std::env::args().nth(1) == Some("--no-create".to_owned())
std::env::args().nth(1).map_or(false, |v| v == "--no-create")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a bit of a weird state, since the script installer does modify the home directory (and even modifies the profile scripts unless turned off). However, it looks like the current Homebrew installer doesn't do that (meaning users will need to run volta setup after brew install volta), and we probably shouldn't change that out from underneath them.

I think having a small flag is a reasonable, though I would prefer to do a more simplistic matching like you showed, as opposed to bringing in all the complexity of StructOpt. I think your solution is pretty good, though I would use args_os since that won't panic if there are non-unicode characters (and you can probably take advantage of the fact that OsString implements PartialEq<&str>):

matches!(std::env::args_os().nth(1), Some(flag) if flag == "--no-create")

We should also probably have a comment around that branch about how it's used by the Homebrew formula to avoid making changes to the user's system.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

matches!(std::env::args_os().nth(1), Some(flag) if flag == "--no-create")

Didn't know that this is even possible! I replaced StructOpt with matches! and added a comment about the purpose of the flag.

Will squash & rebase If there is nothing else to discuss.

@charlespierce

Copy link
Copy Markdown
Contributor

FYI I just merged #940 that includes (among other things) the ARM update you did here, as well as the formatting fix. GitHub at the moment doesn't seem to think there are conflicts, but it's possible there will be some merge conflicts.

@uasi

uasi commented Feb 15, 2021

Copy link
Copy Markdown
Contributor Author

would you also remove the call to regenerate_shims_for_dir

No problem. I removed it.

@uasi

uasi commented Feb 15, 2021

Copy link
Copy Markdown
Contributor Author

Rebased onto main and dropped commits included in #940.

Comment thread src/volta-migrate.rs

if volta_migrate.no_create && !volta_home().map_or(false, |home| home.root().exists()) {
// In order to migrate the existing Volta directory while avoiding unconditional changes to the user's system,
// the Homebrew formula runs volta-migrate with `--no-create` flag in the post-install phase.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If there is anything wrong with my English, please feel free to correct it :)

@charlespierce charlespierce left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thanks for this!

@charlespierce
charlespierce merged commit 320194e into volta-cli:main Feb 15, 2021
@uasi
uasi deleted the regenerate-shims branch February 15, 2021 05:26
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.

2 participants