From 8fc5e6e459d277a4780c9fc8b0aca29956672b35 Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Wed, 27 Dec 2023 12:48:24 +0800 Subject: [PATCH 1/2] fix(mf): should not have extra empty chunk --- .../src/plugin/impl_plugin_for_js_plugin.rs | 26 ++++++++++++++++--- .../2-transitive-overriding/index.js | 1 + .../2-transitive-overriding/test.filter.js | 3 --- .../container/3-container-full/test.filter.js | 3 --- 4 files changed, 23 insertions(+), 10 deletions(-) delete mode 100644 webpack-test/configCases/container/2-transitive-overriding/test.filter.js delete mode 100644 webpack-test/configCases/container/3-container-full/test.filter.js 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 b42b4461b35..a9f8b27d359 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 @@ -4,10 +4,10 @@ use std::sync::Arc; use async_trait::async_trait; use rspack_core::rspack_sources::BoxSource; use rspack_core::{ - get_js_chunk_filename_template, AdditionalChunkRuntimeRequirementsArgs, ChunkHashArgs, ChunkKind, - CompilationArgs, CompilationParams, CompilerOptions, DependencyType, ErrorSpan, - IgnoreErrorModuleFactory, ModuleType, ParserAndGenerator, PathData, Plugin, - PluginAdditionalChunkRuntimeRequirementsOutput, PluginChunkHashHookOutput, + get_js_chunk_filename_template, AdditionalChunkRuntimeRequirementsArgs, ChunkGraph, + ChunkHashArgs, ChunkKind, ChunkUkey, CompilationArgs, CompilationParams, CompilerOptions, + DependencyType, ErrorSpan, IgnoreErrorModuleFactory, ModuleGraph, ModuleType, ParserAndGenerator, + PathData, Plugin, PluginAdditionalChunkRuntimeRequirementsOutput, PluginChunkHashHookOutput, PluginCompilationHookOutput, PluginContext, PluginRenderManifestHookOutput, RenderManifestEntry, RuntimeGlobals, SelfModuleFactory, SourceType, }; @@ -252,6 +252,13 @@ impl Plugin for JsPlugin { } else if chunk.has_runtime(&compilation.chunk_group_by_ukey) { self.render_main(&args).await? } else { + if !chunk_has_js( + &args.chunk_ukey, + &compilation.chunk_graph, + &compilation.module_graph, + ) { + return Ok(vec![]); + } self.render_chunk_impl(&args).await? }; @@ -306,3 +313,14 @@ pub struct ExtractedCommentsInfo { pub source: BoxSource, pub comments_file_name: String, } + +fn chunk_has_js(chunk: &ChunkUkey, chunk_graph: &ChunkGraph, module_graph: &ModuleGraph) -> bool { + if chunk_graph.get_number_of_entry_modules(chunk) > 0 { + true + } else { + chunk_graph + .get_chunk_modules_iterable_by_source_type(chunk, SourceType::JavaScript, module_graph) + .next() + .is_some() + } +} diff --git a/webpack-test/configCases/container/2-transitive-overriding/index.js b/webpack-test/configCases/container/2-transitive-overriding/index.js index f7771726839..53398777b08 100644 --- a/webpack-test/configCases/container/2-transitive-overriding/index.js +++ b/webpack-test/configCases/container/2-transitive-overriding/index.js @@ -27,6 +27,7 @@ it("should have good module ids", async () => { "./b.js", "./modules-from-remote.js", "./modules.js", + "./shared.js", // remove this line once concatenateModules is supported https://github.com/web-infra-dev/rspack/issues/3823 "webpack/container/entry/container-no-shared", "webpack/container/reference/container-with-shared", "webpack/container/remote/container-with-shared/b", diff --git a/webpack-test/configCases/container/2-transitive-overriding/test.filter.js b/webpack-test/configCases/container/2-transitive-overriding/test.filter.js deleted file mode 100644 index 4b5c98afaa9..00000000000 --- a/webpack-test/configCases/container/2-transitive-overriding/test.filter.js +++ /dev/null @@ -1,3 +0,0 @@ -const { FilteredStatus } = require("../../../lib/util/filterUtil") - -module.exports = () => {return [FilteredStatus.PARTIAL_PASS, "Rspack has an extra empty chunk"]} \ No newline at end of file diff --git a/webpack-test/configCases/container/3-container-full/test.filter.js b/webpack-test/configCases/container/3-container-full/test.filter.js deleted file mode 100644 index cf0fdae9fc3..00000000000 --- a/webpack-test/configCases/container/3-container-full/test.filter.js +++ /dev/null @@ -1,3 +0,0 @@ -const { FilteredStatus } = require("../../../lib/util/filterUtil") - -module.exports = () => {return [FilteredStatus.PARTIAL_PASS, "Emit detect version warning"]} \ No newline at end of file From 9ba8a3a327b3444901c62597623076bbe7cb97ee Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Wed, 27 Dec 2023 14:01:05 +0800 Subject: [PATCH 2/2] fix --- .../configCases/container/3-container-full/test.filter.js | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 webpack-test/configCases/container/3-container-full/test.filter.js diff --git a/webpack-test/configCases/container/3-container-full/test.filter.js b/webpack-test/configCases/container/3-container-full/test.filter.js new file mode 100644 index 00000000000..ed2f483e2f5 --- /dev/null +++ b/webpack-test/configCases/container/3-container-full/test.filter.js @@ -0,0 +1,3 @@ +const { FilteredStatus } = require("../../../lib/util/filterUtil") +// this test depend on 1-container-full +module.exports = () => {return [FilteredStatus.PARTIAL_PASS, "https://github.com/web-infra-dev/rspack/issues/4784"]}