Skip to content

Commit 04fd686

Browse files
authored
feat: js api get outgoing connections in order (#9510)
1 parent 423fd69 commit 04fd686

File tree

13 files changed

+73
-4
lines changed

13 files changed

+73
-4
lines changed

crates/node_binding/binding.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ export declare class JsModuleGraph {
264264
getExportsInfo(module: JsModule): JsExportsInfo
265265
getConnection(dependency: JsDependency): JsModuleGraphConnection | null
266266
getOutgoingConnections(module: JsModule): JsModuleGraphConnection[]
267+
getOutgoingConnectionsInOrder(module: JsModule): JsModuleGraphConnection[]
267268
getIncomingConnections(module: JsModule): JsModuleGraphConnection[]
268269
getParentModule(jsDependency: JsDependency): JsModule | null
269270
getParentBlockIndex(jsDependency: JsDependency): number

crates/node_binding/src/module_graph.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,20 @@ impl JsModuleGraph {
137137
)
138138
}
139139

140+
#[napi(ts_return_type = "JsModuleGraphConnection[]")]
141+
pub fn get_outgoing_connections_in_order(
142+
&self,
143+
module: &JsModule,
144+
) -> napi::Result<Vec<JsModuleGraphConnectionWrapper>> {
145+
let (compilation, module_graph) = self.as_ref()?;
146+
Ok(
147+
module_graph
148+
.get_outgoing_connections_in_order(&module.identifier)
149+
.map(|dependency_id| JsModuleGraphConnectionWrapper::new(*dependency_id, compilation))
150+
.collect::<Vec<_>>(),
151+
)
152+
}
153+
140154
#[napi(ts_return_type = "JsModuleGraphConnection[]")]
141155
pub fn get_incoming_connections(
142156
&self,

crates/rspack_core/src/build_chunk_graph/code_splitter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
15971597
Vec<DependencyId>,
15981598
> = IndexMap::default();
15991599

1600-
for dep_id in module_graph.get_ordered_outgoing_connections(&module) {
1600+
for dep_id in module_graph.get_outgoing_connections_in_order(&module) {
16011601
let dep = module_graph
16021602
.dependency_by_id(dep_id)
16031603
.expect("should have dep");

crates/rspack_core/src/chunk_graph/chunk_graph_module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ impl ChunkGraph {
305305
let mut visited_modules = IdentifierSet::default();
306306
visited_modules.insert(module.identifier());
307307
for connection in mg
308-
.get_ordered_outgoing_connections(&module.identifier())
308+
.get_outgoing_connections_in_order(&module.identifier())
309309
.filter_map(|c| mg.connection_by_dependency_id(c))
310310
{
311311
let module_identifier = connection.module_identifier();

crates/rspack_core/src/module_graph/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ impl<'a> ModuleGraph<'a> {
806806
exports_info.get_export_info(self, export_name)
807807
}
808808

809-
pub(crate) fn get_ordered_outgoing_connections(
809+
pub fn get_outgoing_connections_in_order(
810810
&self,
811811
module_identifier: &ModuleIdentifier,
812812
) -> impl Iterator<Item = &DependencyId> {

crates/rspack_core/src/old_cache/local/code_splitting_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl CodeSplittingCache {
6666
let mut visited = IdentifierSet::default();
6767
let mut active_modules = IdentifierSet::default();
6868
module_graph
69-
.get_ordered_outgoing_connections(&module)
69+
.get_outgoing_connections_in_order(&module)
7070
.filter_map(|dep| module_graph.connection_by_dependency_id(dep))
7171
.map(|conn| {
7272
let m = *conn.module_identifier();

packages/rspack-test-tools/tests/configCases/module-graph/get-outgoing-connections-in-order/a.js

Whitespace-only changes.

packages/rspack-test-tools/tests/configCases/module-graph/get-outgoing-connections-in-order/b.js

Whitespace-only changes.

packages/rspack-test-tools/tests/configCases/module-graph/get-outgoing-connections-in-order/c.js

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import "./a";
2+
import "./b";
3+
import "./c";
4+

0 commit comments

Comments
 (0)