rsnext/packages/next/next-server/server/get-page-files.ts
Joe Haddad 3597978d7f
Modify low priority files in manifest (#16181)
This pull request edits the `BuildManifest` that is sent to `/_document` instead of modifying a single input array to decouple its implementation details.

Optimally, we'd eliminate the `files` key all together.

---

Related to #16182
2020-08-14 04:30:25 +00:00

30 lines
745 B
TypeScript

import { normalizePagePath, denormalizePagePath } from './normalize-page-path'
export type BuildManifest = {
devFiles: readonly string[]
ampDevFiles: readonly string[]
polyfillFiles: readonly string[]
lowPriorityFiles: readonly string[]
pages: {
'/_app': readonly string[]
[page: string]: readonly string[]
}
ampFirstPages: readonly string[]
}
export function getPageFiles(
buildManifest: BuildManifest,
page: string
): readonly string[] {
const normalizedPage = denormalizePagePath(normalizePagePath(page))
let files = buildManifest.pages[normalizedPage]
if (!files) {
console.warn(
`Could not find files for ${normalizedPage} in .next/build-manifest.json`
)
return []
}
return files
}