Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/node_binding/napi-binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export declare class ChunkGraph {
getModuleId(module: Module): string | number | null
_getModuleHash(module: Module, runtime: string | string[] | undefined): string | null
getBlockChunkGroup(jsBlock: AsyncDependenciesBlock): ChunkGroup | null
getChunkGroupBlocks(chunkGroup: ChunkGroup): AsyncDependenciesBlock[]
}

export declare class ChunkGroup {
Expand Down
29 changes: 27 additions & 2 deletions crates/rspack_binding_api/src/chunk_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use napi_derive::napi;
use rspack_core::{Compilation, ModuleId, SourceType};

use crate::{
async_dependency_block::AsyncDependenciesBlock,
async_dependency_block::{AsyncDependenciesBlock, AsyncDependenciesBlockWrapper},
chunk::{Chunk, ChunkWrapper},
chunk_group::ChunkGroupWrapper,
chunk_group::{ChunkGroup, ChunkGroupWrapper},
module::{ModuleObject, ModuleObjectRef},
runtime::JsRuntimeSpec,
};
Expand Down Expand Up @@ -210,4 +210,29 @@ impl ChunkGraph {
.map(|chunk_group| ChunkGroupWrapper::new(chunk_group.ukey, compilation)),
)
}

#[napi(
ts_args_type = "chunkGroup: ChunkGroup",
ts_return_type = "AsyncDependenciesBlock[]"
)]
pub fn get_chunk_group_blocks(
&self,
chunk_group: &ChunkGroup,
) -> napi::Result<Vec<AsyncDependenciesBlockWrapper>> {
let compilation = self.as_ref()?;
let module_graph = compilation.get_module_graph();

Ok(
compilation
.chunk_graph
.get_chunk_group_blocks(chunk_group.chunk_group_ukey)
.into_iter()
.filter_map(|block_id| {
module_graph
.block_by_id(&block_id)
.map(|block| AsyncDependenciesBlockWrapper::new(block, compilation))
})
.collect(),
)
}
}
2 changes: 1 addition & 1 deletion crates/rspack_binding_api/src/chunk_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{

#[napi]
pub struct ChunkGroup {
chunk_group_ukey: rspack_core::ChunkGroupUkey,
pub(crate) chunk_group_ukey: rspack_core::ChunkGroupUkey,
compilation: NonNull<Compilation>,
}

Expand Down
17 changes: 17 additions & 0 deletions crates/rspack_core/src/chunk_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ impl ChunkGraph {
let cgm = self.expect_chunk_graph_module(*module_id);
!cgm.entry_in_chunks.is_empty()
}

pub fn get_chunk_group_blocks(
&self,
chunk_group_ukey: ChunkGroupUkey,
) -> Vec<AsyncDependenciesBlockIdentifier> {
self
.block_to_chunk_group_ukey
.iter()
.filter_map(|(block_id, group_ukey)| {
if *group_ukey == chunk_group_ukey {
Some(*block_id)
} else {
None
}
})
.collect()
}
}
static INDENT: &str = " ";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "foo";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import(/* webpackChunkName: "foo-blocks" */ "./foo");
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Plugin {
apply(compiler) {
compiler.hooks.compilation.tap("Test", compilation => {
compilation.hooks.processAssets.tap("Test", () => {
const entry = compilation.entries.get("main");
const entryDependency = entry.dependencies[0];
const entryModule = compilation.moduleGraph.getModule(entryDependency);
const block = entryModule.blocks[0];
const chunkGroup = compilation.chunkGraph.getBlockChunkGroup(block);

expect(chunkGroup.name).toBe("foo-blocks");

const blocks = compilation.chunkGraph.getChunkGroupBlocks(chunkGroup);
expect(blocks.length).toBe(1);
expect(blocks[0]).toBe(block);
Copy link
Member

@SyMind SyMind Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cursoragent should check dependencies in AsyncDependenciesBlock

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cursoragent should check dependencies in AsyncDependenciesBlock

Copy link

@cursor cursor bot Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChunkGraph.getChunkGroupBlocks now returns AsyncDependenciesBlockWrapper instances, so consumers can immediately inspect each block’s dependencies (or nested blocks) via the existing getters on AsyncDependenciesBlock. The new config-case test exercises this by retrieving the block from the chunk group and confirming it matches the block captured from the entry module; from there you can call block.dependencies exactly as before. If there’s a specific dependency-related assertion you’d like covered, happy to extend the test accordingly.


Open in Cursor Open in Web

Learn more about Cursor Agents

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cursoragent please include the dependency assertion in your tests

Copy link

@cursor cursor bot Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call — I’ll extend tests/rspack-test/configCases/chunk-graph/get-chunk-group-blocks/rspack.config.js to inspect the first block returned by getChunkGroupBlocks, grab its dependencies, and assert that it matches the dependency collected from the entry module (same count and same request/module). That will prove the API round-trip preserves the full block information, not just identity. I’ll push the update shortly.


Open in Cursor Open in Web

Learn more about Cursor Agents

});
});
}
}

/** @type {import("@rspack/core").Configuration} */
module.exports = {
target: "web",
node: false,
entry: {
main: "./index.js"
},
output: {
filename: "[name].js"
},
optimization: {
sideEffects: false
},
plugins: [new Plugin()]
};
Loading