Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
a32af59e
Commit
a32af59e
authored
Dec 14, 2019
by
JJ Kasper
Committed by
Joe Haddad
Dec 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Shared Sizes Missing Commons (#9752)
* Fix shared sizes missing commons * Add tests
parent
eee4efd0
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
70 additions
and
6 deletions
+70
-6
index.ts
packages/next/build/index.ts
+4
-1
utils.ts
packages/next/build/utils.ts
+30
-5
amp.js
test/integration/build-output/fixtures/with-amp/pages/amp.js
+2
-0
hybrid.js
...ntegration/build-output/fixtures/with-amp/pages/hybrid.js
+2
-0
index.js
...integration/build-output/fixtures/with-amp/pages/index.js
+3
-0
index.test.js
test/integration/build-output/test/index.test.js
+29
-0
No files found.
packages/next/build/index.ts
View file @
a32af59e
...
@@ -384,8 +384,9 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -384,8 +384,9 @@ export default async function build(dir: string, conf = null): Promise<void> {
bundleRelative
bundleRelative
)
)
let
isStatic
=
false
let
isSsg
=
false
let
isSsg
=
false
let
isStatic
=
false
let
isHybridAmp
=
false
let
ssgPageRoutes
:
string
[]
|
null
=
null
let
ssgPageRoutes
:
string
[]
|
null
=
null
pagesManifest
[
page
]
=
bundleRelative
.
replace
(
/
\\
/g
,
'/'
)
pagesManifest
[
page
]
=
bundleRelative
.
replace
(
/
\\
/g
,
'/'
)
...
@@ -430,6 +431,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -430,6 +431,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
)
)
if
(
result
.
isHybridAmp
)
{
if
(
result
.
isHybridAmp
)
{
isHybridAmp
=
true
hybridAmpPages
.
add
(
page
)
hybridAmpPages
.
add
(
page
)
}
}
...
@@ -456,6 +458,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -456,6 +458,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
serverBundle
,
serverBundle
,
static
:
isStatic
,
static
:
isStatic
,
isSsg
,
isSsg
,
isHybridAmp
,
ssgPageRoutes
,
ssgPageRoutes
,
})
})
})
})
...
...
packages/next/build/utils.ts
View file @
a32af59e
...
@@ -32,6 +32,7 @@ export function collectPages(
...
@@ -32,6 +32,7 @@ export function collectPages(
export
interface
PageInfo
{
export
interface
PageInfo
{
isAmp
?:
boolean
isAmp
?:
boolean
isHybridAmp
?:
boolean
size
:
number
size
:
number
static
:
boolean
static
:
boolean
isSsg
:
boolean
isSsg
:
boolean
...
@@ -135,7 +136,12 @@ export async function printTreeView(
...
@@ -135,7 +136,12 @@ export async function printTreeView(
}
}
})
})
const
sharedData
=
await
getSharedSizes
(
distPath
,
buildManifest
,
isModern
)
const
sharedData
=
await
getSharedSizes
(
distPath
,
buildManifest
,
isModern
,
pageInfos
)
messages
.
push
([
'+ shared by all'
,
getPrettySize
(
sharedData
.
total
)])
messages
.
push
([
'+ shared by all'
,
getPrettySize
(
sharedData
.
total
)])
Object
.
keys
(
sharedData
.
files
)
Object
.
keys
(
sharedData
.
files
)
...
@@ -255,15 +261,18 @@ let cachedBuildManifest: BuildManifestShape | undefined
...
@@ -255,15 +261,18 @@ let cachedBuildManifest: BuildManifestShape | undefined
let
lastCompute
:
ComputeManifestShape
|
undefined
let
lastCompute
:
ComputeManifestShape
|
undefined
let
lastComputeModern
:
boolean
|
undefined
let
lastComputeModern
:
boolean
|
undefined
let
lastComputePageInfo
:
boolean
|
undefined
async
function
computeFromManifest
(
async
function
computeFromManifest
(
manifest
:
BuildManifestShape
,
manifest
:
BuildManifestShape
,
distPath
:
string
,
distPath
:
string
,
isModern
:
boolean
isModern
:
boolean
,
pageInfos
?:
Map
<
string
,
PageInfo
>
):
Promise
<
ComputeManifestShape
>
{
):
Promise
<
ComputeManifestShape
>
{
if
(
if
(
Object
.
is
(
cachedBuildManifest
,
manifest
)
&&
Object
.
is
(
cachedBuildManifest
,
manifest
)
&&
lastComputeModern
===
isModern
lastComputeModern
===
isModern
&&
lastComputePageInfo
===
!!
pageInfos
)
{
)
{
return
lastCompute
!
return
lastCompute
!
}
}
...
@@ -275,6 +284,15 @@ async function computeFromManifest(
...
@@ -275,6 +284,15 @@ async function computeFromManifest(
return
return
}
}
if
(
pageInfos
)
{
const
cleanKey
=
key
.
replace
(
/
\/
index$/
,
''
)
||
'/'
const
pageInfo
=
pageInfos
.
get
(
cleanKey
)
// don't include AMP pages since they don't rely on shared bundles
if
(
pageInfo
?.
isHybridAmp
||
pageInfo
?.
isAmp
)
{
return
}
}
++
expected
++
expected
manifest
.
pages
[
key
].
forEach
(
file
=>
{
manifest
.
pages
[
key
].
forEach
(
file
=>
{
if
(
if
(
...
@@ -321,6 +339,7 @@ async function computeFromManifest(
...
@@ -321,6 +339,7 @@ async function computeFromManifest(
cachedBuildManifest
=
manifest
cachedBuildManifest
=
manifest
lastComputeModern
=
isModern
lastComputeModern
=
isModern
lastComputePageInfo
=
!!
pageInfos
return
lastCompute
!
return
lastCompute
!
}
}
...
@@ -333,9 +352,15 @@ function difference<T>(main: T[], sub: T[]): T[] {
...
@@ -333,9 +352,15 @@ function difference<T>(main: T[], sub: T[]): T[] {
export
async
function
getSharedSizes
(
export
async
function
getSharedSizes
(
distPath
:
string
,
distPath
:
string
,
buildManifest
:
BuildManifestShape
,
buildManifest
:
BuildManifestShape
,
isModern
:
boolean
isModern
:
boolean
,
pageInfos
:
Map
<
string
,
PageInfo
>
):
Promise
<
{
total
:
number
;
files
:
{
[
page
:
string
]:
number
}
}
>
{
):
Promise
<
{
total
:
number
;
files
:
{
[
page
:
string
]:
number
}
}
>
{
const
data
=
await
computeFromManifest
(
buildManifest
,
distPath
,
isModern
)
const
data
=
await
computeFromManifest
(
buildManifest
,
distPath
,
isModern
,
pageInfos
)
return
{
total
:
data
.
sizeCommonFiles
,
files
:
data
.
sizeCommonFile
}
return
{
total
:
data
.
sizeCommonFiles
,
files
:
data
.
sizeCommonFile
}
}
}
...
...
test/integration/build-output/fixtures/with-amp/pages/amp.js
0 → 100644
View file @
a32af59e
export
const
config
=
{
amp
:
true
}
export
default
()
=>
'hi'
test/integration/build-output/fixtures/with-amp/pages/hybrid.js
0 → 100644
View file @
a32af59e
export
const
config
=
{
amp
:
'hybrid'
}
export
default
()
=>
'hi'
test/integration/build-output/fixtures/with-amp/pages/index.js
0 → 100644
View file @
a32af59e
export
default
function
()
{
return
<
div
/>
}
test/integration/build-output/test/index.test.js
View file @
a32af59e
...
@@ -25,6 +25,7 @@ describe('Build Output', () => {
...
@@ -25,6 +25,7 @@ describe('Build Output', () => {
expect
(
stdout
).
toMatch
(
/
\/
[
]
*
\d{1,}
B/
)
expect
(
stdout
).
toMatch
(
/
\/
[
]
*
\d{1,}
B/
)
expect
(
stdout
).
toMatch
(
/
\+
shared by all
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/
\+
shared by all
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/ runtime
\/
main
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/ runtime
\/
main
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/ chunks
\/
commons
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
not
.
toContain
(
'/_document'
)
expect
(
stdout
).
not
.
toContain
(
'/_document'
)
expect
(
stdout
).
not
.
toContain
(
'/_app'
)
expect
(
stdout
).
not
.
toContain
(
'/_app'
)
...
@@ -50,6 +51,7 @@ describe('Build Output', () => {
...
@@ -50,6 +51,7 @@ describe('Build Output', () => {
expect
(
stdout
).
toMatch
(
/
\/
_app
[
]
*
\d{1,}
B/
)
expect
(
stdout
).
toMatch
(
/
\/
_app
[
]
*
\d{1,}
B/
)
expect
(
stdout
).
toMatch
(
/
\+
shared by all
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/
\+
shared by all
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/ runtime
\/
main
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/ runtime
\/
main
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/ chunks
\/
commons
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
not
.
toContain
(
'/_document'
)
expect
(
stdout
).
not
.
toContain
(
'/_document'
)
expect
(
stdout
).
not
.
toContain
(
'/_error'
)
expect
(
stdout
).
not
.
toContain
(
'/_error'
)
...
@@ -59,6 +61,32 @@ describe('Build Output', () => {
...
@@ -59,6 +61,32 @@ describe('Build Output', () => {
})
})
})
})
describe
(
'With AMP Output'
,
()
=>
{
const
appDir
=
join
(
fixturesDir
,
'with-amp'
)
beforeAll
(
async
()
=>
{
await
remove
(
join
(
appDir
,
'.next'
))
})
it
(
'should not include custom error'
,
async
()
=>
{
const
{
stdout
}
=
await
nextBuild
(
appDir
,
[],
{
stdout
:
true
,
})
expect
(
stdout
).
toMatch
(
/
\/
[
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
(
/ runtime
\/
main
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/ chunks
\/
commons
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
not
.
toContain
(
'/_document'
)
expect
(
stdout
).
not
.
toContain
(
'/_error'
)
expect
(
stdout
).
toContain
(
'○ /'
)
})
})
describe
(
'Custom Error Output'
,
()
=>
{
describe
(
'Custom Error Output'
,
()
=>
{
const
appDir
=
join
(
fixturesDir
,
'with-error'
)
const
appDir
=
join
(
fixturesDir
,
'with-error'
)
...
@@ -75,6 +103,7 @@ describe('Build Output', () => {
...
@@ -75,6 +103,7 @@ describe('Build Output', () => {
expect
(
stdout
).
toMatch
(
/λ
\/
_error
[
]
*
\d{1,}
B/
)
expect
(
stdout
).
toMatch
(
/λ
\/
_error
[
]
*
\d{1,}
B/
)
expect
(
stdout
).
toMatch
(
/
\+
shared by all
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/
\+
shared by all
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/ runtime
\/
main
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/ runtime
\/
main
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/ chunks
\/
commons
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
not
.
toContain
(
'/_document'
)
expect
(
stdout
).
not
.
toContain
(
'/_document'
)
expect
(
stdout
).
not
.
toContain
(
'/_app'
)
expect
(
stdout
).
not
.
toContain
(
'/_app'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment