Unverified Commit c6a4c3b3 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

update routes-manifest to include whether app has pages routes (#86051)

The Vercel CLI produces a lot of `/_next/data` routes regardless of if
pages router is in-use. There's a lot of different metadata we emit but
nothing concretely tells us if an app has pages router enabled. For app
router, we rely on the presence of `app-paths-manifest`, but in pages
router, we always emit a `pages-manifest`.

Rather than trying to cobble together something in the CLI, this updates
the routes manifest to explicitly output the app type (pages, app, or
hybrid).
parent 56fa9cd4
...@@ -435,6 +435,7 @@ type ManifestDataRoute = { ...@@ -435,6 +435,7 @@ type ManifestDataRoute = {
export type RoutesManifest = { export type RoutesManifest = {
version: number version: number
pages404: boolean pages404: boolean
appType: 'app' | 'pages' | 'hybrid'
basePath: string basePath: string
redirects: Array<ManifestRedirectRoute> redirects: Array<ManifestRedirectRoute>
rewrites: { rewrites: {
...@@ -923,6 +924,7 @@ export default async function build( ...@@ -923,6 +924,7 @@ export default async function build(
NextBuildContext.isCompileMode = isCompileMode NextBuildContext.isCompileMode = isCompileMode
NextBuildContext.analyze = experimentalAnalyze NextBuildContext.analyze = experimentalAnalyze
const buildStartTime = Date.now() const buildStartTime = Date.now()
let appType: RoutesManifest['appType']
let loadedConfig: NextConfigComplete | undefined let loadedConfig: NextConfigComplete | undefined
try { try {
...@@ -1077,6 +1079,14 @@ export default async function build( ...@@ -1077,6 +1079,14 @@ export default async function build(
const publicDir = path.join(dir, 'public') const publicDir = path.join(dir, 'public')
const { pagesDir, appDir } = findPagesDir(dir) const { pagesDir, appDir } = findPagesDir(dir)
if (pagesDir && appDir) {
appType = 'hybrid'
} else if (pagesDir) {
appType = 'pages'
} else if (appDir) {
appType = 'app'
}
if (!appDirOnly && !pagesDir) { if (!appDirOnly && !pagesDir) {
appDirOnly = true appDirOnly = true
} }
...@@ -1619,6 +1629,7 @@ export default async function build( ...@@ -1619,6 +1629,7 @@ export default async function build(
return { return {
version: 3, version: 3,
pages404: true, pages404: true,
appType,
caseSensitive: !!config.experimental.caseSensitiveRoutes, caseSensitive: !!config.experimental.caseSensitiveRoutes,
basePath: config.basePath, basePath: config.basePath,
redirects: redirects.map((r) => redirects: redirects.map((r) =>
......
...@@ -1500,6 +1500,7 @@ const runTests = (isDev = false) => { ...@@ -1500,6 +1500,7 @@ const runTests = (isDev = false) => {
]) ])
).toMatchInlineSnapshot(` ).toMatchInlineSnapshot(`
{ {
"appType": "pages",
"basePath": "", "basePath": "",
"caseSensitive": true, "caseSensitive": true,
"dataRoutes": [ "dataRoutes": [
......
...@@ -1257,6 +1257,7 @@ function runTests({ dev }) { ...@@ -1257,6 +1257,7 @@ function runTests({ dev }) {
expect(normalizeManifest(manifest, [[buildId, 'BUILD_ID']])) expect(normalizeManifest(manifest, [[buildId, 'BUILD_ID']]))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
{ {
"appType": "pages",
"basePath": "", "basePath": "",
"caseSensitive": false, "caseSensitive": false,
"dataRoutes": [ "dataRoutes": [
......
import { nextTestSetup } from 'e2e-utils'
import path from 'path'
describe('app-type', () => {
describe('app-only', () => {
const { next } = nextTestSetup({
files: path.join(__dirname, 'fixtures', 'app-only'),
})
it('should have the app-only app type', async () => {
const requiredServerFiles = JSON.parse(
await next.readFile('.next/routes-manifest.json')
)
expect(requiredServerFiles.appType).toBe('app')
})
})
describe('pages-only', () => {
const { next } = nextTestSetup({
files: path.join(__dirname, 'fixtures', 'pages-only'),
})
it('should have the pages-only app type', async () => {
const requiredServerFiles = JSON.parse(
await next.readFile('.next/routes-manifest.json')
)
expect(requiredServerFiles.appType).toBe('pages')
})
})
describe('hybrid', () => {
const { next } = nextTestSetup({
files: path.join(__dirname, 'fixtures', 'hybrid'),
})
it('should have the hybrid app type', async () => {
const requiredServerFiles = JSON.parse(
await next.readFile('.next/routes-manifest.json')
)
expect(requiredServerFiles.appType).toBe('hybrid')
})
})
})
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function Page() {
return <div>Hello, world!</div>
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function Page() {
return <div>Hello, world!</div>
}
export default function Page() {
return <div>Hello, world!</div>
}
export default function Page() {
return <div>Hello, world!</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