From 9611bd1e12fe8d797f70346f272acd541d2efd64 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Wed, 20 Dec 2023 17:30:24 -0800 Subject: [PATCH] deps: Update plugins. (#354) --- CHANGELOG.md | 17 +++++++++++++++++ crates/cli/src/main_shim.rs | 4 ++-- crates/cli/tests/bin_test.rs | 2 +- crates/cli/tests/utils.rs | 8 +++----- crates/core/src/proto_config.rs | 14 +++++++------- crates/core/src/tool.rs | 24 ++++++++++++------------ crates/shim/src/lib.rs | 9 ++------- crates/shim/src/unix.rs | 5 +++++ crates/shim/src/windows.rs | 11 ++++++++++- 9 files changed, 59 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de8522b72..97e236700 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/crates/cli/src/main_shim.rs b/crates/cli/src/main_shim.rs index 8b4021fb7..8fa993565 100644 --- a/crates/cli/src/main_shim.rs +++ b/crates/cli/src/main_shim.rs @@ -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; @@ -72,7 +72,7 @@ fn create_command(args: Vec, shim_name: &str) -> Result { } // 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"); diff --git a/crates/cli/tests/bin_test.rs b/crates/cli/tests/bin_test.rs index 5928121f5..7bad7fc74 100644 --- a/crates/cli/tests/bin_test.rs +++ b/crates/cli/tests/bin_test.rs @@ -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")); } diff --git a/crates/cli/tests/utils.rs b/crates/cli/tests/utils.rs index 9fcf44d64..ad28d5b01 100644 --- a/crates/cli/tests/utils.rs +++ b/crates/cli/tests/utils.rs @@ -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; @@ -51,11 +52,8 @@ pub fn create_shim_command>(path: T, name: &str) -> assert_cmd::C pub fn create_shim_command_std>(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 diff --git a/crates/core/src/proto_config.rs b/crates/core/src/proto_config.rs index 9f83e0fc3..052c05a9d 100644 --- a/crates/core/src/proto_config.rs +++ b/crates/core/src/proto_config.rs @@ -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() } ); } @@ -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() } ); } @@ -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() } ); } @@ -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() } ); } @@ -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() } ); } @@ -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() } ); } @@ -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() } ); } diff --git a/crates/core/src/tool.rs b/crates/core/src/tool.rs index 9dd371f8a..1c0a6defe 100644 --- a/crates/core/src/tool.rs +++ b/crates/core/src/tool.rs @@ -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; @@ -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)?; @@ -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, @@ -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(), } diff --git a/crates/shim/src/lib.rs b/crates/shim/src/lib.rs index 51020c066..795384dd0 100644 --- a/crates/shim/src/lib.rs +++ b/crates/shim/src/lib.rs @@ -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 { - let bin = if cfg!(windows) { - format!("{bin}.exe") - } else { - bin.to_owned() - }; - +pub fn locate_proto_exe(bin: &str) -> Option { + let bin = get_exe_file_name(bin); let mut lookup_dirs = vec![]; // When in development, ensure we're using the target built proto, diff --git a/crates/shim/src/unix.rs b/crates/shim/src/unix.rs index 550c1fda9..2f516a726 100644 --- a/crates/shim/src/unix.rs +++ b/crates/shim/src/unix.rs @@ -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() diff --git a/crates/shim/src/windows.rs b/crates/shim/src/windows.rs index deefa3248..fc70ab55c 100644 --- a/crates/shim/src/windows.rs +++ b/crates/shim/src/windows.rs @@ -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,