Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split parcel_core crate #9698

Merged
merged 5 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 4 additions & 4 deletions crates/node-bindings/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,10 +15,10 @@ 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;
#[cfg(not(target_arch = "wasm32"))]
mod image;
mod resolver;
Expand Down
24 changes: 24 additions & 0 deletions crates/parcel_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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