Skip to content

Commit

Permalink
Update build output with renamed column (#11401)
Browse files Browse the repository at this point in the history
* Update build output with renamed column

* Update build output test

* Update naming of column

Co-authored-by: Tim Neutkens <timneutkens@me.com>
  • Loading branch information
ijjk and timneutkens committed Apr 1, 2020
1 parent 1992e2a commit 3f6bd47
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import { isWriteable } from './is-writeable'
import createSpinner from './spinner'
import {
collectPages,
getPageSizeInKb,
getJsPageSizeInKb,
hasCustomGetInitialProps,
isPageStatic,
PageInfo,
Expand Down Expand Up @@ -482,7 +482,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
await Promise.all(
pageKeys.map(async page => {
const actualPage = normalizePagePath(page)
const [selfSize, allSize] = await getPageSizeInKb(
const [selfSize, allSize] = await getJsPageSizeInKb(
actualPage,
distDir,
buildId,
Expand Down
18 changes: 12 additions & 6 deletions packages/next/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export async function printTreeView(
.replace(/[.-]([0-9a-z]{6})[0-9a-z]{14}(?=\.)/, '.$1')

const messages: [string, string, string][] = [
['Page', 'Size', 'First Load'].map(entry => chalk.underline(entry)) as [
['Page', 'Size', 'First Load JS'].map(entry => chalk.underline(entry)) as [
string,
string,
string
Expand Down Expand Up @@ -203,7 +203,11 @@ export async function printTreeView(
const sharedFilesSize = sizeData.sizeCommonFiles
const sharedFiles = sizeData.sizeCommonFile

messages.push(['+ shared by all', getPrettySize(sharedFilesSize), ''])
messages.push([
'+ First Load JS shared by all',
getPrettySize(sharedFilesSize),
'',
])
const sharedFileKeys = Object.keys(sharedFiles)
const sharedCssFiles: string[] = []
;[
Expand Down Expand Up @@ -463,7 +467,10 @@ async function computeFromManifest(
(obj, n) => Object.assign(obj, { [n[0]]: n[1] }),
{}
),
sizeCommonFiles: stats.reduce((size, [, stat]) => size + stat, 0),
sizeCommonFiles: stats.reduce((size, [f, stat]) => {
if (f.endsWith('.css')) return size
return size + stat
}, 0),
}

cachedBuildManifest = manifest
Expand All @@ -488,7 +495,7 @@ function sum(a: number[]): number {
return a.reduce((size, stat) => size + stat, 0)
}

export async function getPageSizeInKb(
export async function getJsPageSizeInKb(
page: string,
distPath: string,
buildId: string,
Expand All @@ -503,8 +510,7 @@ export async function getPageSizeInKb(
)

const fnFilterModern = (entry: string) =>
(entry.endsWith('.js') && entry.endsWith('.module.js') === isModern) ||
entry.endsWith('.css')
entry.endsWith('.js') && entry.endsWith('.module.js') === isModern

const pageFiles = (buildManifest.pages[page] || []).filter(fnFilterModern)
const appFiles = (buildManifest.pages['/_app'] || []).filter(fnFilterModern)
Expand Down
8 changes: 4 additions & 4 deletions test/integration/build-output/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Build Output', () => {
})

expect(stdout).toMatch(/\/ [ ]* \d{1,} B/)
expect(stdout).toMatch(/\+ shared by all [ 0-9.]* kB/)
expect(stdout).toMatch(/\+ First Load JS shared by all [ 0-9.]* kB/)
expect(stdout).toMatch(/ runtime\/main\.[0-9a-z]{6}\.js [ 0-9.]* kB/)
expect(stdout).toMatch(/ chunks\/framework\.[0-9a-z]{6}\.js [ 0-9. ]* kB/)

Expand All @@ -50,7 +50,7 @@ describe('Build Output', () => {

expect(stdout).toMatch(/\/ [ ]* \d{1,} B/)
expect(stdout).toMatch(/\/_app [ ]* \d{1,} B/)
expect(stdout).toMatch(/\+ shared by all [ 0-9.]* kB/)
expect(stdout).toMatch(/\+ First Load JS shared by all [ 0-9.]* kB/)
expect(stdout).toMatch(/ runtime\/main\.[0-9a-z]{6}\.js [ 0-9.]* kB/)
expect(stdout).toMatch(/ chunks\/framework\.[0-9a-z]{6}\.js [ 0-9. ]* kB/)

Expand Down Expand Up @@ -78,7 +78,7 @@ describe('Build Output', () => {
expect(stdout).toMatch(/\/ [ 0-9.]* B [ 0-9.]* kB/)
expect(stdout).toMatch(/\/amp .* AMP/)
expect(stdout).toMatch(/\/hybrid [ 0-9.]* B/)
expect(stdout).toMatch(/\+ shared by all [ 0-9.]* kB/)
expect(stdout).toMatch(/\+ First Load JS shared by all [ 0-9.]* kB/)
expect(stdout).toMatch(/ runtime\/main\.[0-9a-z]{6}\.js [ 0-9.]* kB/)
expect(stdout).toMatch(/ chunks\/framework\.[0-9a-z]{6}\.js [ 0-9. ]* kB/)

Expand All @@ -104,7 +104,7 @@ describe('Build Output', () => {

expect(stdout).toMatch(/\/ [ ]* \d{1,} B/)
expect(stdout).toMatch(/λ \/_error [ ]* \d{1,} B/)
expect(stdout).toMatch(/\+ shared by all [ 0-9.]* kB/)
expect(stdout).toMatch(/\+ First Load JS shared by all [ 0-9.]* kB/)
expect(stdout).toMatch(/ runtime\/main\.[0-9a-z]{6}\.js [ 0-9.]* kB/)
expect(stdout).toMatch(/ chunks\/framework\.[0-9a-z]{6}\.js [ 0-9. ]* kB/)

Expand Down

0 comments on commit 3f6bd47

Please sign in to comment.