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
a133f850
Commit
a133f850
authored
Dec 12, 2019
by
Joe Haddad
Committed by
Tim Neutkens
Dec 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine Pages Output (#9725)
parent
25ee71f3
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
180 additions
and
57 deletions
+180
-57
index.ts
packages/next/build/index.ts
+11
-4
utils.ts
packages/next/build/utils.ts
+67
-53
index.js
...ntegration/build-output/fixtures/basic-app/pages/index.js
+3
-0
_app.js
.../integration/build-output/fixtures/with-app/pages/_app.js
+3
-0
index.js
...integration/build-output/fixtures/with-app/pages/index.js
+3
-0
_error.js
...egration/build-output/fixtures/with-error/pages/_error.js
+18
-0
index.js
...tegration/build-output/fixtures/with-error/pages/index.js
+3
-0
index.test.js
test/integration/build-output/test/index.test.js
+72
-0
No files found.
packages/next/build/index.ts
View file @
a133f850
...
@@ -8,8 +8,8 @@ import nanoid from 'next/dist/compiled/nanoid/index.js'
...
@@ -8,8 +8,8 @@ import nanoid from 'next/dist/compiled/nanoid/index.js'
import
path
from
'path'
import
path
from
'path'
import
{
pathToRegexp
}
from
'path-to-regexp'
import
{
pathToRegexp
}
from
'path-to-regexp'
import
{
promisify
}
from
'util'
import
{
promisify
}
from
'util'
import
formatWebpackMessages
from
'../client/dev/error-overlay/format-webpack-messages'
import
formatWebpackMessages
from
'../client/dev/error-overlay/format-webpack-messages'
import
checkCustomRoutes
from
'../lib/check-custom-routes'
import
{
PUBLIC_DIR_MIDDLEWARE_CONFLICT
}
from
'../lib/constants'
import
{
PUBLIC_DIR_MIDDLEWARE_CONFLICT
}
from
'../lib/constants'
import
{
findPagesDir
}
from
'../lib/find-pages-dir'
import
{
findPagesDir
}
from
'../lib/find-pages-dir'
import
{
recursiveDelete
}
from
'../lib/recursive-delete'
import
{
recursiveDelete
}
from
'../lib/recursive-delete'
...
@@ -22,8 +22,8 @@ import {
...
@@ -22,8 +22,8 @@ import {
PHASE_PRODUCTION_BUILD
,
PHASE_PRODUCTION_BUILD
,
PRERENDER_MANIFEST
,
PRERENDER_MANIFEST
,
ROUTES_MANIFEST
,
ROUTES_MANIFEST
,
SERVER_DIRECTORY
,
SERVERLESS_DIRECTORY
,
SERVERLESS_DIRECTORY
,
SERVER_DIRECTORY
,
}
from
'../next-server/lib/constants'
}
from
'../next-server/lib/constants'
import
{
import
{
getRouteRegex
,
getRouteRegex
,
...
@@ -55,7 +55,6 @@ import {
...
@@ -55,7 +55,6 @@ import {
}
from
'./utils'
}
from
'./utils'
import
getBaseWebpackConfig
from
'./webpack-config'
import
getBaseWebpackConfig
from
'./webpack-config'
import
{
writeBuildId
}
from
'./write-build-id'
import
{
writeBuildId
}
from
'./write-build-id'
import
checkCustomRoutes
from
'../lib/check-custom-routes'
const
fsAccess
=
promisify
(
fs
.
access
)
const
fsAccess
=
promisify
(
fs
.
access
)
const
fsUnlink
=
promisify
(
fs
.
unlink
)
const
fsUnlink
=
promisify
(
fs
.
unlink
)
...
@@ -722,7 +721,15 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -722,7 +721,15 @@ export default async function build(dir: string, conf = null): Promise<void> {
allPageInfos
.
set
(
key
,
info
)
allPageInfos
.
set
(
key
,
info
)
})
})
printTreeView
(
Object
.
keys
(
mappedPages
),
allPageInfos
,
isLikeServerless
)
await
printTreeView
(
Object
.
keys
(
mappedPages
),
allPageInfos
,
isLikeServerless
,
{
pagesDir
,
pageExtensions
:
config
.
pageExtensions
,
}
)
printCustomRoutes
({
redirects
,
rewrites
})
printCustomRoutes
({
redirects
,
rewrites
})
if
(
tracer
)
{
if
(
tracer
)
{
...
...
packages/next/build/utils.ts
View file @
a133f850
...
@@ -5,14 +5,14 @@ import path from 'path'
...
@@ -5,14 +5,14 @@ import path from 'path'
import
{
isValidElementType
}
from
'react-is'
import
{
isValidElementType
}
from
'react-is'
import
stripAnsi
from
'strip-ansi'
import
stripAnsi
from
'strip-ansi'
import
{
promisify
}
from
'util'
import
{
promisify
}
from
'util'
import
{
Redirect
,
Rewrite
}
from
'../lib/check-custom-routes'
import
{
SPR_GET_INITIAL_PROPS_CONFLICT
}
from
'../lib/constants'
import
{
SPR_GET_INITIAL_PROPS_CONFLICT
}
from
'../lib/constants'
import
prettyBytes
from
'../lib/pretty-bytes'
import
prettyBytes
from
'../lib/pretty-bytes'
import
{
recursiveReadDir
}
from
'../lib/recursive-readdir'
import
{
recursiveReadDir
}
from
'../lib/recursive-readdir'
import
{
DEFAULT_REDIRECT_STATUS
}
from
'../next-server/lib/constants'
import
{
getRouteMatcher
,
getRouteRegex
}
from
'../next-server/lib/router/utils'
import
{
getRouteMatcher
,
getRouteRegex
}
from
'../next-server/lib/router/utils'
import
{
isDynamicRoute
}
from
'../next-server/lib/router/utils/is-dynamic'
import
{
isDynamicRoute
}
from
'../next-server/lib/router/utils/is-dynamic'
import
{
Redirect
,
Rewrite
}
from
'../lib/check-custom-routes'
import
{
findPageFile
}
from
'../server/lib/find-page-file'
import
{
DEFAULT_REDIRECT_STATUS
}
from
'../next-server/lib/constants'
const
fsStatPromise
=
promisify
(
fs
.
stat
)
const
fsStatPromise
=
promisify
(
fs
.
stat
)
const
fileStats
:
{
[
k
:
string
]:
Promise
<
fs
.
Stats
>
}
=
{}
const
fileStats
:
{
[
k
:
string
]:
Promise
<
fs
.
Stats
>
}
=
{}
...
@@ -43,10 +43,11 @@ export interface PageInfo {
...
@@ -43,10 +43,11 @@ export interface PageInfo {
serverBundle
:
string
serverBundle
:
string
}
}
export
function
printTreeView
(
export
async
function
printTreeView
(
list
:
string
[],
list
:
readonly
string
[],
pageInfos
:
Map
<
string
,
PageInfo
>
,
pageInfos
:
Map
<
string
,
PageInfo
>
,
serverless
:
boolean
serverless
:
boolean
,
{
pagesDir
,
pageExtensions
}:
{
pagesDir
:
string
;
pageExtensions
:
string
[]
}
)
{
)
{
const
getPrettySize
=
(
_size
:
number
):
string
=>
{
const
getPrettySize
=
(
_size
:
number
):
string
=>
{
const
size
=
prettyBytes
(
_size
)
const
size
=
prettyBytes
(
_size
)
...
@@ -62,56 +63,69 @@ export function printTreeView(
...
@@ -62,56 +63,69 @@ export function printTreeView(
[
'Page'
,
'Size'
].
map
(
entry
=>
chalk
.
underline
(
entry
))
as
[
string
,
string
],
[
'Page'
,
'Size'
].
map
(
entry
=>
chalk
.
underline
(
entry
))
as
[
string
,
string
],
]
]
list
const
hasCustomApp
=
await
findPageFile
(
pagesDir
,
'/_app'
,
pageExtensions
)
const
hasCustomError
=
await
findPageFile
(
pagesDir
,
'/_error'
,
pageExtensions
)
const
pageList
=
list
.
slice
()
.
filter
(
e
=>
!
(
e
===
'/_document'
||
(
!
hasCustomApp
&&
e
===
'/_app'
)
||
(
!
hasCustomError
&&
e
===
'/_error'
)
)
)
.
sort
((
a
,
b
)
=>
a
.
localeCompare
(
b
))
.
sort
((
a
,
b
)
=>
a
.
localeCompare
(
b
))
.
forEach
((
item
,
i
)
=>
{
const
symbol
=
i
===
0
?
list
.
length
===
1
?
'─'
:
'┌'
:
i
===
list
.
length
-
1
?
'└'
:
'├'
const
pageInfo
=
pageInfos
.
get
(
item
)
messages
.
push
([
`
${
symbol
}
${
item
.
startsWith
(
'/_'
)
?
' '
:
pageInfo
&&
pageInfo
.
static
?
'○'
:
pageInfo
&&
pageInfo
.
isSsg
?
'●'
:
'λ'
}
${
item
}
`
,
pageInfo
?
pageInfo
.
isAmp
?
chalk
.
cyan
(
'AMP'
)
:
pageInfo
.
size
>=
0
?
getPrettySize
(
pageInfo
.
size
)
:
''
:
''
,
])
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
})
=>
{
pageList
.
forEach
((
item
,
i
,
arr
)
=>
{
const
innerSymbol
=
index
===
length
-
1
?
'└'
:
'├'
const
symbol
=
messages
.
push
([
`
${
contSymbol
}
${
innerSymbol
}
${
slug
}
`
,
''
])
i
===
0
})
?
arr
.
length
===
1
?
'─'
:
'┌'
:
i
===
arr
.
length
-
1
?
'└'
:
'├'
const
pageInfo
=
pageInfos
.
get
(
item
)
messages
.
push
([
`
${
symbol
}
${
item
.
startsWith
(
'/_'
)
?
' '
:
pageInfo
&&
pageInfo
.
static
?
'○'
:
pageInfo
&&
pageInfo
.
isSsg
?
'●'
:
'λ'
}
${
item
}
`
,
pageInfo
?
pageInfo
.
isAmp
?
chalk
.
cyan
(
'AMP'
)
:
pageInfo
.
size
>=
0
?
getPrettySize
(
pageInfo
.
size
)
:
''
:
''
,
])
if
(
pageInfo
&&
pageInfo
.
ssgPageRoutes
&&
pageInfo
.
ssgPageRoutes
.
length
)
{
const
totalRoutes
=
pageInfo
.
ssgPageRoutes
.
length
const
previewPages
=
totalRoutes
===
4
?
4
:
3
const
contSymbol
=
i
===
arr
.
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
,
{
...
...
test/integration/build-output/fixtures/basic-app/pages/index.js
0 → 100644
View file @
a133f850
export
default
function
()
{
return
<
div
/>
}
test/integration/build-output/fixtures/with-app/pages/_app.js
0 → 100644
View file @
a133f850
export
default
function
MyApp
({
Component
,
pageProps
})
{
return
<
Component
{...
pageProps
}
/
>
}
test/integration/build-output/fixtures/with-app/pages/index.js
0 → 100644
View file @
a133f850
export
default
function
()
{
return
<
div
/>
}
test/integration/build-output/fixtures/with-error/pages/_error.js
0 → 100644
View file @
a133f850
import
React
from
'react'
function
Error
({
statusCode
})
{
return
(
<
p
>
{
statusCode
?
`An error
${
statusCode
}
occurred on server`
:
'An error occurred on client'
}
<
/p
>
)
}
Error
.
getInitialProps
=
({
res
,
err
})
=>
{
const
statusCode
=
res
?
res
.
statusCode
:
err
?
err
.
statusCode
:
404
return
{
statusCode
}
}
export
default
Error
test/integration/build-output/fixtures/with-error/pages/index.js
0 → 100644
View file @
a133f850
export
default
function
()
{
return
<
div
/>
}
test/integration/build-output/test/index.test.js
0 → 100644
View file @
a133f850
/* eslint-env jest */
/* global jasmine */
import
'flat-map-polyfill'
import
{
remove
}
from
'fs-extra'
import
{
nextBuild
}
from
'next-test-utils'
import
{
join
}
from
'path'
jasmine
.
DEFAULT_TIMEOUT_INTERVAL
=
1000
*
60
*
2
const
fixturesDir
=
join
(
__dirname
,
'..'
,
'fixtures'
)
describe
(
'Build Output'
,
()
=>
{
describe
(
'Basic Application Output'
,
()
=>
{
const
appDir
=
join
(
fixturesDir
,
'basic-app'
)
beforeAll
(
async
()
=>
{
await
remove
(
join
(
appDir
,
'.next'
))
})
it
(
'should not include internal pages'
,
async
()
=>
{
const
{
stdout
}
=
await
nextBuild
(
appDir
,
[],
{
stdout
:
true
,
})
expect
(
stdout
).
not
.
toContain
(
'/_document'
)
expect
(
stdout
).
not
.
toContain
(
'/_app'
)
expect
(
stdout
).
not
.
toContain
(
'/_error'
)
expect
(
stdout
).
toContain
(
'○ /'
)
})
})
describe
(
'Custom App Output'
,
()
=>
{
const
appDir
=
join
(
fixturesDir
,
'with-app'
)
beforeAll
(
async
()
=>
{
await
remove
(
join
(
appDir
,
'.next'
))
})
it
(
'should not include internal pages'
,
async
()
=>
{
const
{
stdout
}
=
await
nextBuild
(
appDir
,
[],
{
stdout
:
true
,
})
expect
(
stdout
).
not
.
toContain
(
'/_document'
)
expect
(
stdout
).
not
.
toContain
(
'/_error'
)
expect
(
stdout
).
toContain
(
'/_app'
)
expect
(
stdout
).
toContain
(
'○ /'
)
})
})
describe
(
'Custom Error Output'
,
()
=>
{
const
appDir
=
join
(
fixturesDir
,
'with-error'
)
beforeAll
(
async
()
=>
{
await
remove
(
join
(
appDir
,
'.next'
))
})
it
(
'should not include internal pages'
,
async
()
=>
{
const
{
stdout
}
=
await
nextBuild
(
appDir
,
[],
{
stdout
:
true
,
})
expect
(
stdout
).
not
.
toContain
(
'/_document'
)
expect
(
stdout
).
not
.
toContain
(
'/_app'
)
expect
(
stdout
).
toContain
(
'/_error'
)
expect
(
stdout
).
toContain
(
'○ /'
)
})
})
})
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