Skip to content

Commit

Permalink
internal: Rename probe to proto. (#474)
Browse files Browse the repository at this point in the history
* Rename.

* Rename folder.

* Rename error.

* Rename struct.
  • Loading branch information
milesj committed Nov 29, 2022
1 parent 70580bf commit 70777cd
Show file tree
Hide file tree
Showing 38 changed files with 265 additions and 265 deletions.
68 changes: 34 additions & 34 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [
"crates/node/*",
"crates/system/*",
"crates/typescript/*",
"crates/probe/*",
"crates/proto/*",
]
default-members = ["crates/cli"]

Expand Down
2 changes: 1 addition & 1 deletion crates/core/logger/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/core/toolchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
4 changes: 2 additions & 2 deletions crates/core/toolchain/src/errors.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -28,5 +28,5 @@ pub enum ToolchainError {
Moon(#[from] MoonError),

#[error(transparent)]
Probe(#[from] ProbeError),
Proto(#[from] ProtoError),
}
10 changes: 5 additions & 5 deletions crates/core/toolchain/src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions crates/core/toolchain/src/tools/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -27,24 +27,24 @@ pub struct NodeTool {
}

impl NodeTool {
pub fn new(probe: &Probe, config: &NodeConfig) -> Result<NodeTool, ToolchainError> {
pub fn new(proto: &Proto, config: &NodeConfig) -> Result<NodeTool, ToolchainError> {
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,
};

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)?);
}
};

Expand Down
10 changes: 5 additions & 5 deletions crates/core/toolchain/src/tools/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,12 +22,12 @@ pub struct NpmTool {
}

impl NpmTool {
pub fn new(probe: &Probe, config: &NpmConfig) -> Result<NpmTool, ToolchainError> {
pub fn new(proto: &Proto, config: &NpmConfig) -> Result<NpmTool, ToolchainError> {
Ok(NpmTool {
config: config.to_owned(),
tool: NodeDependencyManager::new(
probe,
probe_node::NodeDependencyManagerType::Npm,
proto,
proto_node::NodeDependencyManagerType::Npm,
Some(&config.version),
),
})
Expand Down
10 changes: 5 additions & 5 deletions crates/core/toolchain/src/tools/pnpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,12 +22,12 @@ pub struct PnpmTool {
}

impl PnpmTool {
pub fn new(probe: &Probe, config: &Option<PnpmConfig>) -> Result<PnpmTool, ToolchainError> {
pub fn new(proto: &Proto, config: &Option<PnpmConfig>) -> Result<PnpmTool, ToolchainError> {
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,
Expand Down
10 changes: 5 additions & 5 deletions crates/core/toolchain/src/tools/yarn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,12 +22,12 @@ pub struct YarnTool {
}

impl YarnTool {
pub fn new(probe: &Probe, config: &Option<YarnConfig>) -> Result<YarnTool, ToolchainError> {
pub fn new(proto: &Proto, config: &Option<YarnConfig>) -> Result<YarnTool, ToolchainError> {
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,
Expand Down
2 changes: 1 addition & 1 deletion crates/core/toolchain/src/traits.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
1 change: 0 additions & 1 deletion crates/probe/README.md

This file was deleted.

1 change: 1 addition & 0 deletions crates/proto/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All proto crates will be extracted into their own repo, and _should not_ import the moon crates.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "probe_core"
name = "proto_core"
version = "0.1.0"
edition = "2021"

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::errors::ProbeError;
use crate::errors::ProtoError;
use crate::resolver::Resolvable;
use log::trace;
use std::fs::File;
Expand All @@ -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/<file>.
fn get_download_path(&self) -> Result<PathBuf, ProbeError>;
/// This is typically ~/.proto/temp/<file>.
fn get_download_path(&self) -> Result<PathBuf, ProtoError>;

/// 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<bool, ProbeError>;
async fn download(&self, to_file: &Path, from_url: Option<&str>) -> Result<bool, ProtoError>;
}

pub async fn download_from_url<U, F>(url: U, dest_file: F) -> Result<(), ProbeError>
pub async fn download_from_url<U, F>(url: U, dest_file: F) -> Result<(), ProtoError>
where
U: AsRef<str>,
F: AsRef<Path>,
{
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
Expand All @@ -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(),
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down
Original file line number Diff line number Diff line change
@@ -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>;
}
Loading

0 comments on commit 70777cd

Please sign in to comment.