Skip to content

Commit

Permalink
new: Add new executables system. (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Nov 8, 2023
1 parent ce88f49 commit 3c4cf8b
Show file tree
Hide file tree
Showing 48 changed files with 957 additions and 1,035 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@
- [Rust](https://github.com/moonrepo/rust-plugin/blob/master/CHANGELOG.md)
- [TOML schema](https://github.com/moonrepo/schema-plugin/blob/master/CHANGELOG.md)

## Unreleased

#### 🚀 Updates

- Refactored and standardized how executables (bins and shims) are managed.
- Binaries (`~/.proto/bin`) and shims (`~/.proto/shims`) now share the same internal data structures.
- For the most part, is a 1:1 relation. There will be a shim for every binary, and vice versa.
- Reduced the amount of WASM calls to locate executables to 1 call.
- Removed the concept of local shims (was a hidden implementation detail).
- Reworked the `proto bin` command.
- By default returns an absolute path to the real executable (`~/.proto/tools/<tool>/<version>/bin`).
- Pass `--bin` to return the `~/.proto/bin` path.
- Pass `--shim` to return the `~/.proto/shims` path.
- Updated `proto clean --purge` and `proto uninstall` to accurately delete all executables.
- WASM API
- Added `locate_executables` function.
- Added `LocateExecutablesInput`, `LocateExecutablesOutput`, `ExecutableConfig` structs.
- Deprecated `locate_bins` and `create_shims` functions.
- Deprecated `LocateBinsInput`, `LocateBinsOutput`, `CreateShimsInput`, `CreateShimsOutput`, `ShimConfig` structs.

#### ⚙️ Internal

- Plugin versions are now pinned and tied to proto releases to avoid unintended drift and API changes.

## 0.21.1

#### 🐞 Fixes
Expand Down
40 changes: 20 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ human-sort = "0.2.2"
miette = "5.10.0"
once_cell = "1.18.0"
once_map = "0.4.10"
regex = { version = "1.10.2", default-features = false, features = [
"std",
"unicode-perl",
] }
regex = { version = "1.10.2", default-features = false, features = ["std"] }
reqwest = { version = "0.11.22", default-features = false }
schematic = { version = "0.12.7", default-features = false, features = [
"schema",
] }
semver = "1.0.20"
serde = { version = "1.0.190", features = ["derive"] }
serde_json = "1.0.107"
serde_json = "1.0.108"
sha2 = "0.10.8"
starbase = "0.2.9"
starbase_archive = { version = "0.2.4", features = [
Expand All @@ -37,7 +34,7 @@ starbase_archive = { version = "0.2.4", features = [
starbase_events = "0.2.2"
starbase_sandbox = { version = "0.1.12" }
starbase_styles = "0.1.16"
starbase_utils = { version = "0.3.6", default-features = false, features = [
starbase_utils = { version = "0.3.7", default-features = false, features = [
"json",
"toml",
] }
Expand Down
7 changes: 4 additions & 3 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ name = "proto"
path = "src/main.rs"

[dependencies]
proto_core = { version = "0.21.2", path = "../core" }
proto_pdk_api = { version = "0.9.0", path = "../pdk-api" }
system_env = { version = "0.1.2", path = "../system-env" }
proto_core = { version = "0.22.1", path = "../core" }
proto_pdk_api = { version = "0.10.1", path = "../pdk-api" }
system_env = { version = "0.1.3", path = "../system-env" }
chrono = "0.4.31"
clap = { workspace = true, features = ["derive", "env"] }
clap_complete = { workspace = true }
Expand All @@ -43,6 +43,7 @@ miette = { workspace = true }
reqwest = { workspace = true, features = ["rustls-tls-native-roots", "stream"] }
semver = { workspace = true }
serde = { workspace = true }
shell-words = "1.1.0"
starbase = { workspace = true }
starbase_archive = { workspace = true }
starbase_styles = { workspace = true }
Expand Down
8 changes: 4 additions & 4 deletions crates/cli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ pub enum Commands {

#[command(
name = "bin",
about = "Display the absolute path to a tools binary.",
long_about = "Display the absolute path to a tools binary. If no version is provided,\nit will detected from the current environment."
about = "Display the absolute path to a tools executable.",
long_about = "Display the absolute path to a tools executable. If no version is provided,\nit will be detected from the current environment."
)]
Bin(BinArgs),

Expand Down Expand Up @@ -144,7 +144,7 @@ pub enum Commands {
alias = "lsg",
name = "list-global",
about = "List installed globals.",
long_about = "List installed globals by scanning the global bins installation directory. Will return the canonical source path."
long_about = "List installed globals by scanning the global packages installation directory. Will return the canonical source path."
)]
ListGlobal(ListGlobalArgs),

Expand Down Expand Up @@ -191,7 +191,7 @@ pub enum Commands {
alias = "r",
name = "run",
about = "Run a tool after detecting a version from the environment.",
long_about = "Run a tool after detecting a version from the environment. In order of priority,\na version will be resolved from a provided CLI argument, a PROTO_VERSION environment variable,\na local version file (.prototools), and lastly a global version file (~/.proto/tools/version).\n\nIf no version can be found, the program will exit with an error."
long_about = "Run a tool after detecting a version from the environment. In order of priority,\na version will be resolved from a provided CLI argument, a PROTO_VERSION environment variable,\na local version file (.prototools), and lastly a global version file (~/.proto/tools).\n\nIf no version can be found, the program will exit with an error."
)]
Run(RunArgs),

Expand Down
27 changes: 19 additions & 8 deletions crates/cli/src/commands/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ pub struct BinArgs {
#[arg(required = true, help = "ID of tool")]
id: Id,

#[arg(long, help = "Display symlinked binary path when available")]
bin: bool,

#[arg(help = "Version or alias of tool")]
spec: Option<UnresolvedVersionSpec>,

Expand All @@ -20,17 +23,25 @@ pub async fn bin(args: ArgsRef<BinArgs>) {
let version = detect_version(&tool, args.spec.clone()).await?;

tool.resolve_version(&version).await?;
tool.locate_bins().await?;
tool.create_executables(true, false).await?;

if args.bin {
for bin in tool.get_bin_locations()? {
if bin.primary {
println!("{}", bin.path.display());
return Ok(());
}
}
}

if args.shim {
tool.setup_shims(true).await?;

if let Some(shim_path) = tool.get_shim_path() {
println!("{}", shim_path.to_string_lossy());

return Ok(());
for shim in tool.get_shim_locations()? {
if shim.primary {
println!("{}", shim.path.display());
return Ok(());
}
}
}

println!("{}", tool.get_bin_path()?.to_string_lossy());
println!("{}", tool.get_exe_path()?.display());
}
33 changes: 7 additions & 26 deletions crates/cli/src/commands/clean.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use clap::Args;
use dialoguer::Confirm;
use proto_core::{
get_plugins_dir, get_shim_file_name, get_temp_dir, load_tool, Id, ProtoError, Tool,
ToolsConfig, VersionSpec,
get_plugins_dir, get_temp_dir, load_tool, Id, ProtoError, Tool, ToolsConfig, VersionSpec,
};
use proto_pdk_api::{CreateShimsInput, CreateShimsOutput};
use starbase::diagnostics::IntoDiagnostic;
use starbase::{system, SystemResult};
use starbase_styles::color;
Expand Down Expand Up @@ -198,31 +196,14 @@ async fn purge_tool(id: &Id, yes: bool) -> SystemResult {
// Delete inventory
fs::remove_dir_all(inventory_dir)?;

// Delete binary
fs::remove_file(tool.proto.bin_dir.join(tool.get_bin_name()))?;
// Delete binaries
for bin in tool.get_bin_locations()? {
fs::remove_file(bin.path)?;
}

// Delete shims
fs::remove_file(
tool.proto
.shims_dir
.join(get_shim_file_name(id.as_str(), true)),
)?;

if tool.plugin.has_func("create_shims") {
let shim_configs: CreateShimsOutput = tool.plugin.cache_func_with(
"create_shims",
CreateShimsInput {
context: tool.create_context(),
},
)?;

for global_shim in shim_configs.global_shims.keys() {
fs::remove_file(
tool.proto
.shims_dir
.join(get_shim_file_name(global_shim, true)),
)?;
}
for shim in tool.get_shim_locations()? {
fs::remove_file(shim.path)?;
}

info!("Removed {}", tool.get_name());
Expand Down
10 changes: 5 additions & 5 deletions crates/cli/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct InstallArgs {
pub passthrough: Vec<String>,
}

fn pin_version(
async fn pin_version(
tool: &mut Tool,
initial_version: &UnresolvedVersionSpec,
global: bool,
Expand All @@ -56,7 +56,7 @@ fn pin_version(
if global {
args.global = true;

return internal_pin(tool, &args, true);
return internal_pin(tool, &args, true).await;
}

// via `pin-latest` setting
Expand All @@ -66,7 +66,7 @@ fn pin_version(
if let Some(pin_type) = user_config.pin_latest {
args.global = matches!(pin_type, PinType::Global);

return internal_pin(tool, &args, true);
return internal_pin(tool, &args, true).await;
}
}

Expand All @@ -89,7 +89,7 @@ pub async fn internal_install(args: InstallArgs, tool: Option<Tool>) -> miette::
tool.disable_caching();

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

info!(
"{} has already been installed at {}",
Expand Down Expand Up @@ -138,7 +138,7 @@ pub async fn internal_install(args: InstallArgs, tool: Option<Tool>) -> miette::
return Ok(tool);
}

pin_version(&mut tool, &version, args.pin)?;
pin_version(&mut tool, &version, args.pin).await?;

info!(
"{} has been installed to {}!",
Expand Down
Loading

0 comments on commit 3c4cf8b

Please sign in to comment.