Unverified Commit 21c2f858 authored by Leah's avatar Leah Committed by GitHub

fix(turbopack): custom page extensions for `_app` (#60789)

### What?
The import alias had no way to resolve the page extensions and we
already have them resolved in the `PagesStructure`, so with this PR we
use the already resolved paths.

Closes PACK-2085
Fixes #59264
parent 072b5cf7
...@@ -54,7 +54,9 @@ use turbopack_binding::{ ...@@ -54,7 +54,9 @@ use turbopack_binding::{
virtual_output::VirtualOutputAsset, virtual_output::VirtualOutputAsset,
}, },
ecmascript::{ ecmascript::{
chunk::EcmascriptChunkingContext, resolve::esm_resolve, EcmascriptModuleAsset, chunk::{EcmascriptChunkPlaceable, EcmascriptChunkingContext},
resolve::esm_resolve,
EcmascriptModuleAsset,
}, },
turbopack::{ turbopack::{
module_options::ModuleOptionsContext, module_options::ModuleOptionsContext,
...@@ -91,13 +93,14 @@ impl PagesProject { ...@@ -91,13 +93,14 @@ impl PagesProject {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn routes(self: Vc<Self>) -> Result<Vc<Routes>> { pub async fn routes(self: Vc<Self>) -> Result<Vc<Routes>> {
let pages_structure = self.pages_structure();
let PagesStructure { let PagesStructure {
api, api,
pages, pages,
app: _, app: _,
document: _, document: _,
error: _, error: _,
} = &*self.pages_structure().await?; } = &*pages_structure.await?;
let mut routes = IndexMap::new(); let mut routes = IndexMap::new();
async fn add_page_to_routes( async fn add_page_to_routes(
...@@ -150,6 +153,7 @@ impl PagesProject { ...@@ -150,6 +153,7 @@ impl PagesProject {
pathname, pathname,
original_name, original_name,
path, path,
pages_structure,
)), )),
} }
}) })
...@@ -163,6 +167,7 @@ impl PagesProject { ...@@ -163,6 +167,7 @@ impl PagesProject {
pathname, pathname,
original_name, original_name,
path, path,
pages_structure,
)), )),
data_endpoint: Vc::upcast(PageEndpoint::new( data_endpoint: Vc::upcast(PageEndpoint::new(
PageEndpointType::Data, PageEndpointType::Data,
...@@ -170,6 +175,7 @@ impl PagesProject { ...@@ -170,6 +175,7 @@ impl PagesProject {
pathname, pathname,
original_name, original_name,
path, path,
pages_structure,
)), )),
}; };
...@@ -201,6 +207,7 @@ impl PagesProject { ...@@ -201,6 +207,7 @@ impl PagesProject {
pathname_vc, pathname_vc,
original_name, original_name,
path, path,
self.pages_structure(),
)); ));
Ok(endpoint) Ok(endpoint)
} }
...@@ -524,6 +531,7 @@ struct PageEndpoint { ...@@ -524,6 +531,7 @@ struct PageEndpoint {
pathname: Vc<String>, pathname: Vc<String>,
original_name: Vc<String>, original_name: Vc<String>,
path: Vc<FileSystemPath>, path: Vc<FileSystemPath>,
pages_structure: Vc<PagesStructure>,
} }
#[derive(Copy, Clone, Serialize, Deserialize, PartialEq, Eq, Debug, TaskInput, TraceRawVcs)] #[derive(Copy, Clone, Serialize, Deserialize, PartialEq, Eq, Debug, TaskInput, TraceRawVcs)]
...@@ -543,6 +551,7 @@ impl PageEndpoint { ...@@ -543,6 +551,7 @@ impl PageEndpoint {
pathname: Vc<String>, pathname: Vc<String>,
original_name: Vc<String>, original_name: Vc<String>,
path: Vc<FileSystemPath>, path: Vc<FileSystemPath>,
pages_structure: Vc<PagesStructure>,
) -> Vc<Self> { ) -> Vc<Self> {
PageEndpoint { PageEndpoint {
ty, ty,
...@@ -550,6 +559,7 @@ impl PageEndpoint { ...@@ -550,6 +559,7 @@ impl PageEndpoint {
pathname, pathname,
original_name, original_name,
path, path,
pages_structure,
} }
.cell() .cell()
} }
...@@ -661,6 +671,7 @@ impl PageEndpoint { ...@@ -661,6 +671,7 @@ impl PageEndpoint {
Vc::upcast(edge_module_context), Vc::upcast(edge_module_context),
self.source(), self.source(),
this.original_name, this.original_name,
this.pages_structure,
config.runtime, config.runtime,
this.pages_project.project().next_config(), this.pages_project.project().next_config(),
); );
...@@ -691,18 +702,34 @@ impl PageEndpoint { ...@@ -691,18 +702,34 @@ impl PageEndpoint {
} }
.cell()) .cell())
} else { } else {
let ssr_module = create_page_ssr_entry_module( let pathname = &**this.pathname.await?;
this.pathname,
reference_type, // `/_app` and `/_document` never get rendered directly so they don't need to be
project_root, // wrapped in the route module.
Vc::upcast(module_context), let ssr_module = if pathname == "/_app" || pathname == "/_document" {
self.source(), let Some(ssr_module) =
this.original_name, Vc::try_resolve_downcast::<Box<dyn EcmascriptChunkPlaceable>>(ssr_module)
config.runtime, .await?
this.pages_project.project().next_config(), else {
); bail!("expected an ECMAScript chunk placeable module");
};
ssr_module
} else {
create_page_ssr_entry_module(
this.pathname,
reference_type,
project_root,
Vc::upcast(module_context),
self.source(),
this.original_name,
this.pages_structure,
config.runtime,
this.pages_project.project().next_config(),
)
};
let asset_path = get_asset_path_from_pathname(&this.pathname.await?, ".js"); let asset_path = get_asset_path_from_pathname(pathname, ".js");
let ssr_entry_chunk_path_string = format!("pages{asset_path}"); let ssr_entry_chunk_path_string = format!("pages{asset_path}");
let ssr_entry_chunk_path = node_path.join(ssr_entry_chunk_path_string); let ssr_entry_chunk_path = node_path.join(ssr_entry_chunk_path_string);
......
...@@ -350,6 +350,7 @@ async fn get_page_entry_for_file( ...@@ -350,6 +350,7 @@ async fn get_page_entry_for_file(
ssr_module_context, ssr_module_context,
source, source,
Vc::cell(original_name), Vc::cell(original_name),
todo_get_pages_structure(),
NextRuntime::NodeJs, NextRuntime::NodeJs,
next_config, next_config,
); );
...@@ -370,6 +371,10 @@ async fn get_page_entry_for_file( ...@@ -370,6 +371,10 @@ async fn get_page_entry_for_file(
.cell()) .cell())
} }
fn todo_get_pages_structure() -> Vc<PagesStructure> {
todo!("add pages structure to next-build");
}
/// Computes the pathname for a given path. /// Computes the pathname for a given path.
#[turbo_tasks::function] #[turbo_tasks::function]
async fn pathname_from_path(next_router_path: Vc<FileSystemPath>) -> Result<Vc<String>> { async fn pathname_from_path(next_router_path: Vc<FileSystemPath>) -> Result<Vc<String>> {
......
export * from '@vercel/turbopack-next/pages/_app'
export { default } from '@vercel/turbopack-next/pages/_app'
export * from '@vercel/turbopack-next/pages/_document'
export { default } from '@vercel/turbopack-next/pages/_document'
export * from '@vercel/turbopack-next/pages/_error'
export { default } from '@vercel/turbopack-next/pages/_error'
...@@ -64,32 +64,7 @@ pub async fn get_next_client_import_map( ...@@ -64,32 +64,7 @@ pub async fn get_next_client_import_map(
.await?; .await?;
match ty.into_value() { match ty.into_value() {
ClientContextType::Pages { pages_dir } => { ClientContextType::Pages { .. } => {}
insert_alias_to_alternatives(
&mut import_map,
format!("{VIRTUAL_PACKAGE_NAME}/pages/_app"),
vec![
request_to_import_mapping(pages_dir, "./_app"),
request_to_import_mapping(pages_dir, "next/app"),
],
);
insert_alias_to_alternatives(
&mut import_map,
format!("{VIRTUAL_PACKAGE_NAME}/pages/_document"),
vec![
request_to_import_mapping(pages_dir, "./_document"),
request_to_import_mapping(pages_dir, "next/document"),
],
);
insert_alias_to_alternatives(
&mut import_map,
format!("{VIRTUAL_PACKAGE_NAME}/pages/_error"),
vec![
request_to_import_mapping(pages_dir, "./_error"),
request_to_import_mapping(pages_dir, "next/error"),
],
);
}
ClientContextType::App { app_dir } => { ClientContextType::App { app_dir } => {
let react_flavor = let react_flavor =
if *next_config.enable_ppr().await? || *next_config.enable_taint().await? { if *next_config.enable_ppr().await? || *next_config.enable_taint().await? {
...@@ -531,32 +506,7 @@ async fn insert_next_server_special_aliases( ...@@ -531,32 +506,7 @@ async fn insert_next_server_special_aliases(
} }
match ty { match ty {
ServerContextType::Pages { pages_dir } | ServerContextType::PagesApi { pages_dir } => { ServerContextType::Pages { .. } | ServerContextType::PagesApi { .. } => {}
insert_alias_to_alternatives(
import_map,
format!("{VIRTUAL_PACKAGE_NAME}/pages/_app"),
vec![
request_to_import_mapping(pages_dir, "./_app"),
external_if_node(pages_dir, "next/app"),
],
);
insert_alias_to_alternatives(
import_map,
format!("{VIRTUAL_PACKAGE_NAME}/pages/_document"),
vec![
request_to_import_mapping(pages_dir, "./_document"),
external_if_node(pages_dir, "next/document"),
],
);
insert_alias_to_alternatives(
import_map,
format!("{VIRTUAL_PACKAGE_NAME}/pages/_error"),
vec![
request_to_import_mapping(pages_dir, "./_error"),
external_if_node(pages_dir, "next/error"),
],
);
}
ServerContextType::PagesData { .. } => {} ServerContextType::PagesData { .. } => {}
// the logic closely follows the one in createRSCAliases in webpack-config.ts // the logic closely follows the one in createRSCAliases in webpack-config.ts
ServerContextType::AppSSR { app_dir } ServerContextType::AppSSR { app_dir }
......
...@@ -14,6 +14,7 @@ use turbopack_binding::{ ...@@ -14,6 +14,7 @@ use turbopack_binding::{
core::{ core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
context::AssetContext, context::AssetContext,
file_source::FileSource,
module::Module, module::Module,
reference_type::{EntryReferenceSubType, ReferenceType}, reference_type::{EntryReferenceSubType, ReferenceType},
source::Source, source::Source,
...@@ -26,6 +27,7 @@ use turbopack_binding::{ ...@@ -26,6 +27,7 @@ use turbopack_binding::{
use crate::{ use crate::{
next_config::NextConfig, next_config::NextConfig,
next_edge::entry::wrap_edge_entry, next_edge::entry::wrap_edge_entry,
pages_structure::{PagesStructure, PagesStructureItem},
util::{file_content_rope, load_next_js_template, NextRuntime}, util::{file_content_rope, load_next_js_template, NextRuntime},
}; };
...@@ -37,6 +39,7 @@ pub async fn create_page_ssr_entry_module( ...@@ -37,6 +39,7 @@ pub async fn create_page_ssr_entry_module(
ssr_module_context: Vc<Box<dyn AssetContext>>, ssr_module_context: Vc<Box<dyn AssetContext>>,
source: Vc<Box<dyn Source>>, source: Vc<Box<dyn Source>>,
next_original_name: Vc<String>, next_original_name: Vc<String>,
pages_structure: Vc<PagesStructure>,
runtime: NextRuntime, runtime: NextRuntime,
next_config: Vc<NextConfig>, next_config: Vc<NextConfig>,
) -> Result<Vc<Box<dyn EcmascriptChunkPlaceable>>> { ) -> Result<Vc<Box<dyn EcmascriptChunkPlaceable>>> {
...@@ -67,6 +70,9 @@ pub async fn create_page_ssr_entry_module( ...@@ -67,6 +70,9 @@ pub async fn create_page_ssr_entry_module(
const INNER: &str = "INNER_PAGE"; const INNER: &str = "INNER_PAGE";
const INNER_DOCUMENT: &str = "INNER_DOCUMENT";
const INNER_APP: &str = "INNER_APP";
let mut replacements = indexmap! { let mut replacements = indexmap! {
"VAR_DEFINITION_PAGE" => definition_page.clone(), "VAR_DEFINITION_PAGE" => definition_page.clone(),
"VAR_DEFINITION_PATHNAME" => definition_pathname.clone(), "VAR_DEFINITION_PATHNAME" => definition_pathname.clone(),
...@@ -74,14 +80,8 @@ pub async fn create_page_ssr_entry_module( ...@@ -74,14 +80,8 @@ pub async fn create_page_ssr_entry_module(
}; };
if reference_type == ReferenceType::Entry(EntryReferenceSubType::Page) { if reference_type == ReferenceType::Entry(EntryReferenceSubType::Page) {
replacements.insert( replacements.insert("VAR_MODULE_DOCUMENT", INNER_DOCUMENT.to_string());
"VAR_MODULE_DOCUMENT", replacements.insert("VAR_MODULE_APP", INNER_APP.to_string());
"@vercel/turbopack-next/pages/_document".to_string(),
);
replacements.insert(
"VAR_MODULE_APP",
"@vercel/turbopack-next/pages/_app".to_string(),
);
} }
// Load the file from the next.js codebase. // Load the file from the next.js codebase.
...@@ -118,12 +118,33 @@ pub async fn create_page_ssr_entry_module( ...@@ -118,12 +118,33 @@ pub async fn create_page_ssr_entry_module(
)); ));
} }
let mut inner_assets = indexmap! {
INNER.to_string() => ssr_module,
};
if reference_type == ReferenceType::Entry(EntryReferenceSubType::Page) {
inner_assets.insert(
INNER_DOCUMENT.to_string(),
process_global_item(
pages_structure.document(),
Value::new(reference_type.clone()),
ssr_module_context,
),
);
inner_assets.insert(
INNER_APP.to_string(),
process_global_item(
pages_structure.app(),
Value::new(reference_type.clone()),
ssr_module_context,
),
);
}
let mut ssr_module = ssr_module_context let mut ssr_module = ssr_module_context
.process( .process(
source, source,
Value::new(ReferenceType::Internal(Vc::cell(indexmap! { Value::new(ReferenceType::Internal(Vc::cell(inner_assets))),
INNER.to_string() => ssr_module,
}))),
) )
.module(); .module();
...@@ -135,6 +156,8 @@ pub async fn create_page_ssr_entry_module( ...@@ -135,6 +156,8 @@ pub async fn create_page_ssr_entry_module(
ssr_module, ssr_module,
definition_page.clone(), definition_page.clone(),
definition_pathname.clone(), definition_pathname.clone(),
Value::new(reference_type),
pages_structure,
next_config, next_config,
); );
} else { } else {
...@@ -156,6 +179,19 @@ pub async fn create_page_ssr_entry_module( ...@@ -156,6 +179,19 @@ pub async fn create_page_ssr_entry_module(
Ok(ssr_module) Ok(ssr_module)
} }
#[turbo_tasks::function]
async fn process_global_item(
item: Vc<PagesStructureItem>,
reference_type: Value<ReferenceType>,
module_context: Vc<Box<dyn AssetContext>>,
) -> Result<Vc<Box<dyn Module>>> {
let source = Vc::upcast(FileSource::new(item.project_path()));
let module = module_context.process(source, reference_type).module();
Ok(module)
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn wrap_edge_page( async fn wrap_edge_page(
context: Vc<Box<dyn AssetContext>>, context: Vc<Box<dyn AssetContext>>,
...@@ -163,10 +199,16 @@ async fn wrap_edge_page( ...@@ -163,10 +199,16 @@ async fn wrap_edge_page(
entry: Vc<Box<dyn Module>>, entry: Vc<Box<dyn Module>>,
page: String, page: String,
pathname: String, pathname: String,
reference_type: Value<ReferenceType>,
pages_structure: Vc<PagesStructure>,
next_config: Vc<NextConfig>, next_config: Vc<NextConfig>,
) -> Result<Vc<Box<dyn Module>>> { ) -> Result<Vc<Box<dyn Module>>> {
const INNER: &str = "INNER_PAGE_ENTRY"; const INNER: &str = "INNER_PAGE_ENTRY";
const INNER_DOCUMENT: &str = "INNER_DOCUMENT";
const INNER_APP: &str = "INNER_APP";
const INNER_ERROR: &str = "INNER_ERROR";
let next_config = &*next_config.await?; let next_config = &*next_config.await?;
// TODO(WEB-1824): add build support // TODO(WEB-1824): add build support
...@@ -188,9 +230,9 @@ async fn wrap_edge_page( ...@@ -188,9 +230,9 @@ async fn wrap_edge_page(
"VAR_USERLAND" => INNER.to_string(), "VAR_USERLAND" => INNER.to_string(),
"VAR_PAGE" => pathname.clone(), "VAR_PAGE" => pathname.clone(),
"VAR_BUILD_ID" => build_id.to_string(), "VAR_BUILD_ID" => build_id.to_string(),
"VAR_MODULE_DOCUMENT" => "@vercel/turbopack-next/pages/_document".to_string(), "VAR_MODULE_DOCUMENT" => INNER_DOCUMENT.to_string(),
"VAR_MODULE_APP" => "@vercel/turbopack-next/pages/_app".to_string(), "VAR_MODULE_APP" => INNER_APP.to_string(),
"VAR_MODULE_GLOBAL_ERROR" => "@vercel/turbopack-next/pages/_error".to_string(), "VAR_MODULE_GLOBAL_ERROR" => INNER_ERROR.to_string(),
}, },
indexmap! { indexmap! {
"pagesType" => StringifyJs("pages").to_string(), "pagesType" => StringifyJs("pages").to_string(),
...@@ -210,7 +252,10 @@ async fn wrap_edge_page( ...@@ -210,7 +252,10 @@ async fn wrap_edge_page(
.await?; .await?;
let inner_assets = indexmap! { let inner_assets = indexmap! {
INNER.to_string() => entry INNER.to_string() => entry,
INNER_DOCUMENT.to_string() => process_global_item(pages_structure.document(), reference_type.clone(), context),
INNER_APP.to_string() => process_global_item(pages_structure.app(), reference_type.clone(), context),
INNER_ERROR.to_string() => process_global_item(pages_structure.error(), reference_type.clone(), context),
}; };
let wrapped = context let wrapped = context
......
...@@ -6,7 +6,7 @@ use turbopack_binding::turbo::tasks_fs::{ ...@@ -6,7 +6,7 @@ use turbopack_binding::turbo::tasks_fs::{
DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath, DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath,
}; };
use crate::embed_js::next_js_file_path; use crate::next_import_map::get_next_package;
/// A final route in the pages directory. /// A final route in the pages directory.
#[turbo_tasks::value] #[turbo_tasks::value]
...@@ -45,6 +45,11 @@ impl PagesStructureItem { ...@@ -45,6 +45,11 @@ impl PagesStructureItem {
this.next_router_path.await?; this.next_router_path.await?;
Ok(Completion::new()) Ok(Completion::new())
} }
#[turbo_tasks::function]
pub fn project_path(&self) -> Vc<FileSystemPath> {
self.project_path
}
} }
/// A (sub)directory in the pages directory with all analyzed routes and /// A (sub)directory in the pages directory with all analyzed routes and
...@@ -82,6 +87,21 @@ impl PagesStructure { ...@@ -82,6 +87,21 @@ impl PagesStructure {
} }
Ok(Completion::new()) Ok(Completion::new())
} }
#[turbo_tasks::function]
pub fn app(&self) -> Vc<PagesStructureItem> {
self.app
}
#[turbo_tasks::function]
pub fn document(&self) -> Vc<PagesStructureItem> {
self.document
}
#[turbo_tasks::function]
pub fn error(&self) -> Vc<PagesStructureItem> {
self.error
}
} }
#[turbo_tasks::value] #[turbo_tasks::value]
...@@ -148,6 +168,7 @@ pub async fn find_pages_structure( ...@@ -148,6 +168,7 @@ pub async fn find_pages_structure(
.await?; .await?;
Ok(get_pages_structure_for_root_directory( Ok(get_pages_structure_for_root_directory(
project_root,
pages_root, pages_root,
next_router_root, next_router_root,
page_extensions, page_extensions,
...@@ -157,6 +178,7 @@ pub async fn find_pages_structure( ...@@ -157,6 +178,7 @@ pub async fn find_pages_structure(
/// Handles the root pages directory. /// Handles the root pages directory.
#[turbo_tasks::function] #[turbo_tasks::function]
async fn get_pages_structure_for_root_directory( async fn get_pages_structure_for_root_directory(
project_root: Vc<FileSystemPath>,
project_path: Vc<FileSystemPathOption>, project_path: Vc<FileSystemPathOption>,
next_router_path: Vc<FileSystemPath>, next_router_path: Vc<FileSystemPath>,
page_extensions: Vc<Vec<String>>, page_extensions: Vc<Vec<String>>,
...@@ -184,7 +206,7 @@ async fn get_pages_structure_for_root_directory( ...@@ -184,7 +206,7 @@ async fn get_pages_structure_for_root_directory(
"_app" => { "_app" => {
let item_next_router_path = let item_next_router_path =
next_router_path.join("_app".to_string()); next_router_path.join("_app".to_string());
let _ = app_item.insert(PagesStructureItem::new( app_item = Some(PagesStructureItem::new(
*file_project_path, *file_project_path,
item_next_router_path, item_next_router_path,
item_next_router_path, item_next_router_path,
...@@ -193,7 +215,7 @@ async fn get_pages_structure_for_root_directory( ...@@ -193,7 +215,7 @@ async fn get_pages_structure_for_root_directory(
"_document" => { "_document" => {
let item_next_router_path = let item_next_router_path =
next_router_path.join("_document".to_string()); next_router_path.join("_document".to_string());
let _ = document_item.insert(PagesStructureItem::new( document_item = Some(PagesStructureItem::new(
*file_project_path, *file_project_path,
item_next_router_path, item_next_router_path,
item_next_router_path, item_next_router_path,
...@@ -202,7 +224,7 @@ async fn get_pages_structure_for_root_directory( ...@@ -202,7 +224,7 @@ async fn get_pages_structure_for_root_directory(
"_error" => { "_error" => {
let item_next_router_path = let item_next_router_path =
next_router_path.join("_error".to_string()); next_router_path.join("_error".to_string());
let _ = error_item.insert(PagesStructureItem::new( error_item = Some(PagesStructureItem::new(
*file_project_path, *file_project_path,
item_next_router_path, item_next_router_path,
item_next_router_path, item_next_router_path,
...@@ -226,7 +248,7 @@ async fn get_pages_structure_for_root_directory( ...@@ -226,7 +248,7 @@ async fn get_pages_structure_for_root_directory(
} }
DirectoryEntry::Directory(dir_project_path) => match name.as_ref() { DirectoryEntry::Directory(dir_project_path) => match name.as_ref() {
"api" => { "api" => {
let _ = api_directory.insert(get_pages_structure_for_directory( api_directory = Some(get_pages_structure_for_directory(
*dir_project_path, *dir_project_path,
next_router_path.join(name.clone()), next_router_path.join(name.clone()),
1, 1,
...@@ -272,7 +294,7 @@ async fn get_pages_structure_for_root_directory( ...@@ -272,7 +294,7 @@ async fn get_pages_structure_for_root_directory(
} else { } else {
let app_router_path = next_router_path.join("_app".to_string()); let app_router_path = next_router_path.join("_app".to_string());
PagesStructureItem::new( PagesStructureItem::new(
next_js_file_path("entry/pages/_app.tsx".to_string()), get_next_package(project_root).join("app.js".to_string()),
app_router_path, app_router_path,
app_router_path, app_router_path,
) )
...@@ -283,7 +305,7 @@ async fn get_pages_structure_for_root_directory( ...@@ -283,7 +305,7 @@ async fn get_pages_structure_for_root_directory(
} else { } else {
let document_router_path = next_router_path.join("_document".to_string()); let document_router_path = next_router_path.join("_document".to_string());
PagesStructureItem::new( PagesStructureItem::new(
next_js_file_path("entry/pages/_document.tsx".to_string()), get_next_package(project_root).join("document.js".to_string()),
document_router_path, document_router_path,
document_router_path, document_router_path,
) )
...@@ -294,7 +316,7 @@ async fn get_pages_structure_for_root_directory( ...@@ -294,7 +316,7 @@ async fn get_pages_structure_for_root_directory(
} else { } else {
let error_router_path = next_router_path.join("_error".to_string()); let error_router_path = next_router_path.join("_error".to_string());
PagesStructureItem::new( PagesStructureItem::new(
next_js_file_path("entry/pages/_error.tsx".to_string()), get_next_package(project_root).join("error.js".to_string()),
error_router_path, error_router_path,
error_router_path, error_router_path,
) )
...@@ -386,10 +408,9 @@ async fn get_pages_structure_for_directory( ...@@ -386,10 +408,9 @@ async fn get_pages_structure_for_directory(
} }
fn page_basename<'a>(name: &'a str, page_extensions: &'a [String]) -> Option<&'a str> { fn page_basename<'a>(name: &'a str, page_extensions: &'a [String]) -> Option<&'a str> {
page_extensions.iter().find_map(|allowed| { page_extensions
name.strip_suffix(allowed) .iter()
.and_then(|name| name.strip_suffix('.')) .find_map(|allowed| name.strip_suffix(allowed)?.strip_suffix('.'))
})
} }
fn next_router_path_for_basename( fn next_router_path_for_basename(
......
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