Skip to content

Commit bac1ca1

Browse files
committed
fix: types
1 parent 650b5df commit bac1ca1

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
@@ -12,7 +12,6 @@ use crate::{
1212
#[derive(Debug, Clone)]
1313
pub struct ModuleFactoryCreateData {
1414
pub compilation_id: CompilationId,
15-
// pub resolve_options: Option<Box<Resolve>>,
1615
pub resolve_options: Option<Arc<Resolve>>,
1716
pub options: Arc<CompilerOptions>,
1817
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
@@ -869,10 +869,27 @@ const externalItemFunctionData = z.strictObject({
869869
.optional(),
870870
getResolve: z
871871
.function()
872-
.returns(z.function().args(z.string(), z.string(), z.function().optional()))
872+
.returns(
873+
z
874+
.function()
875+
.args(z.string(), z.string())
876+
.returns(z.promise(z.string()))
877+
.or(
878+
z
879+
.function()
880+
.args(
881+
z.string(),
882+
z.string(),
883+
z
884+
.function()
885+
.args(z.instanceof(Error).optional(), z.string().optional())
886+
.returns(z.void())
887+
)
888+
.returns(z.void())
889+
)
890+
)
873891
.optional()
874-
});
875-
export type ExternalItemFunctionData = z.infer<typeof externalItemFunctionData>;
892+
}) satisfies z.ZodType<t.ExternalItemFunctionData>;
876893

877894
const externalItem = z
878895
.string()
@@ -882,7 +899,7 @@ const externalItem = z
882899
z
883900
.function()
884901
.args(
885-
externalItemFunctionData,
902+
externalItemFunctionData as z.ZodType<t.ExternalItemFunctionData>,
886903
z
887904
.function()
888905
.args(
@@ -896,14 +913,13 @@ const externalItem = z
896913
.or(
897914
z
898915
.function()
899-
.args(externalItemFunctionData)
916+
.args(externalItemFunctionData as z.ZodType<t.ExternalItemFunctionData>)
900917
.returns(z.promise(externalItemValue))
901918
) satisfies z.ZodType<t.ExternalItem>;
902919

903920
const externals = externalItem
904921
.array()
905922
.or(externalItem) satisfies z.ZodType<t.Externals>;
906-
//#endregion
907923

908924
//#region ExternalsPresets
909925
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)