Skip to content

Commit 44a389d

Browse files
committed
Use two separate columns for revalidate and expire
1 parent 6e03dc5 commit 44a389d

File tree

3 files changed

+69
-41
lines changed

3 files changed

+69
-41
lines changed

packages/next/src/build/output/format.ts

+11-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const timeUnits = [
55
{ label: 'w', seconds: 604800 },
66
{ label: 'd', seconds: 86400 },
77
{ label: 'h', seconds: 3600 },
8-
{ label: 'min', seconds: 60 },
8+
{ label: 'm', seconds: 60 },
99
{ label: 's', seconds: 1 },
1010
]
1111

@@ -30,26 +30,25 @@ function humanReadableTimeRounded(seconds: number): string {
3030
const nextValue = seconds / nextUnit.seconds
3131

3232
if (Number.isInteger(nextValue)) {
33-
return `${nextValue} ${nextUnit.label}`
33+
return `${nextValue}${nextUnit.label}`
3434
}
3535
}
3636

3737
if (isExact) {
38-
return `${value} ${candidate.label}`
38+
return `${value}${candidate.label}`
3939
}
4040

41-
return `≈${Math.round(value)} ${candidate.label}`
41+
return `≈${Math.round(value)}${candidate.label}`
4242
}
4343

44-
export function formatCacheControl(cacheControl: CacheControl): string {
45-
const { revalidate, expire } = cacheControl
44+
export function formatRevalidate(cacheControl: CacheControl): string {
45+
const { revalidate } = cacheControl
4646

47-
if (!revalidate) {
48-
return ''
49-
}
47+
return revalidate ? humanReadableTimeRounded(revalidate) : ''
48+
}
5049

51-
const readableRevalidate = humanReadableTimeRounded(revalidate)
52-
const readableExpire = expire ? humanReadableTimeRounded(expire) : '∞'
50+
export function formatExpire(cacheControl: CacheControl): string {
51+
const { expire } = cacheControl
5352

54-
return `${readableRevalidate} / ${readableExpire}`
53+
return expire ? humanReadableTimeRounded(expire) : ''
5554
}

packages/next/src/build/utils.ts

+47-17
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ import { buildAppStaticPaths } from './static-paths/app'
8282
import { buildPagesStaticPaths } from './static-paths/pages'
8383
import type { PrerenderedRoute } from './static-paths/types'
8484
import type { CacheControl } from '../server/lib/cache-control'
85-
import { formatCacheControl } from './output/format'
85+
import { formatExpire, formatRevalidate } from './output/format'
8686

8787
export type ROUTER_TYPE = 'pages' | 'app'
8888

@@ -447,9 +447,7 @@ export async function printTreeView(
447447
// Collect all the symbols we use so we can print the icons out.
448448
const usedSymbols = new Set()
449449

450-
const messages: [string, string, string, string][] = []
451-
452-
let showCacheLife = false
450+
const messages: [string, string, string, string, string][] = []
453451

454452
const stats = await computeFromManifest(
455453
{ build: buildManifest, app: appBuildManifest },
@@ -470,17 +468,39 @@ export async function printTreeView(
470468
return
471469
}
472470

473-
showCacheLife = filteredPages.some(
474-
(page) => pageInfos.get(page)?.initialCacheControl?.revalidate
475-
)
471+
let showRevalidate = false
472+
let showExpire = false
473+
474+
for (const page of filteredPages) {
475+
const cacheControl = pageInfos.get(page)?.initialCacheControl
476+
477+
if (cacheControl?.revalidate) {
478+
showRevalidate = true
479+
}
480+
481+
if (cacheControl?.expire) {
482+
showExpire = true
483+
}
484+
485+
if (showRevalidate && showExpire) {
486+
break
487+
}
488+
}
476489

477490
messages.push(
478491
[
479492
routerType === 'app' ? 'Route (app)' : 'Route (pages)',
480493
'Size',
481494
'First Load JS',
482-
showCacheLife ? 'Cache Life' : '',
483-
].map((entry) => underline(entry)) as [string, string, string, string]
495+
showRevalidate ? 'Revalidate' : '',
496+
showExpire ? 'Expire' : '',
497+
].map((entry) => underline(entry)) as [
498+
string,
499+
string,
500+
string,
501+
string,
502+
string,
503+
]
484504
)
485505

486506
filteredPages.forEach((item, i, arr) => {
@@ -549,8 +569,11 @@ export async function printTreeView(
549569
? getPrettySize(pageInfo.totalSize, { strong: true })
550570
: ''
551571
: '',
552-
showCacheLife && pageInfo?.initialCacheControl
553-
? formatCacheControl(pageInfo.initialCacheControl)
572+
showRevalidate && pageInfo?.initialCacheControl
573+
? formatRevalidate(pageInfo.initialCacheControl)
574+
: '',
575+
showExpire && pageInfo?.initialCacheControl
576+
? formatExpire(pageInfo.initialCacheControl)
554577
: '',
555578
])
556579

@@ -572,6 +595,7 @@ export async function printTreeView(
572595
typeof size === 'number' ? getPrettySize(size) : '',
573596
'',
574597
'',
598+
'',
575599
])
576600
})
577601
}
@@ -642,8 +666,11 @@ export async function printTreeView(
642666
}`,
643667
'',
644668
'',
645-
showCacheLife && initialCacheControl
646-
? formatCacheControl(initialCacheControl)
669+
showRevalidate && initialCacheControl
670+
? formatRevalidate(initialCacheControl)
671+
: '',
672+
showExpire && initialCacheControl
673+
? formatExpire(initialCacheControl)
647674
: '',
648675
])
649676
}
@@ -664,6 +691,7 @@ export async function printTreeView(
664691
: '',
665692
'',
666693
'',
694+
'',
667695
])
668696
const sharedCssFiles: string[] = []
669697
const sharedJsChunks = [
@@ -702,6 +730,7 @@ export async function printTreeView(
702730
getPrettySize(size),
703731
'',
704732
'',
733+
'',
705734
])
706735
})
707736

@@ -711,6 +740,7 @@ export async function printTreeView(
711740
getPrettySize(restChunkSize),
712741
'',
713742
'',
743+
'',
714744
])
715745
}
716746
}
@@ -722,7 +752,7 @@ export async function printTreeView(
722752
list: lists.app,
723753
})
724754

725-
messages.push(['', '', '', ''])
755+
messages.push(['', '', '', '', ''])
726756
}
727757

728758
pageInfos.set('/404', {
@@ -752,18 +782,19 @@ export async function printTreeView(
752782
.map(gzipSize ? fsStatGzip : fsStat)
753783
)
754784

755-
messages.push(['', '', '', ''])
785+
messages.push(['', '', '', '', ''])
756786
messages.push([
757787
'ƒ Middleware',
758788
getPrettySize(sum(middlewareSizes), { strong: true }),
759789
'',
760790
'',
791+
'',
761792
])
762793
}
763794

764795
print(
765796
textTable(messages, {
766-
align: ['l', 'r', 'r', 'r'],
797+
align: ['l', 'r', 'r', 'r', 'r'],
767798
stringLength: (str) => stripAnsi(str).length,
768799
})
769800
)
@@ -790,7 +821,6 @@ export async function printTreeView(
790821
'prerendered as static HTML with dynamic server-streamed content',
791822
],
792823
usedSymbols.has('ƒ') && ['ƒ', '(Dynamic)', `server-rendered on demand`],
793-
showCacheLife && ['', '(Cache Life)', 'revalidate / expire'],
794824
].filter((x) => x) as [string, string, string][],
795825
{
796826
align: ['l', 'l', 'l'],

test/production/app-dir/build-output-tree-view/build-output-tree-view.test.ts

+11-12
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,32 @@ describe('build-output-tree-view', () => {
1717
// TODO: Fix double-listing of the /ppr/[slug] fallback.
1818

1919
expect(getTreeView(next.cliOutput)).toMatchInlineSnapshot(`
20-
"Route (app) Size First Load JS Cache Life
20+
"Route (app) Size First Load JS Revalidate Expire
2121
┌ ○ /_not-found N/A kB N/A kB
2222
├ ƒ /api N/A kB N/A kB
2323
├ ○ /api/force-static N/A kB N/A kB
2424
├ ○ /app-static N/A kB N/A kB
25-
├ ○ /cache-life N/A kB N/A kB 1 h / 1 d
25+
├ ○ /cache-life N/A kB N/A kB 1h 1d
2626
├ ƒ /dynamic N/A kB N/A kB
27-
├ ◐ /ppr/[slug] N/A kB N/A kB 1 w / 30 d
28-
├ ├ /ppr/[slug] 1 w / 30 d
29-
├ ├ /ppr/[slug] 1 w / 30 d
30-
├ ├ /ppr/days 1 d / 1 w
31-
├ └ /ppr/weeks 1 w / 30 d
32-
└ ○ /revalidate N/A kB N/A kB 15 min / 1 y
27+
├ ◐ /ppr/[slug] N/A kB N/A kB 1w 30d
28+
├ ├ /ppr/[slug] 1w 30d
29+
├ ├ /ppr/[slug] 1w 30d
30+
├ ├ /ppr/days 1d 1w
31+
├ └ /ppr/weeks 1w 30d
32+
└ ○ /revalidate N/A kB N/A kB 15m 1y
3333
+ First Load JS shared by all N/A kB
3434
35-
Route (pages) Size First Load JS Cache Life
35+
Route (pages) Size First Load JS Revalidate Expire
3636
┌ ƒ /api/hello N/A kB N/A kB
37-
├ ● /gsp-revalidate N/A kB N/A kB 5 min / 1 y
37+
├ ● /gsp-revalidate N/A kB N/A kB 5m 1y
3838
├ ƒ /gssp N/A kB N/A kB
3939
└ ○ /static N/A kB N/A kB
4040
+ First Load JS shared by all N/A kB
4141
4242
○ (Static) prerendered as static content
4343
● (SSG) prerendered as static HTML (uses generateStaticParams)
4444
◐ (Partial Prerender) prerendered as static HTML with dynamic server-streamed content
45-
ƒ (Dynamic) server-rendered on demand
46-
(Cache Life) revalidate / expire"
45+
ƒ (Dynamic) server-rendered on demand"
4746
`)
4847
})
4948
})

0 commit comments

Comments
 (0)