Skip to content

Commit

Permalink
feat: stats origin moduleid (#6955)
Browse files Browse the repository at this point in the history
* feat: add stats.chunks[].origins[].moduleId

* feat: add stats.chunks[].origins[].moduleId
  • Loading branch information
LingyuCoder authored Jun 27, 2024
1 parent a3eb1c6 commit 2d591e9
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 85 deletions.
1 change: 1 addition & 0 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ export interface JsNormalModuleFactoryCreateModuleArgs {

export interface JsOriginRecord {
module: string
moduleId: string
moduleIdentifier: string
moduleName: string
loc: string
Expand Down
2 changes: 2 additions & 0 deletions crates/rspack_binding_values/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ impl From<rspack_core::StatsModuleReason> for JsStatsModuleReason {
#[napi(object)]
pub struct JsOriginRecord {
pub module: String,
pub module_id: String,
pub module_identifier: String,
pub module_name: String,
pub loc: String,
Expand Down Expand Up @@ -531,6 +532,7 @@ impl TryFrom<rspack_core::StatsChunk<'_>> for JsStatsChunk {
.into_iter()
.map(|origin| JsOriginRecord {
module: origin.module,
module_id: origin.module_id,
module_identifier: origin.module_identifier,
module_name: origin.module_name,
loc: origin.loc,
Expand Down
25 changes: 20 additions & 5 deletions crates/rspack_core/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,22 +324,36 @@ impl Stats<'_> {
.flat_map(|ukey| {
let chunk_group = chunk_group_by_ukey.expect_get(ukey);
chunk_group.origins().iter().map(|origin| {
let id = origin
let module_identifier = origin
.module_id
.map(|id| id.to_string())
.unwrap_or_default();
let module_name = origin
.module_id
.map(|module_id| {
.map(|identifier| {
module_graph
.module_by_identifier(&module_id)
.module_by_identifier(&identifier)
.map(|module| module.readable_identifier(context).to_string())
.unwrap_or_default()
})
.unwrap_or_default();

let module_id = origin
.module_id
.map(|identifier| {
self
.compilation
.chunk_graph
.get_module_id(identifier)
.clone()
.unwrap_or_default()
})
.unwrap_or_default();

StatsOriginRecord {
module: id.clone(),
module_identifier: id,
module: module_identifier.clone(),
module_id,
module_identifier,
module_name,
loc: origin
.loc
Expand Down Expand Up @@ -1136,6 +1150,7 @@ pub struct StatsModuleProfile {
#[derive(Debug)]
pub struct StatsOriginRecord {
pub module: String,
pub module_id: String,
pub module_identifier: String,
pub module_name: String,
pub loc: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Object {
Object {
"loc": "main",
"module": "",
"moduleId": "",
"moduleIdentifier": "",
"moduleName": "",
"request": "./fixtures/a",
Expand Down Expand Up @@ -535,6 +536,7 @@ Object {
Object {
"loc": "main",
"module": "",
"moduleId": "",
"moduleIdentifier": "",
"moduleName": "",
"request": "./fixtures/esm/abc",
Expand Down Expand Up @@ -1375,6 +1377,7 @@ exports.c = require(\\"./c?c=3\\");
Object {
"loc": "main",
"module": "",
"moduleId": "",
"moduleIdentifier": "",
"moduleName": "",
"request": "./fixtures/abc-query",
Expand Down
2 changes: 2 additions & 0 deletions packages/rspack-test-tools/tests/statsAPICases/chunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ module.exports = {
Object {
"loc": "2:9-46",
"module": "<PROJECT_ROOT>/tests/fixtures/chunk-b.js",
"moduleId": "725",
"moduleIdentifier": "<PROJECT_ROOT>/tests/fixtures/chunk-b.js",
"moduleName": "./fixtures/chunk-b.js",
"request": "./b",
Expand Down Expand Up @@ -202,6 +203,7 @@ module.exports = {
Object {
"loc": "main",
"module": "",
"moduleId": "",
"moduleIdentifier": "",
"moduleName": "",
"request": "./fixtures/chunk-b",
Expand Down
160 changes: 80 additions & 80 deletions webpack-test/__snapshots__/StatsTestCases.basictest.js.snap

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions website/docs/en/api/stats.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ type StatsChunk = {
origins: Array<{
// Path to the module
module: string;
// ID of the module
moduleId: string;
// The identifier of the module
moduleIdentifier: string;
// Relative path to the module
Expand Down
2 changes: 2 additions & 0 deletions website/docs/zh/api/stats.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ type StatsChunk = {
origins: Array<{
// 来源 module 的路径
module: string;
// 来源 module 的 ID
moduleId: string;
// 来源 module 的唯一标识
moduleIdentifier: string;
// 来源 module 的相对路径
Expand Down

1 comment on commit 2d591e9

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
_selftest ✅ success
nx ✅ success
rspress ❌ failure
rsbuild ❌ failure
compat ❌ failure
examples ❌ failure

Please sign in to comment.