Skip to content
Draft
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 20 additions & 27 deletions crates/next-api/src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ use turbopack_core::{
asset::{Asset, AssetContent},
chunk::ChunkingType,
module::Module,
module_graph::ModuleGraph,
output::{OutputAsset, OutputAssets, OutputAssetsReference},
reference::all_assets_from_entries,
};

use crate::route::ModuleGraphs;

pub struct EdgesData {
pub offsets: Vec<u32>,
pub data: Vec<u32>,
Expand Down Expand Up @@ -431,30 +430,28 @@ pub async fn analyze_output_assets(output_assets: Vc<OutputAssets>) -> Result<Vc
}

#[turbo_tasks::function]
pub async fn analyze_module_graphs(module_graphs: Vc<ModuleGraphs>) -> Result<Vc<FileContent>> {
pub async fn analyze_module_graph(module_graph: Vc<ModuleGraph>) -> Result<Vc<FileContent>> {
let mut builder = ModulesDataBuilder::new();

let mut all_modules = FxIndexSet::default();
let mut all_edges = FxIndexSet::default();
let mut all_async_edges = FxIndexSet::default();
for &module_graph in module_graphs.await? {
let module_graph = module_graph.await?;
module_graph.traverse_edges_unordered(|parent, node| {
if let Some((parent_node, reference)) = parent {
all_modules.insert(parent_node);
all_modules.insert(node);
match reference.chunking_type {
ChunkingType::Async => {
all_async_edges.insert((parent_node, node));
}
_ => {
all_edges.insert((parent_node, node));
}
let module_graph = module_graph.await?;
module_graph.traverse_edges_unordered(|parent, node| {
if let Some((parent_node, reference)) = parent {
all_modules.insert(parent_node);
all_modules.insert(node);
match reference.chunking_type {
ChunkingType::Async => {
all_async_edges.insert((parent_node, node));
}
_ => {
all_edges.insert((parent_node, node));
}
}
Ok(())
})?;
}
}
Ok(())
})?;

type ModulePair = (ResolvedVc<Box<dyn Module>>, ResolvedVc<Box<dyn Module>>);
async fn mapper((from, to): ModulePair) -> Result<Option<(RcStr, RcStr)>> {
Expand Down Expand Up @@ -568,26 +565,22 @@ impl OutputAsset for AnalyzeDataOutputAsset {
#[turbo_tasks::value]
pub struct ModulesDataOutputAsset {
pub path: FileSystemPath,
pub module_graphs: ResolvedVc<ModuleGraphs>,
pub module_graph: ResolvedVc<ModuleGraph>,
}

#[turbo_tasks::value_impl]
impl ModulesDataOutputAsset {
#[turbo_tasks::function]
pub async fn new(path: FileSystemPath, module_graphs: Vc<ModuleGraphs>) -> Result<Vc<Self>> {
Ok(Self {
path,
module_graphs: module_graphs.to_resolved().await?,
}
.cell())
pub fn new(path: FileSystemPath, module_graph: ResolvedVc<ModuleGraph>) -> Vc<Self> {
Self { path, module_graph }.cell()
}
}

#[turbo_tasks::value_impl]
impl Asset for ModulesDataOutputAsset {
#[turbo_tasks::function]
fn content(&self) -> Vc<AssetContent> {
let file_content = analyze_module_graphs(*self.module_graphs);
let file_content = analyze_module_graph(*self.module_graph);
AssetContent::file(file_content)
}
}
Expand Down
Loading
Loading