Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: stats origin moduleid #6955

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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/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
Loading