diff --git a/crates/rspack_binding_api/src/raw_options/raw_external.rs b/crates/rspack_binding_api/src/raw_options/raw_external.rs index 7fad146f9d78..b24a87aa7f79 100644 --- a/crates/rspack_binding_api/src/raw_options/raw_external.rs +++ b/crates/rspack_binding_api/src/raw_options/raw_external.rs @@ -6,8 +6,8 @@ use napi::{ }; use napi_derive::napi; use rspack_core::{ - ExternalItem, ExternalItemFnCtx, ExternalItemFnResult, ExternalItemValue, - ResolveOptionsWithDependencyType, ResolverFactory, + Context, DependencyCategory, ExternalItem, ExternalItemFnCtx, ExternalItemFnResult, + ExternalItemValue, ResolveOptionsWithDependencyType, ResolverFactory, }; use rspack_napi::threadsafe_function::ThreadsafeFunction; use rspack_regex::RspackRegex; @@ -90,8 +90,8 @@ pub struct RawExternalItemFnCtxData<'a> { #[derive(Debug)] struct RawExternalItemFnCtxInner { request: String, - context: String, - dependency_type: String, + context: Context, + dependency_type: DependencyCategory, context_info: ContextInfo, resolve_options_with_dependency_type: Arc, resolver_factory: Arc, diff --git a/crates/rspack_core/src/options/externals.rs b/crates/rspack_core/src/options/externals.rs index 7021ef10b5b0..82e639226754 100644 --- a/crates/rspack_core/src/options/externals.rs +++ b/crates/rspack_core/src/options/externals.rs @@ -5,7 +5,7 @@ use rspack_error::Result; use rspack_regex::RspackRegex; use rustc_hash::FxHashMap as HashMap; -use crate::{ResolveOptionsWithDependencyType, ResolverFactory}; +use crate::{Context, DependencyCategory, ResolveOptionsWithDependencyType, ResolverFactory}; pub type Externals = Vec; @@ -26,8 +26,8 @@ pub struct ContextInfo { pub struct ExternalItemFnCtx { pub request: String, - pub context: String, - pub dependency_type: String, + pub context: Context, + pub dependency_type: DependencyCategory, pub context_info: ContextInfo, pub resolve_options_with_dependency_type: ResolveOptionsWithDependencyType, pub resolver_factory: Arc, diff --git a/crates/rspack_plugin_externals/src/http_externals_plugin.rs b/crates/rspack_plugin_externals/src/http_externals_plugin.rs index f4a9ff7b8a76..9921a5711198 100644 --- a/crates/rspack_plugin_externals/src/http_externals_plugin.rs +++ b/crates/rspack_plugin_externals/src/http_externals_plugin.rs @@ -1,5 +1,6 @@ use rspack_core::{ - BoxPlugin, ExternalItem, ExternalItemFnCtx, ExternalItemFnResult, ExternalItemValue, PluginExt, + BoxPlugin, DependencyCategory, ExternalItem, ExternalItemFnCtx, ExternalItemFnResult, + ExternalItemValue, PluginExt, }; use crate::ExternalsPlugin; @@ -25,14 +26,14 @@ pub fn http_externals_rspack_plugin(css: bool, web_async: bool) -> BoxPlugin { fn http_external_item_web(css: bool) -> ExternalItem { ExternalItem::Fn(Box::new(move |ctx: ExternalItemFnCtx| { Box::pin(async move { - if ctx.dependency_type == "url" { + if ctx.dependency_type == DependencyCategory::Url { if is_external_http_request(&ctx.request) { return Ok(ExternalItemFnResult { external_type: Some("asset".to_owned()), result: Some(ExternalItemValue::String(ctx.request)), }); } - } else if css && ctx.dependency_type == "css-import" { + } else if css && ctx.dependency_type == DependencyCategory::CssImport { if is_external_http_request(&ctx.request) { return Ok(ExternalItemFnResult { external_type: Some("css-import".to_owned()), @@ -63,14 +64,14 @@ fn http_external_item_web(css: bool) -> ExternalItem { fn http_external_item_web_async(css: bool) -> ExternalItem { ExternalItem::Fn(Box::new(move |ctx: ExternalItemFnCtx| { Box::pin(async move { - if ctx.dependency_type == "url" { + if ctx.dependency_type == DependencyCategory::Url { if is_external_http_request(&ctx.request) { return Ok(ExternalItemFnResult { external_type: Some("asset".to_owned()), result: Some(ExternalItemValue::String(ctx.request)), }); } - } else if css && ctx.dependency_type == "css-import" { + } else if css && ctx.dependency_type == DependencyCategory::CssImport { if is_external_http_request(&ctx.request) { return Ok(ExternalItemFnResult { external_type: Some("css-import".to_owned()), diff --git a/crates/rspack_plugin_externals/src/plugin.rs b/crates/rspack_plugin_externals/src/plugin.rs index 4205f392b0d4..bf121c9cd55a 100644 --- a/crates/rspack_plugin_externals/src/plugin.rs +++ b/crates/rspack_plugin_externals/src/plugin.rs @@ -184,9 +184,9 @@ async fn factorize(&self, data: &mut ModuleFactoryCreateData) -> Result { let request = dependency.request(); let result = f(ExternalItemFnCtx { - context: context.to_string(), + context: context.clone(), request: request.to_string(), - dependency_type: dependency.category().to_string(), + dependency_type: *dependency.category(), context_info: ContextInfo { issuer: data .issuer