Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ async-recursion = { version = "1.1.0" }
async-scoped = { version = "0.9.0" }
async-trait = { version = "0.1.79" }
bitflags = { version = "2.5.0" }
camino = { version = "1.1.8" }
concat-string = "1.0.1"
css-module-lexer = "0.0.14"
dashmap = { version = "5.5.3" }
Expand Down
6 changes: 4 additions & 2 deletions crates/node_binding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ rspack_fs_node = { version = "0.1.0", path = "../rspack_fs_node" }
rspack_hash = { version = "0.1.0", path = "../rspack_hash" }
rspack_hook = { version = "0.1.0", path = "../rspack_hook" }
rspack_napi = { version = "0.1.0", path = "../rspack_napi" }
rspack_paths = { version = "0.1.0", path = "../rspack_paths" }
rspack_plugin_javascript = { version = "0.1.0", path = "../rspack_plugin_javascript" }
rspack_tracing = { version = "0.1.0", path = "../rspack_tracing" }
tokio = { workspace = true, features = ["rt", "rt-multi-thread"] }

rspack_tracing = { version = "0.1.0", path = "../rspack_tracing" }
tokio = { workspace = true, features = ["rt", "rt-multi-thread"] }

async-trait = { workspace = true }
once_cell = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,7 @@ export interface RawSwcJsMinimizerRspackPluginOptions {

export interface RawToOptions {
context: string
absoluteFilename?: string
absoluteFilename: string
}

export interface RawTrustedTypes {
Expand Down
12 changes: 6 additions & 6 deletions crates/node_binding/src/plugins/interceptor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{
borrow::Cow,
hash::Hash,
path::PathBuf,
sync::{Arc, RwLock},
};

Expand Down Expand Up @@ -56,6 +55,7 @@ use rspack_core::{
use rspack_hash::RspackHash;
use rspack_hook::{Hook, Interceptor};
use rspack_napi::threadsafe_function::ThreadsafeFunction;
use rspack_paths::Utf8PathBuf;
use rspack_plugin_javascript::{JavascriptModulesChunkHash, JavascriptModulesChunkHashHook};

#[napi(object)]
Expand Down Expand Up @@ -881,8 +881,8 @@ impl CompilerAssetEmitted for CompilerAssetEmittedTap {
.function
.call_with_promise(JsAssetEmittedArgs {
filename: filename.to_string(),
output_path: info.output_path.to_string_lossy().into_owned(),
target_path: info.target_path.to_string_lossy().into_owned(),
output_path: info.output_path.as_str().to_owned(),
target_path: info.target_path.as_str().to_owned(),
})
.await
}
Expand Down Expand Up @@ -1290,7 +1290,7 @@ impl NormalModuleFactoryResolveForScheme for NormalModuleFactoryResolveForScheme
})
.await?;
resource_data.set_resource(new_resource_data.resource);
resource_data.set_path_optional(new_resource_data.path.map(PathBuf::from));
resource_data.set_path_optional(new_resource_data.path.map(Utf8PathBuf::from));
resource_data.set_query_optional(new_resource_data.query);
resource_data.set_fragment_optional(new_resource_data.fragment);
Ok(bail)
Expand Down Expand Up @@ -1440,7 +1440,7 @@ impl ContextModuleFactoryAfterResolve for ContextModuleFactoryAfterResolveTap {
AfterResolveResult::Ignored => JsContextModuleFactoryAfterResolveResult::A(false),
AfterResolveResult::Data(d) => {
JsContextModuleFactoryAfterResolveResult::B(JsContextModuleFactoryAfterResolveData {
resource: d.resource.to_owned(),
resource: d.resource.as_str().to_owned(),
context: d.context.to_owned(),
request: d.request.to_owned(),
reg_exp: d.reg_exp.clone().map(|r| r.into()),
Expand All @@ -1451,7 +1451,7 @@ impl ContextModuleFactoryAfterResolve for ContextModuleFactoryAfterResolveTap {
napi::Either::A(_) => Ok(AfterResolveResult::Ignored),
napi::Either::B(d) => {
let data = AfterResolveData {
resource: d.resource,
resource: d.resource.into(),
context: d.context,
request: d.request,
reg_exp: match d.reg_exp {
Expand Down
22 changes: 22 additions & 0 deletions crates/rspack_allocator/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2022-present Bytedance, Inc. and its affiliates.


Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions crates/rspack_binding_options/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ rspack_loader_swc = { version = "0.1.0", path = "../rspack_l
rspack_loader_testing = { version = "0.1.0", path = "../rspack_loader_testing" }
rspack_napi = { version = "0.1.0", path = "../rspack_napi" }
rspack_napi_macros = { version = "0.1.0", path = "../rspack_napi_macros" }
rspack_paths = { version = "0.1.0", path = "../rspack_paths" }
rspack_plugin_asset = { version = "0.1.0", path = "../rspack_plugin_asset" }
rspack_plugin_banner = { version = "0.1.0", path = "../rspack_plugin_banner" }
rspack_plugin_copy = { version = "0.1.0", path = "../rspack_plugin_copy" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::path::PathBuf;

use derivative::Derivative;
use napi::{bindgen_prelude::Buffer, Either};
use napi_derive::napi;
Expand All @@ -20,7 +18,7 @@ type RawTo = Either<String, RawToFn>;
#[napi(object)]
pub struct RawToOptions {
pub context: String,
pub absolute_filename: Option<String>,
pub absolute_filename: String,
}

#[derive(Derivative)]
Expand Down Expand Up @@ -103,14 +101,14 @@ impl From<RawCopyPattern> for CopyPattern {
let f = f.clone();
Box::pin(async move {
f.call(RawToOptions {
context: ctx.context.to_owned(),
absolute_filename: ctx.absolute_filename.map(|filename| filename.to_owned()),
context: ctx.context.as_str().to_owned(),
absolute_filename: ctx.absolute_filename.as_str().to_owned(),
})
.await
})
})),
}),
context: context.map(PathBuf::from),
context: context.map(Into::into),
to_type: if let Some(to_type) = to_type {
match to_type.to_lowercase().as_str() {
"dir" => Some(ToType::Dir),
Expand Down
31 changes: 12 additions & 19 deletions crates/rspack_binding_options/src/plugins/js_loader/resolver.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{path::Path, sync::Arc};
use std::sync::Arc;

use rspack_collections::{Identifiable, Identifier};
use rspack_core::{
Expand All @@ -11,6 +11,7 @@ use rspack_loader_lightningcss::LIGHTNINGCSS_LOADER_IDENTIFIER;
use rspack_loader_preact_refresh::PREACT_REFRESH_LOADER_IDENTIFIER;
use rspack_loader_react_refresh::REACT_REFRESH_LOADER_IDENTIFIER;
use rspack_loader_swc::SWC_LOADER_IDENTIFIER;
use rspack_paths::Utf8Path;

use super::{JsLoaderRspackPlugin, JsLoaderRspackPluginInner};

Expand Down Expand Up @@ -81,15 +82,15 @@ pub(crate) async fn resolve_loader(
resolver: &Resolver,
l: &ModuleRuleUseLoader,
) -> Result<Option<BoxLoader>> {
let context = context.as_ref();
let context = context.as_path();
let loader_request = &l.loader;
let loader_options = l.options.as_deref();
let mut rest = None;
let prev = if let Some(index) = loader_request.find('?') {
rest = Some(&loader_request[index..]);
Path::new(&loader_request[0..index])
Utf8Path::new(&loader_request[0..index])
} else {
Path::new(loader_request)
Utf8Path::new(loader_request)
};

// FIXME: not belong to napi
Expand All @@ -98,16 +99,12 @@ pub(crate) async fn resolve_loader(
}

let resolve_result = resolver
.resolve(context, &prev.to_string_lossy())
.map_err(|err| {
let loader_request = prev.display();
let context = context.display();
error!("Failed to resolve loader: {loader_request} in {context} {err:?}")
})?;
.resolve(context.as_std_path(), prev.as_str())
.map_err(|err| error!("Failed to resolve loader: {prev} in {context}, error: {err:?}"))?;

match resolve_result {
ResolveResult::Resource(resource) => {
let path = resource.path.to_string_lossy().to_ascii_lowercase();
let path = resource.path.as_str();
let r#type = if path.ends_with(".mjs") {
Some("module")
} else if path.ends_with(".cjs") {
Expand All @@ -119,20 +116,16 @@ pub(crate) async fn resolve_loader(
.and_then(|data| data.json().get("type").and_then(|t| t.as_str()))
};
// TODO: Should move this logic to `resolver`, since `resolve.alias` may contain query or fragment too.
let resource = resource.path.to_string_lossy().to_string() + rest.unwrap_or_default();
let resource = resource.path.as_str().to_owned() + rest.unwrap_or_default();
let ident = if let Some(ty) = r#type {
format!("{ty}|{resource}")
} else {
resource
};
Ok(Some(Arc::new(JsLoader(ident.into()))))
}
ResolveResult::Ignored => {
let loader_request = prev.display();
let context = context.to_string_lossy();
Err(error!(
"Failed to resolve loader: loader_request={loader_request}, context={context}"
))
}
ResolveResult::Ignored => Err(error!(
"Failed to resolve loader: loader_request={prev}, context={context}"
)),
}
}
12 changes: 4 additions & 8 deletions crates/rspack_binding_options/src/plugins/js_loader/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,21 @@ pub(crate) fn merge_loader_context(
to.additional_data.insert(data.clone());
}
to.cacheable = from.cacheable;
to.file_dependencies = from
.file_dependencies
.into_iter()
.map(std::path::PathBuf::from)
.collect();
to.file_dependencies = from.file_dependencies.into_iter().map(Into::into).collect();
to.context_dependencies = from
.context_dependencies
.into_iter()
.map(std::path::PathBuf::from)
.map(Into::into)
.collect();
to.missing_dependencies = from
.missing_dependencies
.into_iter()
.map(std::path::PathBuf::from)
.map(Into::into)
.collect();
to.build_dependencies = from
.build_dependencies
.into_iter()
.map(std::path::PathBuf::from)
.map(Into::into)
.collect();
to.content = match from.content {
Either::A(_) => None,
Expand Down
Loading