Skip to content

Commit

Permalink
Enable proto.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Feb 21, 2025
1 parent bd4cf3d commit 1996f36
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 23 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@
- [Rust](https://github.com/moonrepo/plugins/blob/master/tools/rust/CHANGELOG.md)
- [Schema (TOML, JSON, YAML)](https://github.com/moonrepo/plugins/blob/master/tools/internal-schema/CHANGELOG.md)

## Unreleased

#### 🚀 Updates

- Added shim support to the internal `proto` tool, allowing the proto version to be pinned in `.prototools`, and the version to dynamically be detected at runtime. This enables a specific proto version to be used per project.
- Updated `proto install` to now install proto if a version has been defined.

#### 🧩 Plugins

- Updated `proto_tool` to v0.5.1.
- Now supports shims.

#### ⚙️ Internal

- Updated Rust to v1.85.
- Updated dependencies.

## 0.46.1

#### 🐞 Fixes
Expand Down
14 changes: 1 addition & 13 deletions crates/cli/src/commands/bin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::session::ProtoSession;
use clap::Args;
use proto_core::{Id, PROTO_PLUGIN_KEY, ToolSpec, detect_version_with_spec};
use proto_shim::{get_exe_file_name, locate_proto_exe};
use proto_core::{Id, ToolSpec, detect_version_with_spec};
use starbase::AppResult;

#[derive(Args, Clone, Debug)]
Expand All @@ -21,17 +20,6 @@ pub struct BinArgs {

#[tracing::instrument(skip_all)]
pub async fn bin(session: ProtoSession, args: BinArgs) -> AppResult {
if args.id == PROTO_PLUGIN_KEY {
session.console.out.write_line(
locate_proto_exe("proto")
.unwrap_or(session.env.store.bin_dir.join(get_exe_file_name("proto")))
.display()
.to_string(),
)?;

return Ok(None);
}

let mut tool = session
.load_tool(&args.id, args.spec.clone().and_then(|spec| spec.backend))
.await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl ProtoSession {
}

// These shouldn't be treated as a "normal plugin"
if id == SCHEMA_PLUGIN_KEY || id == PROTO_PLUGIN_KEY {
if id == SCHEMA_PLUGIN_KEY {
continue;
}

Expand Down
2 changes: 2 additions & 0 deletions crates/cli/src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ pub async fn download_versioned_proto_tool(session: &ProtoSession) -> miette::Re

let mut tool = session.load_proto_tool().await?;

tool.resolve_version_with_spec(spec, true).await?;

if !tool.is_installed() {
debug!(
version = spec.to_string(),
Expand Down
7 changes: 1 addition & 6 deletions crates/cli/src/workflows/install_workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::utils::tool_record::ToolRecord;
use iocraft::element;
use miette::IntoDiagnostic;
use proto_core::flow::install::{InstallOptions, InstallPhase};
use proto_core::{Id, PROTO_PLUGIN_KEY, PinLocation, ToolSpec};
use proto_core::{Id, PinLocation, ToolSpec};
use proto_pdk_api::{
InstallHook, InstallStrategy, Switch, SyncShellProfileInput, SyncShellProfileOutput,
};
Expand Down Expand Up @@ -278,11 +278,6 @@ impl InstallWorkflow {
spec: &ToolSpec,
arg_pin_to: &Option<PinLocation>,
) -> miette::Result<bool> {
// Don't pin the proto tool itself as it's internal only
if self.tool.id.as_str() == PROTO_PLUGIN_KEY {
return Ok(false);
}

let config = self.tool.proto.load_config()?;
let mut pin_to = PinLocation::Local;
let mut pin = false;
Expand Down
36 changes: 34 additions & 2 deletions crates/cli/tests/install_uninstall_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,38 @@ mod install_uninstall {
assert!(sandbox.path().join(".proto/tools/node/16.20.2").exists());
}

#[test]
fn installs_and_uninstalls_proto() {
let sandbox = create_empty_proto_sandbox();
let tool_dir = sandbox.path().join(".proto/tools/proto/0.45.0");

assert!(!tool_dir.exists());

// Install
let assert = sandbox
.run_bin(|cmd| {
cmd.arg("install").arg("proto").arg("0.45.0");
})
.success();

assert!(tool_dir.exists());

assert.stdout(predicate::str::contains("proto 0.45.0 has been installed"));

// Uninstall
let assert = sandbox
.run_bin(|cmd| {
cmd.arg("uninstall").arg("proto").arg("0.45.0").arg("--yes");
})
.success();

assert!(!tool_dir.exists());

assert.stdout(predicate::str::contains(
"proto 0.45.0 has been uninstalled!",
));
}

#[test]
fn installs_and_uninstalls_tool() {
let sandbox = create_empty_proto_sandbox();
Expand Down Expand Up @@ -87,7 +119,7 @@ mod install_uninstall {
// Uninstall
let assert = sandbox
.run_bin(|cmd| {
cmd.arg("uninstall").arg("node").arg("19.0.0");
cmd.arg("uninstall").arg("node").arg("19.0.0").arg("--yes");
})
.success();

Expand Down Expand Up @@ -274,7 +306,7 @@ mod install_uninstall {
// Uninstall
sandbox
.run_bin(|cmd| {
cmd.arg("uninstall").arg("node").arg("19.0.0");
cmd.arg("uninstall").arg("node").arg("19.0.0").arg("--yes");
})
.success();

Expand Down
68 changes: 68 additions & 0 deletions crates/cli/tests/pin_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,26 @@ npm = "9.0.0"
"npm = \"6.14.18\"\n"
)
}

#[test]
fn can_set_proto() {
let sandbox = create_empty_proto_sandbox();
let version_file = sandbox.path().join(".prototools");

assert!(!version_file.exists());

sandbox
.run_bin(|cmd| {
cmd.arg("pin").arg("proto").arg("0.45.0");
})
.success();

assert!(version_file.exists());
assert_eq!(
fs::read_to_string(version_file).unwrap(),
"proto = \"0.45.0\"\n"
)
}
}

mod pin_global {
Expand Down Expand Up @@ -269,6 +289,30 @@ mod pin_global {

assert!(!link.exists());
}

#[test]
fn can_set_proto() {
let sandbox = create_empty_proto_sandbox();
let version_file = sandbox.path().join(".proto/.prototools");

assert!(!version_file.exists());

sandbox
.run_bin(|cmd| {
cmd.arg("pin")
.arg("proto")
.arg("0.45.0")
.arg("--to")
.arg("global");
})
.success();

assert!(version_file.exists());
assert_eq!(
fs::read_to_string(version_file).unwrap(),
"proto = \"0.45.0\"\n"
)
}
}

mod pin_user {
Expand Down Expand Up @@ -297,4 +341,28 @@ mod pin_user {
"node = \"19.0.0\"\n"
)
}

#[test]
fn can_set_proto() {
let sandbox = create_empty_proto_sandbox();
let version_file = sandbox.path().join(".home/.prototools");

assert!(!version_file.exists());

sandbox
.run_bin(|cmd| {
cmd.arg("pin")
.arg("proto")
.arg("0.45.0")
.arg("--to")
.arg("home");
})
.success();

assert!(version_file.exists());
assert_eq!(
fs::read_to_string(version_file).unwrap(),
"proto = \"0.45.0\"\n"
)
}
}
2 changes: 1 addition & 1 deletion crates/core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl ProtoConfig {

pub fn builtin_proto_plugin(&self) -> PluginLocator {
PluginLocator::Url(Box::new(UrlLocator {
url: "https://github.com/moonrepo/plugins/releases/download/proto_tool-v0.5.0/proto_tool.wasm".into()
url: "https://github.com/moonrepo/plugins/releases/download/proto_tool-v0.5.1/proto_tool.wasm".into()
}))
}

Expand Down

0 comments on commit 1996f36

Please sign in to comment.