Skip to content

Commit

Permalink
Update node and system.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Sep 20, 2023
1 parent 7071c1f commit c2e6b2f
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/core/tool/src/manager.rs
Original file line number Diff line number Diff line change
@@ -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<T: Tool> {
Expand Down Expand Up @@ -50,7 +50,7 @@ impl<T: Tool> ToolManager<T> {
pub async fn setup(
&mut self,
req: &RuntimeReq,
last_versions: &mut FxHashMap<String, SemVersion>,
last_versions: &mut FxHashMap<String, Version>,
) -> miette::Result<u8> {
match self.cache.get_mut(&req) {
Some(cache) => Ok(cache.setup(last_versions).await?),
Expand Down
4 changes: 2 additions & 2 deletions crates/deno/platform/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -148,7 +148,7 @@ impl Platform for DenoPlatform {
&mut self,
_context: &ActionContext,
runtime: &Runtime,
last_versions: &mut FxHashMap<String, SemVersion>,
last_versions: &mut FxHashMap<String, Version>,
) -> miette::Result<u8> {
let req = &runtime.requirement;

Expand Down
62 changes: 32 additions & 30 deletions crates/node/platform/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
}
Expand All @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -251,8 +257,8 @@ impl Platform for NodePlatform {
Ok(Box::new(tool))
}

fn get_tool_for_version(&self, version: Version) -> miette::Result<Box<&dyn Tool>> {
let tool = self.toolchain.get_for_version(&version)?;
fn get_tool_for_version(&self, req: RuntimeReq) -> miette::Result<Box<&dyn Tool>> {
let tool = self.toolchain.get_for_version(&req)?;

Ok(Box::new(tool))
}
Expand All @@ -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(())
}
Expand All @@ -299,24 +305,20 @@ impl Platform for NodePlatform {
&mut self,
_context: &ActionContext,
runtime: &Runtime,
last_versions: &mut FxHashMap<String, SemVersion>,
last_versions: &mut FxHashMap<String, Version>,
) -> miette::Result<u8> {
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)
}
Expand All @@ -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?;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -422,7 +424,7 @@ impl Platform for NodePlatform {
) -> miette::Result<Command> {
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,
Expand Down
2 changes: 1 addition & 1 deletion crates/node/tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
14 changes: 6 additions & 8 deletions crates/node/tool/src/node_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -34,7 +32,7 @@ impl NodeTool {
pub async fn new(
proto: &ProtoEnvironment,
config: &NodeConfig,
version: &Version,
req: &RuntimeReq,
) -> miette::Result<NodeTool> {
let mut node = NodeTool {
global: false,
Expand All @@ -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 {
Expand Down Expand Up @@ -160,7 +158,7 @@ impl Tool for NodeTool {

async fn setup(
&mut self,
last_versions: &mut FxHashMap<String, SemVersion>,
last_versions: &mut FxHashMap<String, Version>,
) -> miette::Result<u8> {
let mut installed = 0;

Expand Down
6 changes: 2 additions & 4 deletions crates/node/tool/src/npm_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,7 +50,7 @@ impl Tool for NpmTool {

async fn setup(
&mut self,
last_versions: &mut FxHashMap<String, SemVersion>,
last_versions: &mut FxHashMap<String, Version>,
) -> miette::Result<u8> {
let mut count = 0;
let version = self.config.version.clone();
Expand Down
5 changes: 2 additions & 3 deletions crates/node/tool/src/pnpm_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,7 +58,7 @@ impl Tool for PnpmTool {

async fn setup(
&mut self,
last_versions: &mut FxHashMap<String, SemVersion>,
last_versions: &mut FxHashMap<String, Version>,
) -> miette::Result<u8> {
let mut count = 0;
let version = self.config.version.clone();
Expand Down
6 changes: 2 additions & 4 deletions crates/node/tool/src/yarn_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -108,7 +106,7 @@ impl Tool for YarnTool {

async fn setup(
&mut self,
last_versions: &mut FxHashMap<String, SemVersion>,
last_versions: &mut FxHashMap<String, Version>,
) -> miette::Result<u8> {
let mut count = 0;
let version = self.config.version.clone();
Expand Down
14 changes: 7 additions & 7 deletions crates/rust/platform/src/rust_platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(())
}
Expand All @@ -203,7 +203,7 @@ impl Platform for RustPlatform {
&mut self,
_context: &ActionContext,
runtime: &Runtime,
last_versions: &mut FxHashMap<String, SemVersion>,
last_versions: &mut FxHashMap<String, Version>,
) -> miette::Result<u8> {
let req = &runtime.requirement;

Expand Down
6 changes: 2 additions & 4 deletions crates/rust/tool/src/rust_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -72,7 +70,7 @@ impl Tool for RustTool {

async fn setup(
&mut self,
last_versions: &mut FxHashMap<String, SemVersion>,
last_versions: &mut FxHashMap<String, Version>,
) -> miette::Result<u8> {
let mut installed = 0;

Expand Down
Loading

0 comments on commit c2e6b2f

Please sign in to comment.