Skip to content
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
468 changes: 267 additions & 201 deletions crates/pack-api/src/app.rs

Large diffs are not rendered by default.

55 changes: 47 additions & 8 deletions crates/pack-api/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
operation::EntrypointsOperation,
project::ProjectContainer,
utils::get_issues,
webpack_stats::generate_webpack_stats,
webpack_stats::{OutputAssetGroups, generate_webpack_stats},
};

#[turbo_tasks::value(shared)]
Expand Down Expand Up @@ -59,15 +59,19 @@ pub async fn all_output_assets_operation(
) -> Result<Vc<OutputAssets>> {
let project = container.project();

let endpoint_assets = project
let endpoint_asset_groups = project
.get_all_endpoints()
.await?
.iter()
.map(|endpoint| async move { endpoint.output().await?.output_assets.await })
.map(|endpoint| async move { Ok(endpoint.output().await?.output_assets) })
.try_join()
.await?;

let output_assets: FxIndexSet<ResolvedVc<Box<dyn OutputAsset>>> = endpoint_assets
let output_assets: FxIndexSet<ResolvedVc<Box<dyn OutputAsset>>> = endpoint_asset_groups
.iter()
.map(|assets| async move { assets.await })
.try_join()
.await?
.iter()
.flat_map(|assets| assets.iter().copied())
.collect();
Expand All @@ -89,22 +93,56 @@ pub async fn all_output_assets_operation(
let mut stats_outputs: Vec<ResolvedVc<Box<dyn OutputAsset>>> = Vec::new();

if !has_server {
stats_outputs.push(make_stats_output(output_assets, dist_root).await?);
stats_outputs.push(
make_stats_output(
output_assets,
Vc::<OutputAssetGroups>::cell(endpoint_asset_groups),
dist_root,
)
.await?,
);
} else {
let server_dist_root_vc = container.project().server_dist_root();
let server_dist_root_read = server_dist_root_vc.await?;
let mut client: Vec<ResolvedVc<Box<dyn OutputAsset>>> = Vec::new();
let mut server: Vec<ResolvedVc<Box<dyn OutputAsset>>> = Vec::new();
let mut client_groups = Vec::with_capacity(endpoint_asset_groups.len());
for assets in endpoint_asset_groups {
let mut group = Vec::new();
for asset in assets.await?.iter().copied() {
if !asset.path().await?.is_inside_ref(&server_dist_root_read) {
group.push(asset);
}
}
if !group.is_empty() {
client_groups.push(ResolvedVc::cell(group));
}
}
for asset in output_assets.await?.iter().copied() {
if asset.path().await?.is_inside_ref(&server_dist_root_read) {
server.push(asset);
} else {
client.push(asset);
}
}
stats_outputs.push(make_stats_output(Vc::cell(client), dist_root).await?);
stats_outputs.push(
make_stats_output(
Vc::cell(client),
Vc::<OutputAssetGroups>::cell(client_groups),
dist_root,
)
.await?,
);
if !server.is_empty() {
stats_outputs.push(make_stats_output(Vc::cell(server), server_dist_root_vc).await?);
let server_assets = ResolvedVc::cell(server);
stats_outputs.push(
make_stats_output(
*server_assets,
Vc::<OutputAssetGroups>::cell(vec![server_assets]),
server_dist_root_vc,
)
.await?,
);
}
}

Expand All @@ -113,9 +151,10 @@ pub async fn all_output_assets_operation(

async fn make_stats_output(
assets: Vc<OutputAssets>,
asset_groups: Vc<OutputAssetGroups>,
dist_root: Vc<FileSystemPath>,
) -> Result<ResolvedVc<Box<dyn OutputAsset>>> {
let webpack_stats = generate_webpack_stats(assets, dist_root).await?;
let webpack_stats = generate_webpack_stats(assets, asset_groups, dist_root).await?;
let stats_json = serde_json::to_string_pretty(&*webpack_stats)?;
let dist_root_owned = dist_root.owned().await?;
let stats_output = VirtualOutputAsset::new(
Expand Down
7 changes: 1 addition & 6 deletions crates/pack-api/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1489,12 +1489,7 @@ impl Project {
let app_project = self.app_project().to_resolved().await?.await?;
Ok(Entrypoints {
apps: match *app_project {
Some(app) => Some(
Endpoints(vec![ResolvedVc::upcast(
app.get_app_endpoint().to_resolved().await?,
)])
.resolved_cell(),
),
Some(app) => Some(app.get_app_endpoints().to_resolved().await?),
None => None,
},
libraries: match *library_project {
Expand Down
53 changes: 41 additions & 12 deletions crates/pack-api/src/webpack_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ pub struct AssetIntermediateInfo {
pub dev_chunk_list: Option<RcStr>,
}

#[turbo_tasks::value(transparent)]
pub struct OutputAssetGroups(pub Vec<ResolvedVc<OutputAssets>>);

fn normalize_stats_path(path: RcStr) -> RcStr {
path.strip_prefix("./").map(Into::into).unwrap_or(path)
}
Expand Down Expand Up @@ -381,6 +384,7 @@ pub async fn get_asset_intermediate_info(
#[turbo_tasks::function]
pub async fn generate_webpack_stats(
entry_assets: Vc<OutputAssets>,
entry_asset_groups: Vc<OutputAssetGroups>,
dist_root: Vc<FileSystemPath>,
) -> Result<Vc<WebpackStats>> {
let mut assets = vec![];
Expand All @@ -402,10 +406,13 @@ pub async fn generate_webpack_stats(
})
.try_join()
.await?;
let asset_info_by_asset: FxHashMap<_, _> = all_assets
.iter()
.copied()
.zip(asset_results.iter())
.collect();

let mut dev_chunk_lists: Vec<RcStr> = vec![];
for info in asset_results {
let info = info;
for info in &asset_results {
if seen_asset_paths.insert(info.asset.name.clone()) {
assets.push(info.asset.clone());
}
Expand All @@ -424,17 +431,39 @@ pub async fn generate_webpack_stats(
modules.insert(module.id.clone(), module.clone());
}
}
if let Some(dev_chunk_list) = &info.dev_chunk_list {
dev_chunk_lists.push(dev_chunk_list.clone());
}
}

for dev_chunk_list in dev_chunk_lists {
for entrypoint in entrypoints.values_mut() {
entrypoint.chunks.push(dev_chunk_list.clone());
entrypoint.assets.push(WebpackStatsEntrypointAssets {
name: dev_chunk_list.clone(),
});
// Endpoint output groups preserve which evaluate entry owns each development chunk list.
// Associating these lists after flattening all output assets made every entrypoint include
// every other page's HMR bootstrap in multi-page builds.
for group in entry_asset_groups.await?.iter().copied() {
let group = group.await?;
let group_entrypoints: FxIndexMap<_, _> = group
.iter()
.filter_map(|asset| asset_info_by_asset.get(asset))
.flat_map(|info| info.entrypoints.iter())
.map(|(name, _)| (name.clone(), ()))
.collect();
let group_chunk_lists: FxIndexMap<_, _> = group
.iter()
.filter_map(|asset| asset_info_by_asset.get(asset))
.filter_map(|info| info.dev_chunk_list.as_ref())
.map(|name| (name.clone(), ()))
.collect();

for entrypoint_name in group_entrypoints.keys() {
let Some(entrypoint) = entrypoints.get_mut(entrypoint_name) else {
continue;
};
for dev_chunk_list in group_chunk_lists.keys() {
if entrypoint.chunks.contains(dev_chunk_list) {
continue;
}
entrypoint.chunks.push(dev_chunk_list.clone());
entrypoint.assets.push(WebpackStatsEntrypointAssets {
name: dev_chunk_list.clone(),
});
}
}
}

Expand Down
14 changes: 5 additions & 9 deletions crates/pack-cli/src/serve/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,17 @@ pub async fn create_web_entry_source(
) -> Result<Vc<Box<dyn ContentSource>>> {
let entries = match &*project.app_project().await? {
Some(app_project) => {
let app_endpoint = app_project.get_app_endpoint();

let asset_context = Vc::upcast(app_endpoint.app_module_context());

let runtime_entries = app_endpoint.app_runtime_entries();

let chunking_context = app_endpoint
let asset_context = Vc::upcast(app_project.app_module_context());
let runtime_entries = app_project.app_runtime_entries();
let chunking_context = app_project
.project()
.client_chunking_context()
.to_resolved()
.await?;

app_endpoint
app_project
.resolved_entrypoints()
.await?
.entrypoints
.iter()
.map(async |app| {
let module_graph = app
Expand Down
Loading
Loading