Filter out pages tree view for app dir only output (#55120)

Only output app routes if there's no pages routes in next build output


For hello world app you'll only see app dir routes
```
Route (app)                              Size     First Load JS
+ First Load JS shared by all            78.1 kB
  ├ chunks/main-app-e4c0616da69beffe.js  76.5 kB
  └ chunks/webpack-bf1a64d1eafd2816.js   1.61 kB


○  (Static)  automatically rendered as static HTML (uses no initial props)
```

Also filter out `/favicon.ico` static route as it's confusing
This commit is contained in:
Jiachi Liu 2023-09-08 02:06:05 +02:00 committed by GitHub
parent 8076d0c68a
commit 60d3ab3e47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 16 deletions

View file

@ -295,6 +295,31 @@ export function isInstrumentationHookFilename(file?: string) {
)
}
const filterAndSortList = (
list: ReadonlyArray<string>,
routeType: ROUTER_TYPE,
hasCustomApp: boolean
) => {
let pages: string[]
if (routeType === 'app') {
// filter out static app route of /favicon.ico
pages = list.filter((e) => e !== '/favicon.ico')
} else {
// filter built-in pages
pages = list
.slice()
.filter(
(e) =>
!(
e === '/_document' ||
e === '/_error' ||
(!hasCustomApp && e === '/_app')
)
)
}
return pages.sort((a, b) => a.localeCompare(b))
}
export interface PageInfo {
isHybridAmp?: boolean
size: number
@ -367,21 +392,9 @@ export async function printTreeView(
.replace(/(?:^|[.-])([0-9a-z]{6})[0-9a-z]{14}(?=\.)/, '.$1')
// Check if we have a custom app.
const hasCustomApp =
const hasCustomApp = !!(
pagesDir && (await findPageFile(pagesDir, '/_app', pageExtensions, false))
const filterAndSortList = (list: ReadonlyArray<string>) =>
list
.slice()
.filter(
(e) =>
!(
e === '/_document' ||
e === '/_error' ||
(!hasCustomApp && e === '/_app')
)
)
.sort((a, b) => a.localeCompare(b))
// Collect all the symbols we use so we can print the icons out.
const usedSymbols = new Set()
@ -402,6 +415,11 @@ export async function printTreeView(
list: ReadonlyArray<string>
routerType: ROUTER_TYPE
}) => {
const filteredPages = filterAndSortList(list, routerType, hasCustomApp)
if (filteredPages.length === 0) {
return
}
messages.push(
[
routerType === 'app' ? 'Route (app)' : 'Route (pages)',
@ -410,7 +428,7 @@ export async function printTreeView(
].map((entry) => chalk.underline(entry)) as [string, string, string]
)
filterAndSortList(list).forEach((item, i, arr) => {
filteredPages.forEach((item, i, arr) => {
const border =
i === 0
? arr.length === 1

View file

@ -23,7 +23,7 @@ createNextDescribe(
it('should not output /404 in tree view logs', async () => {
const output = await next.cliOutput
expect(output).not.toContain('/404')
expect(output).not.toContain('/404')
})
it('should use root not-found content for 404 html', async () => {

View file

@ -0,0 +1,23 @@
import { createNextDescribe } from 'e2e-utils'
createNextDescribe(
'production - app dir - build output',
{
files: {
'app/page.js': `export default function Page() { return null }`,
'app/layout.js': `export default function Layout({ children }) {
return (
<html><body>{children}</body></html>
)
}`,
},
},
({ next }) => {
it('should only log app routes', async () => {
const output = next.cliOutput
expect(output).toContain('Route (app)')
expect(output).not.toContain('Route (pages)')
expect(output).not.toContain('/favicon.ico')
})
}
)