Skip to content
Draft
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
8 changes: 4 additions & 4 deletions crates/rspack_binding_api/src/raw_options/raw_external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,8 +90,8 @@ pub struct RawExternalItemFnCtxData<'a> {
#[derive(Debug)]
struct RawExternalItemFnCtxInner {
request: String,
context: String,
dependency_type: String,
context: Context,
dependency_type: DependencyCategory,
Comment on lines +93 to +94
Copy link
Preview

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RawExternalItemFnCtxInner struct now uses typed fields but this change may break the JavaScript/TypeScript binding layer. The raw bindings typically need to convert between Rust types and JavaScript types, and changing from strings to typed enums could require additional conversion logic in the getter methods.

Copilot uses AI. Check for mistakes.

context_info: ContextInfo,
resolve_options_with_dependency_type: Arc<ResolveOptionsWithDependencyType>,
resolver_factory: Arc<ResolverFactory>,
Expand Down
6 changes: 3 additions & 3 deletions crates/rspack_core/src/options/externals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExternalItem>;

Expand All @@ -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<ResolverFactory>,
Expand Down
11 changes: 6 additions & 5 deletions crates/rspack_plugin_externals/src/http_externals_plugin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rspack_core::{
BoxPlugin, ExternalItem, ExternalItemFnCtx, ExternalItemFnResult, ExternalItemValue, PluginExt,
BoxPlugin, DependencyCategory, ExternalItem, ExternalItemFnCtx, ExternalItemFnResult,
ExternalItemValue, PluginExt,
};

use crate::ExternalsPlugin;
Expand All @@ -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()),
Expand Down Expand Up @@ -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()),
Expand Down
4 changes: 2 additions & 2 deletions crates/rspack_plugin_externals/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ async fn factorize(&self, data: &mut ModuleFactoryCreateData) -> Result<Option<B
ExternalItem::Fn(f) => {
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
Expand Down
Loading