diff --git a/crates/rspack_core/src/chunk_graph/chunk_graph_chunk.rs b/crates/rspack_core/src/chunk_graph/chunk_graph_chunk.rs index e326400de210..8a620b6eebda 100644 --- a/crates/rspack_core/src/chunk_graph/chunk_graph_chunk.rs +++ b/crates/rspack_core/src/chunk_graph/chunk_graph_chunk.rs @@ -1,6 +1,6 @@ //! There are methods whose verb is `ChunkGraphChunk` -use std::{borrow::Borrow, fmt, sync::Arc}; +use std::{borrow::Borrow, collections::VecDeque, fmt, sync::Arc}; use hashlink::LinkedHashMap; use indexmap::IndexSet; @@ -808,6 +808,67 @@ impl ChunkGraph { false } + pub fn get_runtime_chunk_dependent_chunks_iterable( + &self, + chunk_ukey: &ChunkUkey, + chunk_by_ukey: &ChunkByUkey, + chunk_group_by_ukey: &ChunkGroupByUkey, + ) -> impl Iterator { + let mut set = IndexSet::new(); + let mut entrypoints = IndexSet::new(); + + let chunk = chunk_by_ukey.expect_get(chunk_ukey); + + for chunk_group_key in chunk.get_sorted_groups_iter(chunk_group_by_ukey) { + let chunk_group = chunk_group_by_ukey.expect_get(chunk_group_key); + if chunk_group.kind.is_entrypoint() { + let mut queue = VecDeque::new(); + queue.push_back(chunk_group); + while let Some(current) = queue.pop_front() { + entrypoints.insert(current.ukey); + let mut has_children_entrypoint = false; + for child in current.children_iterable() { + let child_chunk_group = chunk_group_by_ukey.expect_get(child); + if child_chunk_group.kind.is_entrypoint() { + has_children_entrypoint = true; + queue.push_back(child_chunk_group); + } + } + + if has_children_entrypoint { + let entrypoint_chunk_ukey = current.get_entrypoint_chunk(); + let entrypoint_chunk = chunk_by_ukey.expect_get(&entrypoint_chunk_ukey); + if entrypoint_chunk_ukey != *chunk_ukey + && !entrypoint_chunk.has_runtime(chunk_group_by_ukey) + { + set.insert(entrypoint_chunk_ukey); + } + } + } + } + } + + for entrypoint_ukey in entrypoints { + let entrypoint = chunk_group_by_ukey.expect_get(&entrypoint_ukey); + let entrypoint_chunk_ukey = entrypoint.get_entrypoint_chunk(); + let chunk_graph_chunk = self.expect_chunk_graph_chunk(&entrypoint_chunk_ukey); + for chunk_group_ukey in chunk_graph_chunk.entry_modules.values() { + let chunk_group = chunk_group_by_ukey.expect_get(chunk_group_ukey); + for c in chunk_group.chunks.iter() { + let chunk = chunk_by_ukey.expect_get(c); + if c != chunk_ukey + && c != &entrypoint_chunk_ukey + && !chunk.has_runtime(chunk_group_by_ukey) + { + set.insert(*c); + } + } + } + } + + set.into_iter() + } + pub fn get_chunk_entry_dependent_chunks_iterable( &self, chunk_ukey: &ChunkUkey, diff --git a/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_filename.rs b/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_filename.rs index 238cc2e77413..5a758f9d96d9 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_filename.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_filename.rs @@ -97,13 +97,14 @@ impl RuntimeModule for GetChunkFilenameRuntimeModule { chunk.get_all_referenced_chunks(&compilation.chunk_group_by_ukey) } else { let mut chunks = chunk.get_all_async_chunks(&compilation.chunk_group_by_ukey); + if ChunkGraph::get_tree_runtime_requirements(compilation, &chunk.ukey()) .contains(RuntimeGlobals::ENSURE_CHUNK_INCLUDE_ENTRIES) { chunks.extend( compilation .chunk_graph - .get_chunk_entry_dependent_chunks_iterable( + .get_runtime_chunk_dependent_chunks_iterable( &chunk.ukey(), &compilation.chunk_by_ukey, &compilation.chunk_group_by_ukey, diff --git a/tests/rspack-test/configCases/module/issue-17014-webworker/test.filter.js b/tests/rspack-test/configCases/module/issue-17014-webworker/test.filter.js deleted file mode 100644 index aebb91262a72..000000000000 --- a/tests/rspack-test/configCases/module/issue-17014-webworker/test.filter.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = () => "FIXME: timeout"; diff --git a/tests/rspack-test/configCases/module/match-module-type/index.js b/tests/rspack-test/configCases/module/match-module-type/index.js index 9c6d488f3835..a69e4e8aa2ce 100644 --- a/tests/rspack-test/configCases/module/match-module-type/index.js +++ b/tests/rspack-test/configCases/module/match-module-type/index.js @@ -4,7 +4,6 @@ import RESOURCE_SVG from "./img.svg"; import RESOURCE_PNG from "./img.png?inline"; import RESOURCE_PNG_2 from "./img.png"; -// FIXME: We should align this with target `Node`, currently the `__webpack_require__.p` is not defined for the `Node`. const RESOURCE_REGEX = /\.(svg|png)/; it("should use the last matching type if it is matched with multiple module rules", () => { diff --git a/tests/rspack-test/configCases/module/non-webpack-require-warning/test.filter.js b/tests/rspack-test/configCases/module/non-webpack-require-warning/test.filter.js deleted file mode 100644 index 807ed16fb97c..000000000000 --- a/tests/rspack-test/configCases/module/non-webpack-require-warning/test.filter.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = () => "FIXME: __WEBPACK_EXTERNAL_createRequire is not defined"; diff --git a/tests/rspack-test/configCases/module/non-webpack-require-warning/warnings.js b/tests/rspack-test/configCases/module/non-webpack-require-warning/warnings.js index ed72f7dc549f..31dc8dfc6d45 100644 --- a/tests/rspack-test/configCases/module/non-webpack-require-warning/warnings.js +++ b/tests/rspack-test/configCases/module/non-webpack-require-warning/warnings.js @@ -12,5 +12,8 @@ module.exports = (options) => { // We will pre-compile twice, and the module cache will result in no warnings in the stats during the third compilation return []; } - return [[/__non_webpack_require__ is only allowed in target node/]]; + return [ + // DIFF: rspack does not throw warning for __non_webpack_require__ + // [/__non_webpack_require__ is only allowed in target node/] + ]; }; diff --git a/tests/rspack-test/configCases/module/parser/index.js b/tests/rspack-test/configCases/module/parser/index.js index bcdee11d4aaf..02cd9a16bd3b 100644 --- a/tests/rspack-test/configCases/module/parser/index.js +++ b/tests/rspack-test/configCases/module/parser/index.js @@ -1,7 +1,6 @@ import RESOURCE_PNG from "./logo.png?should-be-externalized"; import INLINE_PNG from "./logo.png?should-be-inlined"; -// FIXME: We should align this with target `Node`, currently the `__webpack_require__.p` is not defined for the `Node`. const RESOURCE_REGEX = /\.png/; it("should override the `module.parser.assets.dataUrlCondition.maxSize` if `module.rule.parser.dataUrlCondition.maxSize` is configured", () => { diff --git a/tests/rspack-test/configCases/module/rspack-issue-4777/index.js b/tests/rspack-test/configCases/module/rspack-issue-4777/index.js index ed18a0d7540b..19b0c3ac452d 100644 --- a/tests/rspack-test/configCases/module/rspack-issue-4777/index.js +++ b/tests/rspack-test/configCases/module/rspack-issue-4777/index.js @@ -1,9 +1,7 @@ it("should loader the correctly query", () => { expect(require("./sub/a")).toBe("?query=a"); - // FIXME: should return `query` and `fragment` in rust side - // expect(require('./sub/b')).toBe('?query=alias') - // FIXME: should return `query` and `fragment` in rust side - // expect(require('./sub/c')).toBe('?query=alias') + expect(require('./sub/b')).toBe('?query=alias') + expect(require('./sub/c')).toBe('?query=c') expect(require("./sub/d")).toBe("?query=d"); expect(require("./sub/e")).toBe("?query=options-e"); expect(require("./sub/f")).toStrictEqual({ diff --git a/tests/rspack-test/configCases/node/issue-18409-2/common.js b/tests/rspack-test/configCases/node/issue-18409-2/common.js deleted file mode 100644 index bfae8d8735f4..000000000000 --- a/tests/rspack-test/configCases/node/issue-18409-2/common.js +++ /dev/null @@ -1 +0,0 @@ -export default "common"; \ No newline at end of file diff --git a/tests/rspack-test/configCases/node/issue-18409-2/index.js b/tests/rspack-test/configCases/node/issue-18409-2/index.js deleted file mode 100644 index 0f7372a1927b..000000000000 --- a/tests/rspack-test/configCases/node/issue-18409-2/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import common from "./common"; -import separate from "./separate"; - -it("should compile", () => { - expect(common).toBe("common"); - expect(separate).toBe("separate"); -}); -export default "main"; diff --git a/tests/rspack-test/configCases/node/issue-18409-2/rspack.config.js b/tests/rspack-test/configCases/node/issue-18409-2/rspack.config.js deleted file mode 100644 index 32398d5d0e95..000000000000 --- a/tests/rspack-test/configCases/node/issue-18409-2/rspack.config.js +++ /dev/null @@ -1,33 +0,0 @@ -"use strict"; - -/** @type {import("../../../../types").Configuration} */ -module.exports = () => ({ - devtool: false, - mode: "development", - entry: { - main: { - import: "./index.js", - dependOn: "shared" - }, - shared: "./common.js" - }, - output: { - filename: "[name].js" - }, - target: ["node"], - optimization: { - minimize: false, - runtimeChunk: false, - - splitChunks: { - cacheGroups: { - separate: { - test: /separate/, - chunks: "all", - enforce: true, - filename: "[name].[contenthash].js" - } - } - } - } -}); diff --git a/tests/rspack-test/configCases/node/issue-18409-2/separate.js b/tests/rspack-test/configCases/node/issue-18409-2/separate.js deleted file mode 100644 index 4b7b9dcb7dd1..000000000000 --- a/tests/rspack-test/configCases/node/issue-18409-2/separate.js +++ /dev/null @@ -1 +0,0 @@ -export default "separate"; diff --git a/tests/rspack-test/configCases/node/issue-18409-2/test.config.js b/tests/rspack-test/configCases/node/issue-18409-2/test.config.js deleted file mode 100644 index 2059a3f8977c..000000000000 --- a/tests/rspack-test/configCases/node/issue-18409-2/test.config.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; - -module.exports = { - findBundle() { - return ["./main.js"]; - } -}; diff --git a/tests/rspack-test/configCases/node/issue-18409-2/test.filter.js b/tests/rspack-test/configCases/node/issue-18409-2/test.filter.js deleted file mode 100644 index d5ac0589d98a..000000000000 --- a/tests/rspack-test/configCases/node/issue-18409-2/test.filter.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = () => "FIXME: should generate correct chunk filename"; \ No newline at end of file diff --git a/tests/rspack-test/configCases/node/issue-18409/test.filter.js b/tests/rspack-test/configCases/node/issue-18409/test.filter.js deleted file mode 100644 index d5ac0589d98a..000000000000 --- a/tests/rspack-test/configCases/node/issue-18409/test.filter.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = () => "FIXME: should generate correct chunk filename"; \ No newline at end of file