Unverified Commit ec195371 authored by Alex Kirszenberg's avatar Alex Kirszenberg Committed by GitHub

Named page chunks (#51921)

Depends on https://github.com/vercel/turbo/pull/5398 (and downstack) on
the Turbo side.

This PR makes it so the output path of Node.js entry chunks for pages is
determined solely from the pathname. This isn't actually necessary for
pages, but it makes for easier debugging anyway. See the Turbo PR for
more details.

This also changes the page structure so it also works if there is no
`pages` directory. In this case, we still want to use pages' default
_app, _document, and _error pages, even with existing app routes. So an
empty page structure should still have an effect.

## Turbopack updates

* https://github.com/vercel/turbo/pull/5415 <!-- Will Binns-Smith -
Turbopack: Execution tests in node.js -->
* https://github.com/vercel/turbo/pull/5461 <!-- Tobias Koppers - use a
lock to ensure atomic invalidation from file changes -->
* https://github.com/vercel/turbo/pull/5398 <!-- Alex Kirszenberg -
Configure the path of the Node.js entry chunk -->
* https://github.com/vercel/turbo/pull/5469 <!-- Tobias Koppers - allow
hmr tests to correctly detect hmr event -->
parent 2743d0c0
This diff is collapsed.
...@@ -42,11 +42,11 @@ swc_core = { version = "0.78.24" } ...@@ -42,11 +42,11 @@ swc_core = { version = "0.78.24" }
testing = { version = "0.33.19" } testing = { version = "0.33.19" }
# Turbo crates # Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230704.5" } turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230706.3" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros.. # [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230704.5" } turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230706.3" }
# [TODO]: need to refactor embed_directory! macro usage in next-core # [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230704.5" } turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230706.3" }
# General Deps # General Deps
......
...@@ -115,6 +115,7 @@ pub(crate) async fn next_build(options: TransientInstance<BuildOptions>) -> Resu ...@@ -115,6 +115,7 @@ pub(crate) async fn next_build(options: TransientInstance<BuildOptions>) -> Resu
let page_chunks = get_page_chunks( let page_chunks = get_page_chunks(
pages_structure, pages_structure,
next_router_root,
project_root, project_root,
execution_context, execution_context,
node_root, node_root,
...@@ -411,9 +412,10 @@ pub(crate) async fn next_build(options: TransientInstance<BuildOptions>) -> Resu ...@@ -411,9 +412,10 @@ pub(crate) async fn next_build(options: TransientInstance<BuildOptions>) -> Resu
continue; continue;
} }
let dependencies = pages_manifest let dependencies = build_manifest
.pages .pages
.get(page) .get(page)
.unwrap()
.iter() .iter()
.map(|dep| dep.as_str()) .map(|dep| dep.as_str())
.filter(|dep| !app_dependencies.contains(*dep)) .filter(|dep| !app_dependencies.contains(*dep))
......
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use next_core::{next_client::RuntimeEntriesVc, turbopack::core::chunk::EvaluatableAssetsVc}; use next_core::{next_client::RuntimeEntriesVc, turbopack::core::chunk::EvaluatableAssetsVc};
use turbo_tasks::primitives::StringVc;
use turbopack_binding::{ use turbopack_binding::{
turbo::{tasks::Value, tasks_fs::FileSystemPathVc}, turbo::{tasks::Value, tasks_fs::FileSystemPathVc},
turbopack::{ turbopack::{
...@@ -10,7 +11,7 @@ use turbopack_binding::{ ...@@ -10,7 +11,7 @@ use turbopack_binding::{
reference_type::{EntryReferenceSubType, ReferenceType}, reference_type::{EntryReferenceSubType, ReferenceType},
resolve::{parse::RequestVc, pattern::QueryMapVc}, resolve::{parse::RequestVc, pattern::QueryMapVc},
}, },
ecmascript::EcmascriptModuleAssetVc, ecmascript::chunk::EcmascriptChunkPlaceableVc,
}, },
}; };
...@@ -83,18 +84,28 @@ impl PagesBuildNodeContextVc { ...@@ -83,18 +84,28 @@ impl PagesBuildNodeContextVc {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn node_chunk( pub async fn node_chunk(
self, self,
asset: AssetVc, source_asset: AssetVc,
original_path: StringVc,
reference_type: Value<ReferenceType>, reference_type: Value<ReferenceType>,
) -> Result<AssetVc> { ) -> Result<AssetVc> {
let this = self.await?; let this = self.await?;
let node_asset_page = this.node_asset_context.process(asset, reference_type); let node_asset_page = this
.node_asset_context
.process(source_asset, reference_type);
let Some(node_module_asset) = EcmascriptModuleAssetVc::resolve_from(node_asset_page).await? else { let Some(node_module_asset) = EcmascriptChunkPlaceableVc::resolve_from(node_asset_page).await? else {
bail!("Expected an EcmaScript module asset"); bail!("Expected an EcmaScript module asset");
}; };
let original_path = original_path.await?;
let chunking_context = self.node_chunking_context(); let chunking_context = self.node_chunking_context();
Ok(chunking_context.generate_exported_chunk(node_module_asset, this.node_runtime_entries)) Ok(chunking_context.generate_entry_chunk(
this.node_root
.join(&format!("server/pages/{original_path}.js")),
node_module_asset,
this.node_runtime_entries,
))
} }
} }
use anyhow::Result; use anyhow::{bail, Result};
use next_core::{ use next_core::{
env::env_for_js, env::env_for_js,
mode::NextMode, mode::NextMode,
...@@ -14,13 +14,14 @@ use next_core::{ ...@@ -14,13 +14,14 @@ use next_core::{
get_server_resolve_options_context, ServerContextType, get_server_resolve_options_context, ServerContextType,
}, },
pages_structure::{ pages_structure::{
OptionPagesStructureVc, PagesDirectoryStructure, PagesDirectoryStructureVc, PagesStructure, PagesDirectoryStructure, PagesDirectoryStructureVc, PagesStructure, PagesStructureItem,
PagesStructureItem, PagesStructureVc, PagesStructureVc,
}, },
pathname_for_path, pathname_for_path,
turbopack::core::asset::AssetsVc, turbopack::core::asset::AssetsVc,
PathType, PathType,
}; };
use turbo_tasks::ValueToString;
use turbopack_binding::{ use turbopack_binding::{
turbo::{ turbo::{
tasks::{primitives::StringVc, Value}, tasks::{primitives::StringVc, Value},
...@@ -57,7 +58,8 @@ impl PageChunksVc { ...@@ -57,7 +58,8 @@ impl PageChunksVc {
/// Returns a list of page chunks. /// Returns a list of page chunks.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn get_page_chunks( pub async fn get_page_chunks(
pages_structure: OptionPagesStructureVc, pages_structure: PagesStructureVc,
next_router_root: FileSystemPathVc,
project_root: FileSystemPathVc, project_root: FileSystemPathVc,
execution_context: ExecutionContextVc, execution_context: ExecutionContextVc,
node_root: FileSystemPathVc, node_root: FileSystemPathVc,
...@@ -67,10 +69,11 @@ pub async fn get_page_chunks( ...@@ -67,10 +69,11 @@ pub async fn get_page_chunks(
next_config: NextConfigVc, next_config: NextConfigVc,
node_addr: ServerAddrVc, node_addr: ServerAddrVc,
) -> Result<PageChunksVc> { ) -> Result<PageChunksVc> {
let Some(pages_structure) = *pages_structure.await? else { let pages_dir = if let Some(pages) = pages_structure.await?.pages {
return Ok(PageChunksVc::empty()); pages.project_path().resolve().await?
} else {
project_root.join("pages")
}; };
let pages_dir = pages_structure.project_path().resolve().await?;
let mode = NextMode::Build; let mode = NextMode::Build;
...@@ -175,6 +178,7 @@ pub async fn get_page_chunks( ...@@ -175,6 +178,7 @@ pub async fn get_page_chunks(
node_build_context, node_build_context,
client_build_context, client_build_context,
pages_structure, pages_structure,
next_router_root,
)) ))
} }
...@@ -183,6 +187,7 @@ async fn get_page_chunks_for_root_directory( ...@@ -183,6 +187,7 @@ async fn get_page_chunks_for_root_directory(
node_build_context: PagesBuildNodeContextVc, node_build_context: PagesBuildNodeContextVc,
client_build_context: PagesBuildClientContextVc, client_build_context: PagesBuildClientContextVc,
pages_structure: PagesStructureVc, pages_structure: PagesStructureVc,
next_router_root: FileSystemPathVc,
) -> Result<PageChunksVc> { ) -> Result<PageChunksVc> {
let PagesStructure { let PagesStructure {
app, app,
...@@ -193,8 +198,6 @@ async fn get_page_chunks_for_root_directory( ...@@ -193,8 +198,6 @@ async fn get_page_chunks_for_root_directory(
} = *pages_structure.await?; } = *pages_structure.await?;
let mut chunks = vec![]; let mut chunks = vec![];
let next_router_root = pages.next_router_path();
// This only makes sense on both the client and the server, but they should map // This only makes sense on both the client and the server, but they should map
// to different assets (server can be an external module). // to different assets (server can be an external module).
let app = app.await?; let app = app.await?;
...@@ -204,6 +207,7 @@ async fn get_page_chunks_for_root_directory( ...@@ -204,6 +207,7 @@ async fn get_page_chunks_for_root_directory(
SourceAssetVc::new(app.project_path).into(), SourceAssetVc::new(app.project_path).into(),
next_router_root, next_router_root,
app.next_router_path, app.next_router_path,
app.original_path,
)); ));
// This only makes sense on the server. // This only makes sense on the server.
...@@ -214,6 +218,7 @@ async fn get_page_chunks_for_root_directory( ...@@ -214,6 +218,7 @@ async fn get_page_chunks_for_root_directory(
SourceAssetVc::new(document.project_path).into(), SourceAssetVc::new(document.project_path).into(),
next_router_root, next_router_root,
document.next_router_path, document.next_router_path,
document.original_path,
)); ));
// This only makes sense on both the client and the server, but they should map // This only makes sense on both the client and the server, but they should map
...@@ -225,6 +230,7 @@ async fn get_page_chunks_for_root_directory( ...@@ -225,6 +230,7 @@ async fn get_page_chunks_for_root_directory(
SourceAssetVc::new(error.project_path).into(), SourceAssetVc::new(error.project_path).into(),
next_router_root, next_router_root,
error.next_router_path, error.next_router_path,
error.original_path,
)); ));
if let Some(api) = api { if let Some(api) = api {
...@@ -241,17 +247,19 @@ async fn get_page_chunks_for_root_directory( ...@@ -241,17 +247,19 @@ async fn get_page_chunks_for_root_directory(
); );
} }
chunks.extend( if let Some(pages) = pages {
get_page_chunks_for_directory( chunks.extend(
node_build_context, get_page_chunks_for_directory(
client_build_context, node_build_context,
pages, client_build_context,
next_router_root, pages,
) next_router_root,
.await? )
.iter() .await?
.copied(), .iter()
); .copied(),
);
}
Ok(PageChunksVc::cell(chunks)) Ok(PageChunksVc::cell(chunks))
} }
...@@ -274,6 +282,7 @@ async fn get_page_chunks_for_directory( ...@@ -274,6 +282,7 @@ async fn get_page_chunks_for_directory(
let PagesStructureItem { let PagesStructureItem {
project_path, project_path,
next_router_path, next_router_path,
original_path,
} = *item.await?; } = *item.await?;
chunks.push(get_page_chunk_for_file( chunks.push(get_page_chunk_for_file(
node_build_context, node_build_context,
...@@ -281,6 +290,7 @@ async fn get_page_chunks_for_directory( ...@@ -281,6 +290,7 @@ async fn get_page_chunks_for_directory(
SourceAssetVc::new(project_path).into(), SourceAssetVc::new(project_path).into(),
next_router_root, next_router_root,
next_router_path, next_router_path,
original_path,
)); ));
} }
...@@ -320,23 +330,42 @@ async fn get_page_chunk_for_file( ...@@ -320,23 +330,42 @@ async fn get_page_chunk_for_file(
page_asset: AssetVc, page_asset: AssetVc,
next_router_root: FileSystemPathVc, next_router_root: FileSystemPathVc,
next_router_path: FileSystemPathVc, next_router_path: FileSystemPathVc,
original_path: FileSystemPathVc,
) -> Result<PageChunkVc> { ) -> Result<PageChunkVc> {
let reference_type = Value::new(ReferenceType::Entry(EntryReferenceSubType::Page)); let reference_type = Value::new(ReferenceType::Entry(EntryReferenceSubType::Page));
let pathname = pathname_for_path(next_router_root, next_router_path, PathType::Page); let pathname = pathname_for_path(next_router_root, next_router_path, PathType::Page);
let original_path = get_original_path(next_router_root, original_path);
Ok(PageChunk { Ok(PageChunk {
pathname, pathname,
node_chunk: node_build_context.node_chunk(page_asset, reference_type.clone()), node_chunk: node_build_context.node_chunk(
page_asset,
original_path,
reference_type.clone(),
),
client_chunks: client_build_context.client_chunk(page_asset, pathname, reference_type), client_chunks: client_build_context.client_chunk(page_asset, pathname, reference_type),
} }
.cell()) .cell())
} }
/// Returns the original path of a file within the Next.js router root.
#[turbo_tasks::function] #[turbo_tasks::function]
async fn pathname_from_path(next_router_path: FileSystemPathVc) -> Result<StringVc> { pub async fn get_original_path(
let pathname = next_router_path.await?; next_router_root: FileSystemPathVc,
Ok(StringVc::cell(pathname.path.clone())) original_path: FileSystemPathVc,
) -> Result<StringVc> {
let original_path_value = &*original_path.await?;
let path = if let Some(path) = next_router_root.await?.get_path_to(original_path_value) {
path
} else {
bail!(
"original_path ({}) is not in next_router_root ({})",
original_path.to_string().await?,
next_router_root.to_string().await?
)
};
Ok(StringVc::cell(path.to_string()))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
"check": "tsc --noEmit" "check": "tsc --noEmit"
}, },
"dependencies": { "dependencies": {
"@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230704.5", "@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230706.3",
"@vercel/turbopack-node": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230704.5", "@vercel/turbopack-node": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230706.3",
"anser": "^2.1.1", "anser": "^2.1.1",
"css.escape": "^1.5.1", "css.escape": "^1.5.1",
"next": "*", "next": "*",
......
/** /**
* This is the runtime entry point for Next.js client-side bundles. * This is the runtime entry point for Next.js Page Router client-side bundles.
*/ */
import './shims' import './shims'
......
...@@ -16,7 +16,7 @@ use turbopack_binding::{ ...@@ -16,7 +16,7 @@ use turbopack_binding::{
asset::{AssetVc, AssetsVc}, asset::{AssetVc, AssetsVc},
chunk::{EvaluatableAssetVc, EvaluatableAssetsVc}, chunk::{EvaluatableAssetVc, EvaluatableAssetsVc},
compile_time_info::CompileTimeInfoVc, compile_time_info::CompileTimeInfoVc,
context::{AssetContext, AssetContextVc}, context::AssetContext,
environment::ServerAddrVc, environment::ServerAddrVc,
issue::{Issue, IssueSeverity, IssueSeverityVc, IssueVc}, issue::{Issue, IssueSeverity, IssueSeverityVc, IssueVc},
reference_type::{ reference_type::{
...@@ -351,7 +351,7 @@ fn app_context( ...@@ -351,7 +351,7 @@ fn app_context(
next_config: NextConfigVc, next_config: NextConfigVc,
server_addr: ServerAddrVc, server_addr: ServerAddrVc,
output_path: FileSystemPathVc, output_path: FileSystemPathVc,
) -> AssetContextVc { ) -> ModuleAssetContextVc {
let next_server_to_client_transition = NextServerToClientTransition { ssr }.cell().into(); let next_server_to_client_transition = NextServerToClientTransition { ssr }.cell().into();
let mode = NextMode::Development; let mode = NextMode::Development;
...@@ -464,7 +464,6 @@ fn app_context( ...@@ -464,7 +464,6 @@ fn app_context(
execution_context, execution_context,
), ),
) )
.into()
} }
/// Create a content source serving the `app` or `src/app` directory as /// Create a content source serving the `app` or `src/app` directory as
...@@ -642,8 +641,8 @@ async fn create_global_metadata_source( ...@@ -642,8 +641,8 @@ async fn create_global_metadata_source(
async fn create_app_page_source_for_route( async fn create_app_page_source_for_route(
pathname: &str, pathname: &str,
loader_tree: LoaderTreeVc, loader_tree: LoaderTreeVc,
context_ssr: AssetContextVc, context_ssr: ModuleAssetContextVc,
context: AssetContextVc, context: ModuleAssetContextVc,
project_path: FileSystemPathVc, project_path: FileSystemPathVc,
app_dir: FileSystemPathVc, app_dir: FileSystemPathVc,
env: ProcessEnvVc, env: ProcessEnvVc,
...@@ -691,8 +690,8 @@ async fn create_app_page_source_for_route( ...@@ -691,8 +690,8 @@ async fn create_app_page_source_for_route(
#[turbo_tasks::function] #[turbo_tasks::function]
async fn create_app_not_found_page_source( async fn create_app_not_found_page_source(
loader_tree: LoaderTreeVc, loader_tree: LoaderTreeVc,
context_ssr: AssetContextVc, context_ssr: ModuleAssetContextVc,
context: AssetContextVc, context: ModuleAssetContextVc,
project_path: FileSystemPathVc, project_path: FileSystemPathVc,
app_dir: FileSystemPathVc, app_dir: FileSystemPathVc,
env: ProcessEnvVc, env: ProcessEnvVc,
...@@ -737,7 +736,7 @@ async fn create_app_not_found_page_source( ...@@ -737,7 +736,7 @@ async fn create_app_not_found_page_source(
async fn create_app_route_source_for_route( async fn create_app_route_source_for_route(
pathname: &str, pathname: &str,
entry_path: FileSystemPathVc, entry_path: FileSystemPathVc,
context_ssr: AssetContextVc, context_ssr: ModuleAssetContextVc,
project_path: FileSystemPathVc, project_path: FileSystemPathVc,
app_dir: FileSystemPathVc, app_dir: FileSystemPathVc,
env: ProcessEnvVc, env: ProcessEnvVc,
...@@ -784,8 +783,8 @@ async fn create_app_route_source_for_route( ...@@ -784,8 +783,8 @@ async fn create_app_route_source_for_route(
struct AppRenderer { struct AppRenderer {
runtime_entries: AssetsVc, runtime_entries: AssetsVc,
app_dir: FileSystemPathVc, app_dir: FileSystemPathVc,
context_ssr: AssetContextVc, context_ssr: ModuleAssetContextVc,
context: AssetContextVc, context: ModuleAssetContextVc,
project_path: FileSystemPathVc, project_path: FileSystemPathVc,
server_root: FileSystemPathVc, server_root: FileSystemPathVc,
intermediate_output_path: FileSystemPathVc, intermediate_output_path: FileSystemPathVc,
...@@ -813,7 +812,7 @@ impl AppRendererVc { ...@@ -813,7 +812,7 @@ impl AppRendererVc {
(context_ssr, intermediate_output_path) (context_ssr, intermediate_output_path)
}; };
let config = parse_segment_config_from_loader_tree(loader_tree, context); let config = parse_segment_config_from_loader_tree(loader_tree, context.into());
let runtime = config.await?.runtime; let runtime = config.await?.runtime;
let rsc_transition = match runtime { let rsc_transition = match runtime {
...@@ -826,7 +825,7 @@ impl AppRendererVc { ...@@ -826,7 +825,7 @@ impl AppRendererVc {
counter: usize, counter: usize,
imports: Vec<String>, imports: Vec<String>,
loader_tree_code: String, loader_tree_code: String,
context: AssetContextVc, context: ModuleAssetContextVc,
unsupported_metadata: Vec<FileSystemPathVc>, unsupported_metadata: Vec<FileSystemPathVc>,
rsc_transition: &'static str, rsc_transition: &'static str,
} }
...@@ -925,8 +924,11 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}"; ...@@ -925,8 +924,11 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}";
.push(format!("import {identifier} from \"{inner_module_id}\";")); .push(format!("import {identifier} from \"{inner_module_id}\";"));
state.inner_assets.insert( state.inner_assets.insert(
inner_module_id, inner_module_id,
StaticModuleAssetVc::new(SourceAssetVc::new(path).into(), state.context) StaticModuleAssetVc::new(
.into(), SourceAssetVc::new(path).into(),
state.context.into(),
)
.into(),
); );
writeln!(state.loader_tree_code, " manifest: {identifier},")?; writeln!(state.loader_tree_code, " manifest: {identifier},")?;
} }
...@@ -1154,7 +1156,7 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}"; ...@@ -1154,7 +1156,7 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}";
runtime_entries runtime_entries
.await? .await?
.iter() .iter()
.map(|entry| EvaluatableAssetVc::from_asset(*entry, context)) .map(|entry| EvaluatableAssetVc::from_asset(*entry, context.into()))
.collect(), .collect(),
), ),
module, module,
...@@ -1186,7 +1188,7 @@ impl NodeEntry for AppRenderer { ...@@ -1186,7 +1188,7 @@ impl NodeEntry for AppRenderer {
#[turbo_tasks::value] #[turbo_tasks::value]
struct AppRoute { struct AppRoute {
runtime_entries: AssetsVc, runtime_entries: AssetsVc,
context: AssetContextVc, context: ModuleAssetContextVc,
entry_path: FileSystemPathVc, entry_path: FileSystemPathVc,
intermediate_output_path: FileSystemPathVc, intermediate_output_path: FileSystemPathVc,
project_path: FileSystemPathVc, project_path: FileSystemPathVc,
...@@ -1230,7 +1232,7 @@ impl AppRouteVc { ...@@ -1230,7 +1232,7 @@ impl AppRouteVc {
route_bootstrap( route_bootstrap(
entry_asset, entry_asset,
this.context, this.context.into(),
this.project_path, this.project_path,
bootstrap_asset, bootstrap_asset,
BootstrapConfigVc::empty(), BootstrapConfigVc::empty(),
...@@ -1264,7 +1266,7 @@ impl AppRouteVc { ...@@ -1264,7 +1266,7 @@ impl AppRouteVc {
this.runtime_entries this.runtime_entries
.await? .await?
.iter() .iter()
.map(|entry| EvaluatableAssetVc::from_asset(*entry, this.context)) .map(|entry| EvaluatableAssetVc::from_asset(*entry, this.context.into()))
.collect(), .collect(),
), ),
module, module,
......
...@@ -5,7 +5,7 @@ use turbopack_binding::{ ...@@ -5,7 +5,7 @@ use turbopack_binding::{
turbopack::{ turbopack::{
core::{ core::{
asset::AssetVc, asset::AssetVc,
context::{AssetContext, AssetContextVc}, context::AssetContext,
reference_type::{InnerAssetsVc, ReferenceType}, reference_type::{InnerAssetsVc, ReferenceType},
resolve::ModulePartVc, resolve::ModulePartVc,
}, },
...@@ -46,9 +46,9 @@ impl StructuredImageModuleType { ...@@ -46,9 +46,9 @@ impl StructuredImageModuleType {
pub(crate) fn create_module( pub(crate) fn create_module(
source: AssetVc, source: AssetVc,
blur_placeholder_mode: BlurPlaceholderMode, blur_placeholder_mode: BlurPlaceholderMode,
context: AssetContextVc, context: ModuleAssetContextVc,
) -> AssetVc { ) -> AssetVc {
let static_asset = StaticModuleAssetVc::new(source, context); let static_asset = StaticModuleAssetVc::new(source, context.into());
context.process( context.process(
StructuredImageSourceAsset { StructuredImageSourceAsset {
image: source, image: source,
......
...@@ -74,8 +74,8 @@ use crate::{ ...@@ -74,8 +74,8 @@ use crate::{
}, },
page_loader::create_page_loader, page_loader::create_page_loader,
pages_structure::{ pages_structure::{
OptionPagesStructureVc, PagesDirectoryStructure, PagesDirectoryStructureVc, PagesStructure, PagesDirectoryStructure, PagesDirectoryStructureVc, PagesStructure, PagesStructureItem,
PagesStructureItem, PagesStructureVc, PagesStructureVc,
}, },
util::{parse_config_from_source, pathname_for_path, render_data, NextRuntime, PathType}, util::{parse_config_from_source, pathname_for_path, render_data, NextRuntime, PathType},
}; };
...@@ -84,7 +84,7 @@ use crate::{ ...@@ -84,7 +84,7 @@ use crate::{
/// Next.js pages folder. /// Next.js pages folder.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn create_page_source( pub async fn create_page_source(
pages_structure: OptionPagesStructureVc, pages_structure: PagesStructureVc,
project_root: FileSystemPathVc, project_root: FileSystemPathVc,
execution_context: ExecutionContextVc, execution_context: ExecutionContextVc,
node_root: FileSystemPathVc, node_root: FileSystemPathVc,
...@@ -94,13 +94,10 @@ pub async fn create_page_source( ...@@ -94,13 +94,10 @@ pub async fn create_page_source(
next_config: NextConfigVc, next_config: NextConfigVc,
server_addr: ServerAddrVc, server_addr: ServerAddrVc,
) -> Result<ContentSourceVc> { ) -> Result<ContentSourceVc> {
let (pages_dir, pages_structure) = if let Some(pages_structure) = *pages_structure.await? { let pages_dir = if let Some(pages) = pages_structure.await?.pages {
( pages.project_path().resolve().await?
pages_structure.project_path().resolve().await?,
Some(pages_structure),
)
} else { } else {
(project_root.join("pages"), None) project_root.join("pages")
}; };
let mode = NextMode::Development; let mode = NextMode::Development;
...@@ -295,22 +292,20 @@ pub async fn create_page_source( ...@@ -295,22 +292,20 @@ pub async fn create_page_source(
.issue_context(pages_dir, "Next.js pages directory not found"), .issue_context(pages_dir, "Next.js pages directory not found"),
); );
if let Some(pages_structure) = pages_structure { sources.push(create_page_source_for_root_directory(
sources.push(create_page_source_for_root_directory( pages_structure,
pages_structure, project_root,
project_root, env,
env, server_context,
server_context, server_data_context,
server_data_context, client_context,
client_context, pages_dir,
pages_dir, server_runtime_entries,
server_runtime_entries, fallback_page,
fallback_page, client_root,
client_root, node_root,
node_root, render_data,
render_data, ));
));
}
sources.push( sources.push(
AssetGraphContentSourceVc::new_eager(client_root, fallback_page.as_asset()) AssetGraphContentSourceVc::new_eager(client_root, fallback_page.as_asset())
...@@ -637,21 +632,23 @@ async fn create_page_source_for_root_directory( ...@@ -637,21 +632,23 @@ async fn create_page_source_for_root_directory(
} = *pages_structure.await?; } = *pages_structure.await?;
let mut sources = vec![]; let mut sources = vec![];
sources.push(create_page_source_for_directory( if let Some(pages) = pages {
*pages, sources.push(create_page_source_for_directory(
project_root, *pages,
env, project_root,
server_context, env,
server_data_context, server_context,
client_context, server_data_context,
pages_dir, client_context,
runtime_entries, pages_dir,
fallback_page, runtime_entries,
client_root, fallback_page,
false, client_root,
node_root, false,
render_data, node_root,
)); render_data,
));
}
if let Some(api) = api { if let Some(api) = api {
sources.push(create_page_source_for_directory( sources.push(create_page_source_for_directory(
...@@ -704,6 +701,7 @@ async fn create_page_source_for_directory( ...@@ -704,6 +701,7 @@ async fn create_page_source_for_directory(
let PagesStructureItem { let PagesStructureItem {
project_path, project_path,
next_router_path, next_router_path,
original_path: _,
} = *item.await?; } = *item.await?;
let source = create_page_source_for_file( let source = create_page_source_for_file(
project_root, project_root,
......
...@@ -19,7 +19,7 @@ use turbopack_binding::turbopack::{ ...@@ -19,7 +19,7 @@ use turbopack_binding::turbopack::{
use crate::{ use crate::{
app_structure::OptionAppDirVc, app_structure::OptionAppDirVc,
next_config::NextConfigVc, next_config::NextConfigVc,
pages_structure::OptionPagesStructureVc, pages_structure::PagesStructureVc,
router::{route, RouterRequest, RouterResult}, router::{route, RouterRequest, RouterResult},
}; };
...@@ -31,7 +31,7 @@ pub struct NextRouterContentSource { ...@@ -31,7 +31,7 @@ pub struct NextRouterContentSource {
next_config: NextConfigVc, next_config: NextConfigVc,
server_addr: ServerAddrVc, server_addr: ServerAddrVc,
app_dir: OptionAppDirVc, app_dir: OptionAppDirVc,
pages_structure: OptionPagesStructureVc, pages_structure: PagesStructureVc,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
...@@ -43,7 +43,7 @@ impl NextRouterContentSourceVc { ...@@ -43,7 +43,7 @@ impl NextRouterContentSourceVc {
next_config: NextConfigVc, next_config: NextConfigVc,
server_addr: ServerAddrVc, server_addr: ServerAddrVc,
app_dir: OptionAppDirVc, app_dir: OptionAppDirVc,
pages_structure: OptionPagesStructureVc, pages_structure: PagesStructureVc,
) -> NextRouterContentSourceVc { ) -> NextRouterContentSourceVc {
NextRouterContentSource { NextRouterContentSource {
inner, inner,
...@@ -60,7 +60,7 @@ impl NextRouterContentSourceVc { ...@@ -60,7 +60,7 @@ impl NextRouterContentSourceVc {
#[turbo_tasks::function] #[turbo_tasks::function]
fn routes_changed( fn routes_changed(
app_dir: OptionAppDirVc, app_dir: OptionAppDirVc,
pages_structure: OptionPagesStructureVc, pages_structure: PagesStructureVc,
next_config: NextConfigVc, next_config: NextConfigVc,
) -> CompletionVc { ) -> CompletionVc {
CompletionsVc::all(vec![ CompletionsVc::all(vec![
...@@ -77,7 +77,7 @@ impl ContentSource for NextRouterContentSource { ...@@ -77,7 +77,7 @@ impl ContentSource for NextRouterContentSource {
// The next-dev server can currently run against projects as simple as // The next-dev server can currently run against projects as simple as
// `index.js`. If this isn't a Next.js project, don't try to use the Next.js // `index.js`. If this isn't a Next.js project, don't try to use the Next.js
// router. // router.
if this.app_dir.await?.is_none() && this.pages_structure.await?.is_none() { if this.app_dir.await?.is_none() && this.pages_structure.await?.pages.is_none() {
return Ok(this.inner.get_routes()); return Ok(this.inner.get_routes());
} }
......
...@@ -992,8 +992,8 @@ importers: ...@@ -992,8 +992,8 @@ importers:
'@types/react': 18.2.7 '@types/react': 18.2.7
'@types/react-dom': 18.2.4 '@types/react-dom': 18.2.4
'@vercel/ncc': ^0.36.0 '@vercel/ncc': ^0.36.0
'@vercel/turbopack-ecmascript-runtime': https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230704.5 '@vercel/turbopack-ecmascript-runtime': https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230706.3
'@vercel/turbopack-node': https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230704.5 '@vercel/turbopack-node': https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230706.3
anser: ^2.1.1 anser: ^2.1.1
css.escape: ^1.5.1 css.escape: ^1.5.1
find-up: ^6.3.0 find-up: ^6.3.0
...@@ -1005,8 +1005,8 @@ importers: ...@@ -1005,8 +1005,8 @@ importers:
stacktrace-parser: ^0.1.10 stacktrace-parser: ^0.1.10
strip-ansi: ^7.0.1 strip-ansi: ^7.0.1
dependencies: dependencies:
'@vercel/turbopack-ecmascript-runtime': '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230704.5_react-refresh@0.12.0' '@vercel/turbopack-ecmascript-runtime': '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230706.3_react-refresh@0.12.0'
'@vercel/turbopack-node': '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230704.5' '@vercel/turbopack-node': '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230706.3'
anser: 2.1.1 anser: 2.1.1
css.escape: 1.5.1 css.escape: 1.5.1
next: link:../../../../next next: link:../../../../next
...@@ -6120,7 +6120,7 @@ packages: ...@@ -6120,7 +6120,7 @@ packages:
dependencies: dependencies:
'@mdx-js/mdx': 2.2.1 '@mdx-js/mdx': 2.2.1
source-map: 0.7.3 source-map: 0.7.3
webpack: 5.86.0 webpack: 5.86.0_@swc+core@1.3.55
transitivePeerDependencies: transitivePeerDependencies:
- supports-color - supports-color
...@@ -6794,7 +6794,6 @@ packages: ...@@ -6794,7 +6794,6 @@ packages:
cpu: [arm64] cpu: [arm64]
os: [darwin] os: [darwin]
requiresBuild: true requiresBuild: true
dev: true
optional: true optional: true
/@swc/core-darwin-x64/1.3.55: /@swc/core-darwin-x64/1.3.55:
...@@ -6803,7 +6802,6 @@ packages: ...@@ -6803,7 +6802,6 @@ packages:
cpu: [x64] cpu: [x64]
os: [darwin] os: [darwin]
requiresBuild: true requiresBuild: true
dev: true
optional: true optional: true
/@swc/core-linux-arm-gnueabihf/1.3.55: /@swc/core-linux-arm-gnueabihf/1.3.55:
...@@ -6812,7 +6810,6 @@ packages: ...@@ -6812,7 +6810,6 @@ packages:
cpu: [arm] cpu: [arm]
os: [linux] os: [linux]
requiresBuild: true requiresBuild: true
dev: true
optional: true optional: true
/@swc/core-linux-arm64-gnu/1.3.55: /@swc/core-linux-arm64-gnu/1.3.55:
...@@ -6821,7 +6818,6 @@ packages: ...@@ -6821,7 +6818,6 @@ packages:
cpu: [arm64] cpu: [arm64]
os: [linux] os: [linux]
requiresBuild: true requiresBuild: true
dev: true
optional: true optional: true
/@swc/core-linux-arm64-musl/1.3.55: /@swc/core-linux-arm64-musl/1.3.55:
...@@ -6830,7 +6826,6 @@ packages: ...@@ -6830,7 +6826,6 @@ packages:
cpu: [arm64] cpu: [arm64]
os: [linux] os: [linux]
requiresBuild: true requiresBuild: true
dev: true
optional: true optional: true
/@swc/core-linux-x64-gnu/1.3.55: /@swc/core-linux-x64-gnu/1.3.55:
...@@ -6839,7 +6834,6 @@ packages: ...@@ -6839,7 +6834,6 @@ packages:
cpu: [x64] cpu: [x64]
os: [linux] os: [linux]
requiresBuild: true requiresBuild: true
dev: true
optional: true optional: true
/@swc/core-linux-x64-musl/1.3.55: /@swc/core-linux-x64-musl/1.3.55:
...@@ -6848,7 +6842,6 @@ packages: ...@@ -6848,7 +6842,6 @@ packages:
cpu: [x64] cpu: [x64]
os: [linux] os: [linux]
requiresBuild: true requiresBuild: true
dev: true
optional: true optional: true
/@swc/core-win32-arm64-msvc/1.3.55: /@swc/core-win32-arm64-msvc/1.3.55:
...@@ -6857,7 +6850,6 @@ packages: ...@@ -6857,7 +6850,6 @@ packages:
cpu: [arm64] cpu: [arm64]
os: [win32] os: [win32]
requiresBuild: true requiresBuild: true
dev: true
optional: true optional: true
/@swc/core-win32-ia32-msvc/1.3.55: /@swc/core-win32-ia32-msvc/1.3.55:
...@@ -6866,7 +6858,6 @@ packages: ...@@ -6866,7 +6858,6 @@ packages:
cpu: [ia32] cpu: [ia32]
os: [win32] os: [win32]
requiresBuild: true requiresBuild: true
dev: true
optional: true optional: true
/@swc/core-win32-x64-msvc/1.3.55: /@swc/core-win32-x64-msvc/1.3.55:
...@@ -6875,7 +6866,6 @@ packages: ...@@ -6875,7 +6866,6 @@ packages:
cpu: [x64] cpu: [x64]
os: [win32] os: [win32]
requiresBuild: true requiresBuild: true
dev: true
optional: true optional: true
/@swc/core/1.3.55_@swc+helpers@0.5.1: /@swc/core/1.3.55_@swc+helpers@0.5.1:
...@@ -6900,7 +6890,6 @@ packages: ...@@ -6900,7 +6890,6 @@ packages:
'@swc/core-win32-arm64-msvc': 1.3.55 '@swc/core-win32-arm64-msvc': 1.3.55
'@swc/core-win32-ia32-msvc': 1.3.55 '@swc/core-win32-ia32-msvc': 1.3.55
'@swc/core-win32-x64-msvc': 1.3.55 '@swc/core-win32-x64-msvc': 1.3.55
dev: true
/@swc/helpers/0.4.14: /@swc/helpers/0.4.14:
resolution: {integrity: sha512-4C7nX/dvpzB7za4Ql9K81xK3HPxCpHMgwTZVyf+9JQ6VUbn9jjZVN7/Nkdz/Ugzs2CSjqnL/UPXroiVBVHUWUw==} resolution: {integrity: sha512-4C7nX/dvpzB7za4Ql9K81xK3HPxCpHMgwTZVyf+9JQ6VUbn9jjZVN7/Nkdz/Ugzs2CSjqnL/UPXroiVBVHUWUw==}
...@@ -23815,7 +23804,6 @@ packages: ...@@ -23815,7 +23804,6 @@ packages:
serialize-javascript: 6.0.1 serialize-javascript: 6.0.1
terser: 5.17.7 terser: 5.17.7
webpack: 5.86.0_@swc+core@1.3.55 webpack: 5.86.0_@swc+core@1.3.55
dev: true
/terser/5.10.0: /terser/5.10.0:
resolution: {integrity: sha512-AMmF99DMfEDiRJfxfY5jj5wNH/bYO09cniSqhfoyxc8sFoYIgkJy86G04UoZU5VjlpnplVu0K6Tx6E9b5+DlHA==} resolution: {integrity: sha512-AMmF99DMfEDiRJfxfY5jj5wNH/bYO09cniSqhfoyxc8sFoYIgkJy86G04UoZU5VjlpnplVu0K6Tx6E9b5+DlHA==}
...@@ -25173,7 +25161,6 @@ packages: ...@@ -25173,7 +25161,6 @@ packages:
- '@swc/core' - '@swc/core'
- esbuild - esbuild
- uglify-js - uglify-js
dev: true
/websocket-driver/0.7.3: /websocket-driver/0.7.3:
resolution: {integrity: sha512-bpxWlvbbB459Mlipc5GBzzZwhoZgGEZLuqPaR0INBGnPAY1vdBX6hPnoFXiw+3yWxDuHyQjO2oXTMyS8A5haFg==} resolution: {integrity: sha512-bpxWlvbbB459Mlipc5GBzzZwhoZgGEZLuqPaR0INBGnPAY1vdBX6hPnoFXiw+3yWxDuHyQjO2oXTMyS8A5haFg==}
...@@ -25582,9 +25569,9 @@ packages: ...@@ -25582,9 +25569,9 @@ packages:
/zwitch/2.0.4: /zwitch/2.0.4:
resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==} resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==}
'@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230704.5_react-refresh@0.12.0': '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230706.3_react-refresh@0.12.0':
resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230704.5} resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230706.3}
id: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230704.5' id: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230706.3'
name: '@vercel/turbopack-ecmascript-runtime' name: '@vercel/turbopack-ecmascript-runtime'
version: 0.0.0 version: 0.0.0
dependencies: dependencies:
...@@ -25595,8 +25582,8 @@ packages: ...@@ -25595,8 +25582,8 @@ packages:
- webpack - webpack
dev: false dev: false
'@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230704.5': '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230706.3':
resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230704.5} resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230706.3}
name: '@vercel/turbopack-node' name: '@vercel/turbopack-node'
version: 0.0.0 version: 0.0.0
dependencies: dependencies:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment