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

new: Allow pin even if already installed. #200

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
- [Rust](https://github.com/moonrepo/rust-plugin/blob/master/CHANGELOG.md)
- [Schema](https://github.com/moonrepo/schema-plugin/blob/master/CHANGELOG.md)

## Unreleased

#### 🚀 Updates

- Updated `proto install --pin` to also pin even if the tool has already been installed.

## 0.17.0

#### 💥 Breaking
Expand Down
14 changes: 12 additions & 2 deletions crates/cli/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ pub struct InstallArgs {
pub passthrough: Vec<String>,
}

pub fn pin_global(tool: &mut Tool) -> SystemResult {
tool.manifest.default_version = Some(tool.get_resolved_version().to_unresolved_spec());
tool.manifest.save()?;

Ok(())
}

pub async fn internal_install(args: InstallArgs) -> SystemResult {
let mut tool = load_tool(&args.id).await?;
let version = if args.canary {
Expand All @@ -45,6 +52,10 @@ pub async fn internal_install(args: InstallArgs) -> SystemResult {
};

if !version.is_canary() && tool.is_setup(&version).await? {
if args.pin {
pin_global(&mut tool)?;
}

info!(
"{} has already been installed at {}",
tool.get_name(),
Expand Down Expand Up @@ -91,8 +102,7 @@ pub async fn internal_install(args: InstallArgs) -> SystemResult {
tool.cleanup().await?;

if args.pin {
tool.manifest.default_version = Some(tool.get_resolved_version().to_unresolved_spec());
tool.manifest.save()?;
pin_global(&mut tool)?;
}

pb.finish_and_clear();
Expand Down
35 changes: 35 additions & 0 deletions crates/cli/tests/install_uninstall_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,39 @@ mod install_uninstall {
])
);
}

#[test]
fn can_pin_when_already_installed() {
let temp = create_empty_sandbox();
let manifest_file = temp.path().join("tools/node/manifest.json");

let mut cmd = create_proto_command(temp.path());
cmd.arg("install")
.arg("node")
.arg("19.0.0")
.arg("--")
.arg("--no-bundled-npm")
.assert();

// Manually change it to something else
let mut manifest = ToolManifest::load(&manifest_file).unwrap();
manifest.default_version = Some(UnresolvedVersionSpec::parse("18.0.0").unwrap());
manifest.save().unwrap();

let mut cmd = create_proto_command(temp.path());
cmd.arg("install")
.arg("node")
.arg("19.0.0")
.arg("--pin")
.arg("--")
.arg("--no-bundled-npm")
.assert();

let manifest = ToolManifest::load(&manifest_file).unwrap();

assert_eq!(
manifest.default_version,
Some(UnresolvedVersionSpec::parse("19.0.0").unwrap())
);
}
}
2 changes: 1 addition & 1 deletion crates/core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ macro_rules! impl_event {
impl_event!($name, (), $impl);
};

($name:ident, $data:ty, $impl:tt) => {
($name:ident, $data:ty, $impl:tt) => {
pub struct $name $impl

impl Event for $name {
Expand Down