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

Turbopack: migrate global module ids to single-graph #73752

Open
wants to merge 11 commits into
base: canary
Choose a base branch
from
Open
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.

1 change: 1 addition & 0 deletions crates/next-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ turbo-rcstr = { workspace = true }
turbo-tasks = { workspace = true }
turbo-tasks-env = { workspace = true }
turbo-tasks-fs = { workspace = true }
turbo-tasks-hash = { workspace = true }
turbo-tasks-memory = { workspace = true }
turbopack = { workspace = true }
turbopack-browser = { workspace = true }
Expand Down
72 changes: 56 additions & 16 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use next_core::{
get_edge_resolve_options_context, get_next_package,
next_app::{
get_app_client_references_chunks, get_app_client_shared_chunk_group, get_app_page_entry,
get_app_route_entry, include_modules_module::IncludeModulesModule,
metadata::route::get_app_metadata_route_entry, AppEntry, AppPage,
get_app_route_entry, metadata::route::get_app_metadata_route_entry, AppEntry, AppPage,
},
next_client::{
get_client_module_options_context, get_client_resolve_options_context,
Expand Down Expand Up @@ -52,7 +51,7 @@ use turbopack::{
use turbopack_core::{
asset::AssetContent,
chunk::{
availability_info::AvailabilityInfo, ChunkingContext, ChunkingContextExt,
availability_info::AvailabilityInfo, ChunkableModule, ChunkingContext, ChunkingContextExt,
EntryChunkGroupResult, EvaluatableAsset, EvaluatableAssets,
},
file_source::FileSource,
Expand All @@ -72,15 +71,15 @@ use crate::{
},
font::create_font_manifest,
loadable_manifest::create_react_loadable_manifest,
module_graph::get_reduced_graphs_for_endpoint,
module_graph::{get_reduced_graphs_for_endpoint, ReducedGraphs},
nft_json::NftJsonAsset,
paths::{
all_paths_in_root, all_server_paths, get_asset_paths_from_root, get_js_paths_from_root,
get_wasm_paths_from_root, paths_to_bindings, wasm_paths_to_bindings,
},
project::Project,
route::{AppPageRoute, Endpoint, Route, Routes, WrittenEndpoint},
server_actions::create_server_actions_manifest,
server_actions::{build_server_actions_loader, create_server_actions_manifest},
webpack_stats::generate_webpack_stats,
};

Expand Down Expand Up @@ -1522,16 +1521,23 @@ impl AppEndpoint {
let client_references = client_references.await?;
let span = tracing::trace_span!("server utils");
async {
let utils_module = IncludeModulesModule::new(
AssetIdent::from_path(this.app_project.project().project_path())
.with_modifier(server_utils_modifier()),
client_references.server_utils.iter().map(|v| **v).collect(),
);

let server_utils = client_references
.server_utils
.iter()
.map(|m| async move {
ResolvedVc::try_downcast::<Box<dyn ChunkableModule>>(*m)
.await?
.context("Expected server utils to be chunkable")
})
.try_join()
.await?;
let chunk_group = chunking_context
.chunk_group(
utils_module.ident(),
Vc::upcast(utils_module),
.chunk_group_multiple(
AssetIdent::from_path(
this.app_project.project().project_path(),
)
.with_modifier(server_utils_modifier()),
Vc::cell(server_utils),
Value::new(current_availability_info),
)
.await?;
Expand Down Expand Up @@ -1736,8 +1742,42 @@ impl Endpoint for AppEndpoint {

#[turbo_tasks::function]
async fn root_modules(self: Vc<Self>) -> Result<Vc<Modules>> {
let rsc_entry = self.app_endpoint_entry().await?.rsc_entry;
Ok(Vc::cell(vec![rsc_entry]))
Ok(Vc::cell(vec![self.app_endpoint_entry().await?.rsc_entry]))
}

#[turbo_tasks::function]
async fn additional_root_modules(
self: Vc<Self>,
graphs: Vc<ReducedGraphs>,
) -> Result<Vc<Modules>> {
let this = self.await?;
let app_entry = self.app_endpoint_entry().await?;
let rsc_entry = app_entry.rsc_entry;
let runtime = app_entry.config.await?.runtime.unwrap_or_default();

let actions = graphs.get_server_actions_for_endpoint(
*rsc_entry,
match runtime {
NextRuntime::Edge => Vc::upcast(this.app_project.edge_rsc_module_context()),
NextRuntime::NodeJs => Vc::upcast(this.app_project.rsc_module_context()),
},
);

let server_actions_loader = ResolvedVc::upcast(
build_server_actions_loader(
this.app_project.project().project_path(),
app_entry.original_name.clone(),
actions,
match runtime {
NextRuntime::Edge => Vc::upcast(this.app_project.edge_rsc_module_context()),
NextRuntime::NodeJs => Vc::upcast(this.app_project.rsc_module_context()),
},
)
.to_resolved()
.await?,
);

Ok(Vc::cell(vec![server_actions_loader]))
}
}

Expand Down
90 changes: 0 additions & 90 deletions crates/next-api/src/global_module_id_strategy.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/next-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ mod dynamic_imports;
mod empty;
pub mod entrypoints;
mod font;
pub mod global_module_id_strategy;
mod instrumentation;
mod loadable_manifest;
mod middleware;
Expand Down
24 changes: 15 additions & 9 deletions crates/next-api/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl MiddlewareEndpoint {
}

#[turbo_tasks::function]
async fn edge_files(&self) -> Result<Vc<OutputAssets>> {
async fn entry_module(&self) -> Vc<Box<dyn Module>> {
let userland_module = self
.asset_context
.process(
Expand All @@ -79,22 +79,28 @@ impl MiddlewareEndpoint {
userland_module,
);

let module = wrap_edge_entry(
wrap_edge_entry(
*self.asset_context,
self.project.project_path(),
module,
"middleware".into(),
);
)
}

#[turbo_tasks::function]
async fn edge_files(self: Vc<Self>) -> Result<Vc<OutputAssets>> {
let this = self.await?;
let module = self.entry_module();

let mut evaluatable_assets = get_server_runtime_entries(
Value::new(ServerContextType::Middleware {
app_dir: self.app_dir,
ecmascript_client_reference_transition_name: self
app_dir: this.app_dir,
ecmascript_client_reference_transition_name: this
.ecmascript_client_reference_transition_name,
}),
self.project.next_mode(),
this.project.next_mode(),
)
.resolve_entries(*self.asset_context)
.resolve_entries(*this.asset_context)
.await?
.clone_value();

Expand All @@ -109,7 +115,7 @@ impl MiddlewareEndpoint {
.context("Entry module must be evaluatable")?;
evaluatable_assets.push(evaluatable.to_resolved().await?);

let edge_chunking_context = self.project.edge_chunking_context(false);
let edge_chunking_context = this.project.edge_chunking_context(false);

let edge_files = edge_chunking_context.evaluated_chunk_group_assets(
module.ident(),
Expand Down Expand Up @@ -322,7 +328,7 @@ impl Endpoint for MiddlewareEndpoint {

#[turbo_tasks::function]
async fn root_modules(self: Vc<Self>) -> Result<Vc<Modules>> {
Ok(Vc::cell(vec![self.userland_module().to_resolved().await?]))
Ok(Vc::cell(vec![self.entry_module().to_resolved().await?]))
}
}

Expand Down
Loading
Loading