Skip to content

Commit

Permalink
deps: Update plugins. (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Dec 21, 2023
1 parent b7eae4f commit 9611bd1
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 35 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@
- Added a `ExecutableConfig.shim_env_vars` field.
- Updated `ExecutableConfig.shim_before_args` and `ExecutableConfig.shim_after_args` to support a list of strings.

#### 🐞 Fixes

- Fixed an issue where binaries were being symlinked with broken versions in their file name (most commonly for Python).

#### 🧩 Plugins

- Updated `bun_plugin` to v0.7.
- Will now symlink a `bunx` binary to `~/.proto/bin`.
- Updated `deno_plugin` to v0.7.
- Updated `go_plugin` to v0.7.
- Updated `node_plugin` and `node_depman_plugin` to v0.7.
- Will no longer symlink binaries (`~/.proto/bin`) for all package managers.
- You'll most likely need to delete any old bins manually.
- Updated `python_plugin` to v0.5.
- Updated `rust_plugin` to v0.6.
- Updated `schema_plugin` (TOML) to v0.7.

#### ⚙️ Internal

- Added basic telemetry to track tool install/uninstall metrics.
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/main_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// not pull in large libraries (tracing is already enough)!

use anyhow::{anyhow, Result};
use proto_shim::{exec_command_and_replace, locate_proto_bin};
use proto_shim::{exec_command_and_replace, locate_proto_exe};
use rust_json::{json_parse, JsonElem as Json};
use starbase::tracing::{self, trace, TracingOptions};
use std::collections::HashMap;
Expand Down Expand Up @@ -72,7 +72,7 @@ fn create_command(args: Vec<OsString>, shim_name: &str) -> Result<Command> {
}

// Find an applicable proto binary to run with
let proto_bin = locate_proto_bin("proto");
let proto_bin = locate_proto_exe("proto");

if let Some(bin) = proto_bin.as_deref() {
trace!(shim = shim_name, proto_bin = ?bin, "Using a located proto binary");
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/tests/bin_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ mod bin {
let assert = cmd.arg("bin").arg("npm").arg("9.0.0").arg("--bin").assert();

if cfg!(windows) {
assert.stdout(predicate::str::contains("bin\\npm.cmd"));
assert.stdout(predicate::str::contains("bin/npm-cli.js"));
} else {
assert.stdout(predicate::str::contains("bin/npm"));
}
Expand Down
8 changes: 3 additions & 5 deletions crates/cli/tests/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(dead_code)]

use proto_core::{ProtoConfig, ProtoConfigManager};
use proto_shim::get_exe_file_name;
use starbase_sandbox::{assert_cmd, create_command_with_name};
pub use starbase_sandbox::{create_empty_sandbox, output_to_string, Sandbox};
use std::path::Path;
Expand Down Expand Up @@ -51,11 +52,8 @@ pub fn create_shim_command<T: AsRef<Path>>(path: T, name: &str) -> assert_cmd::C
pub fn create_shim_command_std<T: AsRef<Path>>(path: T, name: &str) -> std::process::Command {
let path = path.as_ref();

let mut cmd = std::process::Command::new(path.join(".proto/shims").join(if cfg!(windows) {
format!("{name}.exe")
} else {
name.to_owned()
}));
let mut cmd =
std::process::Command::new(path.join(".proto/shims").join(get_exe_file_name(name)));
cmd.env("PROTO_LOG", "trace");
cmd.env("PROTO_HOME", path.join(".proto"));
cmd.env("PROTO_NODE_VERSION", "latest"); // For package managers
Expand Down
14 changes: 7 additions & 7 deletions crates/core/src/proto_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl ProtoConfig {
self.plugins.insert(
Id::raw("deno"),
PluginLocator::SourceUrl {
url: "https://github.com/moonrepo/deno-plugin/releases/download/v0.6.0/deno_plugin.wasm".into()
url: "https://github.com/moonrepo/deno-plugin/releases/download/v0.7.0/deno_plugin.wasm".into()
}
);
}
Expand All @@ -137,7 +137,7 @@ impl ProtoConfig {
self.plugins.insert(
Id::raw("go"),
PluginLocator::SourceUrl {
url: "https://github.com/moonrepo/go-plugin/releases/download/v0.6.0/go_plugin.wasm".into()
url: "https://github.com/moonrepo/go-plugin/releases/download/v0.7.0/go_plugin.wasm".into()
}
);
}
Expand All @@ -146,7 +146,7 @@ impl ProtoConfig {
self.plugins.insert(
Id::raw("node"),
PluginLocator::SourceUrl {
url: "https://github.com/moonrepo/node-plugin/releases/download/v0.6.1/node_plugin.wasm".into()
url: "https://github.com/moonrepo/node-plugin/releases/download/v0.7.0/node_plugin.wasm".into()
}
);
}
Expand All @@ -156,7 +156,7 @@ impl ProtoConfig {
self.plugins.insert(
Id::raw(depman),
PluginLocator::SourceUrl {
url: "https://github.com/moonrepo/node-plugin/releases/download/v0.6.1/node_depman_plugin.wasm".into()
url: "https://github.com/moonrepo/node-plugin/releases/download/v0.7.0/node_depman_plugin.wasm".into()
}
);
}
Expand All @@ -166,7 +166,7 @@ impl ProtoConfig {
self.plugins.insert(
Id::raw("python"),
PluginLocator::SourceUrl {
url: "https://github.com/moonrepo/python-plugin/releases/download/v0.4.0/python_plugin.wasm".into()
url: "https://github.com/moonrepo/python-plugin/releases/download/v0.5.0/python_plugin.wasm".into()
}
);
}
Expand All @@ -175,7 +175,7 @@ impl ProtoConfig {
self.plugins.insert(
Id::raw("rust"),
PluginLocator::SourceUrl {
url: "https://github.com/moonrepo/rust-plugin/releases/download/v0.5.0/rust_plugin.wasm".into()
url: "https://github.com/moonrepo/rust-plugin/releases/download/v0.6.0/rust_plugin.wasm".into()
}
);
}
Expand All @@ -184,7 +184,7 @@ impl ProtoConfig {
self.plugins.insert(
Id::raw(SCHEMA_PLUGIN_KEY),
PluginLocator::SourceUrl {
url: "https://github.com/moonrepo/schema-plugin/releases/download/v0.6.0/schema_plugin.wasm".into()
url: "https://github.com/moonrepo/schema-plugin/releases/download/v0.7.0/schema_plugin.wasm".into()
}
);
}
Expand Down
24 changes: 12 additions & 12 deletions crates/core/src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use crate::version_resolver::VersionResolver;
use extism::{manifest::Wasm, Manifest as PluginManifest};
use miette::IntoDiagnostic;
use proto_pdk_api::*;
use proto_shim::{create_shim, get_shim_file_name, locate_proto_bin, SHIM_VERSION};
use proto_shim::{
create_shim, get_exe_file_name, get_shim_file_name, locate_proto_exe, SHIM_VERSION,
};
use serde::Serialize;
use starbase_archive::Archiver;
use starbase_events::Emitter;
Expand Down Expand Up @@ -923,11 +925,7 @@ impl Tool {

// Not an archive, assume a binary and copy
} else {
let install_path = install_dir.join(if cfg!(windows) {
format!("{}.exe", self.id)
} else {
self.id.to_string()
});
let install_path = install_dir.join(get_exe_file_name(&self.id));

fs::rename(&download_file, &install_path)?;
fs::update_perms(install_path, None)?;
Expand Down Expand Up @@ -1206,12 +1204,14 @@ impl Tool {

let mut add = |name: &str, config: ExecutableConfig, primary: bool| {
if !config.no_bin {
if let Some(exe_path) = config.exe_link_path.as_ref().or(config.exe_path.as_ref()) {
if config
.exe_link_path
.as_ref()
.or(config.exe_path.as_ref())
.is_some()
{
locations.push(ExecutableLocation {
path: self.proto.bin_dir.join(match exe_path.extension() {
Some(ext) => format!("{name}.{}", ext.to_string_lossy()),
None => name.to_owned(),
}),
path: self.proto.bin_dir.join(get_exe_file_name(name)),
name: name.to_owned(),
config,
primary,
Expand Down Expand Up @@ -1396,7 +1396,7 @@ impl Tool {
registry.insert(self.id.to_string(), Shim::default());

let shim_binary =
fs::read_file_bytes(locate_proto_bin("proto-shim").ok_or_else(|| {
fs::read_file_bytes(locate_proto_exe("proto-shim").ok_or_else(|| {
ProtoError::MissingShimBinary {
bin_dir: self.proto.bin_dir.clone(),
}
Expand Down
9 changes: 2 additions & 7 deletions crates/shim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@ pub const SHIM_VERSION: u8 = 0;
#[cfg(not(debug_assertions))]
pub const SHIM_VERSION: u8 = 11;

pub fn locate_proto_bin(bin: &str) -> Option<PathBuf> {
let bin = if cfg!(windows) {
format!("{bin}.exe")
} else {
bin.to_owned()
};

pub fn locate_proto_exe(bin: &str) -> Option<PathBuf> {
let bin = get_exe_file_name(bin);
let mut lookup_dirs = vec![];

// When in development, ensure we're using the target built proto,
Expand Down
5 changes: 5 additions & 0 deletions crates/shim/src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ pub fn exec_command_and_replace(mut command: Command) -> io::Result<()> {
Err(command.exec())
}

// Return the file name as-is.
pub fn get_exe_file_name(name: &str) -> String {
name.to_owned()
}

// Return the file name as-is.
pub fn get_shim_file_name(name: &str) -> String {
name.to_owned()
Expand Down
11 changes: 10 additions & 1 deletion crates/shim/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@ pub fn exec_command_and_replace(mut command: Command) -> io::Result<()> {
exit(status.code().unwrap_or(1))
}

// Always use an `.exe` extension.
pub fn get_exe_file_name(name: &str) -> String {
if name.ends_with(".exe") {
name.to_owned()
} else {
format!("{name}.exe")
}
}

// Always use an `.exe` extension.
pub fn get_shim_file_name(name: &str) -> String {
format!("{name}.exe")
get_exe_file_name(name)
}

// We can't remove or overwrite an executable that is currently running,
Expand Down

0 comments on commit 9611bd1

Please sign in to comment.