Skip to content

Commit

Permalink
Split parcel_core crate (#9698)
Browse files Browse the repository at this point in the history
* Split parcel_core crate

* Reorganise project slightly

* Fix rust node-bindings imports

* Fix hash include in the module tree

* Fix doctests
  • Loading branch information
yamadapc committed May 7, 2024
1 parent a007691 commit 59ed066
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 38 deletions.
27 changes: 23 additions & 4 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/node-bindings/Cargo.toml
Expand Up @@ -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"] }
Expand Down
Expand Up @@ -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.
Expand Down
11 changes: 6 additions & 5 deletions crates/node-bindings/src/core/js_requests/entry_request/mod.rs
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion 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;
10 changes: 2 additions & 8 deletions 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;
7 changes: 4 additions & 3 deletions 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;
Expand All @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions 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"] }
8 changes: 8 additions & 0 deletions 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)
}
7 changes: 7 additions & 0 deletions 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;
Expand Up @@ -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]
Expand Down
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
Expand Up @@ -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)]
Expand Down
File renamed without changes.
Expand Up @@ -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.
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit 59ed066

Please sign in to comment.