diff --git a/examples/basic/src/index.js b/examples/basic/src/index.js
index ef0f9de7..caee53bd 100644
--- a/examples/basic/src/index.js
+++ b/examples/basic/src/index.js
@@ -1 +1 @@
-document.body.innerHTML = '
Hello World!
'
\ No newline at end of file
+document.body.innerHTML = 'Hello World!
'
diff --git a/packages/mach/src/bench.rs b/packages/mach/src/bench.rs
index f39a168f..2072489a 100644
--- a/packages/mach/src/bench.rs
+++ b/packages/mach/src/bench.rs
@@ -1,8 +1,8 @@
#![allow(unused)]
pub mod cmd;
-pub mod kit;
pub mod core;
+pub mod kit;
pub mod plugins;
pub mod public;
pub mod rpc;
diff --git a/packages/mach/src/cmd/build/build.rs b/packages/mach/src/cmd/build/build.rs
index 84f74605..942db8ff 100644
--- a/packages/mach/src/cmd/build/build.rs
+++ b/packages/mach/src/cmd/build/build.rs
@@ -6,25 +6,10 @@ use serde::Deserialize;
use serde::Serialize;
use super::super::MachOptions;
-// use super::build_parse_config::parse_config;
-// use super::create_result::create_build_result;
-// use crate::platform::bundling::bundle;
use crate::core::plugins::load_plugins;
use crate::core::resolve_and_transform::resolve_and_transform;
-// use crate::public::AssetGraphSync;
-// use crate::public::AssetMap;
-// use crate::public::AssetMapSync;
-// use crate::public::BundleGraphSync;
-// use crate::public::BundleManifestSync;
-// use crate::public::BundleMapSync;
use crate::public::Compilation;
use crate::public::MachConfig;
-// use crate::public::DependencyMapSync;
-// use crate::rpc::Engine;
-// use crate::platform::emit::emit;
-// use crate::platform::packaging::package;
-// use crate::rpc::RpcHost;
-// use crate::public::OutputsSync;
#[derive(Debug)]
pub struct BuildOptions {
@@ -63,16 +48,13 @@ pub struct BuildResult {
pub fn build(
mach_options: MachOptions,
- options: BuildOptions,
+ _options: BuildOptions,
) -> anyhow::Result {
- // let config = parse_config(&options).map_err(|e| anyhow::anyhow!(e))?;
-
/*
- This is the bundler state. It is passed into
- the bundling phases with read or write access
+ This is the bundler state. It is passed into the bundling phases with read or write access
depending on how that phase uses them
*/
- let mut compilation = Compilation{
+ let mut compilation = Compilation {
machrc: mach_options.config,
rpc_hosts: mach_options.rpc_hosts,
config: MachConfig {
@@ -98,8 +80,7 @@ pub fn build(
It does this by crawling the source files, identify import statements, modifying their contents
(like removing TypeScript types) and looping until there are no more import statements to resolve.
*/
- resolve_and_transform(&mut compilation)
- .map_err(|e| anyhow::anyhow!(e))?;
+ resolve_and_transform(&mut compilation)?;
println!("{}", &compilation.asset_graph.into_dot(&compilation.config));
diff --git a/packages/mach/src/cmd/build/build_event.rs b/packages/mach/src/cmd/build/build_event.rs
deleted file mode 100644
index c7903666..00000000
--- a/packages/mach/src/cmd/build/build_event.rs
+++ /dev/null
@@ -1,50 +0,0 @@
-use std::time::SystemTime;
-
-#[derive(Clone, Debug)]
-pub enum BuildEvent {
- BuildStart {
- timestamp: SystemTime,
- },
- ConfigLoaded {
- timestamp: SystemTime,
- },
- InitializationComplete {
- timestamp: SystemTime,
- },
- TransformationComplete {
- timestamp: SystemTime,
- },
- BundlingComplete {
- timestamp: SystemTime,
- },
- PackagingComplete {
- timestamp: SystemTime,
- },
- BuildComplete {
- timestamp: SystemTime,
- },
-}
-
-impl BuildEvent {
- pub fn build_start() -> Self {
- Self::BuildStart { timestamp: SystemTime::now() }
- }
- pub fn config_loaded() -> Self {
- Self::ConfigLoaded { timestamp: SystemTime::now() }
- }
- pub fn initialization_complete() -> Self {
- Self::InitializationComplete { timestamp: SystemTime::now() }
- }
- pub fn transformation_complete() -> Self {
- Self::TransformationComplete { timestamp: SystemTime::now() }
- }
- pub fn bundling_complete() -> Self {
- Self::BundlingComplete { timestamp: SystemTime::now() }
- }
- pub fn packaging_complete() -> Self {
- Self::PackagingComplete { timestamp: SystemTime::now() }
- }
- pub fn build_complete() -> Self {
- Self::BuildComplete { timestamp: SystemTime::now() }
- }
-}
diff --git a/packages/mach/src/cmd/build/build_parse_config.rs b/packages/mach/src/cmd/build/build_parse_config.rs
deleted file mode 100644
index 4ba89fd0..00000000
--- a/packages/mach/src/cmd/build/build_parse_config.rs
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- TODO rewrite this
-*/
-use std::collections::HashMap;
-use std::env;
-use std::fs;
-use std::path::Path;
-use std::path::PathBuf;
-use std::sync::Arc;
-use std::time::SystemTime;
-
-use normalize_path::NormalizePath;
-
-use super::BuildOptions;
-use crate::public::MachConfig;
-use crate::public::MachConfigSync;
-use crate::public::Machrc;
-
-pub fn parse_config(command: &BuildOptions) -> Result {
- let start_time = SystemTime::now();
-
- // Auto detect project root
- let project_root = 'block: {
- if let Some(project_root) = &command.project_root {
- break 'block get_absolute_path(None, &project_root);
- };
- env::current_dir().unwrap()
- };
-
- return Ok(Arc::new(MachConfig {
- start_time,
- entries: command.entries.clone(),
- dist_dir: get_dist_dir(&command, &project_root),
- clean_dist_dir: command.clean,
- bundle_splitting: command.bundle_splitting,
- project_root: project_root.clone(),
- machrc: parse_machrc(project_root.join(".machrc"))?,
- // threads: get_threads(&command),
- optimize: command.optimize,
- env: get_env(),
- }));
-}
-
-fn get_dist_dir(
- options: &BuildOptions,
- project_root: &Path,
-) -> PathBuf {
- let dist_dir_arg = options.out_folder.clone();
- if dist_dir_arg.is_absolute() {
- dist_dir_arg
- } else {
- project_root.join(dist_dir_arg).normalize()
- }
-}
-
-fn get_env() -> HashMap {
- let mut vars = HashMap::::new();
- for (k, v) in std::env::vars() {
- vars.insert(k, v);
- }
- vars
-}
-
-// fn find_entry(project_root: &Path) -> Option {
-// for test in [
-// project_root.join("index.html"),
-// project_root.join("index.tsx"),
-// project_root.join("index.ts"),
-// project_root.join("index.jsx"),
-// project_root.join("index.js"),
-// project_root.join("src").join("index.html"),
-// project_root.join("src").join("index.tsx"),
-// project_root.join("src").join("index.ts"),
-// project_root.join("src").join("index.jsx"),
-// project_root.join("src").join("index.js"),
-// ] {
-// if test.exists() {
-// return Some(test);
-// }
-// }
-
-// return None;
-// }
-
-fn parse_machrc(file_path: PathBuf) -> Result {
- if !file_path.exists() {
- return Ok(Machrc::default());
- };
-
- let mut mach_config = Machrc {
- resolvers: None,
- transformers: None,
- };
-
- let Ok(json_file) = fs::read_to_string(&file_path) else {
- return Err("Unable to read file".to_string());
- };
-
- let Ok(json) = serde_json::from_str::(&json_file) else {
- return Err("Unable to parse json".to_string());
- };
-
- if let Some(resolvers_value) = json.get("resolvers") {
- let mut resolvers = Vec::::new();
- let Some(resolvers_values) = resolvers_value.as_array() else {
- return Err("'resolvers' should be array".to_string());
- };
- for resolver_value in resolvers_values {
- let Some(resolver_value) = resolver_value.as_str() else {
- return Err("'resolvers[n]' should be string".to_string());
- };
- resolvers.push(resolver_value.to_string());
- }
- mach_config.resolvers = Some(resolvers);
- };
-
- if let Some(transformers_value) = json.get("transformers") {
- let mut transformers = HashMap::>::new();
- let Some(transformers_value) = transformers_value.as_object() else {
- return Err("'transformers' should be object".to_string());
- };
- for (key, value) in transformers_value {
- let mut values = Vec::::new();
- let Some(value) = value.as_array() else {
- return Err("'transformers[key]' should be array".to_string());
- };
- for value in value {
- let Some(value) = value.as_str() else {
- return Err("'transformers[key][n]' should be string".to_string());
- };
- values.push(value.to_string());
- }
- transformers.insert(key.clone(), values);
- }
- mach_config.transformers = Some(transformers);
- }
-
- return Ok(mach_config);
-}
-
-fn _parse_json_file(target: &PathBuf) -> Result {
- let Ok(json_file) = fs::read_to_string(target) else {
- return Err("Unable to read file".to_string());
- };
- let Ok(json) = serde_json::from_str::(&json_file) else {
- return Err("Unable to parse json".to_string());
- };
- return Ok(json);
-}
-
-// fn parse_yaml_file(target: &PathBuf) -> Result {
-// let Ok(yaml_file) = fs::read_to_string(target) else {
-// return Err("Unable to read file".to_string());
-// };
-// let Ok(yaml) = serde_yaml::from_str::(&yaml_file) else {
-// return Err("Unable to parse json".to_string());
-// };
-// return Ok(yaml);
-// }
-
-// fn find_crawl_up(
-// start: &Path,
-// targets: &[&str],
-// ) -> Option<(PathBuf, PathBuf)> {
-// let mut current = start.to_path_buf();
-
-// loop {
-// for entry in fs::read_dir(¤t).unwrap() {
-// let Ok(entry) = entry else {
-// continue;
-// };
-// for target in targets {
-// if entry.file_name() == *target {
-// let complete = current.join(target);
-// return Some((current, complete));
-// }
-// }
-// }
-// if !current.pop() {
-// break;
-// }
-// }
-
-// None
-// }
-
-fn get_absolute_path(
- cwd: Option,
- target: &Path,
-) -> PathBuf {
- let file_path = target.to_path_buf();
-
- if file_path.is_absolute() {
- return file_path.normalize();
- }
-
- if let Some(cwd) = cwd {
- return cwd.join(target).normalize();
- }
-
- std::env::current_dir().unwrap().join(file_path).normalize()
-}
diff --git a/packages/mach/src/cmd/build/create_result.rs b/packages/mach/src/cmd/build/create_result.rs
deleted file mode 100644
index 6a231389..00000000
--- a/packages/mach/src/cmd/build/create_result.rs
+++ /dev/null
@@ -1,43 +0,0 @@
-// use std::collections::HashMap;
-
-// use crate::public::AssetMapSync;
-// use crate::public::BundleManifestSync;
-// use crate::public::BundleMapSync;
-// use crate::BuildResult;
-
-// pub fn create_build_result(
-// asset_map: AssetMapSync,
-// bundles: BundleMapSync,
-// bundle_manifest: BundleManifestSync,
-// ) -> BuildResult {
-// let asset_map = asset_map.read().unwrap();
-// let bundles = bundles.read().unwrap();
-// let bundle_manifest = bundle_manifest.read().unwrap();
-
-// let mut build_report = BuildResult {
-// bundle_manifest: HashMap::new(),
-// entries: HashMap::new(),
-// };
-
-// for (key, value) in bundle_manifest.iter() {
-// build_report
-// .bundle_manifest
-// .insert(key.clone(), value.clone());
-// }
-
-// for (_bundle_id, bundle) in bundles.iter() {
-// let Some(asset_id) = &bundle.entry_asset else {
-// continue;
-// };
-// let Some(asset) = asset_map.get(asset_id) else {
-// continue;
-// };
-// let asset_file_path = asset.file_path_relative.to_str().unwrap().to_string();
-
-// build_report
-// .entries
-// .insert(asset_file_path, bundle.name.clone());
-// }
-
-// return build_report;
-// }
diff --git a/packages/mach/src/cmd/build/mod.rs b/packages/mach/src/cmd/build/mod.rs
index 5eb1fed2..50941db2 100644
--- a/packages/mach/src/cmd/build/mod.rs
+++ b/packages/mach/src/cmd/build/mod.rs
@@ -1,6 +1,3 @@
mod build;
-// mod build_parse_config;
-mod create_result;
-// mod build_event;
pub use self::build::*;
diff --git a/packages/mach/src/cmd/mach.rs b/packages/mach/src/cmd/mach.rs
index bb08f8ac..9ecd65e7 100644
--- a/packages/mach/src/cmd/mach.rs
+++ b/packages/mach/src/cmd/mach.rs
@@ -1,6 +1,8 @@
-use std::{collections::HashMap, path::PathBuf};
+use std::collections::HashMap;
+use std::path::PathBuf;
-use crate::{public::Machrc, rpc::RpcHosts};
+use crate::public::Machrc;
+use crate::rpc::RpcHosts;
#[derive(Clone, Debug)]
pub struct MachOptions {
@@ -22,7 +24,45 @@ impl Default for MachOptions {
config: Default::default(),
env: Default::default(),
out_folder: Default::default(),
- project_root: Default::default(),
+ project_root: Default::default(),
}
}
}
+
+pub struct Mach {
+ options: MachOptions,
+}
+
+impl Mach {
+ pub fn new(options: MachOptions) -> Self {
+ Self { options }
+ }
+
+ pub fn build(
+ &self,
+ options: super::BuildOptions,
+ ) -> anyhow::Result {
+ super::build(self.options.clone(), options)
+ }
+
+ pub fn watch(
+ &self,
+ options: super::WatchOptions,
+ ) -> Result {
+ super::watch(options)
+ }
+
+ pub fn dev(
+ &self,
+ options: super::DevOptions,
+ ) -> Result {
+ super::dev(options)
+ }
+
+ pub fn version(
+ &self,
+ options: super::VersionOptions,
+ ) -> super::VersionResult {
+ super::version(options)
+ }
+}
diff --git a/packages/mach/src/core/mod.rs b/packages/mach/src/core/mod.rs
index b2b41f14..bf523596 100644
--- a/packages/mach/src/core/mod.rs
+++ b/packages/mach/src/core/mod.rs
@@ -3,5 +3,5 @@ pub mod config;
// pub mod emit;
// pub mod packaging;
pub mod plugins;
-pub mod resolve_and_transform;
pub mod request_tracker;
+pub mod resolve_and_transform;
diff --git a/packages/mach/src/core/plugins/load_plugins.rs b/packages/mach/src/core/plugins/load_plugins.rs
index b3a19ba5..7b063c3d 100644
--- a/packages/mach/src/core/plugins/load_plugins.rs
+++ b/packages/mach/src/core/plugins/load_plugins.rs
@@ -13,15 +13,15 @@ use crate::plugins::transformer_rpc::TransformerAdapter;
use crate::public::Compilation;
use crate::public::Transformer;
-pub fn load_plugins(
- c: &mut Compilation,
-) -> anyhow::Result<()> {
+pub fn load_plugins(c: &mut Compilation) -> anyhow::Result<()> {
if let Some(resolvers) = &c.machrc.resolvers {
for plugin_string in resolvers {
match plugin_string.as_str() {
// Built-in
"mach:resolver" => {
- c.plugins.resolvers.push(Arc::new(ResolverJavaScript::new()));
+ c.plugins
+ .resolvers
+ .push(Arc::new(ResolverJavaScript::new()));
continue;
}
// External
@@ -32,14 +32,14 @@ pub fn load_plugins(
plugin_string
)));
};
-
+
let Some(adapter) = c.rpc_hosts.get(engine) else {
return Err(anyhow::anyhow!(format!(
"No plugin runtime for engine: {}\nCannot load plugin: {}",
engine, specifier
)));
};
-
+
c.plugins.resolvers.push(Arc::new(ResolverAdapter::new(
&c.config,
specifier,
@@ -108,6 +108,6 @@ pub fn load_plugins(
.insert(pattern.clone(), transformers);
}
}
-
+
return Ok(());
}
diff --git a/packages/mach/src/core/request_tracker/request.rs b/packages/mach/src/core/request_tracker/request.rs
index a6c4e91a..9f87853f 100644
--- a/packages/mach/src/core/request_tracker/request.rs
+++ b/packages/mach/src/core/request_tracker/request.rs
@@ -23,7 +23,10 @@ impl<'a, T: Clone> RunRequestContext<'a, T> {
}
}
- pub fn run_request(&mut self, request: &dyn Request) -> anyhow::Result {
+ pub fn run_request(
+ &mut self,
+ request: &dyn Request,
+ ) -> anyhow::Result {
self
.request_tracker
.run_child_request(request, self.parent_request_hash)
@@ -40,8 +43,10 @@ pub trait Request: DynHash {
hasher.finish()
}
- fn run(&self, request_context: RunRequestContext)
- -> Result, RunRequestError>;
+ fn run(
+ &self,
+ request_context: RunRequestContext,
+ ) -> Result, RunRequestError>;
}
dyn_hash::hash_trait_object!( Request);
diff --git a/packages/mach/src/core/request_tracker/request_tracker.rs b/packages/mach/src/core/request_tracker/request_tracker.rs
index 80c6b969..4ea1c9ee 100644
--- a/packages/mach/src/core/request_tracker/request_tracker.rs
+++ b/packages/mach/src/core/request_tracker/request_tracker.rs
@@ -1,6 +1,6 @@
-use anyhow::anyhow;
use std::collections::HashMap;
+use anyhow::anyhow;
use petgraph::graph::NodeIndex;
use petgraph::stable_graph::StableDiGraph;
@@ -27,7 +27,10 @@ impl RequestTracker {
}
}
- pub fn run_request(&mut self, request: &dyn Request) -> anyhow::Result {
+ pub fn run_request(
+ &mut self,
+ request: &dyn Request,
+ ) -> anyhow::Result {
self.run_child_request(request, None)
}
@@ -46,7 +49,10 @@ impl RequestTracker {
Ok(self.get_request(parent_request_hash, &request_id)?)
}
- fn prepare_request(&mut self, request_id: u64) -> anyhow::Result {
+ fn prepare_request(
+ &mut self,
+ request_id: u64,
+ ) -> anyhow::Result {
let node_index = self
.request_index
.entry(request_id)
diff --git a/packages/mach/src/core/request_tracker/test.rs b/packages/mach/src/core/request_tracker/test.rs
index 5e5d2830..588fdaf7 100644
--- a/packages/mach/src/core/request_tracker/test.rs
+++ b/packages/mach/src/core/request_tracker/test.rs
@@ -87,14 +87,20 @@ pub struct TestRequest<'a> {
}
impl<'a> std::fmt::Debug for TestRequest<'a> {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ fn fmt(
+ &self,
+ f: &mut std::fmt::Formatter<'_>,
+ ) -> std::fmt::Result {
f.debug_struct(&format!("TestRequest({})", self.name))
.finish()
}
}
impl<'a> TestRequest<'a> {
- pub fn new>(name: T, sub_requests: &[&'a TestRequest<'a>]) -> Self {
+ pub fn new>(
+ name: T,
+ sub_requests: &[&'a TestRequest<'a>],
+ ) -> Self {
Self {
runs: Default::default(),
name: name.as_ref().to_string(),
@@ -108,7 +114,10 @@ impl<'a> TestRequest<'a> {
}
impl<'a> std::hash::Hash for TestRequest<'a> {
- fn hash(&self, state: &mut H) {
+ fn hash(
+ &self,
+ state: &mut H,
+ ) {
self.name.hash(state);
}
}
diff --git a/packages/mach/src/core/resolve_and_transform/mod.rs b/packages/mach/src/core/resolve_and_transform/mod.rs
index 5a6a95be..d91a2225 100644
--- a/packages/mach/src/core/resolve_and_transform/mod.rs
+++ b/packages/mach/src/core/resolve_and_transform/mod.rs
@@ -1,5 +1,7 @@
mod resolve_and_transform;
mod run_resolvers;
mod run_transformers;
+#[cfg(test)]
+mod testing;
pub use self::resolve_and_transform::*;
diff --git a/packages/mach/src/core/resolve_and_transform/resolve_and_transform.rs b/packages/mach/src/core/resolve_and_transform/resolve_and_transform.rs
index 106d8e55..79dea683 100644
--- a/packages/mach/src/core/resolve_and_transform/resolve_and_transform.rs
+++ b/packages/mach/src/core/resolve_and_transform/resolve_and_transform.rs
@@ -3,7 +3,6 @@ use std::path::PathBuf;
use super::run_resolvers::run_resolvers;
use crate::core::config::ROOT_ASSET;
-use crate::core::plugins::PluginContainerSync;
use crate::core::resolve_and_transform::run_transformers::run_transformers;
use crate::public::Asset;
use crate::public::AssetId;
@@ -11,11 +10,8 @@ use crate::public::Compilation;
use crate::public::Dependency;
use crate::public::DependencyId;
use crate::public::LinkingSymbol;
-use crate::public::MachConfigSync;
-pub fn resolve_and_transform(
- c: &mut Compilation,
-) -> anyhow::Result<()> {
+pub fn resolve_and_transform(c: &mut Compilation) -> anyhow::Result<()> {
let mut queue = vec![];
c.asset_graph.add_asset(ROOT_ASSET.clone());
@@ -60,8 +56,7 @@ pub fn resolve_and_transform(
};
completed_assets.insert(resolve_result.file_path.clone(), new_asset_id.clone());
- let mut asset_dependencies =
- run_transformers(&c, &mut new_asset, &resolve_result)?;
+ let mut asset_dependencies = run_transformers(&c, &mut new_asset, &resolve_result)?;
while let Some(dependency_options) = asset_dependencies.pop() {
let new_dependency = Dependency {
diff --git a/packages/mach/src/core/resolve_and_transform/run_resolvers.rs b/packages/mach/src/core/resolve_and_transform/run_resolvers.rs
index 7d7b7171..b286eab0 100644
--- a/packages/mach/src/core/resolve_and_transform/run_resolvers.rs
+++ b/packages/mach/src/core/resolve_and_transform/run_resolvers.rs
@@ -1,9 +1,7 @@
use std::path::PathBuf;
-use crate::core::plugins::PluginContainerSync;
use crate::public::Compilation;
use crate::public::Dependency;
-use crate::public::MachConfig;
#[derive(Debug)]
pub struct RunResolversResult {
diff --git a/packages/mach/src/core/resolve_and_transform/run_transformers.rs b/packages/mach/src/core/resolve_and_transform/run_transformers.rs
index 88f5723f..fdf0c831 100644
--- a/packages/mach/src/core/resolve_and_transform/run_transformers.rs
+++ b/packages/mach/src/core/resolve_and_transform/run_transformers.rs
@@ -1,13 +1,11 @@
use std::fs;
use super::run_resolvers::RunResolversResult;
-use crate::core::plugins::PluginContainerSync;
use crate::core::plugins::TransformerTarget;
use crate::public::Asset;
use crate::public::Compilation;
use crate::public::DependencyOptions;
use crate::public::LinkingSymbol;
-use crate::public::MachConfig;
use crate::public::MutableAsset;
pub fn run_transformers(
diff --git a/packages/mach/src/core/resolve_and_transform/testing/mod.rs b/packages/mach/src/core/resolve_and_transform/testing/mod.rs
index b7710d86..61b6ebea 100644
--- a/packages/mach/src/core/resolve_and_transform/testing/mod.rs
+++ b/packages/mach/src/core/resolve_and_transform/testing/mod.rs
@@ -1,5 +1,5 @@
// mod bench;
-// mod snapshot;
-// mod test;
-// mod test_update;
-// mod utils;
+mod snapshot;
+mod test;
+mod test_update;
+mod utils;
diff --git a/packages/mach/src/core/resolve_and_transform/testing/snapshot.rs b/packages/mach/src/core/resolve_and_transform/testing/snapshot.rs
index 0107b397..8db8fea3 100644
--- a/packages/mach/src/core/resolve_and_transform/testing/snapshot.rs
+++ b/packages/mach/src/core/resolve_and_transform/testing/snapshot.rs
@@ -8,9 +8,9 @@ use petgraph::visit::NodeRef;
use serde::Deserialize;
use serde::Serialize;
-use crate::core::transformation::build_asset_graph;
-use crate::core::transformation::testing::utils::setup_root;
-use crate::core::transformation::testing::utils::SNAPSHOT_FILENAME;
+use super::utils::setup_root;
+use super::utils::SNAPSHOT_FILENAME;
+use crate::core::resolve_and_transform::resolve_and_transform;
use crate::public::BundleBehavior;
use crate::public::DependencyPriority;
use crate::public::LinkingSymbol;
@@ -75,9 +75,9 @@ impl GraphSnapshot {
pub fn _generate_project_snapshot(project_root: &Path) {
let snapshot_path = project_root.join(SNAPSHOT_FILENAME);
- let (mach_config, plugins, mut c) = setup_root(&project_root, &["./index.js"]);
+ let mut c = setup_root(&project_root, &["./index.js"]);
- if let Err(msg) = build_asset_graph(mach_config.clone(), plugins, &mut c) {
+ if let Err(msg) = resolve_and_transform(&mut c) {
println!("{msg}");
panic!()
};
diff --git a/packages/mach/src/core/resolve_and_transform/testing/utils.rs b/packages/mach/src/core/resolve_and_transform/testing/utils.rs
index 95d18997..e66dd9d1 100644
--- a/packages/mach/src/core/resolve_and_transform/testing/utils.rs
+++ b/packages/mach/src/core/resolve_and_transform/testing/utils.rs
@@ -1,20 +1,15 @@
use std::path::Path;
use std::path::PathBuf;
-use std::sync::Arc;
use once_cell::sync::Lazy;
use petgraph::visit::EdgeRef;
use petgraph::visit::NodeRef;
-use super::super::build_asset_graph;
+use super::super::resolve_and_transform;
use super::snapshot::GraphSnapshot;
use crate::core::plugins::load_plugins;
-use crate::core::plugins::PluginContainerSync;
use crate::public::Compilation;
use crate::public::MachConfig;
-use crate::public::MachConfigSync;
-use crate::public::Machrc;
-use crate::rpc::RpcHosts;
pub static SNAPSHOT_FILENAME: &str = "__graph.json";
pub static CARGO_DIR: Lazy = Lazy::new(|| PathBuf::from(env!("CARGO_MANIFEST_DIR")));
@@ -30,19 +25,28 @@ pub static FIXTURES: Lazy = Lazy::new(|| {
pub fn setup_root>(
project_root: &Path,
entries: &[T],
-) -> (MachConfigSync, PluginContainerSync, Compilation) {
- let mach_config = Arc::new(MachConfig {
- entries: entries
- .iter()
- .map(|e| e.as_ref().to_string())
- .collect::>(),
- project_root: project_root.to_owned(),
- ..Default::default()
- });
-
- let plugins = load_plugins(&mach_config, &Machrc::default(), &RpcHosts::new()).unwrap();
- let compilation = Compilation::new();
- (mach_config, plugins, compilation)
+) -> Compilation {
+ let mut compilation = Compilation {
+ machrc: Default::default(),
+ rpc_hosts: Default::default(),
+ config: MachConfig {
+ entries: entries
+ .iter()
+ .map(|e| PathBuf::from(e.as_ref().to_string()))
+ .collect::>(),
+ project_root: project_root.to_owned(),
+ threads: 1,
+ env: Default::default(),
+ out_folder: Default::default(),
+ },
+ asset_contents: Default::default(),
+ asset_graph: Default::default(),
+ plugins: Default::default(),
+ };
+
+ load_plugins(&mut compilation).unwrap();
+
+ compilation
}
pub fn test_project_snapshot(
@@ -56,9 +60,9 @@ pub fn test_project_snapshot(
let snapshot = GraphSnapshot::load(&snapshot_path);
- let (mach_config, plugins, mut c) = setup_root(&project_root, &snapshot.get_entries());
+ let mut c = setup_root(&project_root, &snapshot.get_entries());
- if let Err(msg) = build_asset_graph(mach_config.clone(), plugins, &mut c) {
+ if let Err(msg) = resolve_and_transform(&mut c) {
println!("{msg}");
panic!()
};
diff --git a/packages/mach/src/lib.rs b/packages/mach/src/lib.rs
index 7e462fbe..949b9335 100644
--- a/packages/mach/src/lib.rs
+++ b/packages/mach/src/lib.rs
@@ -2,8 +2,8 @@
#[cfg(feature = "cli_parser")]
pub mod cli;
pub mod cmd;
-pub mod kit;
pub mod core;
+pub mod kit;
pub mod plugins;
pub mod public;
pub mod rpc;
@@ -15,46 +15,9 @@ pub use self::cmd::BuildOptions;
pub use self::cmd::BuildResult;
pub use self::cmd::DevOptions;
pub use self::cmd::DevResult;
+pub use self::cmd::Mach;
pub use self::cmd::MachOptions;
pub use self::cmd::VersionOptions;
pub use self::cmd::VersionResult;
pub use self::cmd::WatchOptions;
pub use self::cmd::WatchResult;
-
-pub struct Mach {
- options: cmd::MachOptions,
-}
-
-impl Mach {
- pub fn new(options: cmd::MachOptions) -> Self {
- Self { options }
- }
-
- pub fn build(
- &self,
- options: cmd::BuildOptions,
- ) -> anyhow::Result {
- cmd::build(self.options.clone(), options)
- }
-
- pub fn watch(
- &self,
- options: cmd::WatchOptions,
- ) -> Result {
- cmd::watch(options)
- }
-
- pub fn dev(
- &self,
- options: cmd::DevOptions,
- ) -> Result {
- cmd::dev(options)
- }
-
- pub fn version(
- &self,
- options: cmd::VersionOptions,
- ) -> cmd::VersionResult {
- cmd::version(options)
- }
-}
diff --git a/packages/mach/src/plugins/mod.rs b/packages/mach/src/plugins/mod.rs
index f69dd3c7..043dfa79 100644
--- a/packages/mach/src/plugins/mod.rs
+++ b/packages/mach/src/plugins/mod.rs
@@ -19,4 +19,4 @@ pub enum Transformer {
Drop(transformer_drop::TransformerDrop),
JSON(transformer_json::TransformerJson),
RPC(transformer_rpc::TransformerAdapter),
-}
\ No newline at end of file
+}
diff --git a/packages/mach/src/plugins/resolver_javascript/resolver.rs b/packages/mach/src/plugins/resolver_javascript/resolver.rs
index edcc6740..3f4964df 100644
--- a/packages/mach/src/plugins/resolver_javascript/resolver.rs
+++ b/packages/mach/src/plugins/resolver_javascript/resolver.rs
@@ -11,9 +11,12 @@ pub struct ResolverJavaScript {
}
impl std::fmt::Debug for ResolverJavaScript {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "ResolverJavaScript")
- }
+ fn fmt(
+ &self,
+ f: &mut std::fmt::Formatter<'_>,
+ ) -> std::fmt::Result {
+ write!(f, "ResolverJavaScript")
+ }
}
impl ResolverJavaScript {
diff --git a/packages/mach/src/public/compilation.rs b/packages/mach/src/public/compilation.rs
index af3154ef..73f3744a 100644
--- a/packages/mach/src/public/compilation.rs
+++ b/packages/mach/src/public/compilation.rs
@@ -1,11 +1,9 @@
-
-use crate::core::plugins::PluginContainer;
-use crate::rpc::RpcHosts;
-
use super::AssetContents;
use super::AssetGraph;
use super::MachConfig;
use super::Machrc;
+use crate::core::plugins::PluginContainer;
+use crate::rpc::RpcHosts;
#[derive(Clone, Debug)]
pub struct Compilation {
diff --git a/packages/mach_npm/bin.js b/packages/mach_npm/bin.js
index 5066bdc3..848fd396 100755
--- a/packages/mach_npm/bin.js
+++ b/packages/mach_npm/bin.js
@@ -1,2 +1,2 @@
#!/usr/bin/env node
-await import("#bin")
+await import('#bin')
diff --git a/packages/mach_npm/cmd/worker.ts b/packages/mach_npm/cmd/worker.ts
index e06a157e..a303b348 100644
--- a/packages/mach_npm/cmd/worker.ts
+++ b/packages/mach_npm/cmd/worker.ts
@@ -1 +1 @@
-console.log('Hello from worker ts')
\ No newline at end of file
+console.log('Hello from worker ts')
diff --git a/packages/mach_npm/platform/mach/index.ts b/packages/mach_npm/platform/mach/index.ts
index 34c72d0b..0e6616d9 100644
--- a/packages/mach_npm/platform/mach/index.ts
+++ b/packages/mach_npm/platform/mach/index.ts
@@ -1,2 +1,2 @@
export * from './mach.js'
-export * from './worker.js'
\ No newline at end of file
+export * from './worker.js'
diff --git a/packages/mach_npm/platform/mach/worker.ts b/packages/mach_npm/platform/mach/worker.ts
index bb0842c2..cd90a9a3 100644
--- a/packages/mach_npm/platform/mach/worker.ts
+++ b/packages/mach_npm/platform/mach/worker.ts
@@ -3,9 +3,12 @@ import { Worker } from 'node:worker_threads'
export class MachWorker extends Worker {
constructor() {
- let workerPath = url.fileURLToPath(import.meta.resolve('#worker'));
+ let workerPath = url.fileURLToPath(import.meta.resolve('#worker'))
if (workerPath.endsWith('.ts')) {
- super(`import('tsx/esm/api').then(({ register }) => { register(); import('${workerPath}') })`, { eval: true })
+ super(
+ `import('tsx/esm/api').then(({ register }) => { register(); import('${workerPath}') })`,
+ { eval: true },
+ )
} else {
super(workerPath)
}
diff --git a/packages/mach_npm/platform/native/index.cjs b/packages/mach_npm/platform/native/index.cjs
index f2648fea..c91b4325 100644
--- a/packages/mach_npm/platform/native/index.cjs
+++ b/packages/mach_npm/platform/native/index.cjs
@@ -1,15 +1,19 @@
// This file selects the correct binary npm package based on the current OS/ARCH
// It falls back to the local version if not found otherwise errors
-const OS = process.env.MACH_OS || {
- win32: 'windows',
- darwin: 'macos',
- linux: 'linux',
-}[process.platform]
+const OS =
+ process.env.MACH_OS ||
+ {
+ win32: 'windows',
+ darwin: 'macos',
+ linux: 'linux',
+ }[process.platform]
-const ARCH = process.env.MACH_ARCH || {
- arm64: 'arm64',
- x64: 'amd64',
-}[process.arch]
+const ARCH =
+ process.env.MACH_ARCH ||
+ {
+ arm64: 'arm64',
+ x64: 'amd64',
+ }[process.arch]
try {
module.exports = require(`@alshdavid/mach-${OS}-${ARCH}`)
@@ -21,8 +25,10 @@ try {
const package_json = JSON.parse(fs.readFileSync(package_json_path, 'utf8'))
if (package_json.version !== '0.0.0-local') {
- throw new Error('Could not find Mach binary for your system. Please compile from source')
+ throw new Error(
+ 'Could not find Mach binary for your system. Please compile from source',
+ )
}
module.exports = require('@alshdavid/mach-os-arch')
-}
\ No newline at end of file
+}
diff --git a/packages/mach_npm_bin/index.d.ts b/packages/mach_npm_bin/index.d.ts
index f4fce273..51a91fc4 100644
--- a/packages/mach_npm_bin/index.d.ts
+++ b/packages/mach_npm_bin/index.d.ts
@@ -37,5 +37,3 @@ export function machNapiBuild(
// Worker.new()
export function machWorkerNew(): any
-
-
diff --git a/packages/mach_npm_bin/src/exec.rs b/packages/mach_npm_bin/src/exec.rs
index 6a080efd..599da9cf 100644
--- a/packages/mach_npm_bin/src/exec.rs
+++ b/packages/mach_npm_bin/src/exec.rs
@@ -23,7 +23,7 @@ pub fn exec(args: Vec) -> napi::Result<()> {
Err(error) => {
eprintln!("{}", error);
return Err(());
- },
+ }
};
let mach = Mach::new(MachOptions::default());
diff --git a/packages/mach_npm_bin/src/lib.rs b/packages/mach_npm_bin/src/lib.rs
index 4f58fc03..d31f808d 100644
--- a/packages/mach_npm_bin/src/lib.rs
+++ b/packages/mach_npm_bin/src/lib.rs
@@ -1,4 +1,4 @@
-mod ext;
pub mod exec;
+mod ext;
pub mod mach;
pub mod worker;
diff --git a/packages/mach_npm_bin/src/mach.rs b/packages/mach_npm_bin/src/mach.rs
index 147a7e0f..05ec30dd 100644
--- a/packages/mach_npm_bin/src/mach.rs
+++ b/packages/mach_npm_bin/src/mach.rs
@@ -58,7 +58,7 @@ pub fn mach_napi_new(
let value = JsString::from_unknown(value)?;
let value = PathBuf::from(value.into_utf8()?.as_str()?.to_string());
vec![value]
- },
+ }
Ok(ValueType::Object) => {
let value = JsObject::from_unknown(value)?;
let mut output = vec![];
@@ -68,8 +68,8 @@ pub fn mach_napi_new(
output.push(element)
}
output
- },
- _ => Default::default()
+ }
+ _ => Default::default(),
}
},
env: 'block: {
@@ -84,7 +84,12 @@ pub fn mach_napi_new(
};
env.from_js_value(value)?
},
- project_root: PathBuf::from(options.get_named_property::("projectRoot")?.into_utf8()?.as_str()?),
+ project_root: PathBuf::from(
+ options
+ .get_named_property::("projectRoot")?
+ .into_utf8()?
+ .as_str()?,
+ ),
config: Default::default(),
};