Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 33 additions & 15 deletions packages/next/src/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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)',
Expand All @@ -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
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')
})
}
)