Skip to content

Commit 6e1ced1

Browse files
committed
fix: types
1 parent 6585bfa commit 6e1ced1

File tree

9 files changed

+49
-183
lines changed

9 files changed

+49
-183
lines changed

crates/rspack_binding_options/src/options/raw_external.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use napi_derive::napi;
77
use rspack_binding_values::JsResolver;
88
use rspack_core::{ExternalItem, ExternalItemFnResult, ExternalItemValue};
99
use rspack_core::{ExternalItemFnCtx, ResolveOptionsWithDependencyType, ResolverFactory};
10-
// use rspack_napi::regexp::{JsRegExp, JsRegExpExt};
1110
use rspack_napi::threadsafe_function::ThreadsafeFunction;
1211
use rspack_regex::RspackRegex;
1312

crates/rspack_core/src/context_module_factory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl ContextModuleFactory {
128128
resolve_options: options
129129
.resolve_options
130130
.clone()
131-
.map(|arc| Box::new(Arc::try_unwrap(arc).unwrap_or_else(|arc| (*arc).clone()))),
131+
.map(|r| Box::new(Arc::unwrap_or_clone(r))),
132132
resolve_to_context: false,
133133
dependency_category: options.context_options.category,
134134
});

crates/rspack_core/src/module_factory.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::{
1111
#[derive(Debug, Clone)]
1212
pub struct ModuleFactoryCreateData {
1313
pub compilation_id: CompilationId,
14-
// pub resolve_options: Option<Box<Resolve>>,
1514
pub resolve_options: Option<Arc<Resolve>>,
1615
pub options: Arc<CompilerOptions>,
1716
pub context: Context,

crates/rspack_plugin_externals/src/plugin.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,11 @@ async fn factorize(&self, data: &mut ModuleFactoryCreateData) -> Result<Option<B
188188
.clone()
189189
.map(|r| Box::new(Arc::unwrap_or_clone(r))),
190190
resolve_to_context: false,
191-
// dependency_category: *data.dependency.category(),
192-
dependency_category: *data.dependencies.get(0).unwrap().category(),
191+
dependency_category: *data
192+
.dependencies
193+
.first()
194+
.expect("Expected at least one dependency")
195+
.category(),
193196
},
194197
resolver_factory: data.resolver_factory.clone(),
195198
})

packages/rspack/etc/core.api.md

+12-168
Large diffs are not rendered by default.

packages/rspack/src/builtin-plugin/ExternalsPlugin.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,15 @@ function getRawExternalItem(
7373
context,
7474
request,
7575
getResolveContext(),
76-
// @ts-expect-error TODO: fix the type
77-
callback
76+
(err, result) => {
77+
if (err) return callback(err);
78+
// Sync with how webpack fixes the type:
79+
// https://github.com/webpack/webpack/blob/a2ad76cd50ae780dead395c68ea67d46de9828f3/lib/ExternalModuleFactoryPlugin.js#L276
80+
callback(
81+
undefined,
82+
typeof result === "string" ? result : undefined
83+
);
84+
}
7885
);
7986
} else {
8087
return new Promise((resolve, reject) => {

packages/rspack/src/config/zod.ts

+22-6
Original file line numberDiff line numberDiff line change
@@ -863,10 +863,27 @@ const externalItemFunctionData = z.strictObject({
863863
.optional(),
864864
getResolve: z
865865
.function()
866-
.returns(z.function().args(z.string(), z.string(), z.function().optional()))
866+
.returns(
867+
z
868+
.function()
869+
.args(z.string(), z.string())
870+
.returns(z.promise(z.string()))
871+
.or(
872+
z
873+
.function()
874+
.args(
875+
z.string(),
876+
z.string(),
877+
z
878+
.function()
879+
.args(z.instanceof(Error).optional(), z.string().optional())
880+
.returns(z.void())
881+
)
882+
.returns(z.void())
883+
)
884+
)
867885
.optional()
868-
});
869-
export type ExternalItemFunctionData = z.infer<typeof externalItemFunctionData>;
886+
}) satisfies z.ZodType<t.ExternalItemFunctionData>;
870887

871888
const externalItem = z
872889
.string()
@@ -876,7 +893,7 @@ const externalItem = z
876893
z
877894
.function()
878895
.args(
879-
externalItemFunctionData,
896+
externalItemFunctionData as z.ZodType<t.ExternalItemFunctionData>,
880897
z
881898
.function()
882899
.args(
@@ -890,14 +907,13 @@ const externalItem = z
890907
.or(
891908
z
892909
.function()
893-
.args(externalItemFunctionData)
910+
.args(externalItemFunctionData as z.ZodType<t.ExternalItemFunctionData>)
894911
.returns(z.promise(externalItemValue))
895912
) satisfies z.ZodType<t.ExternalItem>;
896913

897914
const externals = externalItem
898915
.array()
899916
.or(externalItem) satisfies z.ZodType<t.Externals>;
900-
//#endregion
901917

902918
//#region ExternalsPresets
903919
const externalsPresets = z.strictObject({

tests/webpack-test/configCases/externals/resolve/node_modules/external.js

Whitespace-only changes.

tests/webpack-test/configCases/externals/resolve/test.filter.js

-2
This file was deleted.

0 commit comments

Comments
 (0)