Commit 5b57a752 authored by Joe Haddad's avatar Joe Haddad Committed by Tim Neutkens

Improve Build Output for SSG (#9719)

* Improve Build Output for SSG

* Swap out symbols and reasons

* adjust text more

* Add test

* Expect more output lines

* fix test case
parent c4567a1a
...@@ -384,6 +384,8 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -384,6 +384,8 @@ export default async function build(dir: string, conf = null): Promise<void> {
) )
let isStatic = false let isStatic = false
let isSsg = false
let ssgPageRoutes: string[] | null = null
pagesManifest[page] = bundleRelative.replace(/\\/g, '/') pagesManifest[page] = bundleRelative.replace(/\\/g, '/')
...@@ -432,17 +434,15 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -432,17 +434,15 @@ export default async function build(dir: string, conf = null): Promise<void> {
if (result.prerender) { if (result.prerender) {
sprPages.add(page) sprPages.add(page)
isSsg = true
if (result.prerenderRoutes) { if (result.prerenderRoutes) {
additionalSprPaths.set(page, result.prerenderRoutes) additionalSprPaths.set(page, result.prerenderRoutes)
ssgPageRoutes = result.prerenderRoutes
} }
} } else if (result.static && customAppGetInitialProps === false) {
if (result.static && customAppGetInitialProps === false) {
staticPages.add(page) staticPages.add(page)
isStatic = true isStatic = true
} else if (result.prerender) {
sprPages.add(page)
} }
} catch (err) { } catch (err) {
if (err.message !== 'INVALID_DEFAULT_EXPORT') throw err if (err.message !== 'INVALID_DEFAULT_EXPORT') throw err
...@@ -450,7 +450,13 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -450,7 +450,13 @@ export default async function build(dir: string, conf = null): Promise<void> {
} }
} }
pageInfos.set(page, { size, serverBundle, static: isStatic }) pageInfos.set(page, {
size,
serverBundle,
static: isStatic,
isSsg,
ssgPageRoutes,
})
}) })
) )
staticCheckWorkers.end() staticCheckWorkers.end()
......
...@@ -37,7 +37,9 @@ export function collectPages( ...@@ -37,7 +37,9 @@ export function collectPages(
export interface PageInfo { export interface PageInfo {
isAmp?: boolean isAmp?: boolean
size: number size: number
static?: boolean static: boolean
isSsg: boolean
ssgPageRoutes: string[] | null
serverBundle: string serverBundle: string
} }
...@@ -56,8 +58,8 @@ export function printTreeView( ...@@ -56,8 +58,8 @@ export function printTreeView(
return chalk.red.bold(size) return chalk.red.bold(size)
} }
const messages: string[][] = [ const messages: [string, string][] = [
['Page', 'Size'].map(entry => chalk.underline(entry)), ['Page', 'Size'].map(entry => chalk.underline(entry)) as [string, string],
] ]
list list
...@@ -79,10 +81,10 @@ export function printTreeView( ...@@ -79,10 +81,10 @@ export function printTreeView(
item.startsWith('/_') item.startsWith('/_')
? ' ' ? ' '
: pageInfo && pageInfo.static : pageInfo && pageInfo.static
? '*' ? '○'
: serverless : pageInfo && pageInfo.isSsg
? 'λ' ? '●'
: 'σ' : 'λ'
} ${item}`, } ${item}`,
pageInfo pageInfo
? pageInfo.isAmp ? pageInfo.isAmp
...@@ -92,11 +94,28 @@ export function printTreeView( ...@@ -92,11 +94,28 @@ export function printTreeView(
: '' : ''
: '', : '',
]) ])
if (pageInfo && pageInfo.ssgPageRoutes && pageInfo.ssgPageRoutes.length) {
const totalRoutes = pageInfo.ssgPageRoutes.length
const previewPages = totalRoutes === 4 ? 4 : 3
const contSymbol = i === list.length - 1 ? ' ' : '├'
const routes = pageInfo.ssgPageRoutes.slice(0, previewPages)
if (totalRoutes > previewPages) {
const remaining = totalRoutes - previewPages
routes.push(`[+${remaining} more paths]`)
}
routes.forEach((slug, index, { length }) => {
const innerSymbol = index === length - 1 ? '└' : '├'
messages.push([`${contSymbol} ${innerSymbol} ${slug}`, ''])
})
}
}) })
console.log( console.log(
textTable(messages, { textTable(messages, {
align: ['l', 'l', 'r', 'r'], align: ['l', 'l'],
stringLength: str => stripAnsi(str).length, stringLength: str => stripAnsi(str).length,
}) })
) )
...@@ -105,23 +124,26 @@ export function printTreeView( ...@@ -105,23 +124,26 @@ export function printTreeView(
console.log( console.log(
textTable( textTable(
[ [
serverless [
? [ 'λ',
'λ', serverless ? '(Lambda)' : '(Server)',
'(Lambda)', `server-side renders at runtime (uses ${chalk.cyan(
`page was emitted as a lambda (i.e. ${chalk.cyan( 'getInitialProps'
'getInitialProps' )} or ${chalk.cyan('getServerProps')})`,
)})`, ],
] [
: [ '○',
'σ', '(Static)',
'(Server)', 'automatically rendered as static HTML (uses no initial props)',
`page will be server rendered (i.e. ${chalk.cyan( ],
'getInitialProps' [
)})`, '●',
], '(SSG)',
['*', '(Static File)', 'page was prerendered as static HTML'], `automatically generated as static HTML + JSON (uses ${chalk.cyan(
], 'getStaticProps'
)})`,
],
] as [string, string, string][],
{ {
align: ['l', 'l', 'l'], align: ['l', 'l', 'l'],
stringLength: str => stripAnsi(str).length, stringLength: str => stripAnsi(str).length,
......
...@@ -8,6 +8,7 @@ export async function unstable_getStaticPaths() { ...@@ -8,6 +8,7 @@ export async function unstable_getStaticPaths() {
'/blog/post-1', '/blog/post-1',
{ params: { post: 'post-2' } }, { params: { post: 'post-2' } },
'/blog/[post3]', '/blog/[post3]',
'/blog/post-4',
'/blog/post.1', '/blog/post.1',
] ]
} }
......
...@@ -66,6 +66,11 @@ const expectedManifestRoutes = () => ({ ...@@ -66,6 +66,11 @@ const expectedManifestRoutes = () => ({
initialRevalidateSeconds: 10, initialRevalidateSeconds: 10,
srcRoute: '/blog/[post]', srcRoute: '/blog/[post]',
}, },
'/blog/post-4': {
dataRoute: `/_next/data/${buildId}/blog/post-4.json`,
initialRevalidateSeconds: 10,
srcRoute: '/blog/[post]',
},
'/blog/post-1/comment-1': { '/blog/post-1/comment-1': {
dataRoute: `/_next/data/${buildId}/blog/post-1/comment-1.json`, dataRoute: `/_next/data/${buildId}/blog/post-1/comment-1.json`,
initialRevalidateSeconds: 2, initialRevalidateSeconds: 2,
...@@ -478,9 +483,12 @@ describe('SPR Prerender', () => { ...@@ -478,9 +483,12 @@ describe('SPR Prerender', () => {
}) })
describe('production mode', () => { describe('production mode', () => {
let buildOutput = ''
beforeAll(async () => { beforeAll(async () => {
await fs.remove(nextConfig) await fs.remove(nextConfig)
await nextBuild(appDir) const { stdout } = await nextBuild(appDir, [], { stdout: true })
buildOutput = stdout
stderr = '' stderr = ''
appPort = await findPort() appPort = await findPort()
app = await nextStart(appDir, appPort, { app = await nextStart(appDir, appPort, {
...@@ -493,6 +501,12 @@ describe('SPR Prerender', () => { ...@@ -493,6 +501,12 @@ describe('SPR Prerender', () => {
}) })
afterAll(() => killApp(app)) afterAll(() => killApp(app))
it('should of formatted build output correctly', () => {
expect(buildOutput).toMatch(/○ \/normal/)
expect(buildOutput).toMatch(/● \/blog\/\[post\]/)
expect(buildOutput).toMatch(/\+2 more paths/)
})
runTests() runTests()
}) })
......
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