Skip to content

Commit

Permalink
Rename Build SPR to SSG (#10114)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Jan 15, 2020
1 parent 563f3c0 commit 57ec121
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions packages/next/build/index.ts
Expand Up @@ -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
Expand All @@ -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<void> {
Expand Down Expand Up @@ -398,11 +398,11 @@ export default async function build(dir: string, conf = null): Promise<void> {
)
const buildManifestPath = path.join(distDir, BUILD_MANIFEST)

const sprPages = new Set<string>()
const ssgPages = new Set<string>()
const staticPages = new Set<string>()
const invalidPages = 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 pagesManifest = JSON.parse(await fsReadFile(manifestPath, 'utf8'))
const buildManifest = JSON.parse(await fsReadFile(buildManifestPath, 'utf8'))
Expand Down Expand Up @@ -491,11 +491,11 @@ export default async function build(dir: string, conf = null): Promise<void> {
}

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) {
Expand Down Expand Up @@ -548,14 +548,13 @@ export default async function build(dir: string, conf = null): Promise<void> {

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,
Expand All @@ -575,15 +574,15 @@ export default async function build(dir: string, conf = null): Promise<void> {
// to do so.
//
// Note: prerendering disables automatic static optimization.
sprPages.forEach(page => {
ssgPages.forEach(page => {
if (isDynamicRoute(page)) {
tbdPrerenderRoutes.push(page)
delete defaultMap[page]
}
})
// 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 }
})
Expand All @@ -603,7 +602,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
const moveExportedPage = async (
page: string,
file: string,
isSpr: boolean,
isSsg: boolean,
ext: 'html' | 'json'
) => {
file = `${file}.${ext}`
Expand All @@ -619,7 +618,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
relativeDest
)

if (!isSpr) {
if (!isSsg) {
pagesManifest[page] = relativeDest
if (page === '/') pagesManifest['/index'] = relativeDest
if (page === '/.amp') pagesManifest['/index.amp'] = relativeDest
Expand All @@ -629,21 +628,21 @@ export default async function build(dir: string, conf = null): Promise<void> {
}

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')

Expand All @@ -658,10 +657,10 @@ export default async function build(dir: string, conf = null): Promise<void> {
),
}
} 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')
Expand Down Expand Up @@ -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'] = {}
tbdPrerenderRoutes.forEach(tbdRoute => {
const dataRoute = path.posix.join(
Expand Down

0 comments on commit 57ec121

Please sign in to comment.