Add a routes manifest with the dynamic routes (#9347)

* Add a routes manifest with the dynamic routes

* Update to use pageKeys for windows compat

* Update routes-manifest test
This commit is contained in:
JJ Kasper 2019-11-08 16:51:19 -08:00 committed by Tim Neutkens
parent b929debd76
commit 820a9790ba
4 changed files with 70 additions and 8 deletions

View file

@ -20,8 +20,13 @@ import {
PRERENDER_MANIFEST,
SERVER_DIRECTORY,
SERVERLESS_DIRECTORY,
ROUTES_MANIFEST,
} from '../next-server/lib/constants'
import { getRouteRegex, isDynamicRoute } from '../next-server/lib/router/utils'
import {
getRouteRegex,
isDynamicRoute,
getSortedRoutes,
} from '../next-server/lib/router/utils'
import loadConfig, {
isTargetLikeServerless,
} from '../next-server/server/config'
@ -464,6 +469,23 @@ export default async function build(dir: string, conf = null): Promise<void> {
}
await writeBuildId(distDir, buildId)
const dynamicRoutes = pageKeys.filter(page => isDynamicRoute(page))
await fsWriteFile(
path.join(distDir, ROUTES_MANIFEST),
JSON.stringify(
{
version: 0,
dynamicRoutes: getSortedRoutes(dynamicRoutes).map(page => ({
page,
regex: getRouteRegex(page).re.source,
})),
},
null,
2
)
)
const finalPrerenderRoutes: { [route: string]: SprRoute } = {}
const tbdPrerenderRoutes: string[] = []

View file

@ -5,6 +5,7 @@ export const PHASE_DEVELOPMENT_SERVER = 'phase-development-server'
export const PAGES_MANIFEST = 'pages-manifest.json'
export const BUILD_MANIFEST = 'build-manifest.json'
export const PRERENDER_MANIFEST = 'prerender-manifest.json'
export const ROUTES_MANIFEST = 'routes-manifest.json'
export const REACT_LOADABLE_MANIFEST = 'react-loadable-manifest.json'
export const SERVER_DIRECTORY = 'server'
export const SERVERLESS_DIRECTORY = 'serverless'

View file

@ -225,6 +225,38 @@ function runTests (dev) {
await fs.access(bundlePath + '.js', fs.constants.F_OK)
await fs.access(bundlePath + '.module.js', fs.constants.F_OK)
})
it('should output a routes-manifest correctly', async () => {
const manifest = await fs.readJson(
join(appDir, '.next/routes-manifest.json')
)
expect(manifest).toEqual({
version: 0,
dynamicRoutes: [
{
page: '/blog/[name]/comment/[id]',
regex: '^\\/blog\\/([^\\/]+?)\\/comment\\/([^\\/]+?)(?:\\/)?$'
},
{
page: '/on-mount/[post]',
regex: '^\\/on\\-mount\\/([^\\/]+?)(?:\\/)?$'
},
{
page: '/[name]',
regex: '^\\/([^\\/]+?)(?:\\/)?$'
},
{
page: '/[name]/comments',
regex: '^\\/([^\\/]+?)\\/comments(?:\\/)?$'
},
{
page: '/[name]/[comment]',
regex: '^\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$'
}
]
})
})
}
}
@ -269,7 +301,7 @@ describe('Dynamic Routing', () => {
runTests()
})
describe('SSR production mode', () => {
describe('serverless mode', () => {
beforeAll(async () => {
await fs.writeFile(
nextConfig,

View file

@ -4761,7 +4761,14 @@ conventional-recommended-bump@^4.0.4:
meow "^4.0.0"
q "^1.5.1"
convert-source-map@1.6.0, convert-source-map@^1.1.0, convert-source-map@^1.4.0:
convert-source-map@1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.7.0.tgz#17a2cb882d7f77d3490585e2ce6c524424a3a442"
integrity sha512-4FJkXzKXEDB1snCFZlLP4gpC3JILicCpGbzG9f9G7tGqGCzETQ2hWPrcinA9oU4wtf2biUaEH5065UnMeR33oA==
dependencies:
safe-buffer "~5.1.1"
convert-source-map@^1.1.0, convert-source-map@^1.4.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.6.0.tgz#51b537a8c43e0f04dec1993bffcdd504e758ac20"
integrity sha512-eFu7XigvxdZ1ETfbgPBohgyQ/Z++C0eEhTor0qRwBw9unw+L0/6V8wkSuGgzdThkiS5lSpdptOQPD8Ak40a+7A==
@ -14026,14 +14033,14 @@ style-loader@1.0.0:
loader-utils "^1.2.3"
schema-utils "^2.0.1"
styled-jsx@3.2.2:
version "3.2.2"
resolved "https://registry.yarnpkg.com/styled-jsx/-/styled-jsx-3.2.2.tgz#03d02d26725195d17b6a979eb8d7c34761a16bf8"
integrity sha512-Xb9TPFY2REShznvHt/fw78wk+nxejTr8poepDeS5fRvkQ7lW49CDIWWGLzzALCLcKBIRFK/1Wi4PDZNetpig4w==
styled-jsx@3.2.4:
version "3.2.4"
resolved "https://registry.yarnpkg.com/styled-jsx/-/styled-jsx-3.2.4.tgz#cbcdedcfb81d717fd355c4a0d8443f8e74527b60"
integrity sha512-UMclQzI1lss38RhyjTf7SmtXJEMbB6Q9slDz8adGtzHjirYb1PPgeWLSP8SlZc8c9f3LF6axmtv+6K/553ANdg==
dependencies:
babel-plugin-syntax-jsx "6.18.0"
babel-types "6.26.0"
convert-source-map "1.6.0"
convert-source-map "1.7.0"
loader-utils "1.2.3"
source-map "0.7.3"
string-hash "1.1.3"