From 57ec121d48cb94bec93a1259d3c3c6c0342c33da Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Wed, 15 Jan 2020 15:57:07 -0500 Subject: [PATCH] Rename Build SPR to SSG (#10114) --- packages/next/build/index.ts | 53 ++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index 1018cf0f30bd223..43e2acf2d1784d5 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -74,13 +74,13 @@ const mkdirp = promisify(mkdirpOrig) const staticCheckWorker = require.resolve('./utils') -export type SprRoute = { +export type SsgRoute = { initialRevalidateSeconds: number | false srcRoute: string | null dataRoute: string } -export type DynamicSprRoute = { +export type DynamicSsgRoute = { routeRegex: string dataRoute: string @@ -89,8 +89,8 @@ export type DynamicSprRoute = { export type PrerenderManifest = { version: number - routes: { [route: string]: SprRoute } - dynamicRoutes: { [route: string]: DynamicSprRoute } + routes: { [route: string]: SsgRoute } + dynamicRoutes: { [route: string]: DynamicSsgRoute } } export default async function build(dir: string, conf = null): Promise { @@ -398,11 +398,11 @@ export default async function build(dir: string, conf = null): Promise { ) const buildManifestPath = path.join(distDir, BUILD_MANIFEST) - const sprPages = new Set() + const ssgPages = new Set() const staticPages = new Set() const invalidPages = new Set() const hybridAmpPages = new Set() - const additionalSprPaths = new Map>() + const additionalSsgPaths = new Map>() const pageInfos = new Map() const pagesManifest = JSON.parse(await fsReadFile(manifestPath, 'utf8')) const buildManifest = JSON.parse(await fsReadFile(buildManifestPath, 'utf8')) @@ -491,11 +491,11 @@ export default async function build(dir: string, conf = null): Promise { } if (result.prerender) { - sprPages.add(page) + ssgPages.add(page) isSsg = true if (result.prerenderRoutes) { - additionalSprPaths.set(page, result.prerenderRoutes) + additionalSsgPaths.set(page, result.prerenderRoutes) ssgPageRoutes = result.prerenderRoutes } } else if (result.static && customAppGetInitialProps === false) { @@ -548,14 +548,13 @@ export default async function build(dir: string, conf = null): Promise { await writeBuildId(distDir, buildId) - const finalPrerenderRoutes: { [route: string]: SprRoute } = {} + const finalPrerenderRoutes: { [route: string]: SsgRoute } = {} const tbdPrerenderRoutes: string[] = [] - if (staticPages.size > 0 || sprPages.size > 0) { - const combinedPages = [...staticPages, ...sprPages] + if (staticPages.size > 0 || ssgPages.size > 0) { + const combinedPages = [...staticPages, ...ssgPages] const exportApp = require('../export').default const exportOptions = { - sprPages, silent: true, buildExport: true, threads: config.experimental.cpus, @@ -575,7 +574,7 @@ export default async function build(dir: string, conf = null): Promise { // to do so. // // Note: prerendering disables automatic static optimization. - sprPages.forEach(page => { + ssgPages.forEach(page => { if (isDynamicRoute(page)) { tbdPrerenderRoutes.push(page) delete defaultMap[page] @@ -583,7 +582,7 @@ export default async function build(dir: string, conf = null): Promise { }) // Append the "well-known" routes we should prerender for, e.g. blog // post slugs. - additionalSprPaths.forEach((routes, page) => { + additionalSsgPaths.forEach((routes, page) => { routes.forEach(route => { defaultMap[route] = { page } }) @@ -603,7 +602,7 @@ export default async function build(dir: string, conf = null): Promise { const moveExportedPage = async ( page: string, file: string, - isSpr: boolean, + isSsg: boolean, ext: 'html' | 'json' ) => { file = `${file}.${ext}` @@ -619,7 +618,7 @@ export default async function build(dir: string, conf = null): Promise { relativeDest ) - if (!isSpr) { + if (!isSsg) { pagesManifest[page] = relativeDest if (page === '/') pagesManifest['/index'] = relativeDest if (page === '/.amp') pagesManifest['/index.amp'] = relativeDest @@ -629,21 +628,21 @@ export default async function build(dir: string, conf = null): Promise { } for (const page of combinedPages) { - const isSpr = sprPages.has(page) + const isSsg = ssgPages.has(page) const isDynamic = isDynamicRoute(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. - if (!(isSpr && isDynamic)) { - await moveExportedPage(page, file, isSpr, 'html') + if (!(isSsg && isDynamic)) { + await moveExportedPage(page, file, isSsg, 'html') } const hasAmp = hybridAmpPages.has(page) if (hasAmp) { - await moveExportedPage(`${page}.amp`, `${file}.amp`, isSpr, 'html') + await moveExportedPage(`${page}.amp`, `${file}.amp`, isSsg, 'html') } - if (isSpr) { - // For a non-dynamic SPR page, we must copy its data file from export. + if (isSsg) { + // For a non-dynamic SSG page, we must copy its data file from export. if (!isDynamic) { await moveExportedPage(page, file, true, 'json') @@ -658,10 +657,10 @@ export default async function build(dir: string, conf = null): Promise { ), } } 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 - // `unstable_getStaticPaths` (additionalSprPaths). - const extraRoutes = additionalSprPaths.get(page) || [] + // `unstable_getStaticPaths` (additionalSsgPaths). + const extraRoutes = additionalSsgPaths.get(page) || [] for (const route of extraRoutes) { await moveExportedPage(route, route, true, 'html') await moveExportedPage(route, route, true, 'json') @@ -699,7 +698,7 @@ export default async function build(dir: string, conf = null): Promise { }) ) - if (sprPages.size > 0) { + if (ssgPages.size > 0) { const finalDynamicRoutes: PrerenderManifest['dynamicRoutes'] = {} tbdPrerenderRoutes.forEach(tbdRoute => { const dataRoute = path.posix.join(