diff --git a/crates/rspack_core/src/compilation/build_chunk_graph/code_splitter.rs b/crates/rspack_core/src/compilation/build_chunk_graph/code_splitter.rs index f35e3224a6cc..c86f75981aa0 100644 --- a/crates/rspack_core/src/compilation/build_chunk_graph/code_splitter.rs +++ b/crates/rspack_core/src/compilation/build_chunk_graph/code_splitter.rs @@ -404,7 +404,6 @@ impl CodeSplitter { ) { incremental_diagnostic = diagnostic; - compilation.chunk_render_artifact.clear(); } } diff --git a/crates/rspack_core/src/compilation/mod.rs b/crates/rspack_core/src/compilation/mod.rs index f469a7904e04..1c20382b1737 100644 --- a/crates/rspack_core/src/compilation/mod.rs +++ b/crates/rspack_core/src/compilation/mod.rs @@ -1254,10 +1254,16 @@ impl Compilation { "Chunk filename that dependent on full hash", "chunk filename that dependent on full hash is not supported in incremental compilation", ) + && let Some(diagnostic) = diagnostic + { + self.push_diagnostic(diagnostic); + } + + // Check if CHUNKS_RENDER pass is disabled, and clear artifact if needed + if !self + .incremental + .passes_enabled(IncrementalPasses::CHUNKS_RENDER) { - if let Some(diagnostic) = diagnostic { - self.push_diagnostic(diagnostic); - } self.chunk_render_artifact.clear(); } @@ -1292,7 +1298,6 @@ impl Compilation { )); chunks } else { - self.chunk_render_artifact.clear(); self.chunk_by_ukey.keys().copied().collect() }; let results = rspack_futures::scope::<_, Result<_>>(|token| { @@ -1732,6 +1737,14 @@ impl Compilation { let start = logger.time("module ids"); + // Check if MODULE_IDS pass is disabled, and clear artifact if needed + if !self + .incremental + .passes_enabled(IncrementalPasses::MODULE_IDS) + { + self.module_ids_artifact.clear(); + } + let mut diagnostics = vec![]; let mut module_ids_artifact = mem::take(&mut self.module_ids_artifact); plugin_driver @@ -1745,6 +1758,15 @@ impl Compilation { logger.time_end(start); let start = logger.time("chunk ids"); + + // Check if CHUNK_IDS pass is disabled, and clear artifact if needed + if !self + .incremental + .passes_enabled(IncrementalPasses::CHUNK_IDS) + { + self.named_chunk_ids_artifact.clear(); + } + let mut diagnostics = vec![]; let mut chunk_by_ukey = mem::take(&mut self.chunk_by_ukey); let mut named_chunk_ids_artifact = mem::take(&mut self.named_chunk_ids_artifact); @@ -1775,6 +1797,14 @@ impl Compilation { .map_err(|e| e.wrap_err("caused by plugins in Compilation.hooks.optimizeCodeGeneration"))?; logger.time_end(start); + // Check if MODULES_HASHES pass is disabled, and clear artifact if needed + if !self + .incremental + .passes_enabled(IncrementalPasses::MODULES_HASHES) + { + self.cgm_hash_artifact.clear(); + } + let create_module_hashes_modules = if let Some(mutations) = self .incremental .mutations_read(IncrementalPasses::MODULES_HASHES) @@ -1851,7 +1881,6 @@ impl Compilation { modules } else { - self.cgm_hash_artifact.clear(); self.get_module_graph().modules().keys().copied().collect() }; self @@ -1947,6 +1976,15 @@ impl Compilation { ) .await?; let runtime_chunks = self.get_chunk_graph_entries().collect(); + + // Check if CHUNKS_RUNTIME_REQUIREMENTS pass is disabled, and clear artifact if needed + if !self + .incremental + .passes_enabled(IncrementalPasses::CHUNKS_RUNTIME_REQUIREMENTS) + { + self.cgc_runtime_requirements_artifact.clear(); + } + let process_runtime_requirements_chunks = if let Some(mutations) = self .incremental .mutations_read(IncrementalPasses::CHUNKS_RUNTIME_REQUIREMENTS) @@ -1979,7 +2017,6 @@ impl Compilation { )); affected_chunks } else { - self.cgc_runtime_requirements_artifact.clear(); self.chunk_by_ukey.keys().copied().collect() }; self @@ -2350,10 +2387,14 @@ impl Compilation { "Chunk content that dependent on full hash", "it requires calculating the hashes of all the chunks, which is a global effect", ) + && let Some(diagnostic) = diagnostic + { + self.push_diagnostic(diagnostic); + } + if !self + .incremental + .passes_enabled(IncrementalPasses::CHUNKS_HASHES) { - if let Some(diagnostic) = diagnostic { - self.push_diagnostic(diagnostic); - } self.chunk_hashes_artifact.clear(); } @@ -2382,7 +2423,6 @@ impl Compilation { )); chunks } else { - self.chunk_hashes_artifact.clear(); self.chunk_by_ukey.keys().copied().collect() }; diff --git a/crates/rspack_plugin_javascript/src/plugin/flag_dependency_usage_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/flag_dependency_usage_plugin.rs index ef25f1c83fc9..7ce8c35f045b 100644 --- a/crates/rspack_plugin_javascript/src/plugin/flag_dependency_usage_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/flag_dependency_usage_plugin.rs @@ -501,7 +501,6 @@ async fn optimize_dependencies( "it requires calculating the used exports based on all modules, which is a global effect", ) { diagnostics.extend(diagnostic); - // compilation.cgm_hash_artifact.clear(); } let mut proxy = diff --git a/crates/rspack_plugin_javascript/src/plugin/inline_exports_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/inline_exports_plugin.rs index 50edeaff9992..1b6ff83b4f2f 100644 --- a/crates/rspack_plugin_javascript/src/plugin/inline_exports_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/inline_exports_plugin.rs @@ -107,7 +107,6 @@ async fn optimize_dependencies( "it requires calculating the export names of all the modules, which is a global effect", ) { diagnostics.extend(diagnostic); - //compilation.cgm_hash_artifact.clear(); } let mg = build_module_graph_artifact.get_module_graph_mut(); diff --git a/crates/rspack_plugin_javascript/src/plugin/mangle_exports_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/mangle_exports_plugin.rs index e998e35c16ca..c5d965053442 100644 --- a/crates/rspack_plugin_javascript/src/plugin/mangle_exports_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/mangle_exports_plugin.rs @@ -64,11 +64,9 @@ async fn optimize_code_generation(&self, compilation: &mut Compilation) -> Resul IncrementalPasses::MODULES_HASHES, "MangleExportsPlugin (optimization.mangleExports = true)", "it requires calculating the export names of all the modules, which is a global effect", - ) { - if let Some(diagnostic) = diagnostic { - compilation.push_diagnostic(diagnostic); - } - compilation.cgm_hash_artifact.clear(); + ) && let Some(diagnostic) = diagnostic + { + compilation.push_diagnostic(diagnostic); } let mg = compilation.get_module_graph_mut(); diff --git a/crates/rspack_plugin_javascript/src/plugin/module_concatenation_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/module_concatenation_plugin.rs index 5f2acab395c0..a1a70ea25b27 100644 --- a/crates/rspack_plugin_javascript/src/plugin/module_concatenation_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/module_concatenation_plugin.rs @@ -1402,15 +1402,8 @@ async fn optimize_chunk_modules(&self, compilation: &mut Compilation) -> Result< | IncrementalPasses::CHUNKS_HASHES, "ModuleConcatenationPlugin (optimization.concatenateModules = true)", "it requires calculating the modules that can be concatenated based on all the modules, which is a global effect", - ) { - if let Some(diagnostic) = diagnostic { + ) && let Some(diagnostic) = diagnostic { compilation.push_diagnostic(diagnostic); - } - compilation.cgm_hash_artifact.clear(); - compilation.module_ids_artifact.clear(); - compilation.named_chunk_ids_artifact.clear(); - compilation.cgc_runtime_requirements_artifact.clear(); - compilation.chunk_hashes_artifact.clear(); } self.optimize_chunk_modules_impl(compilation).await?;