Skip to content

Commit

Permalink
Filter out pages tree view for app dir only output
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Sep 7, 2023
1 parent 068002b commit ca1e387
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 16 deletions.
48 changes: 33 additions & 15 deletions packages/next/src/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,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
Expand Down Expand Up @@ -369,21 +394,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()
Expand All @@ -404,6 +417,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)',
Expand All @@ -412,7 +430,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
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/not-found/basic/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
23 changes: 23 additions & 0 deletions test/production/app-dir/build-output/index.test.ts
Original file line number Diff line number Diff line change
@@ -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')
})
}
)

0 comments on commit ca1e387

Please sign in to comment.