Unverified Commit 674ba172 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update prerender-manifest structure (#8497)

parent 483cd105
...@@ -44,8 +44,8 @@ const mkdirp = promisify(mkdirpOrig) ...@@ -44,8 +44,8 @@ const mkdirp = promisify(mkdirpOrig)
const staticCheckWorker = require.resolve('./static-checker') const staticCheckWorker = require.resolve('./static-checker')
export type PrerenderRoute = { export type PrerenderFile = {
path: string lambda: string
contentTypes: string[] contentTypes: string[]
} }
...@@ -187,7 +187,6 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -187,7 +187,6 @@ export default async function build(dir: string, conf = null): Promise<void> {
console.log(chalk.green('Compiled successfully.\n')) console.log(chalk.green('Compiled successfully.\n'))
} }
const distPath = path.join(dir, config.distDir)
const pageKeys = Object.keys(mappedPages) const pageKeys = Object.keys(mappedPages)
const manifestPath = path.join( const manifestPath = path.join(
distDir, distDir,
...@@ -221,13 +220,13 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -221,13 +220,13 @@ export default async function build(dir: string, conf = null): Promise<void> {
const chunks = getPageChunks(page) const chunks = getPageChunks(page)
const actualPage = page === '/' ? '/index' : page const actualPage = page === '/' ? '/index' : page
const size = await getPageSizeInKb(actualPage, distPath, buildId) const size = await getPageSizeInKb(actualPage, distDir, buildId)
const bundleRelative = path.join( const bundleRelative = path.join(
isLikeServerless ? 'pages' : `static/${buildId}/pages`, isLikeServerless ? 'pages' : `static/${buildId}/pages`,
actualPage + '.js' actualPage + '.js'
) )
const serverBundle = path.join( const serverBundle = path.join(
distPath, distDir,
isLikeServerless ? SERVERLESS_DIRECTORY : SERVER_DIRECTORY, isLikeServerless ? SERVERLESS_DIRECTORY : SERVER_DIRECTORY,
bundleRelative bundleRelative
) )
...@@ -247,7 +246,7 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -247,7 +246,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
isLikeServerless isLikeServerless
? serverBundle ? serverBundle
: path.join( : path.join(
distPath, distDir,
SERVER_DIRECTORY, SERVER_DIRECTORY,
`/static/${buildId}/pages/_app.js` `/static/${buildId}/pages/_app.js`
), ),
...@@ -330,6 +329,7 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -330,6 +329,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
} }
await writeBuildId(distDir, buildId) await writeBuildId(distDir, buildId)
const prerenderFiles: { [path: string]: PrerenderFile } = {}
if (staticPages.size > 0 || sprPages.size > 0) { if (staticPages.size > 0 || sprPages.size > 0) {
const combinedPages = [...staticPages, ...sprPages] const combinedPages = [...staticPages, ...sprPages]
...@@ -369,7 +369,17 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -369,7 +369,17 @@ export default async function build(dir: string, conf = null): Promise<void> {
relativeDest relativeDest
) )
if (!isSpr) { if (isSpr) {
const projectRelativeDest = path.join(
config.distDir,
isLikeServerless ? SERVERLESS_DIRECTORY : SERVER_DIRECTORY,
relativeDest
)
prerenderFiles[projectRelativeDest] = {
lambda: projectRelativeDest.replace(/\.html$/, '.js'),
contentTypes: ['application/json', 'text/html'],
}
} else {
pagesManifest[page] = relativeDest pagesManifest[page] = relativeDest
if (page === '/') pagesManifest['/index'] = relativeDest if (page === '/') pagesManifest['/index'] = relativeDest
if (page === '/.amp') pagesManifest['/index.amp'] = relativeDest if (page === '/.amp') pagesManifest['/index.amp'] = relativeDest
...@@ -392,18 +402,9 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -392,18 +402,9 @@ export default async function build(dir: string, conf = null): Promise<void> {
} }
if (sprPages.size > 0) { if (sprPages.size > 0) {
const prerenderRoutes: PrerenderRoute[] = []
sprPages.forEach(pg => {
prerenderRoutes.push({
path: pg,
contentTypes: ['application/json', 'text/html'],
})
})
await fsWriteFile( await fsWriteFile(
path.join(distDir, PRERENDER_MANIFEST), path.join(distDir, PRERENDER_MANIFEST),
JSON.stringify({ prerenderRoutes }), JSON.stringify({ prerenderFiles }),
'utf8' 'utf8'
) )
} }
......
...@@ -149,17 +149,19 @@ describe('SPR Prerender', () => { ...@@ -149,17 +149,19 @@ describe('SPR Prerender', () => {
it('outputs a prerender-manifest correctly', async () => { it('outputs a prerender-manifest correctly', async () => {
const manifest = require(join(appDir, '.next', 'prerender-manifest.json')) const manifest = require(join(appDir, '.next', 'prerender-manifest.json'))
const pages = manifest.prerenderRoutes.map(route => route.path) const prerenderablePaths = Object.keys(manifest.prerenderFiles)
expect(JSON.stringify(pages.sort())).toBe( expect(JSON.stringify(prerenderablePaths.sort())).toBe(
JSON.stringify( JSON.stringify(
[ [
'/', '/index.html',
'/another', '/another.html',
'/something', '/something.html',
'/blog/[post]', '/blog/[post].html',
'/blog/[post]/[comment]' '/blog/[post]/[comment].html'
].sort() ]
.map(pg => join('.next/serverless/pages/', pg))
.sort()
) )
) )
}) })
......
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