Unverified Commit 57ec121d authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Rename Build SPR to SSG (#10114)

parent 563f3c08
...@@ -74,13 +74,13 @@ const mkdirp = promisify(mkdirpOrig) ...@@ -74,13 +74,13 @@ const mkdirp = promisify(mkdirpOrig)
const staticCheckWorker = require.resolve('./utils') const staticCheckWorker = require.resolve('./utils')
export type SprRoute = { export type SsgRoute = {
initialRevalidateSeconds: number | false initialRevalidateSeconds: number | false
srcRoute: string | null srcRoute: string | null
dataRoute: string dataRoute: string
} }
export type DynamicSprRoute = { export type DynamicSsgRoute = {
routeRegex: string routeRegex: string
dataRoute: string dataRoute: string
...@@ -89,8 +89,8 @@ export type DynamicSprRoute = { ...@@ -89,8 +89,8 @@ export type DynamicSprRoute = {
export type PrerenderManifest = { export type PrerenderManifest = {
version: number version: number
routes: { [route: string]: SprRoute } routes: { [route: string]: SsgRoute }
dynamicRoutes: { [route: string]: DynamicSprRoute } dynamicRoutes: { [route: string]: DynamicSsgRoute }
} }
export default async function build(dir: string, conf = null): Promise<void> { export default async function build(dir: string, conf = null): Promise<void> {
...@@ -398,11 +398,11 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -398,11 +398,11 @@ export default async function build(dir: string, conf = null): Promise<void> {
) )
const buildManifestPath = path.join(distDir, BUILD_MANIFEST) const buildManifestPath = path.join(distDir, BUILD_MANIFEST)
const sprPages = new Set<string>() const ssgPages = new Set<string>()
const staticPages = new Set<string>() const staticPages = new Set<string>()
const invalidPages = new Set<string>() const invalidPages = new Set<string>()
const hybridAmpPages = new Set<string>() const hybridAmpPages = new Set<string>()
const additionalSprPaths = new Map<string, Array<string>>() const additionalSsgPaths = new Map<string, Array<string>>()
const pageInfos = new Map<string, PageInfo>() const pageInfos = new Map<string, PageInfo>()
const pagesManifest = JSON.parse(await fsReadFile(manifestPath, 'utf8')) const pagesManifest = JSON.parse(await fsReadFile(manifestPath, 'utf8'))
const buildManifest = JSON.parse(await fsReadFile(buildManifestPath, 'utf8')) const buildManifest = JSON.parse(await fsReadFile(buildManifestPath, 'utf8'))
...@@ -491,11 +491,11 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -491,11 +491,11 @@ export default async function build(dir: string, conf = null): Promise<void> {
} }
if (result.prerender) { if (result.prerender) {
sprPages.add(page) ssgPages.add(page)
isSsg = true isSsg = true
if (result.prerenderRoutes) { if (result.prerenderRoutes) {
additionalSprPaths.set(page, result.prerenderRoutes) additionalSsgPaths.set(page, result.prerenderRoutes)
ssgPageRoutes = result.prerenderRoutes ssgPageRoutes = result.prerenderRoutes
} }
} else if (result.static && customAppGetInitialProps === false) { } else if (result.static && customAppGetInitialProps === false) {
...@@ -548,14 +548,13 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -548,14 +548,13 @@ export default async function build(dir: string, conf = null): Promise<void> {
await writeBuildId(distDir, buildId) await writeBuildId(distDir, buildId)
const finalPrerenderRoutes: { [route: string]: SprRoute } = {} const finalPrerenderRoutes: { [route: string]: SsgRoute } = {}
const tbdPrerenderRoutes: string[] = [] const tbdPrerenderRoutes: string[] = []
if (staticPages.size > 0 || sprPages.size > 0) { if (staticPages.size > 0 || ssgPages.size > 0) {
const combinedPages = [...staticPages, ...sprPages] const combinedPages = [...staticPages, ...ssgPages]
const exportApp = require('../export').default const exportApp = require('../export').default
const exportOptions = { const exportOptions = {
sprPages,
silent: true, silent: true,
buildExport: true, buildExport: true,
threads: config.experimental.cpus, threads: config.experimental.cpus,
...@@ -575,7 +574,7 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -575,7 +574,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
// to do so. // to do so.
// //
// Note: prerendering disables automatic static optimization. // Note: prerendering disables automatic static optimization.
sprPages.forEach(page => { ssgPages.forEach(page => {
if (isDynamicRoute(page)) { if (isDynamicRoute(page)) {
tbdPrerenderRoutes.push(page) tbdPrerenderRoutes.push(page)
delete defaultMap[page] delete defaultMap[page]
...@@ -583,7 +582,7 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -583,7 +582,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
}) })
// Append the "well-known" routes we should prerender for, e.g. blog // Append the "well-known" routes we should prerender for, e.g. blog
// post slugs. // post slugs.
additionalSprPaths.forEach((routes, page) => { additionalSsgPaths.forEach((routes, page) => {
routes.forEach(route => { routes.forEach(route => {
defaultMap[route] = { page } defaultMap[route] = { page }
}) })
...@@ -603,7 +602,7 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -603,7 +602,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
const moveExportedPage = async ( const moveExportedPage = async (
page: string, page: string,
file: string, file: string,
isSpr: boolean, isSsg: boolean,
ext: 'html' | 'json' ext: 'html' | 'json'
) => { ) => {
file = `${file}.${ext}` file = `${file}.${ext}`
...@@ -619,7 +618,7 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -619,7 +618,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
relativeDest relativeDest
) )
if (!isSpr) { if (!isSsg) {
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
...@@ -629,21 +628,21 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -629,21 +628,21 @@ export default async function build(dir: string, conf = null): Promise<void> {
} }
for (const page of combinedPages) { for (const page of combinedPages) {
const isSpr = sprPages.has(page) const isSsg = ssgPages.has(page)
const isDynamic = isDynamicRoute(page) const isDynamic = isDynamicRoute(page)
let file = page === '/' ? '/index' : page let file = page === '/' ? '/index' : page
// The dynamic version of SPR pages are not prerendered. Below, we handle // The dynamic version of SSG pages are not prerendered. Below, we handle
// the specific prerenders of these. // the specific prerenders of these.
if (!(isSpr && isDynamic)) { if (!(isSsg && isDynamic)) {
await moveExportedPage(page, file, isSpr, 'html') await moveExportedPage(page, file, isSsg, 'html')
} }
const hasAmp = hybridAmpPages.has(page) const hasAmp = hybridAmpPages.has(page)
if (hasAmp) { if (hasAmp) {
await moveExportedPage(`${page}.amp`, `${file}.amp`, isSpr, 'html') await moveExportedPage(`${page}.amp`, `${file}.amp`, isSsg, 'html')
} }
if (isSpr) { if (isSsg) {
// For a non-dynamic SPR page, we must copy its data file from export. // For a non-dynamic SSG page, we must copy its data file from export.
if (!isDynamic) { if (!isDynamic) {
await moveExportedPage(page, file, true, 'json') await moveExportedPage(page, file, true, 'json')
...@@ -658,10 +657,10 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -658,10 +657,10 @@ export default async function build(dir: string, conf = null): Promise<void> {
), ),
} }
} else { } else {
// For a dynamic SPR page, we did not copy its html nor data exports. // For a dynamic SSG page, we did not copy its html nor data exports.
// Instead, we must copy specific versions of this page as defined by // Instead, we must copy specific versions of this page as defined by
// `unstable_getStaticPaths` (additionalSprPaths). // `unstable_getStaticPaths` (additionalSsgPaths).
const extraRoutes = additionalSprPaths.get(page) || [] const extraRoutes = additionalSsgPaths.get(page) || []
for (const route of extraRoutes) { for (const route of extraRoutes) {
await moveExportedPage(route, route, true, 'html') await moveExportedPage(route, route, true, 'html')
await moveExportedPage(route, route, true, 'json') await moveExportedPage(route, route, true, 'json')
...@@ -699,7 +698,7 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -699,7 +698,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
}) })
) )
if (sprPages.size > 0) { if (ssgPages.size > 0) {
const finalDynamicRoutes: PrerenderManifest['dynamicRoutes'] = {} const finalDynamicRoutes: PrerenderManifest['dynamicRoutes'] = {}
tbdPrerenderRoutes.forEach(tbdRoute => { tbdPrerenderRoutes.forEach(tbdRoute => {
const dataRoute = path.posix.join( const dataRoute = path.posix.join(
......
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