diff --git a/Cargo.lock b/Cargo.lock index b3d13b8fe8a..3a5103036dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2248,8 +2248,8 @@ dependencies = [ "moon_platform", "moon_terminal", "moon_utils", - "probe_core", - "probe_node", + "proto_core", + "proto_node", "rustc-hash", "thiserror", ] @@ -2827,38 +2827,6 @@ dependencies = [ "yansi", ] -[[package]] -name = "probe_core" -version = "0.1.0" -dependencies = [ - "async-trait", - "flate2", - "lenient_semver", - "log", - "reqwest", - "serde", - "serde_json", - "sha2", - "tar", - "thiserror", - "tokio", - "zip", -] - -[[package]] -name = "probe_node" -version = "0.1.0" -dependencies = [ - "assert_fs", - "clean-path", - "log", - "probe_core", - "rustc-hash", - "serde", - "serde_json", - "tokio", -] - [[package]] name = "proc-macro-error" version = "1.0.4" @@ -2925,6 +2893,38 @@ dependencies = [ "prost", ] +[[package]] +name = "proto_core" +version = "0.1.0" +dependencies = [ + "async-trait", + "flate2", + "lenient_semver", + "log", + "reqwest", + "serde", + "serde_json", + "sha2", + "tar", + "thiserror", + "tokio", + "zip", +] + +[[package]] +name = "proto_node" +version = "0.1.0" +dependencies = [ + "assert_fs", + "clean-path", + "log", + "proto_core", + "rustc-hash", + "serde", + "serde_json", + "tokio", +] + [[package]] name = "quote" version = "1.0.20" diff --git a/Cargo.toml b/Cargo.toml index 71b550da2bd..6a36b8ad78d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ members = [ "crates/node/*", "crates/system/*", "crates/typescript/*", - "crates/probe/*", + "crates/proto/*", ] default-members = ["crates/cli"] diff --git a/crates/core/logger/src/logger.rs b/crates/core/logger/src/logger.rs index 9446834e58c..244c63b01bc 100644 --- a/crates/core/logger/src/logger.rs +++ b/crates/core/logger/src/logger.rs @@ -24,7 +24,7 @@ impl Logger { let mut dispatcher = Dispatch::new() .filter(|metadata| { - metadata.target().starts_with("moon") || metadata.target().starts_with("probe") + metadata.target().starts_with("moon") || metadata.target().starts_with("proto") }) .level(level) // Terminal logger diff --git a/crates/core/toolchain/Cargo.toml b/crates/core/toolchain/Cargo.toml index 850b9323cc3..5232436dd16 100644 --- a/crates/core/toolchain/Cargo.toml +++ b/crates/core/toolchain/Cargo.toml @@ -13,7 +13,7 @@ moon_node_lang = { path = "../../node/lang" } moon_platform = { path = "../platform" } moon_terminal = { path = "../terminal" } moon_utils = { path = "../utils" } -probe_core = { path = "../../probe/core" } -probe_node = { path = "../../probe/node" } +proto_core = { path = "../../proto/core" } +proto_node = { path = "../../proto/node" } rustc-hash = { workspace = true } thiserror = { workspace = true } diff --git a/crates/core/toolchain/src/errors.rs b/crates/core/toolchain/src/errors.rs index 6c0de58cc7c..209d421f3c1 100644 --- a/crates/core/toolchain/src/errors.rs +++ b/crates/core/toolchain/src/errors.rs @@ -1,7 +1,7 @@ use moon_error::MoonError; use moon_lang::LangError; use moon_platform::Runtime; -use probe_core::ProbeError; +use proto_core::ProtoError; use thiserror::Error; #[derive(Error, Debug)] @@ -28,5 +28,5 @@ pub enum ToolchainError { Moon(#[from] MoonError), #[error(transparent)] - Probe(#[from] ProbeError), + Proto(#[from] ProtoError), } diff --git a/crates/core/toolchain/src/toolchain.rs b/crates/core/toolchain/src/toolchain.rs index 44bc3fbf437..a7a6083f1a7 100644 --- a/crates/core/toolchain/src/toolchain.rs +++ b/crates/core/toolchain/src/toolchain.rs @@ -6,7 +6,7 @@ use moon_constants::CONFIG_DIRNAME; use moon_logger::{color, debug}; use moon_platform::{Runtime, Version}; use moon_utils::{fs, path}; -use probe_core::Probe; +use proto_core::Proto; use std::path::{Path, PathBuf}; #[derive(Debug)] @@ -47,19 +47,19 @@ impl Toolchain { // Tools node: ToolManager::new(Runtime::Node(Version::default())), }; - let probe = toolchain.get_paths(); + let proto = toolchain.get_paths(); if let Some(node_config) = &workspace_config.node { toolchain .node - .register(NodeTool::new(&probe, node_config)?, true); + .register(NodeTool::new(&proto, node_config)?, true); } Ok(toolchain) } - pub fn get_paths(&self) -> Probe { - Probe::new(&self.dir) + pub fn get_paths(&self) -> Proto { + Proto::new(&self.dir) } /// Uninstall all tools from the toolchain, and delete any temporary files. diff --git a/crates/core/toolchain/src/tools/node.rs b/crates/core/toolchain/src/tools/node.rs index 00e227af255..c668a46b71c 100644 --- a/crates/core/toolchain/src/tools/node.rs +++ b/crates/core/toolchain/src/tools/node.rs @@ -8,8 +8,8 @@ use moon_logger::debug; use moon_node_lang::node; use moon_terminal::{print_checkpoint, Checkpoint}; use moon_utils::process::Command; -use probe_core::{async_trait, Describable, Executable, Installable, Probe, Resolvable, Tool}; -use probe_node::NodeLanguage; +use proto_core::{async_trait, Describable, Executable, Installable, Proto, Resolvable, Tool}; +use proto_node::NodeLanguage; use rustc_hash::FxHashMap; use std::path::Path; @@ -27,10 +27,10 @@ pub struct NodeTool { } impl NodeTool { - pub fn new(probe: &Probe, config: &NodeConfig) -> Result { + pub fn new(proto: &Proto, config: &NodeConfig) -> Result { let mut node = NodeTool { config: config.to_owned(), - tool: NodeLanguage::new(probe, Some(&config.version)), + tool: NodeLanguage::new(proto, Some(&config.version)), npm: None, pnpm: None, yarn: None, @@ -38,13 +38,13 @@ impl NodeTool { match config.package_manager { NodePackageManager::Npm => { - node.npm = Some(NpmTool::new(probe, &config.npm)?); + node.npm = Some(NpmTool::new(proto, &config.npm)?); } NodePackageManager::Pnpm => { - node.pnpm = Some(PnpmTool::new(probe, &config.pnpm)?); + node.pnpm = Some(PnpmTool::new(proto, &config.pnpm)?); } NodePackageManager::Yarn => { - node.yarn = Some(YarnTool::new(probe, &config.yarn)?); + node.yarn = Some(YarnTool::new(proto, &config.yarn)?); } }; diff --git a/crates/core/toolchain/src/tools/npm.rs b/crates/core/toolchain/src/tools/npm.rs index cc55acb7905..ae60133e870 100644 --- a/crates/core/toolchain/src/tools/npm.rs +++ b/crates/core/toolchain/src/tools/npm.rs @@ -8,8 +8,8 @@ use moon_node_lang::{npm, NPM}; use moon_terminal::{print_checkpoint, Checkpoint}; use moon_utils::process::Command; use moon_utils::{fs, is_ci}; -use probe_core::{async_trait, Describable, Executable, Probe, Resolvable, Tool}; -use probe_node::NodeDependencyManager; +use proto_core::{async_trait, Describable, Executable, Proto, Resolvable, Tool}; +use proto_node::NodeDependencyManager; use rustc_hash::FxHashMap; use std::env; use std::path::Path; @@ -22,12 +22,12 @@ pub struct NpmTool { } impl NpmTool { - pub fn new(probe: &Probe, config: &NpmConfig) -> Result { + pub fn new(proto: &Proto, config: &NpmConfig) -> Result { Ok(NpmTool { config: config.to_owned(), tool: NodeDependencyManager::new( - probe, - probe_node::NodeDependencyManagerType::Npm, + proto, + proto_node::NodeDependencyManagerType::Npm, Some(&config.version), ), }) diff --git a/crates/core/toolchain/src/tools/pnpm.rs b/crates/core/toolchain/src/tools/pnpm.rs index 7744b1b1b94..6d5fe930780 100644 --- a/crates/core/toolchain/src/tools/pnpm.rs +++ b/crates/core/toolchain/src/tools/pnpm.rs @@ -8,8 +8,8 @@ use moon_node_lang::{pnpm, PNPM}; use moon_terminal::{print_checkpoint, Checkpoint}; use moon_utils::process::Command; use moon_utils::{fs, is_ci}; -use probe_core::{async_trait, Describable, Executable, Probe, Resolvable, Tool}; -use probe_node::NodeDependencyManager; +use proto_core::{async_trait, Describable, Executable, Proto, Resolvable, Tool}; +use proto_node::NodeDependencyManager; use rustc_hash::FxHashMap; use std::env; use std::path::Path; @@ -22,12 +22,12 @@ pub struct PnpmTool { } impl PnpmTool { - pub fn new(probe: &Probe, config: &Option) -> Result { + pub fn new(proto: &Proto, config: &Option) -> Result { Ok(PnpmTool { config: config.to_owned().unwrap_or_default(), tool: NodeDependencyManager::new( - probe, - probe_node::NodeDependencyManagerType::Pnpm, + proto, + proto_node::NodeDependencyManagerType::Pnpm, match &config { Some(cfg) => Some(&cfg.version), None => None, diff --git a/crates/core/toolchain/src/tools/yarn.rs b/crates/core/toolchain/src/tools/yarn.rs index 130e0e82d2e..fdeb0693394 100644 --- a/crates/core/toolchain/src/tools/yarn.rs +++ b/crates/core/toolchain/src/tools/yarn.rs @@ -8,8 +8,8 @@ use moon_node_lang::{yarn, YARN}; use moon_terminal::{print_checkpoint, Checkpoint}; use moon_utils::process::Command; use moon_utils::{fs, get_workspace_root, is_ci}; -use probe_core::{async_trait, Describable, Executable, Probe, Resolvable, Tool}; -use probe_node::NodeDependencyManager; +use proto_core::{async_trait, Describable, Executable, Proto, Resolvable, Tool}; +use proto_node::NodeDependencyManager; use rustc_hash::FxHashMap; use std::env; use std::path::Path; @@ -22,12 +22,12 @@ pub struct YarnTool { } impl YarnTool { - pub fn new(probe: &Probe, config: &Option) -> Result { + pub fn new(proto: &Proto, config: &Option) -> Result { Ok(YarnTool { config: config.to_owned().unwrap_or_default(), tool: NodeDependencyManager::new( - probe, - probe_node::NodeDependencyManagerType::Yarn, + proto, + proto_node::NodeDependencyManagerType::Yarn, match &config { Some(cfg) => Some(&cfg.version), None => None, diff --git a/crates/core/toolchain/src/traits.rs b/crates/core/toolchain/src/traits.rs index 9134bc2e338..eba53034910 100644 --- a/crates/core/toolchain/src/traits.rs +++ b/crates/core/toolchain/src/traits.rs @@ -1,7 +1,7 @@ use crate::errors::ToolchainError; use moon_lang::LockfileDependencyVersions; use moon_utils::process::Command; -use probe_core::async_trait; +use proto_core::async_trait; use rustc_hash::FxHashMap; use std::path::Path; diff --git a/crates/probe/README.md b/crates/probe/README.md deleted file mode 100644 index a7ed4467807..00000000000 --- a/crates/probe/README.md +++ /dev/null @@ -1 +0,0 @@ -All probe crates will be extracted into their own repo, and _should not_ import the moon crates. diff --git a/crates/proto/README.md b/crates/proto/README.md new file mode 100644 index 00000000000..1a3f79acf3c --- /dev/null +++ b/crates/proto/README.md @@ -0,0 +1 @@ +All proto crates will be extracted into their own repo, and _should not_ import the moon crates. diff --git a/crates/probe/core/Cargo.toml b/crates/proto/core/Cargo.toml similarity index 95% rename from crates/probe/core/Cargo.toml rename to crates/proto/core/Cargo.toml index e1c08e82a38..3a096948634 100644 --- a/crates/probe/core/Cargo.toml +++ b/crates/proto/core/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "probe_core" +name = "proto_core" version = "0.1.0" edition = "2021" diff --git a/crates/probe/core/src/describer.rs b/crates/proto/core/src/describer.rs similarity index 100% rename from crates/probe/core/src/describer.rs rename to crates/proto/core/src/describer.rs diff --git a/crates/probe/core/src/downloader.rs b/crates/proto/core/src/downloader.rs similarity index 77% rename from crates/probe/core/src/downloader.rs rename to crates/proto/core/src/downloader.rs index 818f9966334..6edbd2bc648 100644 --- a/crates/probe/core/src/downloader.rs +++ b/crates/proto/core/src/downloader.rs @@ -1,4 +1,4 @@ -use crate::errors::ProbeError; +use crate::errors::ProtoError; use crate::resolver::Resolvable; use log::trace; use std::fs::File; @@ -10,28 +10,28 @@ use tokio::fs; pub trait Downloadable<'tool>: Send + Sync + Resolvable<'tool> { /// Returns an absolute file path to the downloaded file. /// This may not exist, as the path is composed ahead of time. - /// This is typically ~/.probe/temp/. - fn get_download_path(&self) -> Result; + /// This is typically ~/.proto/temp/. + fn get_download_path(&self) -> Result; /// Download the tool (as an archive) from its distribution registry - /// into the ~/.probe/temp folder and return an absolute file path. + /// into the ~/.proto/temp folder and return an absolute file path. /// A custom URL that points to the downloadable archive can be /// provided as the 2nd argument. - async fn download(&self, to_file: &Path, from_url: Option<&str>) -> Result; + async fn download(&self, to_file: &Path, from_url: Option<&str>) -> Result; } -pub async fn download_from_url(url: U, dest_file: F) -> Result<(), ProbeError> +pub async fn download_from_url(url: U, dest_file: F) -> Result<(), ProtoError> where U: AsRef, F: AsRef, { let url = url.as_ref(); let dest_file = dest_file.as_ref(); - let handle_io_error = |e: io::Error| ProbeError::Fs(dest_file.to_path_buf(), e.to_string()); - let handle_http_error = |e: reqwest::Error| ProbeError::Http(url.to_owned(), e.to_string()); + let handle_io_error = |e: io::Error| ProtoError::Fs(dest_file.to_path_buf(), e.to_string()); + let handle_http_error = |e: reqwest::Error| ProtoError::Http(url.to_owned(), e.to_string()); trace!( - target: "probe:downloader", + target: "proto:downloader", "Downloading {} from {}", dest_file.to_string_lossy(), url @@ -47,7 +47,7 @@ where let status = response.status(); if !status.is_success() { - return Err(ProbeError::DownloadFailed( + return Err(ProtoError::DownloadFailed( url.to_owned(), status.to_string(), )); diff --git a/crates/probe/core/src/errors.rs b/crates/proto/core/src/errors.rs similarity index 98% rename from crates/probe/core/src/errors.rs rename to crates/proto/core/src/errors.rs index 00cadf8a5d7..51e00766bca 100644 --- a/crates/probe/core/src/errors.rs +++ b/crates/proto/core/src/errors.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use thiserror::Error; #[derive(Error, Debug)] -pub enum ProbeError { +pub enum ProtoError { #[error("Failed to download tool from {0}. {1}")] DownloadFailed(String, String), diff --git a/crates/probe/core/src/executor.rs b/crates/proto/core/src/executor.rs similarity index 69% rename from crates/probe/core/src/executor.rs rename to crates/proto/core/src/executor.rs index 310269b39c8..bbdb862deae 100644 --- a/crates/probe/core/src/executor.rs +++ b/crates/proto/core/src/executor.rs @@ -1,14 +1,14 @@ -use crate::errors::ProbeError; +use crate::errors::ProtoError; use std::path::Path; #[async_trait::async_trait] pub trait Executable<'tool>: Send + Sync { /// Find the absolute file path to the tool's binary that will be executed. /// This happens after a tool has been downloaded and installed. - async fn find_bin_path(&mut self) -> Result<(), ProbeError> { + async fn find_bin_path(&mut self) -> Result<(), ProtoError> { Ok(()) } /// Returns an absolute file path to the executable binary for the tool. - fn get_bin_path(&self) -> Result<&Path, ProbeError>; + fn get_bin_path(&self) -> Result<&Path, ProtoError>; } diff --git a/crates/probe/core/src/installer.rs b/crates/proto/core/src/installer.rs similarity index 83% rename from crates/probe/core/src/installer.rs rename to crates/proto/core/src/installer.rs index c257f65de0c..611ad88c464 100644 --- a/crates/probe/core/src/installer.rs +++ b/crates/proto/core/src/installer.rs @@ -1,4 +1,4 @@ -use crate::errors::ProbeError; +use crate::errors::ProtoError; use flate2::read::GzDecoder; use log::trace; use std::fs::{self, File}; @@ -10,27 +10,27 @@ use zip::ZipArchive; #[async_trait::async_trait] pub trait Installable<'tool>: Send + Sync { /// Returns an absolute file path to the directory containing the installed tool. - /// This is typically ~/.probe/tools//. - fn get_install_dir(&self) -> Result; + /// This is typically ~/.proto/tools//. + fn get_install_dir(&self) -> Result; /// Run any installation steps after downloading and verifying the tool. /// This is typically unzipping an archive, and running any installers/binaries. - async fn install(&self, install_dir: &Path, download_path: &Path) -> Result; + async fn install(&self, install_dir: &Path, download_path: &Path) -> Result; } pub fn untar, O: AsRef>( input_file: I, output_dir: O, remove_prefix: Option<&str>, -) -> Result<(), ProbeError> { +) -> Result<(), ProtoError> { let input_file = input_file.as_ref(); let output_dir = output_dir.as_ref(); - let handle_input_error = |e: io::Error| ProbeError::Fs(input_file.to_path_buf(), e.to_string()); + let handle_input_error = |e: io::Error| ProtoError::Fs(input_file.to_path_buf(), e.to_string()); let handle_output_error = - |e: io::Error| ProbeError::Fs(output_dir.to_path_buf(), e.to_string()); + |e: io::Error| ProtoError::Fs(output_dir.to_path_buf(), e.to_string()); trace!( - target: "probe:installer", + target: "proto:installer", "Unpacking tar archive {} to {}", input_file.to_string_lossy(), output_dir.to_string_lossy(), @@ -65,12 +65,12 @@ pub fn untar, O: AsRef>( // Create parent dirs if let Some(parent_dir) = output_path.parent() { fs::create_dir_all(parent_dir) - .map_err(|e| ProbeError::Fs(parent_dir.to_path_buf(), e.to_string()))?; + .map_err(|e| ProtoError::Fs(parent_dir.to_path_buf(), e.to_string()))?; } entry .unpack(&output_path) - .map_err(|e| ProbeError::Fs(output_path.to_path_buf(), e.to_string()))?; + .map_err(|e| ProtoError::Fs(output_path.to_path_buf(), e.to_string()))?; } Ok(()) @@ -80,15 +80,15 @@ pub fn unzip, O: AsRef>( input_file: I, output_dir: O, remove_prefix: Option<&str>, -) -> Result<(), ProbeError> { +) -> Result<(), ProtoError> { let input_file = input_file.as_ref(); let output_dir = output_dir.as_ref(); - let handle_input_error = |e: io::Error| ProbeError::Fs(input_file.to_path_buf(), e.to_string()); + let handle_input_error = |e: io::Error| ProtoError::Fs(input_file.to_path_buf(), e.to_string()); let handle_output_error = - |e: io::Error| ProbeError::Fs(output_dir.to_path_buf(), e.to_string()); + |e: io::Error| ProtoError::Fs(output_dir.to_path_buf(), e.to_string()); trace!( - target: "probe:installer", + target: "proto:installer", "Unzipping zip archive {} to {}", input_file.to_string_lossy(), output_dir.to_string_lossy(), @@ -120,12 +120,12 @@ pub fn unzip, O: AsRef>( } let output_path = output_dir.join(&path); - let handle_error = |e: io::Error| ProbeError::Fs(output_path.to_path_buf(), e.to_string()); + let handle_error = |e: io::Error| ProtoError::Fs(output_path.to_path_buf(), e.to_string()); // Create parent dirs if let Some(parent_dir) = &output_path.parent() { fs::create_dir_all(parent_dir) - .map_err(|e| ProbeError::Fs(parent_dir.to_path_buf(), e.to_string()))?; + .map_err(|e| ProtoError::Fs(parent_dir.to_path_buf(), e.to_string()))?; } // If a folder, create the dir diff --git a/crates/probe/core/src/lib.rs b/crates/proto/core/src/lib.rs similarity index 81% rename from crates/probe/core/src/lib.rs rename to crates/proto/core/src/lib.rs index a74454641e2..85694f6dc16 100644 --- a/crates/probe/core/src/lib.rs +++ b/crates/proto/core/src/lib.rs @@ -18,14 +18,14 @@ use std::fs; use std::path::{Path, PathBuf}; pub use verifier::*; -pub struct Probe { +pub struct Proto { pub temp_dir: PathBuf, pub tools_dir: PathBuf, } -impl Probe { +impl Proto { pub fn new(root: &Path) -> Self { - Probe { + Proto { temp_dir: root.join("temp"), tools_dir: root.join("tools"), } @@ -43,11 +43,11 @@ pub trait Tool<'tool>: + Installable<'tool> + Executable<'tool> { - async fn before_setup(&mut self) -> Result<(), ProbeError> { + async fn before_setup(&mut self) -> Result<(), ProtoError> { Ok(()) } - async fn setup(&mut self, initial_version: &str) -> Result { + async fn setup(&mut self, initial_version: &str) -> Result { // Resolve a semantic version self.resolve_version(initial_version, None).await?; @@ -71,7 +71,7 @@ pub trait Tool<'tool>: Ok(installed) } - async fn is_setup(&mut self) -> Result { + async fn is_setup(&mut self) -> Result { let install_dir = self.get_install_dir()?; if install_dir.exists() { @@ -86,11 +86,11 @@ pub trait Tool<'tool>: Ok(false) } - async fn after_setup(&mut self) -> Result<(), ProbeError> { + async fn after_setup(&mut self) -> Result<(), ProtoError> { Ok(()) } - async fn cleanup(&mut self) -> Result<(), ProbeError> { + async fn cleanup(&mut self) -> Result<(), ProtoError> { let download_path = self.get_download_path()?; let checksum_path = self.get_checksum_path()?; @@ -105,24 +105,24 @@ pub trait Tool<'tool>: Ok(()) } - async fn before_teardown(&mut self) -> Result<(), ProbeError> { + async fn before_teardown(&mut self) -> Result<(), ProtoError> { Ok(()) } - async fn teardown(&mut self) -> Result<(), ProbeError> { + async fn teardown(&mut self) -> Result<(), ProtoError> { self.cleanup().await?; let install_dir = self.get_install_dir()?; if install_dir.exists() { fs::remove_dir_all(&install_dir) - .map_err(|e| ProbeError::Fs(install_dir, e.to_string()))?; + .map_err(|e| ProtoError::Fs(install_dir, e.to_string()))?; } Ok(()) } - async fn after_teardown(&mut self) -> Result<(), ProbeError> { + async fn after_teardown(&mut self) -> Result<(), ProtoError> { Ok(()) } } diff --git a/crates/probe/core/src/resolver.rs b/crates/proto/core/src/resolver.rs similarity index 81% rename from crates/probe/core/src/resolver.rs rename to crates/proto/core/src/resolver.rs index fd854fa335e..8d964ca9092 100644 --- a/crates/probe/core/src/resolver.rs +++ b/crates/proto/core/src/resolver.rs @@ -1,4 +1,4 @@ -use crate::errors::ProbeError; +use crate::errors::ProtoError; use lenient_semver::Version; use log::trace; use serde::de::DeserializeOwned; @@ -15,7 +15,7 @@ pub trait Resolvable<'tool>: Send + Sync { &mut self, initial_version: &str, manifest_url: Option<&str>, - ) -> Result; + ) -> Result; } // Aliases are words that map to version. For example, "latest" -> "1.2.3". @@ -39,16 +39,16 @@ pub fn remove_v_prefix(value: &str) -> String { value.to_owned() } -pub async fn load_versions_manifest(url: U) -> Result +pub async fn load_versions_manifest(url: U) -> Result where T: DeserializeOwned, U: AsRef, { let url = url.as_ref(); - let handle_error = |e: reqwest::Error| ProbeError::Http(url.to_owned(), e.to_string()); + let handle_error = |e: reqwest::Error| ProtoError::Http(url.to_owned(), e.to_string()); trace!( - target: "probe:resolver", + target: "proto:resolver", "Loading versions manifest from {}", url ); @@ -57,12 +57,12 @@ where let content = response.text().await.map_err(handle_error)?; let manifest: T = serde_json::from_str(&content) - .map_err(|e| ProbeError::Http(url.to_owned(), e.to_string()))?; + .map_err(|e| ProtoError::Http(url.to_owned(), e.to_string()))?; Ok(manifest) } -pub fn parse_version(version: &str) -> Result { +pub fn parse_version(version: &str) -> Result { Version::parse(version) - .map_err(|e| ProbeError::VersionParseFailed(version.to_owned(), e.to_string())) + .map_err(|e| ProtoError::VersionParseFailed(version.to_owned(), e.to_string())) } diff --git a/crates/probe/core/src/verifier.rs b/crates/proto/core/src/verifier.rs similarity index 80% rename from crates/probe/core/src/verifier.rs rename to crates/proto/core/src/verifier.rs index ca93650144e..c210d82487a 100644 --- a/crates/probe/core/src/verifier.rs +++ b/crates/proto/core/src/verifier.rs @@ -1,5 +1,5 @@ use crate::downloader::Downloadable; -use crate::errors::ProbeError; +use crate::errors::ProtoError; use log::trace; use sha2::{Digest, Sha256}; use std::fs::File; @@ -11,14 +11,14 @@ pub trait Verifiable<'tool>: Send + Sync + Downloadable<'tool> { /// Returns an absolute file path to the checksum file. /// This may not exist, as the path is composed ahead of time. /// This is typically ~/.prove/temp/. - fn get_checksum_path(&self) -> Result; + fn get_checksum_path(&self) -> Result; /// If applicable, download all files necessary for verifying checksums. async fn download_checksum( &self, to_file: &Path, from_url: Option<&str>, - ) -> Result; + ) -> Result; /// Verify the downloaded file using the checksum strategy for the tool. /// Common strategies are SHA256 and MD5. @@ -26,15 +26,15 @@ pub trait Verifiable<'tool>: Send + Sync + Downloadable<'tool> { &self, checksum_file: &Path, download_file: &Path, - ) -> Result; + ) -> Result; } -pub fn get_sha256_hash_of_file>(path: P) -> Result { +pub fn get_sha256_hash_of_file>(path: P) -> Result { let path = path.as_ref(); - let handle_error = |e: io::Error| ProbeError::Fs(path.to_path_buf(), e.to_string()); + let handle_error = |e: io::Error| ProtoError::Fs(path.to_path_buf(), e.to_string()); trace!( - target: "probe:verifier", + target: "proto:verifier", "Calculating SHA256 checksum for file {}", path.to_string_lossy() ); @@ -47,7 +47,7 @@ pub fn get_sha256_hash_of_file>(path: P) -> Result for NodeDependencyManager { - fn get_download_path(&self) -> Result { + fn get_download_path(&self) -> Result { Ok(self .temp_dir .join(format!("{}.tgz", self.get_resolved_version()))) } - async fn download(&self, to_file: &Path, from_url: Option<&str>) -> Result { + async fn download(&self, to_file: &Path, from_url: Option<&str>) -> Result { if to_file.exists() { debug!(target: self.get_log_target(), "Dependency manager already downloaded, continuing"); diff --git a/crates/probe/node/src/depman/execute.rs b/crates/proto/node/src/depman/execute.rs similarity index 77% rename from crates/probe/node/src/depman/execute.rs rename to crates/proto/node/src/depman/execute.rs index f44230908a6..e65ec48f368 100644 --- a/crates/probe/node/src/depman/execute.rs +++ b/crates/proto/node/src/depman/execute.rs @@ -1,6 +1,6 @@ use crate::depman::NodeDependencyManager; use clean_path::Clean; -use probe_core::{async_trait, Describable, Executable, Installable, ProbeError}; +use proto_core::{async_trait, Describable, Executable, Installable, ProtoError}; use serde_json::Value; use std::fs; use std::path::{Path, PathBuf}; @@ -8,14 +8,14 @@ use std::path::{Path, PathBuf}; pub fn extract_bin_from_package_json( package_path: PathBuf, bin_name: &str, -) -> Result, ProbeError> { +) -> Result, ProtoError> { let mut bin_path = None; let data = fs::read_to_string(&package_path) - .map_err(|e| ProbeError::Fs(package_path.clone(), e.to_string()))?; + .map_err(|e| ProtoError::Fs(package_path.clone(), e.to_string()))?; let json: Value = - serde_json::from_str(&data).map_err(|e| ProbeError::Json(package_path, e.to_string()))?; + serde_json::from_str(&data).map_err(|e| ProtoError::Json(package_path, e.to_string()))?; if let Some(bin_field) = json.get("bin") { match bin_field { @@ -42,7 +42,7 @@ pub fn extract_bin_from_package_json( #[async_trait] impl Executable<'_> for NodeDependencyManager { - async fn find_bin_path(&mut self) -> Result<(), ProbeError> { + async fn find_bin_path(&mut self) -> Result<(), ProtoError> { let install_dir = self.get_install_dir()?; let bin_name = self.type_of.get_package_name(); let package_json = install_dir.join("package.json"); @@ -55,16 +55,16 @@ impl Executable<'_> for NodeDependencyManager { } } - return Err(ProbeError::ExecuteMissingBin( + return Err(ProtoError::ExecuteMissingBin( self.get_name(), install_dir.join(format!("bin/{}.js", bin_name)), )); } - fn get_bin_path(&self) -> Result<&Path, ProbeError> { + fn get_bin_path(&self) -> Result<&Path, ProtoError> { match self.bin_path.as_ref() { Some(bin) => Ok(bin), - None => Err(ProbeError::MissingTool(self.get_name())), + None => Err(ProtoError::MissingTool(self.get_name())), } } } diff --git a/crates/probe/node/src/depman/install.rs b/crates/proto/node/src/depman/install.rs similarity index 85% rename from crates/probe/node/src/depman/install.rs rename to crates/proto/node/src/depman/install.rs index c703dfef39c..98ca5ae1baa 100644 --- a/crates/probe/node/src/depman/install.rs +++ b/crates/proto/node/src/depman/install.rs @@ -1,15 +1,15 @@ use crate::{depman::NodeDependencyManager, NodeDependencyManagerType}; use log::debug; -use probe_core::{async_trait, untar, Describable, Installable, ProbeError, Resolvable}; +use proto_core::{async_trait, untar, Describable, Installable, ProtoError, Resolvable}; use std::path::{Path, PathBuf}; #[async_trait] impl Installable<'_> for NodeDependencyManager { - fn get_install_dir(&self) -> Result { + fn get_install_dir(&self) -> Result { Ok(self.install_dir.join(self.get_resolved_version())) } - async fn install(&self, install_dir: &Path, download_path: &Path) -> Result { + async fn install(&self, install_dir: &Path, download_path: &Path) -> Result { if install_dir.exists() { debug!(target: self.get_log_target(), "Dependency manager already installed, continuing"); diff --git a/crates/probe/node/src/depman/mod.rs b/crates/proto/node/src/depman/mod.rs similarity index 83% rename from crates/probe/node/src/depman/mod.rs rename to crates/proto/node/src/depman/mod.rs index 6fa3566f71e..2b3bffb5347 100644 --- a/crates/probe/node/src/depman/mod.rs +++ b/crates/proto/node/src/depman/mod.rs @@ -4,7 +4,7 @@ mod install; mod resolve; mod verify; -use probe_core::{Describable, Probe, Tool}; +use proto_core::{Describable, Proto, Tool}; use resolve::NDMVersionDist; use std::path::PathBuf; @@ -37,15 +37,15 @@ pub struct NodeDependencyManager { } impl NodeDependencyManager { - pub fn new(probe: &Probe, type_of: NodeDependencyManagerType, version: Option<&str>) -> Self { + pub fn new(proto: &Proto, type_of: NodeDependencyManagerType, version: Option<&str>) -> Self { let package_name = type_of.get_package_name(); NodeDependencyManager { bin_path: None, dist: None, - install_dir: probe.tools_dir.join(&package_name), - log_target: format!("probe:tool:{}", &package_name), - temp_dir: probe.temp_dir.join(&package_name), + install_dir: proto.tools_dir.join(&package_name), + log_target: format!("proto:tool:{}", &package_name), + temp_dir: proto.temp_dir.join(&package_name), type_of, version: version.unwrap_or("latest").into(), } diff --git a/crates/probe/node/src/depman/resolve.rs b/crates/proto/node/src/depman/resolve.rs similarity index 94% rename from crates/probe/node/src/depman/resolve.rs rename to crates/proto/node/src/depman/resolve.rs index 9bccefb6f9a..9835a0d7c25 100644 --- a/crates/probe/node/src/depman/resolve.rs +++ b/crates/proto/node/src/depman/resolve.rs @@ -1,8 +1,8 @@ use crate::depman::{NodeDependencyManager, NodeDependencyManagerType}; use log::debug; -use probe_core::{ +use proto_core::{ async_trait, is_version_alias, load_versions_manifest, parse_version, remove_v_prefix, - Describable, ProbeError, Resolvable, + Describable, ProtoError, Resolvable, }; use rustc_hash::FxHashMap; use serde::Deserialize; @@ -48,7 +48,7 @@ impl Resolvable<'_> for NodeDependencyManager { &mut self, initial_version: &str, manifest_url: Option<&str>, - ) -> Result { + ) -> Result { let mut initial_version = remove_v_prefix(initial_version); // Yarn is installed through npm, but only v1 exists in the npm registry, @@ -87,7 +87,7 @@ impl Resolvable<'_> for NodeDependencyManager { initial_version = match manifest.dist_tags.get(&initial_version) { Some(version) => version.to_owned(), None => { - return Err(ProbeError::VersionUnknownAlias(initial_version)); + return Err(ProtoError::VersionUnknownAlias(initial_version)); } }; } @@ -95,7 +95,7 @@ impl Resolvable<'_> for NodeDependencyManager { // Infer the possible candidate from the versions map let candidate = match manifest.versions.get(&initial_version) { Some(version) => Some(&version.version), - None => return Err(ProbeError::VersionResolveFailed(initial_version)), + None => return Err(ProtoError::VersionResolveFailed(initial_version)), }; let version = parse_version(candidate.unwrap())?.to_string(); diff --git a/crates/probe/node/src/depman/verify.rs b/crates/proto/node/src/depman/verify.rs similarity index 75% rename from crates/probe/node/src/depman/verify.rs rename to crates/proto/node/src/depman/verify.rs index 9443ba3c920..19b4f0507c5 100644 --- a/crates/probe/node/src/depman/verify.rs +++ b/crates/proto/node/src/depman/verify.rs @@ -1,12 +1,12 @@ use crate::depman::NodeDependencyManager; -use probe_core::{async_trait, ProbeError, Resolvable, Verifiable}; +use proto_core::{async_trait, ProtoError, Resolvable, Verifiable}; use std::path::{Path, PathBuf}; // TODO: implement PGP/ECDSA signature verify // https://docs.npmjs.com/about-registry-signatures #[async_trait] impl Verifiable<'_> for NodeDependencyManager { - fn get_checksum_path(&self) -> Result { + fn get_checksum_path(&self) -> Result { Ok(self .temp_dir .join(format!("{}.pub", self.get_resolved_version()))) @@ -16,7 +16,7 @@ impl Verifiable<'_> for NodeDependencyManager { &self, _to_file: &Path, _from_url: Option<&str>, - ) -> Result { + ) -> Result { Ok(true) } @@ -24,7 +24,7 @@ impl Verifiable<'_> for NodeDependencyManager { &self, _checksum_file: &Path, _download_file: &Path, - ) -> Result { + ) -> Result { Ok(true) } } diff --git a/crates/probe/node/src/download.rs b/crates/proto/node/src/download.rs similarity index 85% rename from crates/probe/node/src/download.rs rename to crates/proto/node/src/download.rs index c7027414aac..acc90535ecb 100644 --- a/crates/probe/node/src/download.rs +++ b/crates/proto/node/src/download.rs @@ -1,19 +1,19 @@ use crate::platform::NodeArch; use crate::NodeLanguage; use log::debug; -use probe_core::{ - async_trait, download_from_url, Describable, Downloadable, ProbeError, Resolvable, +use proto_core::{ + async_trait, download_from_url, Describable, Downloadable, ProtoError, Resolvable, }; use std::env::consts; use std::path::{Path, PathBuf}; use std::str::FromStr; #[cfg(target_os = "macos")] -pub fn get_archive_file_path(version: &str) -> Result { +pub fn get_archive_file_path(version: &str) -> Result { let arch = NodeArch::from_str(consts::ARCH)?; if !matches!(arch, NodeArch::X64 | NodeArch::Arm64) { - return Err(ProbeError::UnsupportedArchitecture( + return Err(ProtoError::UnsupportedArchitecture( "Node.js".into(), arch.to_string(), )); @@ -23,14 +23,14 @@ pub fn get_archive_file_path(version: &str) -> Result { } #[cfg(target_os = "linux")] -pub fn get_archive_file_path(version: &str) -> Result { +pub fn get_archive_file_path(version: &str) -> Result { let arch = NodeArch::from_str(consts::ARCH)?; if !matches!( arch, NodeArch::X64 | NodeArch::Arm64 | NodeArch::Armv7l | NodeArch::Ppc64le | NodeArch::S390x ) { - return Err(ProbeError::UnsupportedArchitecture( + return Err(ProtoError::UnsupportedArchitecture( "Node.js".into(), arch.to_string(), )); @@ -40,11 +40,11 @@ pub fn get_archive_file_path(version: &str) -> Result { } #[cfg(target_os = "windows")] -pub fn get_archive_file_path(version: &str) -> Result { +pub fn get_archive_file_path(version: &str) -> Result { let arch = NodeArch::from_str(consts::ARCH)?; if !matches!(arch, NodeArch::X64 | NodeArch::X86) { - return Err(ProbeError::UnsupportedArchitecture( + return Err(ProtoError::UnsupportedArchitecture( "Node.js".into(), arch.to_string(), )); @@ -53,7 +53,7 @@ pub fn get_archive_file_path(version: &str) -> Result { Ok(format!("node-v{version}-win-{arch}")) } -pub fn get_archive_file(version: &str) -> Result { +pub fn get_archive_file(version: &str) -> Result { let ext = if consts::OS == "windows" { "zip" } else { @@ -65,13 +65,13 @@ pub fn get_archive_file(version: &str) -> Result { #[async_trait] impl Downloadable<'_> for NodeLanguage { - fn get_download_path(&self) -> Result { + fn get_download_path(&self) -> Result { Ok(self .temp_dir .join(get_archive_file(self.get_resolved_version())?)) } - async fn download(&self, to_file: &Path, from_url: Option<&str>) -> Result { + async fn download(&self, to_file: &Path, from_url: Option<&str>) -> Result { if to_file.exists() { debug!(target: self.get_log_target(), "Tool already downloaded, continuing"); diff --git a/crates/probe/node/src/execute.rs b/crates/proto/node/src/execute.rs similarity index 67% rename from crates/probe/node/src/execute.rs rename to crates/proto/node/src/execute.rs index 5effbea46c5..7bb6c4d4a37 100644 --- a/crates/probe/node/src/execute.rs +++ b/crates/proto/node/src/execute.rs @@ -1,5 +1,5 @@ use crate::NodeLanguage; -use probe_core::{async_trait, Describable, Executable, Installable, ProbeError}; +use proto_core::{async_trait, Describable, Executable, Installable, ProtoError}; use std::path::Path; #[cfg(target_os = "windows")] @@ -14,22 +14,22 @@ pub fn get_bin_name>(name: T) -> String { #[async_trait] impl Executable<'_> for NodeLanguage { - async fn find_bin_path(&mut self) -> Result<(), ProbeError> { + async fn find_bin_path(&mut self) -> Result<(), ProtoError> { let bin_path = self.get_install_dir()?.join(get_bin_name("node")); if bin_path.exists() { self.bin_path = Some(bin_path); } else { - return Err(ProbeError::ExecuteMissingBin(self.get_name(), bin_path)); + return Err(ProtoError::ExecuteMissingBin(self.get_name(), bin_path)); } Ok(()) } - fn get_bin_path(&self) -> Result<&Path, ProbeError> { + fn get_bin_path(&self) -> Result<&Path, ProtoError> { match self.bin_path.as_ref() { Some(bin) => Ok(bin), - None => Err(ProbeError::MissingTool(self.get_name())), + None => Err(ProtoError::MissingTool(self.get_name())), } } } diff --git a/crates/probe/node/src/install.rs b/crates/proto/node/src/install.rs similarity index 81% rename from crates/probe/node/src/install.rs rename to crates/proto/node/src/install.rs index d1eeb1cebf8..e908ffa8553 100644 --- a/crates/probe/node/src/install.rs +++ b/crates/proto/node/src/install.rs @@ -1,16 +1,16 @@ use crate::download::get_archive_file_path; use crate::NodeLanguage; use log::debug; -use probe_core::{async_trait, untar, unzip, Describable, Installable, ProbeError, Resolvable}; +use proto_core::{async_trait, untar, unzip, Describable, Installable, ProtoError, Resolvable}; use std::path::{Path, PathBuf}; #[async_trait] impl Installable<'_> for NodeLanguage { - fn get_install_dir(&self) -> Result { + fn get_install_dir(&self) -> Result { Ok(self.install_dir.join(self.get_resolved_version())) } - async fn install(&self, install_dir: &Path, download_path: &Path) -> Result { + async fn install(&self, install_dir: &Path, download_path: &Path) -> Result { if install_dir.exists() { debug!(target: self.get_log_target(), "Tool already installed, continuing"); @@ -18,7 +18,7 @@ impl Installable<'_> for NodeLanguage { } if !download_path.exists() { - return Err(ProbeError::InstallMissingDownload(self.get_name())); + return Err(ProtoError::InstallMissingDownload(self.get_name())); } let prefix = get_archive_file_path(self.get_resolved_version())?; diff --git a/crates/probe/node/src/lib.rs b/crates/proto/node/src/lib.rs similarity index 72% rename from crates/probe/node/src/lib.rs rename to crates/proto/node/src/lib.rs index 7aaa334e3a6..187a190e86b 100644 --- a/crates/probe/node/src/lib.rs +++ b/crates/proto/node/src/lib.rs @@ -7,7 +7,7 @@ mod resolve; mod verify; pub use depman::*; -use probe_core::{Describable, Probe, Tool}; +use proto_core::{Describable, Proto, Tool}; use std::path::PathBuf; #[derive(Debug)] @@ -20,12 +20,12 @@ pub struct NodeLanguage { } impl NodeLanguage { - pub fn new(probe: &Probe, version: Option<&str>) -> Self { + pub fn new(proto: &Proto, version: Option<&str>) -> Self { NodeLanguage { bin_path: None, - install_dir: probe.tools_dir.join("node"), - log_target: "probe:tool:node".into(), - temp_dir: probe.temp_dir.join("node"), + install_dir: proto.tools_dir.join("node"), + log_target: "proto:tool:node".into(), + temp_dir: proto.temp_dir.join("node"), version: version.unwrap_or("latest").into(), } } diff --git a/crates/probe/node/src/platform.rs b/crates/proto/node/src/platform.rs similarity index 90% rename from crates/probe/node/src/platform.rs rename to crates/proto/node/src/platform.rs index b219577ccde..9bc8a41ff8c 100644 --- a/crates/probe/node/src/platform.rs +++ b/crates/proto/node/src/platform.rs @@ -1,4 +1,4 @@ -use probe_core::ProbeError; +use proto_core::ProtoError; use std::fmt; pub enum NodeArch { @@ -12,7 +12,7 @@ pub enum NodeArch { } impl std::str::FromStr for NodeArch { - type Err = ProbeError; + type Err = ProtoError; fn from_str(s: &str) -> Result { match s { @@ -23,7 +23,7 @@ impl std::str::FromStr for NodeArch { "s390x" => Ok(NodeArch::S390x), "x86_64" => Ok(NodeArch::X64), "x86" => Ok(NodeArch::X86), - unknown => Err(ProbeError::UnsupportedArchitecture( + unknown => Err(ProtoError::UnsupportedArchitecture( "Node.js".into(), unknown.to_owned(), )), diff --git a/crates/probe/node/src/resolve.rs b/crates/proto/node/src/resolve.rs similarity index 91% rename from crates/probe/node/src/resolve.rs rename to crates/proto/node/src/resolve.rs index 6c497c29583..f4b09cb16e8 100644 --- a/crates/probe/node/src/resolve.rs +++ b/crates/proto/node/src/resolve.rs @@ -2,9 +2,9 @@ use crate::NodeLanguage; use log::debug; -use probe_core::{ +use proto_core::{ add_v_prefix, async_trait, is_version_alias, load_versions_manifest, parse_version, - Describable, ProbeError, Resolvable, + Describable, ProtoError, Resolvable, }; use serde::Deserialize; @@ -31,7 +31,7 @@ impl Resolvable<'_> for NodeLanguage { &mut self, initial_version: &str, manifest_url: Option<&str>, - ) -> Result { + ) -> Result { let mut candidate = None; let initial_version = initial_version.to_lowercase(); @@ -75,7 +75,7 @@ impl Resolvable<'_> for NodeLanguage { } if candidate.is_none() { - return Err(ProbeError::VersionUnknownAlias(initial_version)); + return Err(ProtoError::VersionUnknownAlias(initial_version)); } // Find the first version with a matching alias @@ -90,7 +90,7 @@ impl Resolvable<'_> for NodeLanguage { } if candidate.is_none() { - return Err(ProbeError::VersionUnknownAlias(initial_version)); + return Err(ProtoError::VersionUnknownAlias(initial_version)); } // An explicit version? Support optional minor and patch @@ -104,7 +104,7 @@ impl Resolvable<'_> for NodeLanguage { } let Some(candidate) = candidate else { - return Err(ProbeError::VersionResolveFailed(initial_version)) + return Err(ProtoError::VersionResolveFailed(initial_version)) }; let version = parse_version(candidate)?.to_string(); diff --git a/crates/probe/node/src/verify.rs b/crates/proto/node/src/verify.rs similarity index 88% rename from crates/probe/node/src/verify.rs rename to crates/proto/node/src/verify.rs index c96e2d3d721..6462b8be3fc 100644 --- a/crates/probe/node/src/verify.rs +++ b/crates/proto/node/src/verify.rs @@ -1,7 +1,7 @@ use crate::NodeLanguage; use log::debug; -use probe_core::{ - async_trait, download_from_url, get_sha256_hash_of_file, Describable, ProbeError, Resolvable, +use proto_core::{ + async_trait, download_from_url, get_sha256_hash_of_file, Describable, ProtoError, Resolvable, Verifiable, }; use std::fs::File; @@ -10,7 +10,7 @@ use std::path::{Path, PathBuf}; #[async_trait] impl Verifiable<'_> for NodeLanguage { - fn get_checksum_path(&self) -> Result { + fn get_checksum_path(&self) -> Result { Ok(self .temp_dir .join(format!("{}-SHASUMS256.txt", self.get_resolved_version()))) @@ -20,7 +20,7 @@ impl Verifiable<'_> for NodeLanguage { &self, to_file: &Path, from_url: Option<&str>, - ) -> Result { + ) -> Result { if to_file.exists() { debug!(target: self.get_log_target(), "Checksum already downloaded, continuing"); @@ -46,7 +46,7 @@ impl Verifiable<'_> for NodeLanguage { &self, checksum_file: &Path, download_file: &Path, - ) -> Result { + ) -> Result { debug!( target: self.get_log_target(), "Verifiying checksum of downloaded file {} using {}", @@ -57,7 +57,7 @@ impl Verifiable<'_> for NodeLanguage { let checksum = get_sha256_hash_of_file(download_file)?; let file = File::open(checksum_file) - .map_err(|e| ProbeError::Fs(checksum_file.to_path_buf(), e.to_string()))?; + .map_err(|e| ProtoError::Fs(checksum_file.to_path_buf(), e.to_string()))?; let file_name = download_file .file_name() .unwrap_or_default() @@ -73,7 +73,7 @@ impl Verifiable<'_> for NodeLanguage { } } - Err(ProbeError::VerifyInvalidChecksum( + Err(ProtoError::VerifyInvalidChecksum( download_file.to_path_buf(), checksum_file.to_path_buf(), )) diff --git a/crates/probe/node/tests/node_depman_test.rs b/crates/proto/node/tests/node_depman_test.rs similarity index 80% rename from crates/probe/node/tests/node_depman_test.rs rename to crates/proto/node/tests/node_depman_test.rs index b062be9a397..9895d167f85 100644 --- a/crates/probe/node/tests/node_depman_test.rs +++ b/crates/proto/node/tests/node_depman_test.rs @@ -1,9 +1,9 @@ -use probe_core::{Downloadable, Executable, Installable, Probe, Resolvable, Tool, Verifiable}; -use probe_node::{NodeDependencyManager, NodeDependencyManagerType}; +use proto_core::{Downloadable, Executable, Installable, Proto, Resolvable, Tool, Verifiable}; +use proto_node::{NodeDependencyManager, NodeDependencyManagerType}; use std::path::Path; -fn create_probe(dir: &Path) -> Probe { - Probe { +fn create_proto(dir: &Path) -> Proto { + Proto { temp_dir: dir.join("temp"), tools_dir: dir.join("tools"), } @@ -12,9 +12,9 @@ fn create_probe(dir: &Path) -> Probe { #[tokio::test] async fn downloads_verifies_installs_npm() { let fixture = assert_fs::TempDir::new().unwrap(); - let probe = create_probe(fixture.path()); + let proto = create_proto(fixture.path()); let mut tool = - NodeDependencyManager::new(&probe, NodeDependencyManagerType::Npm, Some("9.0.0")); + NodeDependencyManager::new(&proto, NodeDependencyManagerType::Npm, Some("9.0.0")); tool.setup("9.0.0").await.unwrap(); @@ -24,16 +24,16 @@ async fn downloads_verifies_installs_npm() { assert_eq!( tool.get_bin_path().unwrap(), - &probe.tools_dir.join("npm/9.0.0/bin/npm-cli.js") + &proto.tools_dir.join("npm/9.0.0/bin/npm-cli.js") ); } #[tokio::test] async fn downloads_verifies_installs_pnpm() { let fixture = assert_fs::TempDir::new().unwrap(); - let probe = create_probe(fixture.path()); + let proto = create_proto(fixture.path()); let mut tool = - NodeDependencyManager::new(&probe, NodeDependencyManagerType::Pnpm, Some("7.0.0")); + NodeDependencyManager::new(&proto, NodeDependencyManagerType::Pnpm, Some("7.0.0")); tool.setup("7.0.0").await.unwrap(); @@ -43,16 +43,16 @@ async fn downloads_verifies_installs_pnpm() { assert_eq!( tool.get_bin_path().unwrap(), - &probe.tools_dir.join("pnpm/7.0.0/bin/pnpm.cjs") + &proto.tools_dir.join("pnpm/7.0.0/bin/pnpm.cjs") ); } #[tokio::test] async fn downloads_verifies_installs_yarn_classic() { let fixture = assert_fs::TempDir::new().unwrap(); - let probe = create_probe(fixture.path()); + let proto = create_proto(fixture.path()); let mut tool = - NodeDependencyManager::new(&probe, NodeDependencyManagerType::Yarn, Some("1.22.0")); + NodeDependencyManager::new(&proto, NodeDependencyManagerType::Yarn, Some("1.22.0")); tool.setup("1.22.0").await.unwrap(); @@ -62,16 +62,16 @@ async fn downloads_verifies_installs_yarn_classic() { assert_eq!( tool.get_bin_path().unwrap(), - &probe.tools_dir.join("yarn/1.22.0/bin/yarn.js") + &proto.tools_dir.join("yarn/1.22.0/bin/yarn.js") ); } #[tokio::test] async fn downloads_verifies_installs_yarn_berry() { let fixture = assert_fs::TempDir::new().unwrap(); - let probe = create_probe(fixture.path()); + let proto = create_proto(fixture.path()); let mut tool = - NodeDependencyManager::new(&probe, NodeDependencyManagerType::Yarn, Some("3.0.0")); + NodeDependencyManager::new(&proto, NodeDependencyManagerType::Yarn, Some("3.0.0")); tool.setup("3.0.0").await.unwrap(); @@ -82,7 +82,7 @@ async fn downloads_verifies_installs_yarn_berry() { assert_eq!(tool.get_resolved_version(), "1.22.19"); assert_eq!( tool.get_bin_path().unwrap(), - &probe.tools_dir.join("yarn/1.22.19/bin/yarn.js") + &proto.tools_dir.join("yarn/1.22.19/bin/yarn.js") ); } @@ -92,13 +92,13 @@ mod downloader { #[tokio::test] async fn sets_path_to_temp() { let fixture = assert_fs::TempDir::new().unwrap(); - let probe = create_probe(fixture.path()); + let proto = create_proto(fixture.path()); let tool = - NodeDependencyManager::new(&probe, NodeDependencyManagerType::Npm, Some("9.0.0")); + NodeDependencyManager::new(&proto, NodeDependencyManagerType::Npm, Some("9.0.0")); assert_eq!( tool.get_download_path().unwrap(), - probe.temp_dir.join("npm").join("9.0.0.tgz") + proto.temp_dir.join("npm").join("9.0.0.tgz") ); } @@ -106,7 +106,7 @@ mod downloader { async fn downloads_to_temp() { let fixture = assert_fs::TempDir::new().unwrap(); let tool = NodeDependencyManager::new( - &create_probe(fixture.path()), + &create_proto(fixture.path()), NodeDependencyManagerType::Npm, Some("9.0.0"), ); @@ -124,7 +124,7 @@ mod downloader { async fn doesnt_download_if_file_exists() { let fixture = assert_fs::TempDir::new().unwrap(); let tool = NodeDependencyManager::new( - &create_probe(fixture.path()), + &create_proto(fixture.path()), NodeDependencyManagerType::Npm, Some("9.0.0"), ); @@ -143,7 +143,7 @@ mod resolver { async fn resolve_latest() { let fixture = assert_fs::TempDir::new().unwrap(); let mut tool = NodeDependencyManager::new( - &create_probe(fixture.path()), + &create_proto(fixture.path()), NodeDependencyManagerType::Npm, None, ); @@ -159,7 +159,7 @@ mod resolver { async fn resolve_custom_dist() { let fixture = assert_fs::TempDir::new().unwrap(); let mut tool = NodeDependencyManager::new( - &create_probe(fixture.path()), + &create_proto(fixture.path()), NodeDependencyManagerType::Yarn, None, ); @@ -171,7 +171,7 @@ mod resolver { async fn handles_npm() { let fixture = assert_fs::TempDir::new().unwrap(); let mut tool = NodeDependencyManager::new( - &create_probe(fixture.path()), + &create_proto(fixture.path()), NodeDependencyManagerType::Npm, None, ); @@ -183,7 +183,7 @@ mod resolver { async fn handles_pnpm() { let fixture = assert_fs::TempDir::new().unwrap(); let mut tool = NodeDependencyManager::new( - &create_probe(fixture.path()), + &create_proto(fixture.path()), NodeDependencyManagerType::Pnpm, None, ); @@ -195,7 +195,7 @@ mod resolver { async fn handles_yarn() { let fixture = assert_fs::TempDir::new().unwrap(); let mut tool = NodeDependencyManager::new( - &create_probe(fixture.path()), + &create_proto(fixture.path()), NodeDependencyManagerType::Yarn, None, ); @@ -211,7 +211,7 @@ mod resolver { async fn errors_invalid_alias() { let fixture = assert_fs::TempDir::new().unwrap(); let mut tool = NodeDependencyManager::new( - &create_probe(fixture.path()), + &create_proto(fixture.path()), NodeDependencyManagerType::Npm, None, ); @@ -224,7 +224,7 @@ mod resolver { async fn errors_invalid_version() { let fixture = assert_fs::TempDir::new().unwrap(); let mut tool = NodeDependencyManager::new( - &create_probe(fixture.path()), + &create_proto(fixture.path()), NodeDependencyManagerType::Npm, None, ); diff --git a/crates/probe/node/tests/node_test.rs b/crates/proto/node/tests/node_test.rs similarity index 77% rename from crates/probe/node/tests/node_test.rs rename to crates/proto/node/tests/node_test.rs index 4a73fb9d9d0..57b9ddc776c 100644 --- a/crates/probe/node/tests/node_test.rs +++ b/crates/proto/node/tests/node_test.rs @@ -1,10 +1,10 @@ -use probe_core::{Downloadable, Executable, Installable, Probe, Resolvable, Tool, Verifiable}; -use probe_node::NodeLanguage; +use proto_core::{Downloadable, Executable, Installable, Proto, Resolvable, Tool, Verifiable}; +use proto_node::NodeLanguage; use std::fs; use std::path::Path; -fn create_probe(dir: &Path) -> Probe { - Probe { +fn create_proto(dir: &Path) -> Proto { + Proto { temp_dir: dir.join("temp"), tools_dir: dir.join("tools"), } @@ -13,8 +13,8 @@ fn create_probe(dir: &Path) -> Probe { #[tokio::test] async fn downloads_verifies_installs_tool() { let fixture = assert_fs::TempDir::new().unwrap(); - let probe = create_probe(fixture.path()); - let mut tool = NodeLanguage::new(&probe, Some("18.0.0")); + let proto = create_proto(fixture.path()); + let mut tool = NodeLanguage::new(&proto, Some("18.0.0")); tool.setup("18.0.0").await.unwrap(); @@ -25,29 +25,29 @@ async fn downloads_verifies_installs_tool() { if cfg!(windows) { assert_eq!( tool.get_bin_path().unwrap(), - &probe.tools_dir.join("node/18.0.0/node.exe") + &proto.tools_dir.join("node/18.0.0/node.exe") ); } else { assert_eq!( tool.get_bin_path().unwrap(), - &probe.tools_dir.join("node/18.0.0/bin/node") + &proto.tools_dir.join("node/18.0.0/bin/node") ); } } mod downloader { use super::*; - use probe_node::download::get_archive_file; + use proto_node::download::get_archive_file; #[tokio::test] async fn sets_path_to_temp() { let fixture = assert_fs::TempDir::new().unwrap(); - let probe = create_probe(fixture.path()); - let tool = NodeLanguage::new(&probe, Some("18.0.0")); + let proto = create_proto(fixture.path()); + let tool = NodeLanguage::new(&proto, Some("18.0.0")); assert_eq!( tool.get_download_path().unwrap(), - probe + proto .temp_dir .join("node") .join(get_archive_file("18.0.0").unwrap()) @@ -57,7 +57,7 @@ mod downloader { #[tokio::test] async fn downloads_to_temp() { let fixture = assert_fs::TempDir::new().unwrap(); - let tool = NodeLanguage::new(&create_probe(fixture.path()), Some("18.0.0")); + let tool = NodeLanguage::new(&create_proto(fixture.path()), Some("18.0.0")); let to_file = tool.get_download_path().unwrap(); @@ -71,7 +71,7 @@ mod downloader { #[tokio::test] async fn doesnt_download_if_file_exists() { let fixture = assert_fs::TempDir::new().unwrap(); - let tool = NodeLanguage::new(&create_probe(fixture.path()), Some("18.0.0")); + let tool = NodeLanguage::new(&create_proto(fixture.path()), Some("18.0.0")); let to_file = tool.get_download_path().unwrap(); @@ -86,12 +86,12 @@ mod installer { #[tokio::test] async fn sets_dir_to_tools() { let fixture = assert_fs::TempDir::new().unwrap(); - let probe = create_probe(fixture.path()); - let tool = NodeLanguage::new(&probe, Some("18.0.0")); + let proto = create_proto(fixture.path()); + let tool = NodeLanguage::new(&proto, Some("18.0.0")); assert_eq!( tool.get_install_dir().unwrap(), - probe.tools_dir.join("node").join("18.0.0") + proto.tools_dir.join("node").join("18.0.0") ); } @@ -99,7 +99,7 @@ mod installer { #[should_panic(expected = "InstallMissingDownload(\"Node.js\")")] async fn errors_for_missing_download() { let fixture = assert_fs::TempDir::new().unwrap(); - let tool = NodeLanguage::new(&create_probe(fixture.path()), Some("18.0.0")); + let tool = NodeLanguage::new(&create_proto(fixture.path()), Some("18.0.0")); let dir = tool.get_install_dir().unwrap(); @@ -111,7 +111,7 @@ mod installer { #[tokio::test] async fn doesnt_install_if_dir_exists() { let fixture = assert_fs::TempDir::new().unwrap(); - let tool = NodeLanguage::new(&create_probe(fixture.path()), Some("18.0.0")); + let tool = NodeLanguage::new(&create_proto(fixture.path()), Some("18.0.0")); let dir = tool.get_install_dir().unwrap(); @@ -130,7 +130,7 @@ mod resolver { #[tokio::test] async fn updates_struct_version() { let fixture = assert_fs::TempDir::new().unwrap(); - let mut tool = NodeLanguage::new(&create_probe(fixture.path()), None); + let mut tool = NodeLanguage::new(&create_proto(fixture.path()), None); assert_ne!(tool.resolve_version("node", None).await.unwrap(), "node"); assert_ne!(tool.get_resolved_version(), "node"); @@ -139,7 +139,7 @@ mod resolver { #[tokio::test] async fn resolve_latest() { let fixture = assert_fs::TempDir::new().unwrap(); - let mut tool = NodeLanguage::new(&create_probe(fixture.path()), None); + let mut tool = NodeLanguage::new(&create_proto(fixture.path()), None); assert_ne!( tool.resolve_version("latest", None).await.unwrap(), @@ -150,7 +150,7 @@ mod resolver { #[tokio::test] async fn resolve_stable() { let fixture = assert_fs::TempDir::new().unwrap(); - let mut tool = NodeLanguage::new(&create_probe(fixture.path()), None); + let mut tool = NodeLanguage::new(&create_proto(fixture.path()), None); assert_ne!( tool.resolve_version("stable", None).await.unwrap(), @@ -161,7 +161,7 @@ mod resolver { #[tokio::test] async fn resolve_lts_wild() { let fixture = assert_fs::TempDir::new().unwrap(); - let mut tool = NodeLanguage::new(&create_probe(fixture.path()), None); + let mut tool = NodeLanguage::new(&create_proto(fixture.path()), None); assert_ne!(tool.resolve_version("lts-*", None).await.unwrap(), "lts-*"); } @@ -169,7 +169,7 @@ mod resolver { #[tokio::test] async fn resolve_lts_dash() { let fixture = assert_fs::TempDir::new().unwrap(); - let mut tool = NodeLanguage::new(&create_probe(fixture.path()), None); + let mut tool = NodeLanguage::new(&create_proto(fixture.path()), None); assert_ne!( tool.resolve_version("lts-gallium", None).await.unwrap(), @@ -180,7 +180,7 @@ mod resolver { #[tokio::test] async fn resolve_lts_slash() { let fixture = assert_fs::TempDir::new().unwrap(); - let mut tool = NodeLanguage::new(&create_probe(fixture.path()), None); + let mut tool = NodeLanguage::new(&create_proto(fixture.path()), None); assert_ne!( tool.resolve_version("lts/gallium", None).await.unwrap(), @@ -191,7 +191,7 @@ mod resolver { #[tokio::test] async fn resolve_alias() { let fixture = assert_fs::TempDir::new().unwrap(); - let mut tool = NodeLanguage::new(&create_probe(fixture.path()), None); + let mut tool = NodeLanguage::new(&create_proto(fixture.path()), None); assert_ne!( tool.resolve_version("Gallium", None).await.unwrap(), @@ -202,7 +202,7 @@ mod resolver { #[tokio::test] async fn resolve_version() { let fixture = assert_fs::TempDir::new().unwrap(); - let mut tool = NodeLanguage::new(&create_probe(fixture.path()), None); + let mut tool = NodeLanguage::new(&create_proto(fixture.path()), None); assert_eq!( tool.resolve_version("18.0.0", None).await.unwrap(), @@ -213,7 +213,7 @@ mod resolver { #[tokio::test] async fn resolve_version_with_prefix() { let fixture = assert_fs::TempDir::new().unwrap(); - let mut tool = NodeLanguage::new(&create_probe(fixture.path()), None); + let mut tool = NodeLanguage::new(&create_proto(fixture.path()), None); assert_eq!( tool.resolve_version("v18.0.0", None).await.unwrap(), @@ -225,7 +225,7 @@ mod resolver { #[should_panic(expected = "VersionUnknownAlias(\"lts-unknown\")")] async fn errors_invalid_lts() { let fixture = assert_fs::TempDir::new().unwrap(); - let mut tool = NodeLanguage::new(&create_probe(fixture.path()), None); + let mut tool = NodeLanguage::new(&create_proto(fixture.path()), None); tool.resolve_version("lts-unknown", None).await.unwrap(); } @@ -234,7 +234,7 @@ mod resolver { #[should_panic(expected = "VersionUnknownAlias(\"unknown\")")] async fn errors_invalid_alias() { let fixture = assert_fs::TempDir::new().unwrap(); - let mut tool = NodeLanguage::new(&create_probe(fixture.path()), None); + let mut tool = NodeLanguage::new(&create_proto(fixture.path()), None); tool.resolve_version("unknown", None).await.unwrap(); } @@ -243,7 +243,7 @@ mod resolver { #[should_panic(expected = "VersionResolveFailed(\"99.99.99\")")] async fn errors_invalid_version() { let fixture = assert_fs::TempDir::new().unwrap(); - let mut tool = NodeLanguage::new(&create_probe(fixture.path()), None); + let mut tool = NodeLanguage::new(&create_proto(fixture.path()), None); tool.resolve_version("99.99.99", None).await.unwrap(); } @@ -255,19 +255,19 @@ mod verifier { #[tokio::test] async fn sets_path_to_temp() { let fixture = assert_fs::TempDir::new().unwrap(); - let probe = create_probe(fixture.path()); - let tool = NodeLanguage::new(&probe, Some("18.0.0")); + let proto = create_proto(fixture.path()); + let tool = NodeLanguage::new(&proto, Some("18.0.0")); assert_eq!( tool.get_checksum_path().unwrap(), - probe.temp_dir.join("node").join("18.0.0-SHASUMS256.txt") + proto.temp_dir.join("node").join("18.0.0-SHASUMS256.txt") ); } #[tokio::test] async fn downloads_to_temp() { let fixture = assert_fs::TempDir::new().unwrap(); - let tool = NodeLanguage::new(&create_probe(fixture.path()), Some("18.0.0")); + let tool = NodeLanguage::new(&create_proto(fixture.path()), Some("18.0.0")); let to_file = tool.get_checksum_path().unwrap(); assert!(!to_file.exists()); @@ -280,7 +280,7 @@ mod verifier { #[tokio::test] async fn doesnt_download_if_file_exists() { let fixture = assert_fs::TempDir::new().unwrap(); - let tool = NodeLanguage::new(&create_probe(fixture.path()), Some("18.0.0")); + let tool = NodeLanguage::new(&create_proto(fixture.path()), Some("18.0.0")); let to_file = tool.get_checksum_path().unwrap(); @@ -292,7 +292,7 @@ mod verifier { #[should_panic(expected = "VerifyInvalidChecksum")] async fn errors_for_checksum_mismatch() { let fixture = assert_fs::TempDir::new().unwrap(); - let tool = NodeLanguage::new(&create_probe(fixture.path()), Some("18.0.0")); + let tool = NodeLanguage::new(&create_proto(fixture.path()), Some("18.0.0")); let dl_path = tool.get_download_path().unwrap(); let cs_path = tool.get_checksum_path().unwrap();