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: support stats.chunkGroup[].childAssets #7517

Merged
merged 3 commits into from
Aug 9, 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
8 changes: 7 additions & 1 deletion crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,11 @@ export interface JsStatsAssetsByChunkName {
files: Array<string>
}

export interface JsStatsChildGroupChildAssets {
preload?: Array<string>
prefetch?: Array<string>
}

export interface JsStatsChunk {
type: string
files: Array<string>
Expand Down Expand Up @@ -709,8 +714,9 @@ export interface JsStatsChunkGroup {
assetsSize: number
auxiliaryAssets?: Array<JsStatsChunkGroupAsset>
auxiliaryAssetsSize?: number
children?: JsStatsChunkGroupChildren
isOverSizeLimit?: boolean
children?: JsStatsChunkGroupChildren
childAssets?: JsStatsChildGroupChildAssets
}

export interface JsStatsChunkGroupAsset {
Expand Down
28 changes: 27 additions & 1 deletion crates/rspack_binding_values/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,8 +1007,9 @@ pub struct JsStatsChunkGroup {
pub assets_size: f64,
pub auxiliary_assets: Option<Vec<JsStatsChunkGroupAsset>>,
pub auxiliary_assets_size: Option<f64>,
pub children: Option<JsStatsChunkGroupChildren>,
pub is_over_size_limit: Option<bool>,
pub children: Option<JsStatsChunkGroupChildren>,
pub child_assets: Option<JsStatsChildGroupChildAssets>,
}

impl FromNapiValue for JsStatsChunkGroup {
Expand All @@ -1032,11 +1033,36 @@ impl From<rspack_core::StatsChunkGroup> for JsStatsChunkGroup {
.map(|assets| assets.into_iter().map(Into::into).collect()),
auxiliary_assets_size: stats.auxiliary_assets_size,
children: stats.children.map(|i| i.into()),
child_assets: stats.child_assets.map(|i| i.into()),
is_over_size_limit: stats.is_over_size_limit,
}
}
}

#[napi(object, object_from_js = false)]
pub struct JsStatsChildGroupChildAssets {
pub preload: Option<Vec<String>>,
pub prefetch: Option<Vec<String>>,
}

impl FromNapiValue for JsStatsChildGroupChildAssets {
unsafe fn from_napi_value(
_env: napi::sys::napi_env,
_napi_val: napi::sys::napi_value,
) -> Result<Self> {
unreachable!()
}
}

impl From<rspack_core::StatschunkGroupChildAssets> for JsStatsChildGroupChildAssets {
fn from(stats: rspack_core::StatschunkGroupChildAssets) -> Self {
Self {
preload: (!stats.preload.is_empty()).then_some(stats.preload),
prefetch: (!stats.prefetch.is_empty()).then_some(stats.prefetch),
}
}
}

#[napi(object, object_from_js = false)]
pub struct JsStatsChunkGroupChildren {
pub preload: Option<Vec<JsStatsChunkGroup>>,
Expand Down
Loading
Loading