From 9284d3facf78e8d9d90ded3e64421f377d7e5778 Mon Sep 17 00:00:00 2001 From: Gengkun Date: Mon, 24 Jun 2024 19:13:36 +0800 Subject: [PATCH] feat: simple custom worker syntax (#6899) --- crates/node_binding/binding.d.ts | 1 + .../src/options/raw_module/mod.rs | 2 + crates/rspack_core/src/options/module.rs | 1 + .../src/parser_plugin/worker_plugin.rs | 128 ++++++++++++++---- .../src/visitors/dependency/parser/mod.rs | 4 +- crates/rspack_util/src/merge.rs | 7 + .../tests/__snapshots__/Defaults.test.js.snap | 12 ++ .../worker/custom-worker-call-syntax/index.js | 24 ++++ .../custom-worker-call-syntax/module.js | 3 + .../custom-worker-call-syntax/test.config.js | 8 ++ .../webpack.config.js | 17 +++ .../custom-worker-call-syntax/worker.js | 4 + packages/rspack/etc/api.md | 107 +++++++++++++++ packages/rspack/src/config/adapter.ts | 17 ++- packages/rspack/src/config/defaults.ts | 1 + packages/rspack/src/config/zod.ts | 4 +- .../custom-worker/node_modules/web-worker.js | 1 + .../worker/custom-worker/test.filter.js | 11 +- 18 files changed, 315 insertions(+), 37 deletions(-) create mode 100644 packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/index.js create mode 100644 packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/module.js create mode 100644 packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/test.config.js create mode 100644 packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/webpack.config.js create mode 100644 packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/worker.js create mode 100644 webpack-test/configCases/worker/custom-worker/node_modules/web-worker.js diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index ee2b06612db..0facd697875 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -1017,6 +1017,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 14771ee44f3..6e6e666dde9 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -4149,6 +4149,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; @@ -4160,6 +4161,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; @@ -4171,6 +4173,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) @@ -5142,6 +5145,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; @@ -5153,6 +5157,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; @@ -5164,6 +5169,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>; @@ -5176,6 +5182,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; @@ -5187,6 +5194,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; @@ -5198,6 +5206,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>; @@ -5210,6 +5219,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; @@ -5221,6 +5231,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; @@ -5232,6 +5243,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>; @@ -5244,6 +5256,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; @@ -5255,6 +5268,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; @@ -5266,6 +5280,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?: { @@ -5293,6 +5308,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; @@ -5305,6 +5321,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; @@ -5317,6 +5334,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; @@ -5329,6 +5347,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?: { @@ -5356,6 +5375,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; @@ -5368,6 +5388,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; @@ -5380,6 +5401,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; @@ -5392,6 +5414,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> | { @@ -5762,6 +5789,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; @@ -5774,6 +5802,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; @@ -5786,6 +5815,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; @@ -5798,6 +5828,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> | { @@ -7301,6 +7332,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; @@ -7312,6 +7344,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; @@ -7323,6 +7356,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>; @@ -7335,6 +7369,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; @@ -7346,6 +7381,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; @@ -7357,6 +7393,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>; @@ -7369,6 +7406,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; @@ -7380,6 +7418,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; @@ -7391,6 +7430,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>; @@ -7403,6 +7443,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; @@ -7414,6 +7455,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; @@ -7425,6 +7467,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?: { @@ -7452,6 +7495,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; @@ -7464,6 +7508,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; @@ -7476,6 +7521,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; @@ -7488,6 +7534,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?: { @@ -7515,6 +7562,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; @@ -7527,6 +7575,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; @@ -7539,6 +7588,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; @@ -7551,6 +7601,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>]>; @@ -7608,6 +7659,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; @@ -7619,6 +7671,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; @@ -7630,6 +7683,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>; @@ -7642,6 +7696,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; @@ -7653,6 +7708,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; @@ -7664,6 +7720,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>; @@ -7676,6 +7733,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; @@ -7687,6 +7745,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; @@ -7698,6 +7757,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>; @@ -7710,6 +7770,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; @@ -7721,6 +7782,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; @@ -7732,6 +7794,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?: { @@ -7759,6 +7822,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; @@ -7771,6 +7835,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; @@ -7783,6 +7848,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; @@ -7795,6 +7861,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?: { @@ -7822,6 +7889,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; @@ -7834,6 +7902,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; @@ -7846,6 +7915,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; @@ -7858,6 +7928,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; }>; @@ -9979,6 +10050,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; @@ -9990,6 +10062,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; @@ -10001,6 +10074,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>; @@ -10013,6 +10087,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; @@ -10024,6 +10099,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; @@ -10035,6 +10111,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>; @@ -10047,6 +10124,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; @@ -10058,6 +10136,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; @@ -10069,6 +10148,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>; @@ -10081,6 +10161,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; @@ -10092,6 +10173,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; @@ -10103,6 +10185,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?: { @@ -10130,6 +10213,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; @@ -10142,6 +10226,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; @@ -10154,6 +10239,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; @@ -10166,6 +10252,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?: { @@ -10193,6 +10280,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; @@ -10205,6 +10293,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; @@ -10217,6 +10306,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; @@ -10229,6 +10319,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> | { @@ -10599,6 +10694,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; @@ -10611,6 +10707,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; @@ -10623,6 +10720,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; @@ -10635,6 +10733,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> | { @@ -11094,6 +11193,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; @@ -11106,6 +11206,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; @@ -11118,6 +11219,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; @@ -11130,6 +11232,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> | { @@ -11579,6 +11682,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; @@ -11591,6 +11695,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; @@ -11603,6 +11708,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; @@ -11615,6 +11721,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(); +};