|
|
use std::{borrow::Cow, collections::hash_map::Entry}; |
|
|
|
|
|
use anyhow::{Ok, Result}; |
|
|
use either::Either; |
|
|
use next_core::{ |
|
|
next_client_reference::{ |
|
|
ClientReference, ClientReferenceGraphResult, ClientReferenceType, ServerEntries, |
|
|
find_server_entries, |
|
|
}, |
|
|
next_dynamic::NextDynamicEntryModule, |
|
|
next_manifests::ActionLayer, |
|
|
}; |
|
|
use rustc_hash::{FxHashMap, FxHashSet}; |
|
|
use tracing::Instrument; |
|
|
use turbo_rcstr::RcStr; |
|
|
use turbo_tasks::{ |
|
|
CollectiblesSource, FxIndexMap, ReadRef, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, |
|
|
ValueToString, Vc, |
|
|
}; |
|
|
use turbo_tasks_fs::FileSystemPath; |
|
|
use turbopack::css::{CssModuleAsset, ModuleCssAsset}; |
|
|
use turbopack_core::{ |
|
|
context::AssetContext, |
|
|
issue::{Issue, IssueExt, IssueSeverity, IssueStage, OptionStyledString, StyledString}, |
|
|
module::Module, |
|
|
module_graph::{GraphTraversalAction, ModuleGraph, SingleModuleGraph}, |
|
|
}; |
|
|
|
|
|
use crate::{ |
|
|
client_references::{ClientManifestEntryType, ClientReferenceManifest, map_client_references}, |
|
|
dynamic_imports::{DynamicImportEntries, DynamicImportEntriesMapType, map_next_dynamic}, |
|
|
server_actions::{AllActions, AllModuleActions, map_server_actions, to_rsc_context}, |
|
|
}; |
|
|
|
|
|
#[turbo_tasks::value] |
|
|
pub struct NextDynamicGraph { |
|
|
is_single_page: bool, |
|
|
graph: ResolvedVc<SingleModuleGraph>, |
|
|
|
|
|
data: ResolvedVc<DynamicImportEntries>, |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value(transparent)] |
|
|
pub struct DynamicImportEntriesWithImporter( |
|
|
pub Vec<( |
|
|
ResolvedVc<NextDynamicEntryModule>, |
|
|
Option<ClientReferenceType>, |
|
|
)>, |
|
|
); |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl NextDynamicGraph { |
|
|
#[turbo_tasks::function] |
|
|
pub async fn new_with_entries( |
|
|
graph: ResolvedVc<SingleModuleGraph>, |
|
|
is_single_page: bool, |
|
|
) -> Result<Vc<Self>> { |
|
|
let mapped = map_next_dynamic(*graph); |
|
|
|
|
|
Ok(NextDynamicGraph { |
|
|
is_single_page, |
|
|
graph, |
|
|
data: mapped.to_resolved().await?, |
|
|
} |
|
|
.cell()) |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub async fn get_next_dynamic_imports_for_endpoint( |
|
|
&self, |
|
|
entry: ResolvedVc<Box<dyn Module>>, |
|
|
) -> Result<Vc<DynamicImportEntriesWithImporter>> { |
|
|
let span = tracing::info_span!("collect next/dynamic imports for endpoint"); |
|
|
async move { |
|
|
let data = &*self.data.await?; |
|
|
let graph = &*self.graph.await?; |
|
|
|
|
|
#[derive(Clone, PartialEq, Eq)] |
|
|
enum VisitState { |
|
|
Entry, |
|
|
InClientReference(ClientReferenceType), |
|
|
} |
|
|
|
|
|
let entries = if !self.is_single_page { |
|
|
if !graph.has_entry_module(entry) { |
|
|
|
|
|
return Ok(Vc::cell(vec![])); |
|
|
} |
|
|
Either::Left(std::iter::once(entry)) |
|
|
} else { |
|
|
Either::Right(graph.entry_modules()) |
|
|
}; |
|
|
|
|
|
let mut result = vec![]; |
|
|
|
|
|
|
|
|
let mut state_map = FxHashMap::default(); |
|
|
graph.traverse_edges_from_entries(entries, |parent_info, node| { |
|
|
let module = node.module; |
|
|
let Some((parent_node, _)) = parent_info else { |
|
|
state_map.insert(module, VisitState::Entry); |
|
|
return GraphTraversalAction::Continue; |
|
|
}; |
|
|
let parent_module = parent_node.module; |
|
|
|
|
|
let module_type = data.get(&module); |
|
|
let parent_state = state_map.get(&parent_module).unwrap().clone(); |
|
|
let parent_client_reference = |
|
|
if let Some(DynamicImportEntriesMapType::ClientReference(module)) = module_type |
|
|
{ |
|
|
Some(ClientReferenceType::EcmascriptClientReference(*module)) |
|
|
} else if let VisitState::InClientReference(ty) = parent_state { |
|
|
Some(ty) |
|
|
} else { |
|
|
None |
|
|
}; |
|
|
|
|
|
match module_type { |
|
|
Some(DynamicImportEntriesMapType::DynamicEntry(dynamic_entry)) => { |
|
|
result.push((*dynamic_entry, parent_client_reference)); |
|
|
|
|
|
state_map.insert(module, parent_state); |
|
|
GraphTraversalAction::Skip |
|
|
} |
|
|
Some(DynamicImportEntriesMapType::ClientReference(client_reference)) => { |
|
|
state_map.insert( |
|
|
module, |
|
|
VisitState::InClientReference( |
|
|
ClientReferenceType::EcmascriptClientReference(*client_reference), |
|
|
), |
|
|
); |
|
|
GraphTraversalAction::Continue |
|
|
} |
|
|
None => { |
|
|
state_map.insert(module, parent_state); |
|
|
GraphTraversalAction::Continue |
|
|
} |
|
|
} |
|
|
})?; |
|
|
Ok(Vc::cell(result)) |
|
|
} |
|
|
.instrument(span) |
|
|
.await |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value] |
|
|
pub struct ServerActionsGraph { |
|
|
is_single_page: bool, |
|
|
graph: ResolvedVc<SingleModuleGraph>, |
|
|
|
|
|
data: ResolvedVc<AllModuleActions>, |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl ServerActionsGraph { |
|
|
#[turbo_tasks::function] |
|
|
pub async fn new_with_entries( |
|
|
graph: ResolvedVc<SingleModuleGraph>, |
|
|
is_single_page: bool, |
|
|
) -> Result<Vc<Self>> { |
|
|
let mapped = map_server_actions(*graph); |
|
|
|
|
|
Ok(ServerActionsGraph { |
|
|
is_single_page, |
|
|
graph, |
|
|
data: mapped.to_resolved().await?, |
|
|
} |
|
|
.cell()) |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub async fn get_server_actions_for_endpoint( |
|
|
&self, |
|
|
entry: ResolvedVc<Box<dyn Module>>, |
|
|
rsc_asset_context: Vc<Box<dyn AssetContext>>, |
|
|
) -> Result<Vc<AllActions>> { |
|
|
let span = tracing::info_span!("collect server actions for endpoint"); |
|
|
async move { |
|
|
let data = &*self.data.await?; |
|
|
let data = if self.is_single_page { |
|
|
|
|
|
Cow::Borrowed(data) |
|
|
} else { |
|
|
|
|
|
let graph = &*self.graph.await?; |
|
|
|
|
|
if !graph.has_entry_module(entry) { |
|
|
|
|
|
return Ok(Vc::cell(Default::default())); |
|
|
} |
|
|
|
|
|
let mut result = FxIndexMap::default(); |
|
|
graph.traverse_from_entry(entry, |node| { |
|
|
if let Some(node_data) = data.get(&node.module) { |
|
|
result.insert(node.module, *node_data); |
|
|
} |
|
|
})?; |
|
|
Cow::Owned(result) |
|
|
}; |
|
|
|
|
|
let actions = data |
|
|
.iter() |
|
|
.map(|(module, (layer, actions))| async move { |
|
|
let actions = actions.await?; |
|
|
actions |
|
|
.actions |
|
|
.iter() |
|
|
.map(async |(hash, name)| { |
|
|
Ok(( |
|
|
hash.to_string(), |
|
|
( |
|
|
*layer, |
|
|
name.to_string(), |
|
|
if *layer == ActionLayer::Rsc { |
|
|
*module |
|
|
} else { |
|
|
to_rsc_context( |
|
|
**module, |
|
|
&actions.entry_path, |
|
|
&actions.entry_query, |
|
|
rsc_asset_context, |
|
|
) |
|
|
.await? |
|
|
}, |
|
|
), |
|
|
)) |
|
|
}) |
|
|
.try_join() |
|
|
.await |
|
|
}) |
|
|
.try_flat_join() |
|
|
.await?; |
|
|
Ok(Vc::cell(actions.into_iter().collect())) |
|
|
} |
|
|
.instrument(span) |
|
|
.await |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value] |
|
|
pub struct ClientReferencesGraph { |
|
|
is_single_page: bool, |
|
|
graph: ResolvedVc<SingleModuleGraph>, |
|
|
|
|
|
data: ResolvedVc<ClientReferenceManifest>, |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl ClientReferencesGraph { |
|
|
#[turbo_tasks::function] |
|
|
pub async fn new_with_entries( |
|
|
graph: ResolvedVc<SingleModuleGraph>, |
|
|
is_single_page: bool, |
|
|
) -> Result<Vc<Self>> { |
|
|
|
|
|
|
|
|
let mapped = map_client_references(*graph); |
|
|
|
|
|
Ok(Self { |
|
|
is_single_page, |
|
|
graph, |
|
|
data: mapped.to_resolved().await?, |
|
|
} |
|
|
.cell()) |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
async fn get_client_references_for_endpoint( |
|
|
&self, |
|
|
entry: ResolvedVc<Box<dyn Module>>, |
|
|
) -> Result<Vc<ClientReferenceGraphResult>> { |
|
|
let span = tracing::info_span!("collect client references for endpoint"); |
|
|
async move { |
|
|
let data = &*self.data.await?; |
|
|
let graph = &*self.graph.await?; |
|
|
|
|
|
let entries = if !self.is_single_page { |
|
|
if !graph.has_entry_module(entry) { |
|
|
|
|
|
return Ok(ClientReferenceGraphResult::default().cell()); |
|
|
} |
|
|
Either::Left(std::iter::once(entry)) |
|
|
} else { |
|
|
Either::Right(graph.entry_modules()) |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
let mut client_references = Vec::new(); |
|
|
let mut client_reference_modules = Vec::new(); |
|
|
let mut server_components = FxHashSet::default(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq, Copy, Clone)] |
|
|
enum ParentType { |
|
|
ServerComponent, |
|
|
Page, |
|
|
Both, |
|
|
} |
|
|
impl ParentType { |
|
|
fn merge(left: Self, right: Self) -> Self { |
|
|
if left == right { |
|
|
left |
|
|
} else { |
|
|
|
|
|
|
|
|
Self::Both |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
graph.traverse_edges_from_entries_dfs( |
|
|
entries, |
|
|
|
|
|
|
|
|
&mut FxHashMap::default(), |
|
|
|parent_info, node, state_map| { |
|
|
let module = node.module(); |
|
|
let module_type = data.manifest.get(&module); |
|
|
|
|
|
let parent_type = |
|
|
if let Some(ClientManifestEntryType::ServerComponent(_)) = module_type { |
|
|
ParentType::ServerComponent |
|
|
} else if let Some((parent_node, _)) = parent_info { |
|
|
*state_map.get(&parent_node.module).unwrap() |
|
|
} else { |
|
|
|
|
|
ParentType::Page |
|
|
}; |
|
|
|
|
|
match state_map.entry(module) { |
|
|
Entry::Occupied(mut occupied_entry) => { |
|
|
let current = occupied_entry.get_mut(); |
|
|
let merged = ParentType::merge(*current, parent_type); |
|
|
if merged != parent_type { |
|
|
*current = merged; |
|
|
} |
|
|
} |
|
|
Entry::Vacant(vacant_entry) => { |
|
|
vacant_entry.insert(parent_type); |
|
|
} |
|
|
} |
|
|
|
|
|
Ok(match module_type { |
|
|
Some( |
|
|
ClientManifestEntryType::EcmascriptClientReference { .. } |
|
|
| ClientManifestEntryType::CssClientReference { .. }, |
|
|
) => GraphTraversalAction::Skip, |
|
|
_ => GraphTraversalAction::Continue, |
|
|
}) |
|
|
}, |
|
|
|_, node, state_map| { |
|
|
let module = node.module(); |
|
|
let Some(module_type) = data.manifest.get(&module) else { |
|
|
return Ok(()); |
|
|
}; |
|
|
|
|
|
let ty = match module_type { |
|
|
ClientManifestEntryType::EcmascriptClientReference { |
|
|
module, |
|
|
ssr_module: _, |
|
|
} => ClientReferenceType::EcmascriptClientReference(*module), |
|
|
ClientManifestEntryType::CssClientReference(module) => { |
|
|
ClientReferenceType::CssClientReference(*module) |
|
|
} |
|
|
ClientManifestEntryType::ServerComponent(sc) => { |
|
|
server_components.insert(*sc); |
|
|
return Ok(()); |
|
|
} |
|
|
}; |
|
|
|
|
|
if *state_map.get(&module).unwrap() == ParentType::ServerComponent { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client_reference_modules.push((module, ty)); |
|
|
} else { |
|
|
|
|
|
|
|
|
client_references.push(ClientReference { |
|
|
server_component: None, |
|
|
ty, |
|
|
}) |
|
|
} |
|
|
|
|
|
Ok(()) |
|
|
}, |
|
|
)?; |
|
|
|
|
|
|
|
|
|
|
|
client_references.extend(client_reference_modules.into_iter().flat_map( |
|
|
|(module, ty)| { |
|
|
data.server_components_for_client_reference(module) |
|
|
.filter(|sc| server_components.contains(sc)) |
|
|
.map(move |sc| ClientReference { |
|
|
server_component: Some(sc), |
|
|
ty, |
|
|
}) |
|
|
}, |
|
|
)); |
|
|
|
|
|
Ok(ClientReferenceGraphResult { |
|
|
client_references: client_references.into_iter().collect(), |
|
|
server_utils: vec![], |
|
|
server_component_entries: vec![], |
|
|
} |
|
|
.cell()) |
|
|
} |
|
|
.instrument(span) |
|
|
.await |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value(shared)] |
|
|
struct CssGlobalImportIssue { |
|
|
parent_module: ResolvedVc<Box<dyn Module>>, |
|
|
module: ResolvedVc<Box<dyn Module>>, |
|
|
} |
|
|
|
|
|
impl CssGlobalImportIssue { |
|
|
fn new( |
|
|
parent_module: ResolvedVc<Box<dyn Module>>, |
|
|
module: ResolvedVc<Box<dyn Module>>, |
|
|
) -> Self { |
|
|
Self { |
|
|
parent_module, |
|
|
module, |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl Issue for CssGlobalImportIssue { |
|
|
#[turbo_tasks::function] |
|
|
async fn title(&self) -> Vc<StyledString> { |
|
|
StyledString::Stack(vec![ |
|
|
StyledString::Text("Failed to compile".into()), |
|
|
StyledString::Text( |
|
|
"Global CSS cannot be imported from files other than your Custom <App>. Due to \ |
|
|
the Global nature of stylesheets, and to avoid conflicts, Please move all \ |
|
|
first-party global CSS imports to pages/_app.js. Or convert the import to \ |
|
|
Component-Level CSS (CSS Modules)." |
|
|
.into(), |
|
|
), |
|
|
StyledString::Text("Read more: https://nextjs.org/docs/messages/css-global".into()), |
|
|
]) |
|
|
.cell() |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
async fn description(&self) -> Result<Vc<OptionStyledString>> { |
|
|
let parent_path = self.parent_module.ident().path().owned().await?; |
|
|
let module_path = self.module.ident().path().owned().await?; |
|
|
let relative_import_location = parent_path.parent(); |
|
|
|
|
|
let import_path = match relative_import_location.get_relative_path_to(&module_path) { |
|
|
Some(path) => path, |
|
|
None => module_path.path.clone(), |
|
|
}; |
|
|
let cleaned_import_path = |
|
|
if import_path.ends_with(".scss.css") || import_path.ends_with(".sass.css") { |
|
|
RcStr::from(import_path.trim_end_matches(".css")) |
|
|
} else { |
|
|
import_path |
|
|
}; |
|
|
|
|
|
Ok(Vc::cell(Some( |
|
|
StyledString::Stack(vec![ |
|
|
StyledString::Text(format!("Location: {}", parent_path.path).into()), |
|
|
StyledString::Text(format!("Import path: {cleaned_import_path}",).into()), |
|
|
]) |
|
|
.resolved_cell(), |
|
|
))) |
|
|
} |
|
|
|
|
|
fn severity(&self) -> IssueSeverity { |
|
|
IssueSeverity::Error |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
fn file_path(&self) -> Vc<FileSystemPath> { |
|
|
self.parent_module.ident().path() |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
fn stage(&self) -> Vc<IssueStage> { |
|
|
IssueStage::ProcessModule.into() |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
type FxModuleNameMap = FxIndexMap<ResolvedVc<Box<dyn Module>>, RcStr>; |
|
|
|
|
|
#[turbo_tasks::value(transparent)] |
|
|
struct ModuleNameMap(pub FxModuleNameMap); |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
async fn validate_pages_css_imports( |
|
|
graph: Vc<SingleModuleGraph>, |
|
|
is_single_page: bool, |
|
|
entry: Vc<Box<dyn Module>>, |
|
|
app_module: ResolvedVc<Box<dyn Module>>, |
|
|
module_name_map: ResolvedVc<ModuleNameMap>, |
|
|
) -> Result<()> { |
|
|
let graph = &*graph.await?; |
|
|
let entry = entry.to_resolved().await?; |
|
|
let module_name_map = module_name_map.await?; |
|
|
|
|
|
let entries = if !is_single_page { |
|
|
if !graph.has_entry_module(entry) { |
|
|
|
|
|
return Ok(()); |
|
|
} |
|
|
Either::Left(std::iter::once(entry)) |
|
|
} else { |
|
|
Either::Right(graph.entry_modules()) |
|
|
}; |
|
|
|
|
|
graph.traverse_edges_from_entries(entries, |parent_info, node| { |
|
|
let module = node.module; |
|
|
|
|
|
|
|
|
let module_is_global_css = |
|
|
ResolvedVc::try_downcast_type::<CssModuleAsset>(module).is_some(); |
|
|
|
|
|
if !module_is_global_css { |
|
|
return GraphTraversalAction::Continue; |
|
|
} |
|
|
|
|
|
|
|
|
let module_name_contains_node_modules = module_name_map |
|
|
.get(&module) |
|
|
.is_some_and(|s| s.contains("node_modules")); |
|
|
|
|
|
if module_name_contains_node_modules { |
|
|
return GraphTraversalAction::Continue; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let Some((parent_node, _)) = parent_info else { |
|
|
return GraphTraversalAction::Continue; |
|
|
}; |
|
|
|
|
|
let parent_module = parent_node.module; |
|
|
let parent_is_css_module = ResolvedVc::try_downcast_type::<ModuleCssAsset>(parent_module) |
|
|
.is_some() |
|
|
|| ResolvedVc::try_downcast_type::<CssModuleAsset>(parent_module).is_some(); |
|
|
|
|
|
|
|
|
if parent_is_css_module { |
|
|
return GraphTraversalAction::Continue; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if parent_module != app_module { |
|
|
CssGlobalImportIssue::new(parent_module, module) |
|
|
.resolved_cell() |
|
|
.emit(); |
|
|
} |
|
|
|
|
|
GraphTraversalAction::Continue |
|
|
})?; |
|
|
|
|
|
Ok(()) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[turbo_tasks::value] |
|
|
pub struct GlobalBuildInformation { |
|
|
next_dynamic: Vec<ResolvedVc<NextDynamicGraph>>, |
|
|
server_actions: Vec<ResolvedVc<ServerActionsGraph>>, |
|
|
client_references: Vec<ResolvedVc<ClientReferencesGraph>>, |
|
|
|
|
|
bare_graphs: ResolvedVc<ModuleGraph>, |
|
|
is_single_page: bool, |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl GlobalBuildInformation { |
|
|
#[turbo_tasks::function] |
|
|
pub async fn new(graphs: Vc<ModuleGraph>, is_single_page: bool) -> Result<Vc<Self>> { |
|
|
let graphs_ref = &graphs.await?.graphs; |
|
|
let next_dynamic = async { |
|
|
graphs_ref |
|
|
.iter() |
|
|
.map(|graph| { |
|
|
NextDynamicGraph::new_with_entries(**graph, is_single_page).to_resolved() |
|
|
}) |
|
|
.try_join() |
|
|
.await |
|
|
} |
|
|
.instrument(tracing::info_span!("generating next/dynamic graphs")); |
|
|
|
|
|
let server_actions = async { |
|
|
graphs_ref |
|
|
.iter() |
|
|
.map(|graph| { |
|
|
ServerActionsGraph::new_with_entries(**graph, is_single_page).to_resolved() |
|
|
}) |
|
|
.try_join() |
|
|
.await |
|
|
} |
|
|
.instrument(tracing::info_span!("generating server actions graphs")); |
|
|
|
|
|
let client_references = async { |
|
|
graphs_ref |
|
|
.iter() |
|
|
.map(|graph| { |
|
|
ClientReferencesGraph::new_with_entries(**graph, is_single_page).to_resolved() |
|
|
}) |
|
|
.try_join() |
|
|
.await |
|
|
} |
|
|
.instrument(tracing::info_span!("generating client references graphs")); |
|
|
|
|
|
let (next_dynamic, server_actions, client_references) = |
|
|
futures::join!(next_dynamic, server_actions, client_references); |
|
|
|
|
|
Ok(Self { |
|
|
next_dynamic: next_dynamic?, |
|
|
server_actions: server_actions?, |
|
|
client_references: client_references?, |
|
|
bare_graphs: graphs.to_resolved().await?, |
|
|
is_single_page, |
|
|
} |
|
|
.cell()) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub async fn get_next_dynamic_imports_for_endpoint( |
|
|
&self, |
|
|
entry: Vc<Box<dyn Module>>, |
|
|
) -> Result<Vc<DynamicImportEntriesWithImporter>> { |
|
|
let span = tracing::info_span!("collect all next/dynamic imports for endpoint"); |
|
|
async move { |
|
|
if let [graph] = &self.next_dynamic[..] { |
|
|
|
|
|
Ok(graph.get_next_dynamic_imports_for_endpoint(entry)) |
|
|
} else { |
|
|
let result = self |
|
|
.next_dynamic |
|
|
.iter() |
|
|
.map(|graph| async move { |
|
|
Ok(graph |
|
|
.get_next_dynamic_imports_for_endpoint(entry) |
|
|
.await? |
|
|
.into_iter() |
|
|
.map(|(k, v)| (*k, *v)) |
|
|
|
|
|
.collect::<Vec<_>>()) |
|
|
}) |
|
|
.try_flat_join() |
|
|
.await?; |
|
|
|
|
|
Ok(Vc::cell(result.into_iter().collect())) |
|
|
} |
|
|
} |
|
|
.instrument(span) |
|
|
.await |
|
|
} |
|
|
|
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub async fn get_server_actions_for_endpoint( |
|
|
&self, |
|
|
entry: Vc<Box<dyn Module>>, |
|
|
rsc_asset_context: Vc<Box<dyn AssetContext>>, |
|
|
) -> Result<Vc<AllActions>> { |
|
|
let span = tracing::info_span!("collect all server actions for endpoint"); |
|
|
async move { |
|
|
if let [graph] = &self.server_actions[..] { |
|
|
|
|
|
Ok(graph.get_server_actions_for_endpoint(entry, rsc_asset_context)) |
|
|
} else { |
|
|
let result = self |
|
|
.server_actions |
|
|
.iter() |
|
|
.map(|graph| async move { |
|
|
graph |
|
|
.get_server_actions_for_endpoint(entry, rsc_asset_context) |
|
|
.owned() |
|
|
.await |
|
|
}) |
|
|
.try_flat_join() |
|
|
.await?; |
|
|
|
|
|
Ok(Vc::cell(result.into_iter().collect())) |
|
|
} |
|
|
} |
|
|
.instrument(span) |
|
|
.await |
|
|
} |
|
|
|
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub async fn get_client_references_for_endpoint( |
|
|
&self, |
|
|
entry: Vc<Box<dyn Module>>, |
|
|
has_layout_segments: bool, |
|
|
include_traced: bool, |
|
|
) -> Result<Vc<ClientReferenceGraphResult>> { |
|
|
let span = tracing::info_span!("collect all client references for endpoint"); |
|
|
async move { |
|
|
let mut result = if let [graph] = &self.client_references[..] { |
|
|
|
|
|
graph |
|
|
.get_client_references_for_endpoint(entry) |
|
|
.owned() |
|
|
.await? |
|
|
} else { |
|
|
let results = self |
|
|
.client_references |
|
|
.iter() |
|
|
.map(|graph| graph.get_client_references_for_endpoint(entry)) |
|
|
.try_join() |
|
|
.await?; |
|
|
|
|
|
let mut iter = results.into_iter(); |
|
|
let mut result = ReadRef::into_owned(iter.next().unwrap()); |
|
|
for r in iter { |
|
|
result.extend(&r); |
|
|
} |
|
|
result |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if has_layout_segments { |
|
|
|
|
|
|
|
|
let ServerEntries { |
|
|
server_utils, |
|
|
server_component_entries, |
|
|
} = &*find_server_entries(entry, include_traced).await?; |
|
|
result.server_utils = server_utils.clone(); |
|
|
result.server_component_entries = server_component_entries.clone(); |
|
|
} |
|
|
|
|
|
Ok(result.cell()) |
|
|
} |
|
|
.instrument(span) |
|
|
.await |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn validate_pages_css_imports( |
|
|
&self, |
|
|
entry: Vc<Box<dyn Module>>, |
|
|
app_module: Vc<Box<dyn Module>>, |
|
|
) -> Result<()> { |
|
|
let span = tracing::info_span!("validate pages css imports"); |
|
|
async move { |
|
|
let graphs = &self.bare_graphs.await?.graphs; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let graph_to_module_ident_tuples = async |graph: &ResolvedVc<SingleModuleGraph>| { |
|
|
graph |
|
|
.await? |
|
|
.graph |
|
|
.node_weights() |
|
|
.map(async |n| Ok((n.module(), n.module().ident().to_string().owned().await?))) |
|
|
.try_join() |
|
|
.await |
|
|
}; |
|
|
|
|
|
let identifier_map = graphs |
|
|
.iter() |
|
|
.map(graph_to_module_ident_tuples) |
|
|
.try_join() |
|
|
.await? |
|
|
.into_iter() |
|
|
.flatten() |
|
|
.collect::<FxIndexMap<_, _>>(); |
|
|
let identifier_map = ModuleNameMap(identifier_map).cell(); |
|
|
|
|
|
graphs |
|
|
.iter() |
|
|
.map(|graph| { |
|
|
validate_pages_css_imports( |
|
|
**graph, |
|
|
self.is_single_page, |
|
|
entry, |
|
|
app_module, |
|
|
identifier_map, |
|
|
) |
|
|
.as_side_effect() |
|
|
}) |
|
|
.try_join() |
|
|
.await?; |
|
|
|
|
|
Ok(()) |
|
|
} |
|
|
.instrument(span) |
|
|
.await |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function(operation)] |
|
|
fn get_global_information_for_endpoint_inner_operation( |
|
|
module_graph: ResolvedVc<ModuleGraph>, |
|
|
is_single_page: bool, |
|
|
) -> Vc<GlobalBuildInformation> { |
|
|
GlobalBuildInformation::new(*module_graph, is_single_page) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub async fn get_global_information_for_endpoint( |
|
|
module_graph: ResolvedVc<ModuleGraph>, |
|
|
is_single_page: bool, |
|
|
) -> Result<Vc<GlobalBuildInformation>> { |
|
|
|
|
|
|
|
|
let result_op = |
|
|
get_global_information_for_endpoint_inner_operation(module_graph, is_single_page); |
|
|
let result_vc = if !is_single_page { |
|
|
let result_vc = result_op.resolve_strongly_consistent().await?; |
|
|
let _issues = result_op.take_collectibles::<Box<dyn Issue>>(); |
|
|
*result_vc |
|
|
} else { |
|
|
result_op.connect() |
|
|
}; |
|
|
Ok(result_vc) |
|
|
} |
|
|
|