From f2bc023ffdb2cdc94dbb2463e3bbdf231fbfbc83 Mon Sep 17 00:00:00 2001 From: Hana Date: Mon, 8 Jul 2024 20:04:04 +0800 Subject: [PATCH] feat!: detect conflicting values in `DefinePlugin` (#7045) feat!: detect conflicting values in `DefinePlugin` (#7045) --------- Co-authored-by: ahabhgk --- Cargo.lock | 1 + .../src/options/raw_builtins/mod.rs | 10 +- .../raw_builtins/raw_to_be_deprecated.rs | 1 - .../rspack_core/src/compiler/compilation.rs | 6 + crates/rspack_core/src/lib.rs | 4 +- .../rspack_core/src/normal_module_factory.rs | 15 +- crates/rspack_core/src/options/builtins.rs | 30 +--- .../rspack_core/src/parser_and_generator.rs | 18 ++- crates/rspack_plugin_extract_css/Cargo.toml | 29 ++-- crates/rspack_plugin_extract_css/src/lib.rs | 4 +- .../src/parser_and_generator.rs | 143 ----------------- .../src/parser_plugin.rs | 80 ++++++++++ .../rspack_plugin_extract_css/src/plugin.rs | 64 ++++---- crates/rspack_plugin_javascript/src/lib.rs | 2 + .../src/parser_and_generator/mod.rs | 24 ++- .../src/parser_plugin/define_plugin.rs | 144 ++++++++++++++---- .../src/parser_plugin/mod.rs | 6 +- .../src/parser_plugin/trait.rs | 6 +- .../src/plugin/impl_plugin_for_js_plugin.rs | 33 ++-- .../src/visitors/dependency/mod.rs | 8 +- .../src/visitors/dependency/parser/mod.rs | 16 +- .../builtins/provide/rspack.config.js | 3 - .../plugins/define-plugin/index.js | 1 + .../plugins/define-plugin/rspack.config.js | 12 ++ .../plugins/define-plugin/stats.err | 2 + packages/rspack/src/builtin-plugin/index.ts | 3 +- tests/plugin-test/copy-plugin/build/main.js | 2 +- 27 files changed, 373 insertions(+), 294 deletions(-) delete mode 100644 crates/rspack_plugin_extract_css/src/parser_and_generator.rs create mode 100644 crates/rspack_plugin_extract_css/src/parser_plugin.rs create mode 100644 packages/rspack-test-tools/tests/diagnosticsCases/plugins/define-plugin/index.js create mode 100644 packages/rspack-test-tools/tests/diagnosticsCases/plugins/define-plugin/rspack.config.js create mode 100644 packages/rspack-test-tools/tests/diagnosticsCases/plugins/define-plugin/stats.err diff --git a/Cargo.lock b/Cargo.lock index 5783f3c07e8..7f5e6779bb4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3516,6 +3516,7 @@ dependencies = [ "rspack_hook", "rspack_identifier", "rspack_plugin_css", + "rspack_plugin_javascript", "rspack_plugin_runtime", "rspack_util", "rustc-hash 1.1.0", diff --git a/crates/rspack_binding_options/src/options/raw_builtins/mod.rs b/crates/rspack_binding_options/src/options/raw_builtins/mod.rs index f5ac70ff663..683c32e97b9 100644 --- a/crates/rspack_binding_options/src/options/raw_builtins/mod.rs +++ b/crates/rspack_binding_options/src/options/raw_builtins/mod.rs @@ -17,7 +17,7 @@ mod raw_to_be_deprecated; use napi::{bindgen_prelude::FromNapiValue, Env, JsUnknown}; use napi_derive::napi; use raw_lightning_css_minimizer::RawLightningCssMinimizerRspackPluginOptions; -use rspack_core::{BoxPlugin, Define, DefinePlugin, Plugin, PluginExt, Provide, ProvidePlugin}; +use rspack_core::{BoxPlugin, Plugin, PluginExt, Provide, ProvidePlugin}; use rspack_error::Result; use rspack_ids::{ DeterministicChunkIdsPlugin, DeterministicModuleIdsPlugin, NamedChunkIdsPlugin, @@ -43,9 +43,9 @@ use rspack_plugin_hmr::HotModuleReplacementPlugin; use rspack_plugin_html::HtmlRspackPlugin; use rspack_plugin_ignore::IgnorePlugin; use rspack_plugin_javascript::{ - api_plugin::APIPlugin, FlagDependencyExportsPlugin, FlagDependencyUsagePlugin, - InferAsyncModulesPlugin, JsPlugin, MangleExportsPlugin, ModuleConcatenationPlugin, - SideEffectsFlagPlugin, + api_plugin::APIPlugin, define_plugin::DefinePlugin, FlagDependencyExportsPlugin, + FlagDependencyUsagePlugin, InferAsyncModulesPlugin, JsPlugin, MangleExportsPlugin, + ModuleConcatenationPlugin, SideEffectsFlagPlugin, }; use rspack_plugin_json::JsonPlugin; use rspack_plugin_library::enable_library_plugin; @@ -191,7 +191,7 @@ impl BuiltinPlugin { match self.name { // webpack also have these plugins BuiltinPluginName::DefinePlugin => { - let plugin = DefinePlugin::new(downcast_into::(self.options)?).boxed(); + let plugin = DefinePlugin::new(downcast_into(self.options)?).boxed(); plugins.push(plugin); } BuiltinPluginName::ProvidePlugin => { diff --git a/crates/rspack_binding_options/src/options/raw_builtins/raw_to_be_deprecated.rs b/crates/rspack_binding_options/src/options/raw_builtins/raw_to_be_deprecated.rs index 22d2d28d8c4..bfd0b294864 100644 --- a/crates/rspack_binding_options/src/options/raw_builtins/raw_to_be_deprecated.rs +++ b/crates/rspack_binding_options/src/options/raw_builtins/raw_to_be_deprecated.rs @@ -121,7 +121,6 @@ pub struct RawBuiltins { impl RawBuiltins { pub fn apply(self) -> rspack_error::Result { Ok(Builtins { - define: Default::default(), provide: Default::default(), }) } diff --git a/crates/rspack_core/src/compiler/compilation.rs b/crates/rspack_core/src/compiler/compilation.rs index 4fce2b1a7b0..6cb8a5ff38b 100644 --- a/crates/rspack_core/src/compiler/compilation.rs +++ b/crates/rspack_core/src/compiler/compilation.rs @@ -119,6 +119,8 @@ impl Default for CompilationId { } } +type ValueCacheVersions = HashMap; + static COMPILATION_ID: AtomicU32 = AtomicU32::new(0); #[derive(Debug)] @@ -168,6 +170,8 @@ pub struct Compilation { pub missing_dependencies: IndexSet>, pub build_dependencies: IndexSet>, + pub value_cache_versions: ValueCacheVersions, + import_var_map: DashMap, pub module_executor: Option, @@ -250,6 +254,8 @@ impl Compilation { missing_dependencies: Default::default(), build_dependencies: Default::default(), + value_cache_versions: ValueCacheVersions::default(), + import_var_map: DashMap::new(), module_executor, diff --git a/crates/rspack_core/src/lib.rs b/crates/rspack_core/src/lib.rs index 76dd9866066..d63dfd29e58 100644 --- a/crates/rspack_core/src/lib.rs +++ b/crates/rspack_core/src/lib.rs @@ -94,7 +94,9 @@ pub use resolver::*; pub mod concatenated_module; pub mod reserved_names; -pub use rspack_loader_runner::{get_scheme, ResourceData, Scheme, BUILTIN_LOADER_PREFIX}; +pub use rspack_loader_runner::{ + get_scheme, AdditionalData, ResourceData, Scheme, BUILTIN_LOADER_PREFIX, +}; pub use rspack_macros::{impl_runtime_module, impl_source_map_config}; pub use rspack_sources; diff --git a/crates/rspack_core/src/normal_module_factory.rs b/crates/rspack_core/src/normal_module_factory.rs index 1d40807247c..fb7df515fac 100644 --- a/crates/rspack_core/src/normal_module_factory.rs +++ b/crates/rspack_core/src/normal_module_factory.rs @@ -14,9 +14,9 @@ use crate::{ stringify_loaders_and_resource, BoxLoader, BoxModule, CompilerOptions, Context, DependencyCategory, FuncUseCtx, GeneratorOptions, ModuleExt, ModuleFactory, ModuleFactoryCreateData, ModuleFactoryResult, ModuleIdentifier, ModuleRule, ModuleRuleEnforce, - ModuleRuleUse, ModuleRuleUseLoader, ModuleType, NormalModule, ParserOptions, RawModule, Resolve, - ResolveArgs, ResolveOptionsWithDependencyType, ResolveResult, Resolver, ResolverFactory, - ResourceData, ResourceParsedData, RunnerContext, SharedPluginDriver, + ModuleRuleUse, ModuleRuleUseLoader, ModuleType, NormalModule, ParserAndGenerator, ParserOptions, + RawModule, Resolve, ResolveArgs, ResolveOptionsWithDependencyType, ResolveResult, Resolver, + ResolverFactory, ResourceData, ResourceParsedData, RunnerContext, SharedPluginDriver, }; define_hook!(NormalModuleFactoryBeforeResolve: AsyncSeriesBail(data: &mut ModuleFactoryCreateData) -> bool); @@ -26,6 +26,7 @@ define_hook!(NormalModuleFactoryResolveForScheme: AsyncSeriesBail(data: &mut Mod define_hook!(NormalModuleFactoryAfterResolve: AsyncSeriesBail(data: &mut ModuleFactoryCreateData, create_data: &mut NormalModuleCreateData) -> bool); define_hook!(NormalModuleFactoryCreateModule: AsyncSeriesBail(data: &mut ModuleFactoryCreateData, create_data: &mut NormalModuleCreateData) -> BoxModule); define_hook!(NormalModuleFactoryModule: AsyncSeries(data: &mut ModuleFactoryCreateData, create_data: &mut NormalModuleCreateData, module: &mut BoxModule)); +define_hook!(NormalModuleFactoryParser: SyncSeries(module_type: &ModuleType, parser: &mut dyn ParserAndGenerator, parser_options: Option<&ParserOptions>)); define_hook!(NormalModuleFactoryResolveLoader: AsyncSeriesBail(context: &Context, resolver: &Resolver, l: &ModuleRuleUseLoader) -> BoxLoader); pub enum NormalModuleFactoryResolveResult { @@ -42,6 +43,7 @@ pub struct NormalModuleFactoryHooks { pub after_resolve: NormalModuleFactoryAfterResolveHook, pub create_module: NormalModuleFactoryCreateModuleHook, pub module: NormalModuleFactoryModuleHook, + pub parser: NormalModuleFactoryParserHook, /// Webpack resolves loaders in `NormalModuleFactory`, /// Rspack resolves it when normalizing configuration. /// So this hook is used to resolve inline loader (inline loader requests). @@ -500,7 +502,7 @@ impl NormalModuleFactory { resolved_generator_options, ); let resolved_side_effects = self.calculate_side_effects(&resolved_module_rules); - let resolved_parser_and_generator = self + let mut resolved_parser_and_generator = self .plugin_driver .registered_parser_and_generator_builder .get(&resolved_module_type) @@ -513,6 +515,11 @@ impl NormalModuleFactory { resolved_parser_options.as_ref(), resolved_generator_options.as_ref(), ); + self.plugin_driver.normal_module_factory_hooks.parser.call( + &resolved_module_type, + resolved_parser_and_generator.as_mut(), + resolved_parser_options.as_ref(), + )?; let mut create_data = { let mut create_data = NormalModuleCreateData { diff --git a/crates/rspack_core/src/options/builtins.rs b/crates/rspack_core/src/options/builtins.rs index 50eb365b8ce..4680c7ca658 100644 --- a/crates/rspack_core/src/options/builtins.rs +++ b/crates/rspack_core/src/options/builtins.rs @@ -1,36 +1,10 @@ use std::fmt::Debug; use rspack_error::Result; -pub use rspack_swc_visitors::{Define, Provide}; +pub use rspack_swc_visitors::Provide; use crate::{ApplyContext, CompilerOptions, Plugin, PluginContext}; -#[derive(Debug)] -pub struct DefinePlugin { - options: Define, -} - -impl DefinePlugin { - pub fn new(options: Define) -> Self { - Self { options } - } -} - -impl Plugin for DefinePlugin { - fn name(&self) -> &'static str { - "rspack.DefinePlugin" - } - - fn apply( - &self, - _ctx: PluginContext<&mut ApplyContext>, - options: &mut CompilerOptions, - ) -> Result<()> { - options.builtins.define.extend(self.options.clone()); - Ok(()) - } -} - #[derive(Debug)] pub struct ProvidePlugin { options: Provide, @@ -67,8 +41,6 @@ pub struct DecoratorOptions { #[derive(Debug, Clone, Default)] pub struct Builtins { - // TODO: refactor to string-replacement based - pub define: Define, // TODO: refactor to string-replacement based pub provide: Provide, } diff --git a/crates/rspack_core/src/parser_and_generator.rs b/crates/rspack_core/src/parser_and_generator.rs index 1709da460b4..5ea9387acf1 100644 --- a/crates/rspack_core/src/parser_and_generator.rs +++ b/crates/rspack_core/src/parser_and_generator.rs @@ -1,9 +1,11 @@ +use std::any::Any; use std::fmt::Debug; use derivative::Derivative; use rspack_error::{Result, TWithDiagnosticArray}; use rspack_loader_runner::{AdditionalData, ResourceData}; use rspack_sources::BoxSource; +use rspack_util::ext::AsAny; use rspack_util::source_map::SourceMapKind; use swc_core::common::Span; @@ -80,7 +82,7 @@ pub struct GenerateContext<'a> { pub concatenation_scope: Option<&'a mut ConcatenationScope>, } -pub trait ParserAndGenerator: Send + Sync + Debug { +pub trait ParserAndGenerator: Send + Sync + Debug + AsAny { /// The source types that the generator can generate (the source types you can make requests for) fn source_types(&self) -> &[SourceType]; /// Parse the source and return the dependencies and the ast or source @@ -102,3 +104,17 @@ pub trait ParserAndGenerator: Send + Sync + Debug { _cg: &ChunkGraph, ) -> Option; } + +impl dyn ParserAndGenerator + '_ { + pub fn downcast_ref(&self) -> Option<&D> { + self.as_any().downcast_ref::() + } + + pub fn downcast_mut(&mut self) -> Option<&mut D> { + self.as_any_mut().downcast_mut::() + } + + pub fn is(&self) -> bool { + self.downcast_ref::().is_some() + } +} diff --git a/crates/rspack_plugin_extract_css/Cargo.toml b/crates/rspack_plugin_extract_css/Cargo.toml index 14295ea9f2e..5446b5e319c 100644 --- a/crates/rspack_plugin_extract_css/Cargo.toml +++ b/crates/rspack_plugin_extract_css/Cargo.toml @@ -6,17 +6,18 @@ repository = "https://github.com/web-infra-dev/rspack" version = "0.1.0" [dependencies] -async-trait = { workspace = true } -once_cell = { workspace = true } -regex = { workspace = true } -rspack_core = { path = "../rspack_core" } -rspack_error = { path = "../rspack_error" } -rspack_hash = { path = "../rspack_hash" } -rspack_hook = { path = "../rspack_hook" } -rspack_identifier = { path = "../rspack_identifier" } -rspack_plugin_css = { path = "../rspack_plugin_css" } -rspack_plugin_runtime = { path = "../rspack_plugin_runtime" } -rspack_util = { path = "../rspack_util" } -rustc-hash = { workspace = true } -serde_json = { workspace = true } -ustr = { workspace = true } +async-trait = { workspace = true } +once_cell = { workspace = true } +regex = { workspace = true } +rspack_core = { path = "../rspack_core" } +rspack_error = { path = "../rspack_error" } +rspack_hash = { path = "../rspack_hash" } +rspack_hook = { path = "../rspack_hook" } +rspack_identifier = { path = "../rspack_identifier" } +rspack_plugin_css = { path = "../rspack_plugin_css" } +rspack_plugin_javascript = { path = "../rspack_plugin_javascript" } +rspack_plugin_runtime = { path = "../rspack_plugin_runtime" } +rspack_util = { path = "../rspack_util" } +rustc-hash = { workspace = true } +serde_json = { workspace = true } +ustr = { workspace = true } diff --git a/crates/rspack_plugin_extract_css/src/lib.rs b/crates/rspack_plugin_extract_css/src/lib.rs index 32b87987daa..02e3d420c32 100644 --- a/crates/rspack_plugin_extract_css/src/lib.rs +++ b/crates/rspack_plugin_extract_css/src/lib.rs @@ -1,7 +1,7 @@ #![feature(let_chains)] pub mod css_dependency; mod css_module; -mod parser_and_generator; -pub use parser_and_generator::{CssExtractJsonData, CssExtractJsonDataList}; +mod parser_plugin; +pub use parser_plugin::{CssExtractJsonData, CssExtractJsonDataList}; pub mod plugin; mod runtime; diff --git a/crates/rspack_plugin_extract_css/src/parser_and_generator.rs b/crates/rspack_plugin_extract_css/src/parser_and_generator.rs deleted file mode 100644 index 849effb6b75..00000000000 --- a/crates/rspack_plugin_extract_css/src/parser_and_generator.rs +++ /dev/null @@ -1,143 +0,0 @@ -use std::path::PathBuf; - -use rspack_core::{ChunkGraph, Dependency, Module, ModuleGraph, ParserAndGenerator}; -use rspack_error::TWithDiagnosticArray; -use rustc_hash::FxHashMap; - -use crate::css_dependency::CssDependency; - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct CssExtractJsonData { - pub identifier: String, - pub content: String, - pub context: String, - pub media: String, - pub supports: String, - pub source_map: String, - pub identifier_index: u32, - pub filepath: PathBuf, -} - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct CssExtractJsonDataList(pub Vec); - -#[derive(Debug)] -pub(crate) struct CssExtractParserAndGenerator { - orig_parser_generator: Box, - #[allow(clippy::vec_box)] - cache: FxHashMap>>, -} - -impl CssExtractParserAndGenerator { - pub(crate) fn new(orig_parser_generator: Box) -> Self { - Self { - orig_parser_generator, - cache: Default::default(), - } - } -} - -impl ParserAndGenerator for CssExtractParserAndGenerator { - fn source_types(&self) -> &[rspack_core::SourceType] { - self.orig_parser_generator.source_types() - } - - fn get_concatenation_bailout_reason( - &self, - module: &dyn Module, - mg: &ModuleGraph, - cg: &ChunkGraph, - ) -> Option { - self - .orig_parser_generator - .get_concatenation_bailout_reason(module, mg, cg) - } - - #[allow(clippy::unwrap_used)] - fn parse( - &mut self, - parse_context: rspack_core::ParseContext, - ) -> rspack_error::Result> { - let deps = if let Some(additional_data) = parse_context - .additional_data - .get::() - { - if let Some(deps) = self.cache.get(additional_data) { - deps.clone() - } else { - let mut idx = 0; - let deps = additional_data - .0 - .iter() - .map( - |CssExtractJsonData { - identifier, - content, - context, - media, - supports, - source_map, - identifier_index, - .. - }| { - let dep = Box::new(CssDependency::new( - identifier.into(), - content.clone(), - context.clone(), - media.clone(), - supports.clone(), - source_map.clone(), - *identifier_index, - idx, - parse_context.build_info.cacheable, - parse_context.build_info.file_dependencies.clone(), - parse_context.build_info.context_dependencies.clone(), - parse_context.build_info.missing_dependencies.clone(), - parse_context.build_info.build_dependencies.clone(), - )); - idx += 1; - dep - }, - ) - .collect::>(); - self.cache.insert(additional_data.clone(), deps.clone()); - deps - } - } else { - vec![] - }; - - let result = self.orig_parser_generator.parse(parse_context); - - if let Ok(result) = result { - let (mut res, diags) = result.split_into_parts(); - - res - .dependencies - .extend(deps.into_iter().map(|dep| dep as Box)); - - Ok(TWithDiagnosticArray::new(res, diags)) - } else { - result - } - } - - fn size( - &self, - module: &dyn rspack_core::Module, - source_type: Option<&rspack_core::SourceType>, - ) -> f64 { - self.orig_parser_generator.size(module, source_type) - } - - fn generate( - &self, - source: &rspack_core::rspack_sources::BoxSource, - module: &dyn rspack_core::Module, - generate_context: &mut rspack_core::GenerateContext, - ) -> rspack_error::Result { - self - .orig_parser_generator - .generate(source, module, generate_context) - } -} diff --git a/crates/rspack_plugin_extract_css/src/parser_plugin.rs b/crates/rspack_plugin_extract_css/src/parser_plugin.rs new file mode 100644 index 00000000000..dcc4fd91233 --- /dev/null +++ b/crates/rspack_plugin_extract_css/src/parser_plugin.rs @@ -0,0 +1,80 @@ +use std::path::PathBuf; + +use rspack_core::BoxDependency; +use rspack_plugin_javascript::{visitors::JavascriptParser, JavascriptParserPlugin}; +use rspack_util::fx_hash::FxDashMap; + +use crate::css_dependency::CssDependency; + +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct CssExtractJsonData { + pub identifier: String, + pub content: String, + pub context: String, + pub media: String, + pub supports: String, + pub source_map: String, + pub identifier_index: u32, + pub filepath: PathBuf, +} + +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct CssExtractJsonDataList(pub Vec); + +#[derive(Debug, Default)] +pub struct PluginCssExtractParserPlugin { + cache: FxDashMap>, +} + +impl JavascriptParserPlugin for PluginCssExtractParserPlugin { + fn finish(&self, parser: &mut JavascriptParser) -> Option { + let deps = if let Some(additional_data) = parser.additional_data.get::() + { + if let Some(deps) = self.cache.get(additional_data) { + deps.clone() + } else { + let mut idx = 0; + let deps = additional_data + .0 + .iter() + .map( + |CssExtractJsonData { + identifier, + content, + context, + media, + supports, + source_map, + identifier_index, + .. + }| { + let dep = Box::new(CssDependency::new( + identifier.into(), + content.clone(), + context.clone(), + media.clone(), + supports.clone(), + source_map.clone(), + *identifier_index, + idx, + parser.build_info.cacheable, + parser.build_info.file_dependencies.clone(), + parser.build_info.context_dependencies.clone(), + parser.build_info.missing_dependencies.clone(), + parser.build_info.build_dependencies.clone(), + )); + idx += 1; + dep as BoxDependency + }, + ) + .collect::>(); + self.cache.insert(additional_data.clone(), deps.clone()); + deps + } + } else { + vec![] + }; + parser.dependencies.extend(deps); + None + } +} diff --git a/crates/rspack_plugin_extract_css/src/plugin.rs b/crates/rspack_plugin_extract_css/src/plugin.rs index ede58083d4d..d732f1d9c5f 100644 --- a/crates/rspack_plugin_extract_css/src/plugin.rs +++ b/crates/rspack_plugin_extract_css/src/plugin.rs @@ -1,9 +1,4 @@ -use std::{ - borrow::Cow, - cmp::max, - hash::Hash, - sync::{atomic::AtomicBool, Arc}, -}; +use std::{borrow::Cow, cmp::max, hash::Hash, sync::Arc}; use once_cell::sync::Lazy; use regex::Regex; @@ -12,19 +7,22 @@ use rspack_core::{ ApplyContext, AssetInfo, Chunk, ChunkGroupUkey, ChunkKind, ChunkUkey, Compilation, CompilationContentHash, CompilationParams, CompilationRenderManifest, CompilationRuntimeRequirementInTree, CompilerCompilation, CompilerOptions, Filename, Module, - ModuleGraph, ModuleIdentifier, ModuleType, PathData, Plugin, PluginContext, RenderManifestEntry, - RuntimeGlobals, SourceType, + ModuleGraph, ModuleIdentifier, ModuleType, NormalModuleFactoryParser, ParserAndGenerator, + ParserOptions, PathData, Plugin, PluginContext, RenderManifestEntry, RuntimeGlobals, SourceType, }; use rspack_error::{Diagnostic, Result}; use rspack_hash::RspackHash; use rspack_hook::{plugin, plugin_hook}; +use rspack_plugin_javascript::{ + parser_and_generator::JavaScriptParserAndGenerator, BoxJavascriptParserPlugin, +}; use rspack_plugin_runtime::GetChunkFilenameRuntimeModule; use rustc_hash::{FxHashMap, FxHashSet}; use ustr::Ustr; use crate::{ css_module::{CssModule, CssModuleFactory, DEPENDENCY_TYPE}, - parser_and_generator::CssExtractParserAndGenerator, + parser_plugin::PluginCssExtractParserPlugin, runtime::CssLoadingRuntimeModule, }; pub static PLUGIN_NAME: &str = "css-extract-rspack-plugin"; @@ -64,7 +62,6 @@ struct CssOrderConflicts { #[derive(Debug)] pub struct PluginCssExtract { pub(crate) options: Arc, - registered: AtomicBool, } impl Eq for PluginCssExtractInner {} @@ -119,7 +116,7 @@ pub enum InsertType { impl PluginCssExtract { pub fn new(options: CssExtractOptions) -> Self { - Self::new_inner(Arc::new(options), false.into()) + Self::new_inner(Arc::new(options)) } // port from https://github.com/webpack-contrib/mini-css-extract-plugin/blob/d5e540baf8280442e523530ebbbe31c57a4c4336/src/index.js#L1127 @@ -435,28 +432,6 @@ async fn compilation( _params: &mut CompilationParams, ) -> Result<()> { compilation.set_dependency_factory(DEPENDENCY_TYPE.clone(), Arc::new(CssModuleFactory)); - - if !self - .registered - .swap(true, std::sync::atomic::Ordering::Relaxed) - { - let (_, parser_and_generator) = compilation - .plugin_driver - .registered_parser_and_generator_builder - .remove(&ModuleType::JsAuto) - .expect("No JavaScript parser registered"); - - compilation - .plugin_driver - .registered_parser_and_generator_builder - .insert( - ModuleType::JsAuto, - Box::new(move |parser_opt, generator_opt| { - let parser = parser_and_generator(parser_opt, generator_opt); - Box::new(CssExtractParserAndGenerator::new(parser)) - }), - ); - } Ok(()) } @@ -677,6 +652,23 @@ despite it was not able to fulfill desired ordering with these modules:\n{}", Ok(()) } +#[plugin_hook(NormalModuleFactoryParser for PluginCssExtract)] +fn nmf_parser( + &self, + module_type: &ModuleType, + parser: &mut dyn ParserAndGenerator, + _parser_options: Option<&ParserOptions>, +) -> Result<()> { + if module_type.is_js_like() + && let Some(parser) = parser.downcast_mut::() + { + parser.add_parser_plugin( + Box::::default() as BoxJavascriptParserPlugin + ); + } + Ok(()) +} + #[async_trait::async_trait] impl Plugin for PluginCssExtract { fn apply( @@ -705,6 +697,12 @@ impl Plugin for PluginCssExtract { .render_manifest .tap(render_manifest::new(self)); + ctx + .context + .normal_module_factory_hooks + .parser + .tap(nmf_parser::new(self)); + Ok(()) } } diff --git a/crates/rspack_plugin_javascript/src/lib.rs b/crates/rspack_plugin_javascript/src/lib.rs index 58fcfbae6fb..8284889d696 100644 --- a/crates/rspack_plugin_javascript/src/lib.rs +++ b/crates/rspack_plugin_javascript/src/lib.rs @@ -13,6 +13,8 @@ pub mod runtime; pub mod utils; pub mod visitors; mod webpack_comment; +pub use parser_plugin::*; + pub use crate::plugin::infer_async_modules_plugin::InferAsyncModulesPlugin; pub use crate::plugin::*; diff --git a/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs b/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs index d2e1edba3b5..46a93e62708 100644 --- a/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs +++ b/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs @@ -21,13 +21,26 @@ use swc_node_comments::SwcComments; use crate::dependency::HarmonyCompatibilityDependency; use crate::visitors::{scan_dependencies, swc_visitor::resolver}; use crate::visitors::{semicolon, PathIgnoredSpans, ScanDependenciesResult}; -use crate::{SideEffectsFlagPluginVisitor, SyntaxContextInfo}; +use crate::{BoxJavascriptParserPlugin, SideEffectsFlagPluginVisitor, SyntaxContextInfo}; -#[derive(Debug)] -pub struct JavaScriptParserAndGenerator; +#[derive(Default)] +pub struct JavaScriptParserAndGenerator { + parser_plugins: Vec, +} + +impl std::fmt::Debug for JavaScriptParserAndGenerator { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("JavaScriptParserAndGenerator") + .field("parser_plugins", &"...") + .finish() + } +} -#[allow(unused)] impl JavaScriptParserAndGenerator { + pub fn add_parser_plugin(&mut self, parser_plugin: BoxJavascriptParserPlugin) { + self.parser_plugins.push(parser_plugin); + } + fn source_block( &self, compilation: &Compilation, @@ -89,6 +102,7 @@ impl ParserAndGenerator for JavaScriptParserAndGenerator { module_identifier, loaders, module_parser_options, + additional_data, .. } = parse_context; let mut diagnostics: Vec> = vec![]; @@ -187,6 +201,8 @@ impl ParserAndGenerator for JavaScriptParserAndGenerator { &mut semicolons, &mut path_ignored_spans, unresolved_mark, + &mut self.parser_plugins, + additional_data, ) }) { Ok(result) => result, diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/define_plugin.rs b/crates/rspack_plugin_javascript/src/parser_plugin/define_plugin.rs index 383c4a1e4a5..8ddbef5bde9 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/define_plugin.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/define_plugin.rs @@ -1,22 +1,125 @@ use std::collections::HashMap; use once_cell::sync::OnceCell; -use rspack_core::{ConstDependency, Plugin, SpanExt}; +use rspack_core::{ + ApplyContext, Compilation, CompilationParams, CompilerCompilation, CompilerOptions, + ConstDependency, ModuleType, NormalModuleFactoryParser, ParserAndGenerator, ParserOptions, + Plugin, PluginContext, SpanExt, +}; +use rspack_error::{ + miette::{self, Diagnostic}, + thiserror::{self, Error}, + DiagnosticExt, Result, +}; +use rspack_hook::{plugin, plugin_hook}; use swc_core::common::Spanned; -use crate::{parser_plugin::JavascriptParserPlugin, visitors::JavascriptParser}; +use crate::{ + parser_and_generator::JavaScriptParserAndGenerator, parser_plugin::JavascriptParserPlugin, + visitors::JavascriptParser, BoxJavascriptParserPlugin, +}; type DefineValue = HashMap; -#[derive(Debug, Default)] +#[plugin] +#[derive(Debug, Default, Clone)] pub struct DefinePlugin { + definitions: DefineValue, cached_names: OnceCell>, } +impl DefinePlugin { + pub fn new(definitions: DefineValue) -> Self { + Self::new_inner(definitions, OnceCell::new()) + } + + fn cached_names(&self) -> &Vec { + self.cached_names.get_or_init(|| { + let names = self.definitions.keys(); + names + .flat_map(|name| { + let splitted: Vec<&str> = name.split('.').collect(); + let mut val = if !splitted.is_empty() { + (0..splitted.len() - 1) + .map(|i| splitted[0..i + 1].join(".")) + .collect::>() + } else { + vec![] + }; + // !isTypeof + val.push(name.to_string()); + val + }) + .collect() + }) + } +} + +#[derive(Debug, Error, Diagnostic)] +#[error("DefinePlugin:\nConflicting values for '{0}' ('{1}' !== '{2}')")] +#[diagnostic(severity(Warning))] +struct ConflictingValuesError(String, String, String); + +#[plugin_hook(CompilerCompilation for DefinePlugin)] +async fn compilation( + &self, + compilation: &mut Compilation, + _params: &mut CompilationParams, +) -> Result<()> { + self.definitions.iter().for_each(|(key, value)| { + let name = format!("{VALUE_DEP_PREFIX}{key}"); + if let Some(prev) = compilation.value_cache_versions.get(&name) + && prev != value + { + compilation.push_diagnostic( + ConflictingValuesError(key.to_string(), prev.clone(), value.clone()) + .boxed() + .into(), + ); + } else { + compilation.value_cache_versions.insert(name, value.clone()); + } + }); + Ok(()) +} + +#[plugin_hook(NormalModuleFactoryParser for DefinePlugin)] +fn nmf_parser( + &self, + module_type: &ModuleType, + parser: &mut dyn ParserAndGenerator, + _parser_options: Option<&ParserOptions>, +) -> Result<()> { + if module_type.is_js_like() + && let Some(parser) = parser.downcast_mut::() + { + parser.add_parser_plugin(Box::new(self.clone()) as BoxJavascriptParserPlugin); + } + Ok(()) +} + impl Plugin for DefinePlugin { fn name(&self) -> &'static str { "rspack.DefinePlugin" } + + fn apply( + &self, + ctx: PluginContext<&mut ApplyContext>, + _options: &mut CompilerOptions, + ) -> Result<()> { + ctx + .context + .compiler_hooks + .compilation + .tap(compilation::new(self)); + ctx + .context + .normal_module_factory_hooks + .parser + .tap(nmf_parser::new(self)); + Ok(()) + } } fn dep( @@ -41,31 +144,14 @@ fn dep( None } -impl JavascriptParserPlugin for DefinePlugin { - fn can_rename(&self, parser: &mut JavascriptParser, str: &str) -> Option { - let names = self.cached_names.get_or_init(|| { - let names = parser.compiler_options.builtins.define.keys(); - names - .flat_map(|name| { - let splitted: Vec<&str> = name.split('.').collect(); - let mut val = if !splitted.is_empty() { - (0..splitted.len() - 1) - .map(|i| splitted[0..i + 1].join(".")) - .collect::>() - } else { - vec![] - }; - // !isTypeof - val.push(name.to_string()); - val - }) - .collect::>() - }); +const VALUE_DEP_PREFIX: &str = "webpack/DefinePlugin "; - if names.iter().any(|l| *l == str) { +impl JavascriptParserPlugin for DefinePlugin { + fn can_rename(&self, _: &mut JavascriptParser, str: &str) -> Option { + let names = self.cached_names(); + if names.iter().any(|l: &String| l.eq(str)) { return Some(true); } - None } @@ -76,7 +162,7 @@ impl JavascriptParserPlugin for DefinePlugin { start: u32, end: u32, ) -> Option { - if let Some(val) = parser.compiler_options.builtins.define.get(ident) { + if let Some(val) = self.definitions.get(ident) { return parser .evaluate(val.to_string(), "DefinePlugin".to_string()) .map(|mut evaluated| { @@ -96,7 +182,7 @@ impl JavascriptParserPlugin for DefinePlugin { dep( parser, for_name, - &parser.compiler_options.builtins.define, + &self.definitions, expr.callee.span().real_lo(), expr.callee.span().real_hi(), !parser.is_asi_position(expr.span_lo()), @@ -118,7 +204,7 @@ impl JavascriptParserPlugin for DefinePlugin { dep( parser, for_name, - &parser.compiler_options.builtins.define, + &self.definitions, expr.span().real_lo(), expr.span().real_hi(), !parser.is_asi_position(expr.span_lo()), @@ -138,7 +224,7 @@ impl JavascriptParserPlugin for DefinePlugin { dep( parser, for_name, - &parser.compiler_options.builtins.define, + &self.definitions, ident.span.real_lo(), ident.span.real_hi(), !parser.is_asi_position(ident.span_lo()), diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/mod.rs b/crates/rspack_plugin_javascript/src/parser_plugin/mod.rs index 600de35b43e..a61d89efa56 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/mod.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/mod.rs @@ -5,7 +5,6 @@ mod common_js_imports_parse_plugin; mod common_js_plugin; mod compatibility_plugin; mod r#const; -mod define_plugin; mod drive; mod exports_info_api_plugin; mod harmony_detection_parser_plugin; @@ -28,13 +27,14 @@ mod use_strict_plugin; mod webpack_included_plugin; mod worker_plugin; +pub mod define_plugin; + pub(crate) use self::api_plugin::APIPlugin; pub(crate) use self::check_var_decl::CheckVarDeclaratorIdent; pub(crate) use self::common_js_exports_parse_plugin::CommonJsExportsParserPlugin; pub(crate) use self::common_js_imports_parse_plugin::CommonJsImportsParserPlugin; pub(crate) use self::common_js_plugin::CommonJsPlugin; pub(crate) use self::compatibility_plugin::CompatibilityPlugin; -pub(crate) use self::define_plugin::DefinePlugin; pub(crate) use self::drive::JavaScriptParserPluginDrive; pub(crate) use self::exports_info_api_plugin::ExportsInfoApiPlugin; pub(crate) use self::harmony_detection_parser_plugin::HarmonyDetectionParserPlugin; @@ -51,7 +51,7 @@ pub(crate) use self::javascript_meta_info_plugin::JavascriptMetaInfoPlugin; pub(crate) use self::node_stuff_plugin::NodeStuffPlugin; pub(crate) use self::provide_plugin::ProviderPlugin; pub(crate) use self::r#const::{is_logic_op, ConstPlugin}; -pub(crate) use self::r#trait::{BoxJavascriptParserPlugin, JavascriptParserPlugin}; +pub use self::r#trait::{BoxJavascriptParserPlugin, JavascriptParserPlugin}; pub(crate) use self::require_context_dependency_parser_plugin::RequireContextDependencyParserPlugin; pub(crate) use self::url_plugin::URLPlugin; pub(crate) use self::use_strict_plugin::UseStrictPlugin; diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/trait.rs b/crates/rspack_plugin_javascript/src/parser_plugin/trait.rs index 081e64ad3c2..cb91128a62c 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/trait.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/trait.rs @@ -13,6 +13,10 @@ use crate::visitors::{ClassDeclOrExpr, ExportedVariableInfo, JavascriptParser}; type KeepRight = bool; pub trait JavascriptParserPlugin { + fn name(&self) -> &'static str { + "unknown" + } + /// Return: /// - `Some(true)` signifies the termination of the current /// statement's visit during the pre-walk phase. @@ -378,4 +382,4 @@ pub trait JavascriptParserPlugin { } } -pub type BoxJavascriptParserPlugin = Box; +pub type BoxJavascriptParserPlugin = Box; diff --git a/crates/rspack_plugin_javascript/src/plugin/impl_plugin_for_js_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/impl_plugin_for_js_plugin.rs index 901b0c305ff..7c036e6ebba 100644 --- a/crates/rspack_plugin_javascript/src/plugin/impl_plugin_for_js_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/impl_plugin_for_js_plugin.rs @@ -310,18 +310,27 @@ impl Plugin for JsPlugin { .render_manifest .tap(render_manifest::new(self)); - ctx.context.register_parser_and_generator_builder( - ModuleType::JsAuto, - Box::new(|_, _| Box::new(JavaScriptParserAndGenerator) as Box), - ); - ctx.context.register_parser_and_generator_builder( - ModuleType::JsEsm, - Box::new(|_, _| Box::new(JavaScriptParserAndGenerator) as Box), - ); - ctx.context.register_parser_and_generator_builder( - ModuleType::JsDynamic, - Box::new(|_, _| Box::new(JavaScriptParserAndGenerator) as Box), - ); + ctx + .context + .register_parser_and_generator_builder(ModuleType::JsAuto, { + Box::new(move |_, _| { + Box::::default() as Box + }) + }); + ctx + .context + .register_parser_and_generator_builder(ModuleType::JsEsm, { + Box::new(move |_, _| { + Box::::default() as Box + }) + }); + ctx + .context + .register_parser_and_generator_builder(ModuleType::JsDynamic, { + Box::new(move |_, _| { + Box::::default() as Box + }) + }); Ok(()) } diff --git a/crates/rspack_plugin_javascript/src/visitors/dependency/mod.rs b/crates/rspack_plugin_javascript/src/visitors/dependency/mod.rs index 61467e70d0d..c0fabd852ec 100644 --- a/crates/rspack_plugin_javascript/src/visitors/dependency/mod.rs +++ b/crates/rspack_plugin_javascript/src/visitors/dependency/mod.rs @@ -6,7 +6,8 @@ use std::sync::Arc; use rspack_ast::javascript::Program; use rspack_core::{ - AsyncDependenciesBlock, BoxDependency, BoxDependencyTemplate, BuildInfo, ParserOptions, + AdditionalData, AsyncDependenciesBlock, BoxDependency, BoxDependencyTemplate, BuildInfo, + ParserOptions, }; use rspack_core::{BuildMeta, CompilerOptions, ModuleIdentifier, ModuleType, ResourceData}; use rspack_error::miette::Diagnostic; @@ -24,6 +25,7 @@ pub use self::parser::{ }; pub use self::util::*; use crate::dependency::Specifier; +use crate::BoxJavascriptParserPlugin; #[derive(Debug)] pub struct ImporterReferenceInfo { @@ -79,6 +81,8 @@ pub fn scan_dependencies( semicolons: &mut FxHashSet, path_ignored_spans: &mut PathIgnoredSpans, unresolved_mark: Mark, + parser_plugins: &mut Vec, + additional_data: AdditionalData, ) -> Result>> { let mut parser = JavascriptParser::new( source_map, @@ -96,6 +100,8 @@ pub fn scan_dependencies( semicolons, path_ignored_spans, unresolved_mark, + parser_plugins, + additional_data, ); parser.walk_program(program.get_inner_program()); 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 75e29d7a997..ec4e83918ee 100644 --- a/crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs +++ b/crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs @@ -11,7 +11,7 @@ use std::sync::Arc; use bitflags::bitflags; pub use call_hooks_name::CallHooksName; use rspack_core::{ - AsyncDependenciesBlock, BoxDependency, BuildInfo, BuildMeta, DependencyTemplate, + AdditionalData, AsyncDependenciesBlock, BoxDependency, BuildInfo, BuildMeta, DependencyTemplate, JavascriptParserOptions, ModuleIdentifier, ResourceData, }; use rspack_core::{CompilerOptions, JavascriptParserUrl, ModuleType, SpanExt}; @@ -37,6 +37,7 @@ use crate::utils::eval::{self, BasicEvaluatedExpression}; use crate::visitors::scope_info::{ FreeName, ScopeInfoDB, ScopeInfoId, TagInfo, TagInfoId, VariableInfo, VariableInfoId, }; +use crate::BoxJavascriptParserPlugin; pub trait TagInfoData: Clone + Sized + 'static { fn into_any(data: Self) -> Box; @@ -248,17 +249,19 @@ pub struct JavascriptParser<'parser> { pub(crate) source_file: &'parser SourceFile, pub(crate) errors: Vec>, pub(crate) warning_diagnostics: Vec>, - pub(crate) dependencies: Vec, + pub dependencies: Vec, pub(crate) presentational_dependencies: Vec>, pub(crate) blocks: Vec, // TODO: remove `import_map` pub(crate) import_map: ImportMap, // TODO: remove `rewrite_usage_span` pub(crate) rewrite_usage_span: FxHashMap, + // TODO: remove `additional_data` once we have builtin:css-extract-loader + pub additional_data: AdditionalData, pub(crate) comments: Option<&'parser dyn Comments>, pub(crate) worker_index: u32, pub(crate) build_meta: &'parser mut BuildMeta, - pub(crate) build_info: &'parser mut BuildInfo, + pub build_info: &'parser mut BuildInfo, pub(crate) resource_data: &'parser ResourceData, pub(crate) plugin_drive: Rc, pub(crate) definitions_db: ScopeInfoDB, @@ -307,6 +310,8 @@ impl<'parser> JavascriptParser<'parser> { semicolons: &'parser mut FxHashSet, path_ignored_spans: &'parser mut PathIgnoredSpans, unresolved_mark: Mark, + parser_plugins: &'parser mut Vec, + additional_data: AdditionalData, ) -> Self { let warning_diagnostics: Vec> = Vec::with_capacity(32); let errors = Vec::with_capacity(32); @@ -373,9 +378,6 @@ impl<'parser> JavascriptParser<'parser> { if !compiler_options.builtins.provide.is_empty() { plugins.push(Box::::default()); } - if !compiler_options.builtins.define.is_empty() { - plugins.push(Box::::default()); - } plugins.push(Box::new(parser_plugin::WebpackIsIncludedPlugin)); plugins.push(Box::new(parser_plugin::ExportsInfoApiPlugin)); plugins.push(Box::new(parser_plugin::APIPlugin::new( @@ -398,6 +400,7 @@ impl<'parser> JavascriptParser<'parser> { unresolved_mark, ))); } + plugins.append(parser_plugins); let plugin_drive = Rc::new(JavaScriptParserPluginDrive::new(plugins)); let mut db = ScopeInfoDB::new(); @@ -440,6 +443,7 @@ impl<'parser> JavascriptParser<'parser> { prev_statement: None, path_ignored_spans, inner_graph: InnerGraphState::new(), + additional_data, } } diff --git a/packages/rspack-test-tools/tests/configCases/builtins/provide/rspack.config.js b/packages/rspack-test-tools/tests/configCases/builtins/provide/rspack.config.js index 72c09fb0a9c..bec2f05a99c 100644 --- a/packages/rspack-test-tools/tests/configCases/builtins/provide/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/builtins/provide/rspack.config.js @@ -5,9 +5,6 @@ module.exports = { entry: { main: ["./index.js"] }, - optimization: { - nodeEnv: false, - }, plugins: [ new rspack.ProvidePlugin({ aaa: "./aaa", diff --git a/packages/rspack-test-tools/tests/diagnosticsCases/plugins/define-plugin/index.js b/packages/rspack-test-tools/tests/diagnosticsCases/plugins/define-plugin/index.js new file mode 100644 index 00000000000..9eab39183ac --- /dev/null +++ b/packages/rspack-test-tools/tests/diagnosticsCases/plugins/define-plugin/index.js @@ -0,0 +1 @@ +if (process.env.NODE_ENV === "production") {} diff --git a/packages/rspack-test-tools/tests/diagnosticsCases/plugins/define-plugin/rspack.config.js b/packages/rspack-test-tools/tests/diagnosticsCases/plugins/define-plugin/rspack.config.js new file mode 100644 index 00000000000..c3c46bdd088 --- /dev/null +++ b/packages/rspack-test-tools/tests/diagnosticsCases/plugins/define-plugin/rspack.config.js @@ -0,0 +1,12 @@ +const rspack = require("@rspack/core") + +module.exports = { + optimization: { + nodeEnv: "development" + }, + plugins: [ + new rspack.DefinePlugin({ + "process.env.NODE_ENV": JSON.stringify("production") + }) + ] +} diff --git a/packages/rspack-test-tools/tests/diagnosticsCases/plugins/define-plugin/stats.err b/packages/rspack-test-tools/tests/diagnosticsCases/plugins/define-plugin/stats.err new file mode 100644 index 00000000000..38f1f05a41c --- /dev/null +++ b/packages/rspack-test-tools/tests/diagnosticsCases/plugins/define-plugin/stats.err @@ -0,0 +1,2 @@ +WARNING in ⚠ DefinePlugin: + │ Conflicting values for 'process.env.NODE_ENV' ('"production"' !== '"development"') \ No newline at end of file diff --git a/packages/rspack/src/builtin-plugin/index.ts b/packages/rspack/src/builtin-plugin/index.ts index 1b96f5eee8c..b7fdeb56087 100644 --- a/packages/rspack/src/builtin-plugin/index.ts +++ b/packages/rspack/src/builtin-plugin/index.ts @@ -1,9 +1,10 @@ +export { RspackBuiltinPlugin } from "./base"; + export * from "./APIPlugin"; export * from "./ArrayPushCallbackChunkFormatPlugin"; export * from "./AssetModulesPlugin"; export * from "./AsyncWebAssemblyModulesPlugin"; export * from "./BannerPlugin"; -export { RspackBuiltinPlugin } from "./base"; export * from "./BundlerInfoRspackPlugin"; export * from "./ChunkPrefetchPreloadPlugin"; export * from "./CommonJsChunkFormatPlugin"; diff --git a/tests/plugin-test/copy-plugin/build/main.js b/tests/plugin-test/copy-plugin/build/main.js index 3104eb78b91..b93be575ad4 100644 --- a/tests/plugin-test/copy-plugin/build/main.js +++ b/tests/plugin-test/copy-plugin/build/main.js @@ -1 +1 @@ -(()=>{"use strict";var r={},t={};function e(i){var o=t[i];if(void 0!==o)return o.exports;var n=t[i]={exports:{}};return r[i](n,n.exports,e),n.exports}e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(r){if("object"==typeof window)return window}}(),e.rv=function(){return"1.0.0-alpha.1"},(()=>{e.g.importScripts&&(r=e.g.location+"");var r,t=e.g.document;if(!r&&t&&(t.currentScript&&(r=t.currentScript.src),!r)){var i=t.getElementsByTagName("script");if(i.length){for(var o=i.length-1;o>-1&&(!r||!/^http(s?):/.test(r));)r=i[o--].src}}if(!r)throw Error("Automatic publicPath is not supported in this browser");r=r.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),e.p=r})(),e.ruid="bundler=rspack@1.0.0-alpha.1";e.p})(); \ No newline at end of file +(()=>{"use strict";var r={},t={};function e(i){var o=t[i];if(void 0!==o)return o.exports;var n=t[i]={exports:{}};return r[i](n,n.exports,e),n.exports}e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(r){if("object"==typeof window)return window}}(),e.rv=function(){return"1.0.0-alpha.2"},(()=>{e.g.importScripts&&(r=e.g.location+"");var r,t=e.g.document;if(!r&&t&&(t.currentScript&&(r=t.currentScript.src),!r)){var i=t.getElementsByTagName("script");if(i.length){for(var o=i.length-1;o>-1&&(!r||!/^http(s?):/.test(r));)r=i[o--].src}}if(!r)throw Error("Automatic publicPath is not supported in this browser");r=r.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),e.p=r})(),e.ruid="bundler=rspack@1.0.0-alpha.2";e.p})(); \ No newline at end of file