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

chore(turbopack): Make TaskInputs use ResolvedVc #77700

Merged
merged 1 commit into from
Apr 2, 2025
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
79 changes: 43 additions & 36 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,10 +1150,8 @@ impl AppEndpoint {
),
};

let node_root = project.node_root();

let client_relative_path = project.client_relative_path();

let node_root = project.node_root().to_resolved().await?;
let client_relative_path = project.client_relative_path().to_resolved().await?;
let server_path = node_root.join("server".into());

let mut server_assets = fxindexset![];
Expand All @@ -1174,16 +1172,20 @@ impl AppEndpoint {
)
.await?;

let client_chunking_context = project.client_chunking_context();
let client_chunking_context = project.client_chunking_context().to_resolved().await?;

let ssr_chunking_context = if process_ssr {
Some(match runtime {
NextRuntime::NodeJs => Vc::upcast(project.server_chunking_context(true)),
NextRuntime::Edge => this
.app_project
.project()
.edge_chunking_context(process_client_assets),
})
Some(
match runtime {
NextRuntime::NodeJs => Vc::upcast(project.server_chunking_context(true)),
NextRuntime::Edge => this
.app_project
.project()
.edge_chunking_context(process_client_assets),
}
.to_resolved()
.await?,
)
} else {
None
};
Expand All @@ -1193,7 +1195,7 @@ impl AppEndpoint {
.with_modifier(client_shared_chunks_modifier()),
this.app_project.client_runtime_entries(),
*module_graphs.full,
client_chunking_context,
*client_chunking_context,
)
.await?;

Expand All @@ -1216,18 +1218,23 @@ impl AppEndpoint {
.get_next_dynamic_imports_for_endpoint(*rsc_entry)
.await?;

let client_references = reduced_graphs.get_client_references_for_endpoint(
*rsc_entry,
matches!(this.ty, AppEndpointType::Page { .. }),
);
let client_references = reduced_graphs
.get_client_references_for_endpoint(
*rsc_entry,
matches!(this.ty, AppEndpointType::Page { .. }),
)
.to_resolved()
.await?;

let client_references_chunks = get_app_client_references_chunks(
client_references,
*client_references,
*module_graphs.full,
client_chunking_context,
*client_chunking_context,
Value::new(client_shared_availability_info),
ssr_chunking_context,
);
ssr_chunking_context.map(|ctx| *ctx),
)
.to_resolved()
.await?;
let client_references_chunks_ref = client_references_chunks.await?;

