Commit 4436f5ac authored by Jiachi Liu's avatar Jiachi Liu Committed by devjiwonchoi

Switch development log item format as JSON (#89168)

Co-authored-by: 's avatarCursor Agent <cursoragent@cursor.com>
Co-authored-by: 's avatarjiachi <jiachi@vercel.com>
parent 9662feb6
...@@ -10,6 +10,7 @@ use next_core::{ ...@@ -10,6 +10,7 @@ use next_core::{
instrumentation::instrumentation_files, instrumentation::instrumentation_files,
middleware::middleware_files, middleware::middleware_files,
mode::NextMode, mode::NextMode,
next_app::{AppPage, AppPath},
next_client::{ next_client::{
ClientChunkingContextOptions, get_client_chunking_context, get_client_compile_time_info, ClientChunkingContextOptions, get_client_chunking_context, get_client_compile_time_info,
}, },
...@@ -218,24 +219,13 @@ struct DebugBuildPathsRouteKeys { ...@@ -218,24 +219,13 @@ struct DebugBuildPathsRouteKeys {
} }
impl DebugBuildPathsRouteKeys { impl DebugBuildPathsRouteKeys {
fn from_debug_build_paths(paths: &DebugBuildPaths) -> Self { fn from_debug_build_paths(paths: &DebugBuildPaths) -> Result<Self> {
Self { Ok(Self {
app: paths app: paths
.app .app
.iter() .iter()
.map(|path| { .map(|path| Ok(AppPath::from(AppPage::parse(path)?).to_string().into()))
// App router: "/blog/[slug]/page.tsx" -> "/blog/[slug]" .collect::<Result<FxHashSet<_>>>()?,
if let Some(last_slash_idx) = path.rfind('/') {
if last_slash_idx == 0 {
"/".into() // Root: "/page.tsx" -> "/"
} else {
path[..last_slash_idx].into()
}
} else {
path.clone()
}
})
.collect(),
pages: paths pages: paths
.pages .pages
.iter() .iter()
...@@ -248,7 +238,23 @@ impl DebugBuildPathsRouteKeys { ...@@ -248,7 +238,23 @@ impl DebugBuildPathsRouteKeys {
} }
}) })
.collect(), .collect(),
})
}
fn should_include_app_route(&self, route_key: &RcStr) -> bool {
// Special app router framework routes
if matches!(route_key.as_str(), "/_not-found" | "/_global-error") {
return true;
} }
self.app.contains(route_key)
}
fn should_include_pages_route(&self, route_key: &RcStr) -> bool {
// Special pages router framework routes
if matches!(route_key.as_str(), "/_error" | "/_document" | "/_app") {
return true;
}
self.pages.contains(route_key)
} }
} }
...@@ -524,24 +530,6 @@ fn define_env_diff_report(old: &DefineEnv, new: &DefineEnv) -> String { ...@@ -524,24 +530,6 @@ fn define_env_diff_report(old: &DefineEnv, new: &DefineEnv) -> String {
report report
} }
/// Checks if an app router route should be included based on pre-converted route keys.
fn should_include_app_route(route_key: &RcStr, route_keys: &FxHashSet<RcStr>) -> bool {
// Special app router framework routes
if matches!(route_key.as_str(), "/_not-found" | "/_global-error") {
return true;
}
route_keys.contains(route_key)
}
/// Checks if a pages router route should be included based on pre-converted route keys.
fn should_include_pages_route(route_key: &RcStr, route_keys: &FxHashSet<RcStr>) -> bool {
// Special pages router framework routes
if matches!(route_key.as_str(), "/_error" | "/_document" | "/_app") {
return true;
}
route_keys.contains(route_key)
}
impl ProjectContainer { impl ProjectContainer {
pub async fn initialize(self: ResolvedVc<Self>, options: ProjectOptions) -> Result<()> { pub async fn initialize(self: ResolvedVc<Self>, options: ProjectOptions) -> Result<()> {
let span = tracing::info_span!( let span = tracing::info_span!(
...@@ -1635,7 +1623,8 @@ impl Project { ...@@ -1635,7 +1623,8 @@ impl Project {
let debug_build_paths_route_keys = this let debug_build_paths_route_keys = this
.debug_build_paths .debug_build_paths
.as_ref() .as_ref()
.map(DebugBuildPathsRouteKeys::from_debug_build_paths); .map(DebugBuildPathsRouteKeys::from_debug_build_paths)
.transpose()?;
if let Some(app_project) = &*app_project.await? { if let Some(app_project) = &*app_project.await? {
let app_routes = app_project.routes(); let app_routes = app_project.routes();
...@@ -1646,17 +1635,20 @@ impl Project { ...@@ -1646,17 +1635,20 @@ impl Project {
.filter(|(k, _)| { .filter(|(k, _)| {
debug_build_paths_route_keys debug_build_paths_route_keys
.as_ref() .as_ref()
.is_none_or(|keys| should_include_app_route(k, &keys.app)) .is_none_or(|keys| keys.should_include_app_route(k))
}) })
.map(|(k, v)| (k.clone(), v.clone())), .map(|(k, v)| (k.clone(), v.clone())),
); );
} }
for (pathname, page_route) in pages_project.routes().await?.iter().filter(|(k, _)| { for (pathname, page_route) in &pages_project.routes().await? {
debug_build_paths_route_keys if debug_build_paths_route_keys
.as_ref() .as_ref()
.is_none_or(|keys| should_include_pages_route(k, &keys.pages)) .is_some_and(|keys| !keys.should_include_pages_route(pathname))
}) { {
continue;
}
match routes.entry(pathname.clone()) { match routes.entry(pathname.clone()) {
Entry::Occupied(mut entry) => { Entry::Occupied(mut entry) => {
ConflictIssue { ConflictIssue {
......
...@@ -246,6 +246,17 @@ impl AppPage { ...@@ -246,6 +246,17 @@ impl AppPage {
app_page.push_str(segment)?; app_page.push_str(segment)?;
} }
if let Some(last) = app_page.0.last_mut()
&& let PageSegment::Static(last_name) = &*last
{
if last_name.starts_with("page.") {
*last = PageSegment::PageType(PageType::Page);
} else if last_name.starts_with("route") {
*last = PageSegment::PageType(PageType::Route);
}
// can also be metadata (and be neither Page nor Route)
}
Ok(app_page) Ok(app_page)
} }
...@@ -529,3 +540,49 @@ impl From<AppPage> for AppPath { ...@@ -529,3 +540,49 @@ impl From<AppPage> for AppPath {
) )
} }
} }
#[cfg(test)]
mod test {
use crate::next_app::{AppPage, PageSegment, PageType};
#[test]
fn test_normalize_metadata_route() {
assert_eq!(
AppPage::parse("(group)/foo/@par/bar/page.tsx").unwrap(),
AppPage(vec![
PageSegment::Group("group".into()),
PageSegment::Static("foo".into()),
PageSegment::Parallel("par".into()),
PageSegment::Static("bar".into()),
PageSegment::PageType(PageType::Page),
])
);
assert_eq!(
AppPage::parse("(group)/foo/@par/bar/route.tsx").unwrap(),
AppPage(vec![
PageSegment::Group("group".into()),
PageSegment::Static("foo".into()),
PageSegment::Parallel("par".into()),
PageSegment::Static("bar".into()),
PageSegment::PageType(PageType::Route),
])
);
assert_eq!(
AppPage::parse("foo/sitemap").unwrap(),
AppPage(vec![
PageSegment::Static("foo".into()),
PageSegment::Static("sitemap".into()),
])
);
assert_eq!(
AppPage::parse("foo/robots.txt").unwrap(),
AppPage(vec![
PageSegment::Static("foo".into()),
PageSegment::Static("robots.txt".into()),
])
);
}
}
...@@ -225,6 +225,32 @@ describe('debug-build-paths', () => { ...@@ -225,6 +225,32 @@ describe('debug-build-paths', () => {
expect(buildResult.cliOutput).toContain('○ /foo') expect(buildResult.cliOutput).toContain('○ /foo')
expect(buildResult.cliOutput).not.toContain('/with-type-error') expect(buildResult.cliOutput).not.toContain('/with-type-error')
}) })
it('should build routes inside route groups', async () => {
const buildResult = await next.build({
args: ['--debug-build-paths', 'app/(group)/**/page.tsx'],
})
expect(buildResult.exitCode).toBe(0)
expect(buildResult.cliOutput).toContain('Route (app)')
// Route groups are stripped from the path, so /nested instead of /(group)/nested
expect(buildResult.cliOutput).toContain('/nested')
// Should not build other routes
expect(buildResult.cliOutput).not.toContain('○ /about')
expect(buildResult.cliOutput).not.toContain('○ /dashboard')
})
it('should build routes with parallel routes', async () => {
const buildResult = await next.build({
args: ['--debug-build-paths', 'app/parallel-test/**/page.tsx'],
})
expect(buildResult.exitCode).toBe(0)
expect(buildResult.cliOutput).toContain('Route (app)')
// Parallel route segments (@sidebar) are stripped from the path
expect(buildResult.cliOutput).toContain('/parallel-test')
// Should not build other routes
expect(buildResult.cliOutput).not.toContain('○ /about')
expect(buildResult.cliOutput).not.toContain('○ /dashboard')
})
}) })
describe('typechecking with debug-build-paths', () => { describe('typechecking with debug-build-paths', () => {
......
export default function Page() {
return <div>Grouped nested page</div>
}
export default function Sidebar() {
return <div>Sidebar parallel route</div>
}
export default function Layout(props: {
children: React.ReactNode
sidebar: React.ReactNode
}) {
return (
<div>
{props.children}
{props.sidebar}
</div>
)
}
export default function Page() {
return <div>Parallel test main page</div>
}
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