From c2e6b2fb51c8897bbabc454f1e49f491cfb21252 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Wed, 20 Sep 2023 10:17:17 -0700 Subject: [PATCH] Update node and system. --- Cargo.lock | 2 +- crates/core/tool/src/manager.rs | 4 +- crates/deno/platform/src/platform.rs | 4 +- crates/node/platform/src/platform.rs | 62 ++++++++++++----------- crates/node/tool/Cargo.toml | 2 +- crates/node/tool/src/node_tool.rs | 14 +++-- crates/node/tool/src/npm_tool.rs | 6 +-- crates/node/tool/src/pnpm_tool.rs | 5 +- crates/node/tool/src/yarn_tool.rs | 6 +-- crates/rust/platform/src/rust_platform.rs | 14 ++--- crates/rust/tool/src/rust_tool.rs | 6 +-- crates/system/platform/src/platform.rs | 8 +-- nextgen/platform-runtime/src/lib.rs | 2 +- 13 files changed, 64 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9820132b506..16ff504971a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3542,7 +3542,7 @@ dependencies = [ "moon_config", "moon_logger", "moon_node_lang", - "moon_platform_runtime", + "moon_platform_runtime2", "moon_process", "moon_terminal", "moon_tool", diff --git a/crates/core/tool/src/manager.rs b/crates/core/tool/src/manager.rs index 763efb7c200..81dcb82d523 100644 --- a/crates/core/tool/src/manager.rs +++ b/crates/core/tool/src/manager.rs @@ -1,7 +1,7 @@ use crate::errors::ToolError; use crate::tool::Tool; use moon_platform_runtime2::{Runtime, RuntimeReq}; -use proto_core::Version as SemVersion; +use proto_core::Version; use rustc_hash::FxHashMap; pub struct ToolManager { @@ -50,7 +50,7 @@ impl ToolManager { pub async fn setup( &mut self, req: &RuntimeReq, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { match self.cache.get_mut(&req) { Some(cache) => Ok(cache.setup(last_versions).await?), diff --git a/crates/deno/platform/src/platform.rs b/crates/deno/platform/src/platform.rs index 8e08f64c974..25e6da3703e 100644 --- a/crates/deno/platform/src/platform.rs +++ b/crates/deno/platform/src/platform.rs @@ -19,7 +19,7 @@ use moon_terminal::{print_checkpoint, Checkpoint}; use moon_tool::{Tool, ToolManager}; use moon_typescript_platform::TypeScriptTargetHash; use moon_utils::async_trait; -use proto_core::{hash_file_contents, ProtoEnvironment, Version as SemVersion}; +use proto_core::{hash_file_contents, ProtoEnvironment, Version}; use rustc_hash::FxHashMap; use std::sync::Arc; use std::{ @@ -148,7 +148,7 @@ impl Platform for DenoPlatform { &mut self, _context: &ActionContext, runtime: &Runtime, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { let req = &runtime.requirement; diff --git a/crates/node/platform/src/platform.rs b/crates/node/platform/src/platform.rs index 2c389c8ea0f..7c359f58221 100644 --- a/crates/node/platform/src/platform.rs +++ b/crates/node/platform/src/platform.rs @@ -12,14 +12,14 @@ use moon_logger::{debug, warn}; use moon_node_lang::node::get_package_manager_workspaces; use moon_node_lang::{PackageJson, NPM}; use moon_node_tool::NodeTool; -use moon_platform::{Platform, Runtime, Version}; +use moon_platform::{Platform, Runtime, RuntimeReq, VersionSpec}; use moon_process::Command; use moon_project::Project; use moon_task::Task; use moon_tool::{Tool, ToolManager}; use moon_typescript_platform::TypeScriptTargetHash; use moon_utils::async_trait; -use proto_core::{ProtoEnvironment, Version as SemVersion}; +use proto_core::{ProtoEnvironment, Version}; use rustc_hash::FxHashMap; use starbase_styles::color; use starbase_utils::glob::GlobSet; @@ -54,7 +54,7 @@ impl NodePlatform { config: config.to_owned(), package_names: FxHashMap::default(), proto_env, - toolchain: ToolManager::new(Runtime::Node(Version::new_global())), + toolchain: ToolManager::new(Runtime::new(PlatformType::Node, RuntimeReq::Global)), typescript_config: typescript_config.to_owned(), workspace_root: workspace_root.to_path_buf(), } @@ -71,17 +71,23 @@ impl Platform for NodePlatform { if let Some(config) = &project_config { if let Some(node_config) = &config.toolchain.node { if let Some(version) = &node_config.version { - return Runtime::Node(Version::new_override(version.to_string())); + return Runtime::new( + PlatformType::Node, + RuntimeReq::ToolchainOverride(VersionSpec::Version(version.to_owned())), + ); } } } if let Some(version) = &self.config.version { - return Runtime::Node(Version::new(version.to_string())); + return Runtime::new( + PlatformType::Node, + RuntimeReq::Toolchain(VersionSpec::Version(version.to_owned())), + ); } // Global - Runtime::Node(Version::new_global()) + Runtime::new(PlatformType::Node, RuntimeReq::Global) } fn matches(&self, platform: &PlatformType, runtime: Option<&Runtime>) -> bool { @@ -90,7 +96,7 @@ impl Platform for NodePlatform { } if let Some(runtime) = &runtime { - return matches!(runtime, Runtime::Node(_)); + return matches!(runtime.platform, PlatformType::Node); } false @@ -251,8 +257,8 @@ impl Platform for NodePlatform { Ok(Box::new(tool)) } - fn get_tool_for_version(&self, version: Version) -> miette::Result> { - let tool = self.toolchain.get_for_version(&version)?; + fn get_tool_for_version(&self, req: RuntimeReq) -> miette::Result> { + let tool = self.toolchain.get_for_version(&req)?; Ok(Box::new(tool)) } @@ -268,21 +274,21 @@ impl Platform for NodePlatform { } async fn setup_toolchain(&mut self) -> miette::Result<()> { - let version = match &self.config.version { - Some(v) => Version::new(v.to_string()), - None => Version::new_global(), + let req = match &self.config.version { + Some(v) => RuntimeReq::Toolchain(VersionSpec::Version(v.to_owned())), + None => RuntimeReq::Global, }; let mut last_versions = FxHashMap::default(); - if !self.toolchain.has(&version) { + if !self.toolchain.has(&req) { self.toolchain.register( - &version, - NodeTool::new(&self.proto_env, &self.config, &version).await?, + &req, + NodeTool::new(&self.proto_env, &self.config, &req).await?, ); } - self.toolchain.setup(&version, &mut last_versions).await?; + self.toolchain.setup(&req, &mut last_versions).await?; Ok(()) } @@ -299,24 +305,20 @@ impl Platform for NodePlatform { &mut self, _context: &ActionContext, runtime: &Runtime, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { - let version = runtime.version(); + let req = &runtime.requirement; - if !self.toolchain.has(&version) { + if !self.toolchain.has(req) { self.toolchain.register( - &version, - NodeTool::new(&self.proto_env, &self.config, &version).await?, + req, + NodeTool::new(&self.proto_env, &self.config, req).await?, ); } - let installed = self.toolchain.setup(&version, last_versions).await?; + let installed = self.toolchain.setup(req, last_versions).await?; - actions::setup_tool( - self.toolchain.get_for_version(runtime.version())?, - &self.workspace_root, - ) - .await?; + actions::setup_tool(self.toolchain.get_for_version(req)?, &self.workspace_root).await?; Ok(installed) } @@ -328,7 +330,7 @@ impl Platform for NodePlatform { working_dir: &Path, ) -> miette::Result<()> { actions::install_deps( - self.toolchain.get_for_version(runtime.version())?, + self.toolchain.get_for_version(&runtime.requirement)?, working_dir, ) .await?; @@ -390,7 +392,7 @@ impl Platform for NodePlatform { hasher_config: &HasherConfig, ) -> miette::Result<()> { let node_hash = actions::create_target_hasher( - self.toolchain.get_for_version(runtime.version()).ok(), + self.toolchain.get_for_version(&runtime.requirement).ok(), project, &self.workspace_root, hasher_config, @@ -422,7 +424,7 @@ impl Platform for NodePlatform { ) -> miette::Result { let command = if self.is_toolchain_enabled()? { actions::create_target_command( - self.toolchain.get_for_version(runtime.version())?, + self.toolchain.get_for_version(&runtime.requirement)?, context, project, task, diff --git a/crates/node/tool/Cargo.toml b/crates/node/tool/Cargo.toml index 6448f180ca3..952ff172eec 100644 --- a/crates/node/tool/Cargo.toml +++ b/crates/node/tool/Cargo.toml @@ -7,7 +7,7 @@ publish = false [dependencies] moon_config = { path = "../../../nextgen/config" } moon_logger = { path = "../../core/logger" } -moon_platform_runtime = { path = "../../core/platform-runtime" } +moon_platform_runtime2 = { path = "../../../nextgen/platform-runtime" } moon_process = { path = "../../../nextgen/process" } moon_node_lang = { path = "../lang" } moon_terminal = { path = "../../core/terminal" } diff --git a/crates/node/tool/src/node_tool.rs b/crates/node/tool/src/node_tool.rs index 974479efe33..2ff1f4c0a51 100644 --- a/crates/node/tool/src/node_tool.rs +++ b/crates/node/tool/src/node_tool.rs @@ -4,15 +4,13 @@ use crate::yarn_tool::YarnTool; use moon_config::{NodeConfig, NodePackageManager}; use moon_logger::debug; use moon_node_lang::node; -use moon_platform_runtime::Version; +use moon_platform_runtime2::RuntimeReq; use moon_process::Command; use moon_terminal::{print_checkpoint, Checkpoint}; use moon_tool::{ async_trait, get_path_env_var, load_tool_plugin, DependencyManager, Tool, ToolError, }; -use proto_core::{ - Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version as SemVersion, -}; +use proto_core::{Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version}; use rustc_hash::FxHashMap; use std::path::{Path, PathBuf}; @@ -34,7 +32,7 @@ impl NodeTool { pub async fn new( proto: &ProtoEnvironment, config: &NodeConfig, - version: &Version, + req: &RuntimeReq, ) -> miette::Result { let mut node = NodeTool { global: false, @@ -46,11 +44,11 @@ impl NodeTool { yarn: None, }; - if version.is_global() { + if req.is_global() { node.global = true; node.config.version = None; } else { - node.config.version = SemVersion::parse(&version.number).ok(); + node.config.version = req.to_version(); }; match config.package_manager { @@ -160,7 +158,7 @@ impl Tool for NodeTool { async fn setup( &mut self, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { let mut installed = 0; diff --git a/crates/node/tool/src/npm_tool.rs b/crates/node/tool/src/npm_tool.rs index faf90430584..173749f2c75 100644 --- a/crates/node/tool/src/npm_tool.rs +++ b/crates/node/tool/src/npm_tool.rs @@ -6,9 +6,7 @@ use moon_process::Command; use moon_terminal::{print_checkpoint, Checkpoint}; use moon_tool::{async_trait, get_path_env_var, load_tool_plugin, DependencyManager, Tool}; use moon_utils::is_ci; -use proto_core::{ - Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version as SemVersion, -}; +use proto_core::{Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version}; use rustc_hash::FxHashMap; use starbase_utils::fs; use std::env; @@ -52,7 +50,7 @@ impl Tool for NpmTool { async fn setup( &mut self, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { let mut count = 0; let version = self.config.version.clone(); diff --git a/crates/node/tool/src/pnpm_tool.rs b/crates/node/tool/src/pnpm_tool.rs index e5d404fff0d..c8db76f009a 100644 --- a/crates/node/tool/src/pnpm_tool.rs +++ b/crates/node/tool/src/pnpm_tool.rs @@ -7,8 +7,7 @@ use moon_terminal::{print_checkpoint, Checkpoint}; use moon_tool::{async_trait, get_path_env_var, load_tool_plugin, DependencyManager, Tool}; use moon_utils::is_ci; use proto_core::{ - Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version as SemVersion, - VersionReq, + Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version, VersionReq, }; use rustc_hash::FxHashMap; use starbase_utils::fs; @@ -59,7 +58,7 @@ impl Tool for PnpmTool { async fn setup( &mut self, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { let mut count = 0; let version = self.config.version.clone(); diff --git a/crates/node/tool/src/yarn_tool.rs b/crates/node/tool/src/yarn_tool.rs index 1c661443a9b..f32779a68fe 100644 --- a/crates/node/tool/src/yarn_tool.rs +++ b/crates/node/tool/src/yarn_tool.rs @@ -8,9 +8,7 @@ use moon_tool::{ async_trait, get_path_env_var, load_tool_plugin, DependencyManager, Tool, ToolError, }; use moon_utils::{get_workspace_root, is_ci}; -use proto_core::{ - Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version as SemVersion, -}; +use proto_core::{Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version}; use rustc_hash::FxHashMap; use starbase_styles::color; use starbase_utils::fs; @@ -108,7 +106,7 @@ impl Tool for YarnTool { async fn setup( &mut self, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { let mut count = 0; let version = self.config.version.clone(); diff --git a/crates/rust/platform/src/rust_platform.rs b/crates/rust/platform/src/rust_platform.rs index 2c9655432c9..e19719004f4 100644 --- a/crates/rust/platform/src/rust_platform.rs +++ b/crates/rust/platform/src/rust_platform.rs @@ -23,7 +23,7 @@ use moon_task::Task; use moon_terminal::{print_checkpoint, Checkpoint}; use moon_tool::{Tool, ToolError, ToolManager}; use moon_utils::async_trait; -use proto_core::{ProtoEnvironment, Version as SemVersion}; +use proto_core::{ProtoEnvironment, Version}; use rustc_hash::FxHashMap; use starbase_styles::color; use starbase_utils::{fs, glob::GlobSet}; @@ -172,21 +172,21 @@ impl Platform for RustPlatform { } async fn setup_toolchain(&mut self) -> miette::Result<()> { - let version = match &self.config.version { + let req = match &self.config.version { Some(v) => RuntimeReq::Toolchain(VersionSpec::Version(v.to_owned())), None => RuntimeReq::Global, }; let mut last_versions = FxHashMap::default(); - if !self.toolchain.has(&version) { + if !self.toolchain.has(&req) { self.toolchain.register( - &version, - RustTool::new(&self.proto_env, &self.config, &version).await?, + &req, + RustTool::new(&self.proto_env, &self.config, &req).await?, ); } - self.toolchain.setup(&version, &mut last_versions).await?; + self.toolchain.setup(&req, &mut last_versions).await?; Ok(()) } @@ -203,7 +203,7 @@ impl Platform for RustPlatform { &mut self, _context: &ActionContext, runtime: &Runtime, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { let req = &runtime.requirement; diff --git a/crates/rust/tool/src/rust_tool.rs b/crates/rust/tool/src/rust_tool.rs index c8335fcafe1..76ffc7e7b73 100644 --- a/crates/rust/tool/src/rust_tool.rs +++ b/crates/rust/tool/src/rust_tool.rs @@ -4,9 +4,7 @@ use moon_platform_runtime2::RuntimeReq; use moon_process::Command; use moon_terminal::{print_checkpoint, Checkpoint}; use moon_tool::{async_trait, load_tool_plugin, Tool}; -use proto_core::{ - Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version as SemVersion, -}; +use proto_core::{Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version}; use rustc_hash::FxHashMap; use std::{ ffi::OsStr, @@ -72,7 +70,7 @@ impl Tool for RustTool { async fn setup( &mut self, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { let mut installed = 0; diff --git a/crates/system/platform/src/platform.rs b/crates/system/platform/src/platform.rs index a1a54082588..32ab5f91d35 100644 --- a/crates/system/platform/src/platform.rs +++ b/crates/system/platform/src/platform.rs @@ -3,7 +3,7 @@ use crate::tool::SystemToolStub; use moon_action_context::ActionContext; use moon_config::{HasherConfig, PlatformType, ProjectConfig}; use moon_hash::ContentHasher; -use moon_platform::{Platform, Runtime, Version}; +use moon_platform::{Platform, Runtime, RuntimeReq}; use moon_process::Command; use moon_project::Project; use moon_task::Task; @@ -23,7 +23,7 @@ impl Platform for SystemPlatform { } fn get_runtime_from_config(&self, _project_config: Option<&ProjectConfig>) -> Runtime { - Runtime::System + Runtime::system() } fn matches(&self, platform: &PlatformType, runtime: Option<&Runtime>) -> bool { @@ -32,7 +32,7 @@ impl Platform for SystemPlatform { } if let Some(runtime) = &runtime { - return matches!(runtime, Runtime::System); + return matches!(runtime.platform, PlatformType::System); } false @@ -48,7 +48,7 @@ impl Platform for SystemPlatform { Ok(Box::new(&self.tool)) } - fn get_tool_for_version(&self, _version: Version) -> miette::Result> { + fn get_tool_for_version(&self, _req: RuntimeReq) -> miette::Result> { Ok(Box::new(&self.tool)) } diff --git a/nextgen/platform-runtime/src/lib.rs b/nextgen/platform-runtime/src/lib.rs index 7c152458675..dcad36fafcd 100644 --- a/nextgen/platform-runtime/src/lib.rs +++ b/nextgen/platform-runtime/src/lib.rs @@ -1,4 +1,4 @@ -use moon_config::{PlatformType, Version, VersionSpec}; +pub use moon_config::{PlatformType, Version, VersionSpec}; use serde::Serialize; use std::fmt;