let mut entry_client_chunks = FxIndexSet::default();
Expand Down Expand Up @@ -1272,7 +1279,7 @@ impl AppEndpoint {
node_root.join(
format!("server/app{manifest_path_prefix}/app-build-manifest.json",).into(),
),
client_relative_path,
*client_relative_path,
)
.await?
.to_resolved()
Expand Down Expand Up @@ -1328,7 +1335,7 @@ impl AppEndpoint {
node_root.join(
format!("server/app{manifest_path_prefix}/build-manifest.json",).into(),
),
client_relative_path,
*client_relative_path,
)
.await?
.to_resolved()
Expand Down Expand Up @@ -1363,7 +1370,7 @@ impl AppEndpoint {
let server_action_manifest = create_server_actions_manifest(
actions,
project.project_path(),
node_root,
*node_root,
app_entry.original_name.clone(),
runtime,
match runtime {
Expand All @@ -1384,7 +1391,7 @@ impl AppEndpoint {

let app_entry_chunks = self
.app_entry_chunks(
client_references,
*client_references,
*server_action_manifest_loader,
server_path,
process_client_assets,
Expand All @@ -1410,13 +1417,13 @@ impl AppEndpoint {
entry_name: app_entry.original_name.clone(),
client_references,
client_references_chunks,
rsc_app_entry_chunks: *app_entry_chunks,
rsc_app_entry_chunks: app_entry_chunks,
client_chunking_context,
ssr_chunking_context,
async_module_info: module_graphs.full.async_module_info(),
next_config: project.next_config(),
async_module_info: module_graphs.full.async_module_info().to_resolved().await?,
next_config: project.next_config().to_resolved().await?,
runtime,
mode: project.next_mode(),
mode: *project.next_mode().await?,
})
.to_resolved()
.await?;
Expand All @@ -1428,7 +1435,7 @@ impl AppEndpoint {

let next_font_manifest_output = create_font_manifest(
project.client_root(),
node_root,
*node_root,
this.app_project.app_dir(),
&app_entry.original_name,
&app_entry.original_name,
Expand Down Expand Up @@ -1476,7 +1483,7 @@ impl AppEndpoint {
if emit_manifests == EmitManifests::Full {
let dynamic_import_entries = collect_next_dynamic_chunks(
*module_graphs.full,
Vc::upcast(client_chunking_context),
*ResolvedVc::upcast(client_chunking_context),
next_dynamic_imports,
NextDynamicChunkAvailability::ClientReferences(
&*(client_references_chunks.await?),
Expand All @@ -1486,7 +1493,7 @@ impl AppEndpoint {

let loadable_manifest_output = create_react_loadable_manifest(
*dynamic_import_entries,
client_relative_path,
*client_relative_path,
node_root.join(
format!(
"server/app{}/react-loadable-manifest",
Expand Down Expand Up @@ -1556,7 +1563,7 @@ impl AppEndpoint {
if emit_manifests != EmitManifests::None {
// create app paths manifest
let app_paths_manifest_output =
create_app_paths_manifest(node_root, &app_entry.original_name, entry_file)
create_app_paths_manifest(*node_root, &app_entry.original_name, entry_file)
.await?;
server_assets.insert(app_paths_manifest_output);
}
Expand All @@ -1576,7 +1583,7 @@ impl AppEndpoint {
if emit_manifests != EmitManifests::None {
// create app paths manifest
let app_paths_manifest_output = create_app_paths_manifest(
node_root,
*node_root,
&app_entry.original_name,
server_path
.await?
Expand All @@ -1594,7 +1601,7 @@ impl AppEndpoint {
// create react-loadable-manifest for next/dynamic
let dynamic_import_entries = collect_next_dynamic_chunks(
*module_graphs.full,
Vc::upcast(client_chunking_context),
*ResolvedVc::upcast(client_chunking_context),
next_dynamic_imports,
NextDynamicChunkAvailability::ClientReferences(
&*(client_references_chunks.await?),
Expand All @@ -1604,7 +1611,7 @@ impl AppEndpoint {

let loadable_manifest_output = create_react_loadable_manifest(
*dynamic_import_entries,
client_relative_path,
*client_relative_path,
node_root.join(
format!(
"server/app{}/react-loadable-manifest",
Expand Down
28 changes: 14 additions & 14 deletions crates/next-core/src/next_manifests/client_reference_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ use crate::{

#[derive(TaskInput, Clone, Hash, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs)]
pub struct ClientReferenceManifestOptions {
pub node_root: Vc<FileSystemPath>,
pub client_relative_path: Vc<FileSystemPath>,
pub node_root: ResolvedVc<FileSystemPath>,
pub client_relative_path: ResolvedVc<FileSystemPath>,
pub entry_name: RcStr,
pub client_references: Vc<ClientReferenceGraphResult>,
pub client_references_chunks: Vc<ClientReferencesChunks>,
pub rsc_app_entry_chunks: Vc<OutputAssets>,
pub client_chunking_context: Vc<Box<dyn ChunkingContext>>,
pub ssr_chunking_context: Option<Vc<Box<dyn ChunkingContext>>>,
pub async_module_info: Vc<AsyncModulesInfo>,
pub next_config: Vc<NextConfig>,
pub client_references: ResolvedVc<ClientReferenceGraphResult>,
pub client_references_chunks: ResolvedVc<ClientReferencesChunks>,
pub rsc_app_entry_chunks: ResolvedVc<OutputAssets>,
pub client_chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
pub ssr_chunking_context: Option<ResolvedVc<Box<dyn ChunkingContext>>>,
pub async_module_info: ResolvedVc<AsyncModulesInfo>,
pub next_config: ResolvedVc<NextConfig>,
pub runtime: NextRuntime,
pub mode: Vc<NextMode>,
pub mode: NextMode,
}

#[turbo_tasks::value_impl]
Expand Down Expand Up @@ -181,7 +181,7 @@ impl ClientReferenceManifest {
let server_path = client_reference_module_ref.server_ident.to_string().await?;
let client_module = client_reference_module_ref.client_module;
let client_chunk_item_id = client_module
.chunk_item_id(Vc::upcast(client_chunking_context))
.chunk_item_id(*ResolvedVc::upcast(client_chunking_context))
.await?;

let (client_chunks_paths, client_is_async) =
Expand Down Expand Up @@ -226,11 +226,11 @@ impl ClientReferenceManifest {
if let Some(ssr_chunking_context) = ssr_chunking_context {
let ssr_module = client_reference_module_ref.ssr_module;
let ssr_chunk_item_id = ssr_module
.chunk_item_id(Vc::upcast(ssr_chunking_context))
.chunk_item_id(*ResolvedVc::upcast(ssr_chunking_context))
.await?;

let rsc_chunk_item_id = client_reference_module
.chunk_item_id(Vc::upcast(ssr_chunking_context))
.chunk_item_id(*ResolvedVc::upcast(ssr_chunking_context))
.await?;

let (ssr_chunks_paths, ssr_is_async) = if runtime == NextRuntime::Edge {
Expand Down Expand Up @@ -385,7 +385,7 @@ impl ClientReferenceManifest {
}

let inlined = next_config.await?.experimental.inline_css.unwrap_or(false)
&& mode.await?.is_production();
&& mode.is_production();
let entry_css_files_vec = entry_css_files_with_chunk
.into_iter()
.map(async |(path, chunk)| {
Expand Down
50 changes: 27 additions & 23 deletions turbopack/crates/turbopack-ecmascript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,9 @@ impl EcmascriptAnalyzable for EcmascriptModuleAsset {
#[turbo_tasks::function]
async fn module_content(
self: Vc<Self>,
module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
async_module_info: Option<Vc<AsyncModuleInfo>>,
module_graph: ResolvedVc<ModuleGraph>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
async_module_info: Option<ResolvedVc<AsyncModuleInfo>>,
) -> Result<Vc<EcmascriptModuleContent>> {
let parsed = self.parse().to_resolved().await?;

Expand All @@ -430,17 +430,17 @@ impl EcmascriptAnalyzable for EcmascriptModuleAsset {
Ok(EcmascriptModuleContent::new(
EcmascriptModuleContentOptions {
parsed,
ident: self.ident(),
ident: self.ident().to_resolved().await?,
specified_module_type: module_type_result.module_type,
module_graph,
chunking_context,
references: analyze.references(),
esm_references: *analyze_ref.esm_references,
code_generation: *analyze_ref.code_generation,
async_module: *analyze_ref.async_module,
references: analyze.references().to_resolved().await?,
esm_references: analyze_ref.esm_references,
code_generation: analyze_ref.code_generation,
async_module: analyze_ref.async_module,
generate_source_map,
original_source_map: analyze_ref.source_map,
exports: *analyze_ref.exports,
exports: analyze_ref.exports,
async_module_info,
},
))
Expand Down Expand Up @@ -775,18 +775,18 @@ pub struct EcmascriptModuleContent {
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, TaskInput, TraceRawVcs)]
pub struct EcmascriptModuleContentOptions {
parsed: ResolvedVc<ParseResult>,
ident: Vc<AssetIdent>,
ident: ResolvedVc<AssetIdent>,
specified_module_type: SpecifiedModuleType,
module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
references: Vc<ModuleReferences>,
esm_references: Vc<EsmAssetReferences>,
code_generation: Vc<CodeGens>,
async_module: Vc<OptionAsyncModule>,
module_graph: ResolvedVc<ModuleGraph>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
references: ResolvedVc<ModuleReferences>,
esm_references: ResolvedVc<EsmAssetReferences>,
code_generation: ResolvedVc<CodeGens>,
async_module: ResolvedVc<OptionAsyncModule>,
generate_source_map: bool,
original_source_map: ResolvedVc<OptionStringifiedSourceMap>,
exports: Vc<EcmascriptExports>,
async_module_info: Option<Vc<AsyncModuleInfo>>,
exports: ResolvedVc<EcmascriptExports>,
async_module_info: Option<ResolvedVc<AsyncModuleInfo>>,
}

#[turbo_tasks::value_impl]
Expand Down Expand Up @@ -815,7 +815,11 @@ impl EcmascriptModuleContent {
if let Some(async_module) = &*async_module.await? {
Some(
async_module
.code_generation(async_module_info, references, chunking_context)
.code_generation(
async_module_info.map(|info| *info),
*references,
*chunking_context,
)
.await?,
)
} else {
Expand All @@ -824,7 +828,7 @@ impl EcmascriptModuleContent {
if let EcmascriptExports::EsmExports(exports) = *exports.await? {
Some(
exports
.code_generation(module_graph, chunking_context, *parsed)
.code_generation(*module_graph, *chunking_context, *parsed)
.await?,
)
} else {
Expand All @@ -835,13 +839,13 @@ impl EcmascriptModuleContent {
let esm_code_gens = esm_references
.await?
.iter()
.map(|r| r.code_generation(chunking_context))
.map(|r| r.code_generation(*chunking_context))
.try_join()
.await?;
let code_gens = code_generation
.await?
.iter()
.map(|c| c.code_generation(module_graph, chunking_context))
.map(|c| c.code_generation(*module_graph, *chunking_context))
.try_join()
.await?;

Expand All @@ -857,7 +861,7 @@ impl EcmascriptModuleContent {

gen_content_with_code_gens(
parsed,
ident,
*ident,
specified_module_type,
code_gens,
generate_source_map,
Expand Down
Loading
Loading