diff --git a/Cargo.lock b/Cargo.lock index 7cee696f3a8..416029e897e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1695,6 +1695,7 @@ dependencies = [ "parcel-js-swc-core", "parcel-macros", "parcel-resolver", + "parcel_core", "parcel_filesystem", "parcel_napi_helpers", "rayon", @@ -1729,6 +1730,24 @@ dependencies = [ "xxhash-rust", ] +[[package]] +name = "parcel_core" +version = "0.1.0" +dependencies = [ + "anyhow", + "glob", + "mockall", + "napi", + "napi-derive", + "parcel-resolver", + "parcel_filesystem", + "parcel_napi_helpers", + "serde", + "serde_json", + "toml", + "xxhash-rust", +] + [[package]] name = "parcel_filesystem" version = "0.1.0" @@ -2493,9 +2512,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.198" +version = "1.0.200" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +checksum = "ddc6f9cc94d67c0e21aaf7eda3a010fd3af78ebf6e096aa6e2e13c79749cce4f" dependencies = [ "serde_derive", ] @@ -2511,9 +2530,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.198" +version = "1.0.200" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +checksum = "856f046b9400cee3c8c94ed572ecdb752444c24528c035cd35882aad6f492bcb" dependencies = [ "proc-macro2", "quote", diff --git a/crates/node-bindings/Cargo.toml b/crates/node-bindings/Cargo.toml index dc412fd787a..547185b1813 100644 --- a/crates/node-bindings/Cargo.toml +++ b/crates/node-bindings/Cargo.toml @@ -18,6 +18,7 @@ napi-derive = "2.16.3" parcel-js-swc-core = { path = "../../packages/transformers/js/core" } parcel-resolver = { path = "../../packages/utils/node-resolver-rs" } parcel_filesystem = { path = "../parcel_filesystem" } +parcel_core = { path = "../parcel_core" } parcel_napi_helpers = { path = "../parcel_napi_helpers" } dashmap = "5.4.0" xxhash-rust = { version = "0.8.2", features = ["xxh3"] } diff --git a/crates/node-bindings/src/core/js_requests/config_request/mod.rs b/crates/node-bindings/src/core/js_requests/config_request/mod.rs index 669f2e4b053..1c924186e43 100644 --- a/crates/node-bindings/src/core/js_requests/config_request/mod.rs +++ b/crates/node-bindings/src/core/js_requests/config_request/mod.rs @@ -4,11 +4,12 @@ use napi::Env; use napi::JsObject; use napi_derive::napi; +use parcel_core::requests::config_request::run_config_request; +use parcel_core::requests::config_request::ConfigRequest; +use parcel_core::requests::request_api::js_request_api::JSRequestApi; + use crate::core::js_requests::request_options::input_fs_from_options; use crate::core::js_requests::request_options::project_root_from_options; -use crate::core::requests::config_request::run_config_request; -use crate::core::requests::config_request::ConfigRequest; -use crate::core::requests::request_api::js_request_api::JSRequestApi; /// JavaScript API for running a config request. /// At the moment the request fields themselves will be copied on call. diff --git a/crates/node-bindings/src/core/js_requests/entry_request/mod.rs b/crates/node-bindings/src/core/js_requests/entry_request/mod.rs index ef1b5c152e6..3f65987fcde 100644 --- a/crates/node-bindings/src/core/js_requests/entry_request/mod.rs +++ b/crates/node-bindings/src/core/js_requests/entry_request/mod.rs @@ -3,14 +3,15 @@ use std::rc::Rc; use napi::Env; use napi::JsObject; use napi_derive::napi; + +use parcel_core::requests::entry_request::run_entry_request; +use parcel_core::requests::entry_request::EntryRequestInput; +use parcel_core::requests::entry_request::EntryResult; +use parcel_core::requests::entry_request::RunEntryRequestParams; +use parcel_core::requests::request_api::js_request_api::JSRequestApi; use parcel_napi_helpers::anyhow_napi; use crate::core::js_requests::request_options::input_fs_from_options; -use crate::core::requests::entry_request::run_entry_request; -use crate::core::requests::entry_request::EntryRequestInput; -use crate::core::requests::entry_request::EntryResult; -use crate::core::requests::entry_request::RunEntryRequestParams; -use crate::core::requests::request_api::js_request_api::JSRequestApi; /// napi entry-point for `run_entry_request`. #[napi] diff --git a/crates/node-bindings/src/core/js_requests/mod.rs b/crates/node-bindings/src/core/js_requests/mod.rs index dd6c18d9314..8aca9777939 100644 --- a/crates/node-bindings/src/core/js_requests/mod.rs +++ b/crates/node-bindings/src/core/js_requests/mod.rs @@ -1,3 +1,3 @@ pub mod config_request; pub mod entry_request; -mod request_options; +pub mod request_options; diff --git a/crates/node-bindings/src/core/mod.rs b/crates/node-bindings/src/core/mod.rs index 74a9650e47f..e38157de5d1 100644 --- a/crates/node-bindings/src/core/mod.rs +++ b/crates/node-bindings/src/core/mod.rs @@ -1,8 +1,2 @@ -//! Core re-implementation in Rust - -/// napi versions of `crate::core::requests` -mod js_requests; -/// New-type for paths relative to a project-root -mod project_path; -/// Request types and run functions -mod requests; +//! JavaScript API for `parcel_core::requests` +pub mod js_requests; diff --git a/crates/node-bindings/src/lib.rs b/crates/node-bindings/src/lib.rs index b494592d7e0..cf3769faf65 100644 --- a/crates/node-bindings/src/lib.rs +++ b/crates/node-bindings/src/lib.rs @@ -1,12 +1,12 @@ #![allow(dead_code)] -mod init_sentry; - #[cfg(target_arch = "wasm32")] use std::alloc::alloc; #[cfg(target_arch = "wasm32")] use std::alloc::Layout; +mod init_sentry; + #[cfg(target_os = "macos")] #[global_allocator] static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc; @@ -15,7 +15,8 @@ static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc; #[global_allocator] static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; -mod core; +/// napi versions of `crate::core::requests` +pub mod core; #[cfg(not(target_arch = "wasm32"))] mod fs_search; mod hash; diff --git a/crates/parcel_core/Cargo.toml b/crates/parcel_core/Cargo.toml new file mode 100644 index 00000000000..ad815fd0c45 --- /dev/null +++ b/crates/parcel_core/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "parcel_core" +version = "0.1.0" +edition = "2021" +description = "Core logic for the parcel bundler" + +[features] +default = [] +napi_noop = ["napi-derive/noop"] + +[dependencies] +parcel_filesystem = { path = "../parcel_filesystem" } +parcel_napi_helpers = { path = "../parcel_napi_helpers" } +parcel-resolver = { path = "../../packages/utils/node-resolver-rs" } + +anyhow = "1.0.82" +glob = "0.3.1" +mockall = "0.12.1" +napi = "2.16.4" +napi-derive = { version = "2.16.3" } +serde = "1.0.200" +serde_json = "1.0.116" +toml = "0.8.12" +xxhash-rust = { version = "0.8.2", features = ["xxh3"] } \ No newline at end of file diff --git a/crates/parcel_core/src/hash.rs b/crates/parcel_core/src/hash.rs new file mode 100644 index 00000000000..c230c10dafe --- /dev/null +++ b/crates/parcel_core/src/hash.rs @@ -0,0 +1,8 @@ +use xxhash_rust::xxh3::xxh3_64; + +/// Copy of one of the `node-bindings/src/hash.rs` functions. +pub fn hash_string(s: String) -> String { + let s = s.as_bytes(); + let res = xxh3_64(s); + format!("{:016x}", res) +} diff --git a/crates/parcel_core/src/lib.rs b/crates/parcel_core/src/lib.rs new file mode 100644 index 00000000000..b32f41ff0cc --- /dev/null +++ b/crates/parcel_core/src/lib.rs @@ -0,0 +1,7 @@ +//! Core re-implementation in Rust + +pub mod hash; +/// New-type for paths relative to a project-root +pub mod project_path; +/// Request types and run functions +pub mod requests; diff --git a/crates/node-bindings/src/core/project_path.rs b/crates/parcel_core/src/project_path.rs similarity index 94% rename from crates/node-bindings/src/core/project_path.rs rename to crates/parcel_core/src/project_path.rs index 588c0995014..06ce096d321 100644 --- a/crates/node-bindings/src/core/project_path.rs +++ b/crates/parcel_core/src/project_path.rs @@ -17,10 +17,12 @@ use napi::sys::napi_value; /// /// Use `ProjectPath` on your input type: /// -/// ``` +/// ```skip +/// use napi_derive::napi; +/// /// #[napi(object)] /// struct MyRequestInput { -/// path: ProjectPath, +/// pub path: parcel_core::project_path::ProjectPath, /// } /// /// #[napi] diff --git a/crates/node-bindings/src/core/requests/config_request/mod.rs b/crates/parcel_core/src/requests/config_request/mod.rs similarity index 98% rename from crates/node-bindings/src/core/requests/config_request/mod.rs rename to crates/parcel_core/src/requests/config_request/mod.rs index 82365331a40..65e8b202a3c 100644 --- a/crates/node-bindings/src/core/requests/config_request/mod.rs +++ b/crates/parcel_core/src/requests/config_request/mod.rs @@ -4,11 +4,11 @@ //! file. use std::path::Path; -use crate::core::project_path::ProjectPath; use napi_derive::napi; use parcel_resolver::FileSystem; -use crate::core::requests::request_api::RequestApi; +use crate::project_path::ProjectPath; +use crate::requests::request_api::RequestApi; pub type InternalGlob = String; @@ -154,12 +154,13 @@ struct RequestOptions {} #[cfg(test)] mod test { - use super::*; - use crate::core::requests::config_request::run_config_request; - use crate::core::requests::request_api::MockRequestApi; use parcel_filesystem::in_memory_file_system::InMemoryFileSystem; use parcel_filesystem::os_file_system::OsFileSystem; + use super::*; + use crate::requests::config_request::run_config_request; + use crate::requests::request_api::MockRequestApi; + #[test] fn test_run_empty_config_request_does_nothing() { let config_request = ConfigRequest { diff --git a/crates/node-bindings/src/core/requests/entry_request/mod.rs b/crates/parcel_core/src/requests/entry_request/mod.rs similarity index 97% rename from crates/node-bindings/src/core/requests/entry_request/mod.rs rename to crates/parcel_core/src/requests/entry_request/mod.rs index e5b1ba3fe71..bc732a6c098 100644 --- a/crates/node-bindings/src/core/requests/entry_request/mod.rs +++ b/crates/parcel_core/src/requests/entry_request/mod.rs @@ -8,9 +8,9 @@ use anyhow::anyhow; use napi_derive::napi; use parcel_resolver::FileSystem; -use crate::core::project_path::ProjectPath; -use crate::core::requests::config_request::InternalFileCreateInvalidation; -use crate::core::requests::request_api::RequestApi; +use crate::project_path::ProjectPath; +use crate::requests::config_request::InternalFileCreateInvalidation; +use crate::requests::request_api::RequestApi; #[napi(object)] #[derive(Debug, Clone, PartialEq)] diff --git a/crates/node-bindings/src/core/requests/mod.rs b/crates/parcel_core/src/requests/mod.rs similarity index 100% rename from crates/node-bindings/src/core/requests/mod.rs rename to crates/parcel_core/src/requests/mod.rs diff --git a/crates/node-bindings/src/core/requests/request_api/js_request_api.rs b/crates/parcel_core/src/requests/request_api/js_request_api.rs similarity index 94% rename from crates/node-bindings/src/core/requests/request_api/js_request_api.rs rename to crates/parcel_core/src/requests/request_api/js_request_api.rs index cd015ffa76b..138597e3f52 100644 --- a/crates/node-bindings/src/core/requests/request_api/js_request_api.rs +++ b/crates/parcel_core/src/requests/request_api/js_request_api.rs @@ -6,9 +6,9 @@ use napi::JsObject; use napi::JsUnknown; use parcel_napi_helpers::call_method; -use crate::core::requests::config_request::InternalFileCreateInvalidation; -use crate::core::requests::request_api::RequestApi; -use crate::core::requests::request_api::RequestApiResult; +use crate::requests::config_request::InternalFileCreateInvalidation; +use crate::requests::request_api::RequestApi; +use crate::requests::request_api::RequestApiResult; /// This is a "delegate" implementation of `RequestApi` that delegates calls to a /// JavaScript object. diff --git a/crates/node-bindings/src/core/requests/request_api/mod.rs b/crates/parcel_core/src/requests/request_api/mod.rs similarity index 95% rename from crates/node-bindings/src/core/requests/request_api/mod.rs rename to crates/parcel_core/src/requests/request_api/mod.rs index ddaa2eb4894..2ccf5763276 100644 --- a/crates/node-bindings/src/core/requests/request_api/mod.rs +++ b/crates/parcel_core/src/requests/request_api/mod.rs @@ -2,8 +2,9 @@ use std::path::Path; use mockall::automock; -use crate::core::requests::config_request::InternalFileCreateInvalidation; +use crate::requests::config_request::InternalFileCreateInvalidation; +#[cfg(not(feature = "napi_noop"))] pub mod js_request_api; // TODO: Move this into an associated type of the struct