diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index 831e55595c9..e25a237ad9b 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -1012,6 +1012,7 @@ export interface RawJavascriptParserOptions { importExportsPresence?: string reexportExportsPresence?: string strictExportPresence: boolean + worker: Array } export interface RawLazyCompilationOption { diff --git a/crates/rspack_binding_options/src/options/raw_module/mod.rs b/crates/rspack_binding_options/src/options/raw_module/mod.rs index 0a39570e348..35a8fb2aeab 100644 --- a/crates/rspack_binding_options/src/options/raw_module/mod.rs +++ b/crates/rspack_binding_options/src/options/raw_module/mod.rs @@ -280,6 +280,7 @@ pub struct RawJavascriptParserOptions { pub import_exports_presence: Option, pub reexport_exports_presence: Option, pub strict_export_presence: bool, + pub worker: Vec, } impl From for JavascriptParserOptions { @@ -301,6 +302,7 @@ impl From for JavascriptParserOptions { .reexport_exports_presence .map(|e| ExportPresenceMode::from(e.as_str())), strict_export_presence: value.strict_export_presence, + worker: value.worker, } } } diff --git a/crates/rspack_core/src/options/module.rs b/crates/rspack_core/src/options/module.rs index 9e159ed93d3..d8d8aa8b396 100644 --- a/crates/rspack_core/src/options/module.rs +++ b/crates/rspack_core/src/options/module.rs @@ -177,6 +177,7 @@ pub struct JavascriptParserOptions { pub import_exports_presence: Option, pub reexport_exports_presence: Option, pub strict_export_presence: bool, + pub worker: Vec, } #[derive(Debug, Clone, MergeFrom)] diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/worker_plugin.rs b/crates/rspack_plugin_javascript/src/parser_plugin/worker_plugin.rs index dc529316602..32c6a484dc2 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/worker_plugin.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/worker_plugin.rs @@ -1,6 +1,8 @@ use std::hash::Hash; use itertools::Itertools; +use once_cell::sync::Lazy; +use regex::Regex; use rspack_core::{ AsyncDependenciesBlock, ConstDependency, DependencyLocation, EntryOptions, ErrorSpan, GroupOptions, SpanExt, @@ -9,7 +11,7 @@ use rspack_hash::RspackHash; use rustc_hash::FxHashSet; use swc_core::{ common::{Span, Spanned}, - ecma::ast::{Expr, ExprOrSpread, NewExpr}, + ecma::ast::{CallExpr, Expr, ExprOrSpread, NewExpr}, }; use super::{ @@ -70,7 +72,7 @@ fn parse_new_worker_options_from_comments( fn add_dependencies( parser: &mut JavascriptParser, - new_expr: &NewExpr, + span: Span, parsed_path: ParsedNewWorkerPath, parsed_options: Option, ) { @@ -86,7 +88,7 @@ fn add_dependencies( let range = parsed_options.as_ref().and_then(|options| options.range); let name = parsed_options.and_then(|options| options.name); let output_module = output_options.module; - let span = ErrorSpan::from(new_expr.span); + let span = ErrorSpan::from(span); let dep = Box::new(WorkerDependency::new( parsed_path.range.0, parsed_path.range.1, @@ -146,12 +148,12 @@ fn add_dependencies( } } -fn parse_new_worker( +fn handle_worker( parser: &mut JavascriptParser, - new_expr: &NewExpr, + args: &[ExprOrSpread], + span: Span, ) -> Option<(ParsedNewWorkerPath, Option)> { - if let Some(args) = &new_expr.args - && let Some(expr_or_spread) = args.first() + if let Some(expr_or_spread) = args.first() && let ExprOrSpread { spread: None, expr: box Expr::New(new_url_expr), @@ -178,7 +180,7 @@ fn parse_new_worker( }) .or_else(|| { // new Worker(/* options */ new URL("worker.js")) - parse_new_worker_options_from_comments(parser, expr_or_spread.span(), new_expr.span()) + parse_new_worker_options_from_comments(parser, expr_or_spread.span(), span) }); Some((path, options)) } else { @@ -188,27 +190,91 @@ fn parse_new_worker( pub struct WorkerPlugin { new_syntax: FxHashSet, - // call_syntax: FxHashSet, + call_syntax: FxHashSet, from_new_syntax: FxHashSet<(String, String)>, - // from_call_syntax: FxHashSet<(String, String)>, + from_call_syntax: FxHashSet<(String, String)>, } +static WORKER_FROM_REGEX: Lazy = + Lazy::new(|| Regex::new(r"^(.+?)(\(\))?\s+from\s+(.+)$").expect("invalid regex")); + impl WorkerPlugin { - pub fn new(/* syntax_list: &[&str] */) -> Self { - Self { - new_syntax: FxHashSet::from_iter(["Worker".into(), "SharedWorker".into()]), - // call_syntax: FxHashSet::default(), - from_new_syntax: FxHashSet::from_iter([("Worker".into(), "worker_threads".into())]), - // from_call_syntax: FxHashSet::default(), + pub fn new(syntax_list: &[String]) -> Self { + let mut this = Self { + new_syntax: FxHashSet::default(), + call_syntax: FxHashSet::default(), + from_new_syntax: FxHashSet::default(), + from_call_syntax: FxHashSet::default(), + }; + for syntax in syntax_list { + if let Some(syntax) = syntax.strip_suffix("()") { + this.call_syntax.insert(syntax.to_string()); + } else if let Some(captures) = WORKER_FROM_REGEX.captures(syntax) { + let ids = &captures[1]; + let is_call = &captures.get(2).is_some(); + let source = &captures[3]; + if *is_call { + this + .from_call_syntax + .insert((ids.to_string(), source.to_string())); + } else { + this + .from_new_syntax + .insert((ids.to_string(), source.to_string())); + } + } else { + this.new_syntax.insert(syntax.to_string()); + } } + this } } impl JavascriptParserPlugin for WorkerPlugin { + fn call( + &self, + parser: &mut JavascriptParser, + call_expr: &CallExpr, + for_name: &str, + ) -> Option { + if for_name == HARMONY_SPECIFIER_TAG { + let tag_info = parser + .definitions_db + .expect_get_tag_info(&parser.current_tag_info?); + let settings = HarmonySpecifierData::downcast(tag_info.data.clone()?); + let ids = settings.ids.iter().map(|id| id.as_str()).join("."); + if self + .from_call_syntax + .contains(&(ids, settings.source.to_string())) + { + return handle_worker(parser, &call_expr.args, call_expr.span).map( + |(parsed_path, parsed_options)| { + add_dependencies(parser, call_expr.span, parsed_path, parsed_options); + if let Some(callee) = call_expr.callee.as_expr() { + parser.walk_expression(callee); + } + true + }, + ); + } + return None; + } + if !self.call_syntax.contains(for_name) { + return None; + } + handle_worker(parser, &call_expr.args, call_expr.span).map(|(parsed_path, parsed_options)| { + add_dependencies(parser, call_expr.span, parsed_path, parsed_options); + if let Some(callee) = call_expr.callee.as_expr() { + parser.walk_expression(callee); + } + true + }) + } + fn new_expression( &self, parser: &mut JavascriptParser, - new_expr: &swc_core::ecma::ast::NewExpr, + new_expr: &NewExpr, for_name: &str, ) -> Option { if for_name == HARMONY_SPECIFIER_TAG { @@ -221,21 +287,29 @@ impl JavascriptParserPlugin for WorkerPlugin { .from_new_syntax .contains(&(ids, settings.source.to_string())) { - return parse_new_worker(parser, new_expr).map(|(parsed_path, parsed_options)| { - add_dependencies(parser, new_expr, parsed_path, parsed_options); - parser.walk_expression(&new_expr.callee); - true - }); + return new_expr + .args + .as_ref() + .and_then(|args| handle_worker(parser, args, new_expr.span)) + .map(|(parsed_path, parsed_options)| { + add_dependencies(parser, new_expr.span, parsed_path, parsed_options); + parser.walk_expression(&new_expr.callee); + true + }); } return None; } if !self.new_syntax.contains(for_name) { return None; } - parse_new_worker(parser, new_expr).map(|(parsed_path, parsed_options)| { - add_dependencies(parser, new_expr, parsed_path, parsed_options); - parser.walk_expression(&new_expr.callee); - true - }) + new_expr + .args + .as_ref() + .and_then(|args| handle_worker(parser, args, new_expr.span)) + .map(|(parsed_path, parsed_options)| { + add_dependencies(parser, new_expr.span, parsed_path, parsed_options); + parser.walk_expression(&new_expr.callee); + true + }) } } diff --git a/crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs b/crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs index 3e3b34aa442..e98293e424a 100644 --- a/crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs +++ b/crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs @@ -355,7 +355,9 @@ impl<'parser> JavascriptParser<'parser> { relative: matches!(parse_url, JavascriptParserUrl::Relative), })); } - plugins.push(Box::new(parser_plugin::WorkerPlugin::new())); + plugins.push(Box::new(parser_plugin::WorkerPlugin::new( + &javascript_options.worker, + ))); } let plugin_drive = Rc::new(JavaScriptParserPluginDrive::new(plugins)); diff --git a/crates/rspack_util/src/merge.rs b/crates/rspack_util/src/merge.rs index e2d65808912..43a88ef2de1 100644 --- a/crates/rspack_util/src/merge.rs +++ b/crates/rspack_util/src/merge.rs @@ -21,6 +21,13 @@ impl MergeFrom for Option { } } +impl MergeFrom for Vec { + fn merge_from(mut self, other: &Self) -> Self { + self.extend(other.iter().cloned()); + self + } +} + impl_merge_from!(i8, i16, i32, i64, i128); impl_merge_from!(u8, u16, u32, u64, u128); impl_merge_from!(bool); diff --git a/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap index 94a15931693..7014050dca4 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap @@ -206,6 +206,9 @@ Object { "reexportExportsPresence": undefined, "strictExportPresence": false, "url": true, + "worker": Array [ + "...", + ], "wrappedContextCritical": false, }, "javascript/auto": Object { @@ -218,6 +221,9 @@ Object { "reexportExportsPresence": undefined, "strictExportPresence": false, "url": true, + "worker": Array [ + "...", + ], "wrappedContextCritical": false, }, "javascript/dynamic": Object { @@ -230,6 +236,9 @@ Object { "reexportExportsPresence": undefined, "strictExportPresence": false, "url": true, + "worker": Array [ + "...", + ], "wrappedContextCritical": false, }, "javascript/esm": Object { @@ -242,6 +251,9 @@ Object { "reexportExportsPresence": undefined, "strictExportPresence": false, "url": true, + "worker": Array [ + "...", + ], "wrappedContextCritical": false, }, }, diff --git a/packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/index.js b/packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/index.js new file mode 100644 index 00000000000..f6501aab994 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/index.js @@ -0,0 +1,24 @@ +it("should allow to create a WebWorker", async () => { + const worker = MyWorker(new URL("./worker.js", import.meta.url), { + type: "module" + }); + worker.postMessage("ok"); + const result = await new Promise(resolve => { + worker.onmessage = event => { + resolve(event.data); + }; + }); + expect(result).toBe("data: OK, thanks"); + await worker.terminate(); +}); + +it("should allow to share chunks", async () => { + const promise = import("./module"); + const script = document.head._children[0]; + const src = script.src; + const file = src.slice(src.lastIndexOf("/")); + __non_webpack_require__(`./${file}`); + script.onload(); + const { upper } = await promise; + expect(upper("ok")).toBe("OK"); +}); diff --git a/packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/module.js b/packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/module.js new file mode 100644 index 00000000000..3a0b527ffb8 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/module.js @@ -0,0 +1,3 @@ +export function upper(str) { + return str.toUpperCase(); +} diff --git a/packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/test.config.js b/packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/test.config.js new file mode 100644 index 00000000000..85b74f2cca4 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/test.config.js @@ -0,0 +1,8 @@ +module.exports = { + findBundle: function(i, options) { + return ["main.js"]; + }, + moduleScope(scope) { + scope["MyWorker"] = (...args) => new scope.Worker(...args); + }, +}; diff --git a/packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/webpack.config.js b/packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/webpack.config.js new file mode 100644 index 00000000000..37bc69444ed --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/webpack.config.js @@ -0,0 +1,17 @@ +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + output: { + filename: "[name].js" + }, + target: "web", + module: { + rules: [ + { + test: /\.[cm]?js$/, + parser: { + worker: ["MyWorker()", "..."] + } + } + ] + } +}; diff --git a/packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/worker.js b/packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/worker.js new file mode 100644 index 00000000000..fc12b94a652 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/worker.js @@ -0,0 +1,4 @@ +onmessage = async event => { + const { upper } = await import("./module"); + postMessage(`data: ${upper(event.data)}, thanks`); +}; diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index f64c55b40e0..48aeebd2788 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -4148,6 +4148,7 @@ const javascriptParserOptions: z.ZodObject<{ importExportsPresence: z.ZodOptional, z.ZodLiteral]>>; reexportExportsPresence: z.ZodOptional, z.ZodLiteral]>>; strictExportPresence: z.ZodOptional; + worker: z.ZodOptional, z.ZodBoolean]>>; }, "strict", z.ZodTypeAny, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -4159,6 +4160,7 @@ const javascriptParserOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -4170,6 +4172,7 @@ const javascriptParserOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }>; // @public (undocumented) @@ -5139,6 +5142,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence: z.ZodOptional, z.ZodLiteral]>>; reexportExportsPresence: z.ZodOptional, z.ZodLiteral]>>; strictExportPresence: z.ZodOptional; + worker: z.ZodOptional, z.ZodBoolean]>>; }, "strict", z.ZodTypeAny, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -5150,6 +5154,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -5161,6 +5166,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }>>; "javascript/auto": z.ZodOptional>; @@ -5173,6 +5179,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence: z.ZodOptional, z.ZodLiteral]>>; reexportExportsPresence: z.ZodOptional, z.ZodLiteral]>>; strictExportPresence: z.ZodOptional; + worker: z.ZodOptional, z.ZodBoolean]>>; }, "strict", z.ZodTypeAny, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -5184,6 +5191,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -5195,6 +5203,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }>>; "javascript/dynamic": z.ZodOptional>; @@ -5207,6 +5216,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence: z.ZodOptional, z.ZodLiteral]>>; reexportExportsPresence: z.ZodOptional, z.ZodLiteral]>>; strictExportPresence: z.ZodOptional; + worker: z.ZodOptional, z.ZodBoolean]>>; }, "strict", z.ZodTypeAny, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -5218,6 +5228,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -5229,6 +5240,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }>>; "javascript/esm": z.ZodOptional>; @@ -5241,6 +5253,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence: z.ZodOptional, z.ZodLiteral]>>; reexportExportsPresence: z.ZodOptional, z.ZodLiteral]>>; strictExportPresence: z.ZodOptional; + worker: z.ZodOptional, z.ZodBoolean]>>; }, "strict", z.ZodTypeAny, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -5252,6 +5265,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -5263,6 +5277,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }>>; }, "strict", z.ZodTypeAny, { asset?: { @@ -5290,6 +5305,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/auto"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -5302,6 +5318,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/dynamic"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -5314,6 +5331,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/esm"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -5326,6 +5344,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; }, { asset?: { @@ -5353,6 +5372,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/auto"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -5365,6 +5385,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/dynamic"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -5377,6 +5398,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/esm"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -5389,6 +5411,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; }>, z.ZodRecord>]>>; generator: z.ZodOptional> | undefined; generator?: Record> | { @@ -5759,6 +5786,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/auto"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -5771,6 +5799,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/dynamic"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -5783,6 +5812,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/esm"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -5795,6 +5825,7 @@ const moduleOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; } | Record> | undefined; generator?: Record> | { @@ -7298,6 +7329,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence: z.ZodOptional, z.ZodLiteral]>>; reexportExportsPresence: z.ZodOptional, z.ZodLiteral]>>; strictExportPresence: z.ZodOptional; + worker: z.ZodOptional, z.ZodBoolean]>>; }, "strict", z.ZodTypeAny, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -7309,6 +7341,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -7320,6 +7353,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }>>; "javascript/auto": z.ZodOptional>; @@ -7332,6 +7366,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence: z.ZodOptional, z.ZodLiteral]>>; reexportExportsPresence: z.ZodOptional, z.ZodLiteral]>>; strictExportPresence: z.ZodOptional; + worker: z.ZodOptional, z.ZodBoolean]>>; }, "strict", z.ZodTypeAny, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -7343,6 +7378,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -7354,6 +7390,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }>>; "javascript/dynamic": z.ZodOptional>; @@ -7366,6 +7403,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence: z.ZodOptional, z.ZodLiteral]>>; reexportExportsPresence: z.ZodOptional, z.ZodLiteral]>>; strictExportPresence: z.ZodOptional; + worker: z.ZodOptional, z.ZodBoolean]>>; }, "strict", z.ZodTypeAny, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -7377,6 +7415,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -7388,6 +7427,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }>>; "javascript/esm": z.ZodOptional>; @@ -7400,6 +7440,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence: z.ZodOptional, z.ZodLiteral]>>; reexportExportsPresence: z.ZodOptional, z.ZodLiteral]>>; strictExportPresence: z.ZodOptional; + worker: z.ZodOptional, z.ZodBoolean]>>; }, "strict", z.ZodTypeAny, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -7411,6 +7452,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -7422,6 +7464,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }>>; }, "strict", z.ZodTypeAny, { asset?: { @@ -7449,6 +7492,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/auto"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -7461,6 +7505,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/dynamic"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -7473,6 +7518,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/esm"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -7485,6 +7531,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; }, { asset?: { @@ -7512,6 +7559,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/auto"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -7524,6 +7572,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/dynamic"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -7536,6 +7585,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/esm"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -7548,6 +7598,7 @@ const parserOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; }>, z.ZodRecord>]>; @@ -7605,6 +7656,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence: z.ZodOptional, z.ZodLiteral]>>; reexportExportsPresence: z.ZodOptional, z.ZodLiteral]>>; strictExportPresence: z.ZodOptional; + worker: z.ZodOptional, z.ZodBoolean]>>; }, "strict", z.ZodTypeAny, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -7616,6 +7668,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -7627,6 +7680,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }>>; "javascript/auto": z.ZodOptional>; @@ -7639,6 +7693,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence: z.ZodOptional, z.ZodLiteral]>>; reexportExportsPresence: z.ZodOptional, z.ZodLiteral]>>; strictExportPresence: z.ZodOptional; + worker: z.ZodOptional, z.ZodBoolean]>>; }, "strict", z.ZodTypeAny, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -7650,6 +7705,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -7661,6 +7717,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }>>; "javascript/dynamic": z.ZodOptional>; @@ -7673,6 +7730,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence: z.ZodOptional, z.ZodLiteral]>>; reexportExportsPresence: z.ZodOptional, z.ZodLiteral]>>; strictExportPresence: z.ZodOptional; + worker: z.ZodOptional, z.ZodBoolean]>>; }, "strict", z.ZodTypeAny, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -7684,6 +7742,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -7695,6 +7754,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }>>; "javascript/esm": z.ZodOptional>; @@ -7707,6 +7767,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence: z.ZodOptional, z.ZodLiteral]>>; reexportExportsPresence: z.ZodOptional, z.ZodLiteral]>>; strictExportPresence: z.ZodOptional; + worker: z.ZodOptional, z.ZodBoolean]>>; }, "strict", z.ZodTypeAny, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -7718,6 +7779,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -7729,6 +7791,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }>>; }, "strict", z.ZodTypeAny, { asset?: { @@ -7756,6 +7819,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/auto"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -7768,6 +7832,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/dynamic"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -7780,6 +7845,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/esm"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -7792,6 +7858,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; }, { asset?: { @@ -7819,6 +7886,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/auto"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -7831,6 +7899,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/dynamic"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -7843,6 +7912,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/esm"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -7855,6 +7925,7 @@ const parserOptionsByModuleTypeKnown: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; }>; @@ -9976,6 +10047,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence: z.ZodOptional, z.ZodLiteral]>>; reexportExportsPresence: z.ZodOptional, z.ZodLiteral]>>; strictExportPresence: z.ZodOptional; + worker: z.ZodOptional, z.ZodBoolean]>>; }, "strict", z.ZodTypeAny, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -9987,6 +10059,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -9998,6 +10071,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }>>; "javascript/auto": z.ZodOptional>; @@ -10010,6 +10084,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence: z.ZodOptional, z.ZodLiteral]>>; reexportExportsPresence: z.ZodOptional, z.ZodLiteral]>>; strictExportPresence: z.ZodOptional; + worker: z.ZodOptional, z.ZodBoolean]>>; }, "strict", z.ZodTypeAny, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -10021,6 +10096,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -10032,6 +10108,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }>>; "javascript/dynamic": z.ZodOptional>; @@ -10044,6 +10121,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence: z.ZodOptional, z.ZodLiteral]>>; reexportExportsPresence: z.ZodOptional, z.ZodLiteral]>>; strictExportPresence: z.ZodOptional; + worker: z.ZodOptional, z.ZodBoolean]>>; }, "strict", z.ZodTypeAny, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -10055,6 +10133,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -10066,6 +10145,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }>>; "javascript/esm": z.ZodOptional>; @@ -10078,6 +10158,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence: z.ZodOptional, z.ZodLiteral]>>; reexportExportsPresence: z.ZodOptional, z.ZodLiteral]>>; strictExportPresence: z.ZodOptional; + worker: z.ZodOptional, z.ZodBoolean]>>; }, "strict", z.ZodTypeAny, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -10089,6 +10170,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }, { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; dynamicImportPreload?: number | boolean | undefined; @@ -10100,6 +10182,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; }>>; }, "strict", z.ZodTypeAny, { asset?: { @@ -10127,6 +10210,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/auto"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -10139,6 +10223,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/dynamic"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -10151,6 +10236,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/esm"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -10163,6 +10249,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; }, { asset?: { @@ -10190,6 +10277,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/auto"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -10202,6 +10290,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/dynamic"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -10214,6 +10303,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/esm"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -10226,6 +10316,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; }>, z.ZodRecord>]>>; generator: z.ZodOptional> | undefined; generator?: Record> | { @@ -10596,6 +10691,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/auto"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -10608,6 +10704,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/dynamic"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -10620,6 +10717,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/esm"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -10632,6 +10730,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; } | Record> | undefined; generator?: Record> | { @@ -11091,6 +11190,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/auto"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -11103,6 +11203,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/dynamic"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -11115,6 +11216,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/esm"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -11127,6 +11229,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; } | Record> | undefined; generator?: Record> | { @@ -11576,6 +11679,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/auto"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -11588,6 +11692,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/dynamic"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -11600,6 +11705,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; "javascript/esm"?: { dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once" | undefined; @@ -11612,6 +11718,7 @@ export const rspackOptions: z.ZodObject<{ importExportsPresence?: false | "error" | "warn" | "auto" | undefined; reexportExportsPresence?: false | "error" | "warn" | "auto" | undefined; strictExportPresence?: boolean | undefined; + worker?: boolean | string[] | undefined; } | undefined; } | Record> | undefined; generator?: Record> | { diff --git a/packages/rspack/src/config/adapter.ts b/packages/rspack/src/config/adapter.ts index 02fa2449bac..f079daba84f 100644 --- a/packages/rspack/src/config/adapter.ts +++ b/packages/rspack/src/config/adapter.ts @@ -642,10 +642,25 @@ function getRawJavascriptParserOptions( parser.reexportExportsPresence === false ? "false" : parser.reexportExportsPresence, - strictExportPresence: parser.strictExportPresence ?? false + strictExportPresence: parser.strictExportPresence ?? false, + worker: getRawJavascriptParserOptionsWorker(parser.worker!) }; } +function getRawJavascriptParserOptionsWorker( + worker: boolean | string[] +): RawJavascriptParserOptions["worker"] { + const DEFAULT_SYNTAX = [ + "Worker", + "SharedWorker", + // "navigator.serviceWorker.register()", + "Worker from worker_threads" + ]; + return ( + worker === false ? [] : Array.isArray(worker) ? worker : ["..."] + ).flatMap(item => (item === "..." ? DEFAULT_SYNTAX : item)); +} + function getRawAssetParserOptions( parser: AssetParserOptions ): RawAssetParserOptions { diff --git a/packages/rspack/src/config/defaults.ts b/packages/rspack/src/config/defaults.ts index a615741df71..5cc89526763 100644 --- a/packages/rspack/src/config/defaults.ts +++ b/packages/rspack/src/config/defaults.ts @@ -255,6 +255,7 @@ const applyJavascriptParserOptionsDefaults = ( "strictExportPresence", fallback?.strictExportPresence ?? false ); + D(parserOptions, "worker", fallback?.worker ?? ["..."]); }; const applyModuleDefaults = ( diff --git a/packages/rspack/src/config/zod.ts b/packages/rspack/src/config/zod.ts index bfbccffa00b..aa8068ec5bc 100644 --- a/packages/rspack/src/config/zod.ts +++ b/packages/rspack/src/config/zod.ts @@ -579,6 +579,7 @@ const reexportExportsPresence = z .enum(["error", "warn", "auto"]) .or(z.literal(false)); const strictExportPresence = z.boolean(); +const worker = z.array(z.string()).or(z.boolean()); const javascriptParserOptions = z.strictObject({ dynamicImportMode: dynamicImportMode.optional(), @@ -590,7 +591,8 @@ const javascriptParserOptions = z.strictObject({ exportsPresence: exportsPresence.optional(), importExportsPresence: importExportsPresence.optional(), reexportExportsPresence: reexportExportsPresence.optional(), - strictExportPresence: strictExportPresence.optional() + strictExportPresence: strictExportPresence.optional(), + worker: worker.optional() }); export type JavascriptParserOptions = z.infer; diff --git a/webpack-test/configCases/worker/custom-worker/node_modules/web-worker.js b/webpack-test/configCases/worker/custom-worker/node_modules/web-worker.js new file mode 100644 index 00000000000..b10d2db26a8 --- /dev/null +++ b/webpack-test/configCases/worker/custom-worker/node_modules/web-worker.js @@ -0,0 +1 @@ +export default Worker; diff --git a/webpack-test/configCases/worker/custom-worker/test.filter.js b/webpack-test/configCases/worker/custom-worker/test.filter.js index 24cbdd6ce6a..7039623344e 100644 --- a/webpack-test/configCases/worker/custom-worker/test.filter.js +++ b/webpack-test/configCases/worker/custom-worker/test.filter.js @@ -1,8 +1,5 @@ +var supportsWorker = require("../../../helpers/supportsWorker"); -// var supportsWorker = require("../../../helpers/supportsWorker"); - -// module.exports = function (config) { -// return supportsWorker(); -// }; - -module.exports = () => {return 'https://github.com/web-infra-dev/rspack/issues/3656'} \ No newline at end of file +module.exports = function (config) { + return supportsWorker(); +};