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
7c7fd3e8
Unverified
Commit
7c7fd3e8
authored
May 20, 2020
by
Joe Haddad
Committed by
GitHub
May 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Record presence of `reportWebVitals` (#13155)
Closes #12897
parent
7cf3c3d2
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
81 additions
and
0 deletions
+81
-0
index.ts
packages/next/build/index.ts
+14
-0
utils.ts
packages/next/build/utils.ts
+8
-0
build.ts
packages/next/telemetry/events/build.ts
+1
-0
_app_withoutreportwebvitals.empty
...gration/telemetry/pages/_app_withoutreportwebvitals.empty
+2
-0
_app_withreportwebvitals.empty
...ntegration/telemetry/pages/_app_withreportwebvitals.empty
+5
-0
index.test.js
test/integration/telemetry/test/index.test.js
+51
-0
No files found.
packages/next/build/index.ts
View file @
7c7fd3e8
...
@@ -69,6 +69,7 @@ import {
...
@@ -69,6 +69,7 @@ import {
PageInfo
,
PageInfo
,
printCustomRoutes
,
printCustomRoutes
,
printTreeView
,
printTreeView
,
getNamedExports
,
}
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'
...
@@ -466,6 +467,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -466,6 +467,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
)
)
let
customAppGetInitialProps
:
boolean
|
undefined
let
customAppGetInitialProps
:
boolean
|
undefined
let
namedExports
:
Array
<
string
>
|
undefined
process
.
env
.
NEXT_PHASE
=
PHASE_PRODUCTION_BUILD
process
.
env
.
NEXT_PHASE
=
PHASE_PRODUCTION_BUILD
...
@@ -538,6 +540,17 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -538,6 +540,17 @@ export default async function build(dir: string, conf = null): Promise<void> {
runtimeEnvConfig
runtimeEnvConfig
)
)
namedExports
=
getNamedExports
(
isLikeServerless
?
serverBundle
:
path
.
join
(
distDir
,
SERVER_DIRECTORY
,
`/static/
${
buildId
}
/pages/_app.js`
),
runtimeEnvConfig
)
if
(
customAppGetInitialProps
)
{
if
(
customAppGetInitialProps
)
{
console
.
warn
(
console
.
warn
(
chalk
.
bold
.
yellow
(
`Warning: `
)
+
chalk
.
bold
.
yellow
(
`Warning: `
)
+
...
@@ -921,6 +934,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -921,6 +934,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
pagePaths
.
length
-
pagePaths
.
length
-
(
staticPages
.
size
+
ssgPages
.
size
+
serverPropsPages
.
size
),
(
staticPages
.
size
+
ssgPages
.
size
+
serverPropsPages
.
size
),
hasStatic404
:
useStatic404
,
hasStatic404
:
useStatic404
,
hasReportWebVitals
:
namedExports
?.
includes
(
'reportWebVitals'
)
??
false
,
})
})
)
)
...
...
packages/next/build/utils.ts
View file @
7c7fd3e8
...
@@ -789,3 +789,11 @@ export function hasCustomGetInitialProps(
...
@@ -789,3 +789,11 @@ export function hasCustomGetInitialProps(
}
}
return
mod
.
getInitialProps
!==
mod
.
origGetInitialProps
return
mod
.
getInitialProps
!==
mod
.
origGetInitialProps
}
}
export
function
getNamedExports
(
bundle
:
string
,
runtimeEnvConfig
:
any
):
Array
<
string
>
{
require
(
'../next-server/lib/runtime-config'
).
setConfig
(
runtimeEnvConfig
)
return
Object
.
keys
(
require
(
bundle
))
}
packages/next/telemetry/events/build.ts
View file @
7c7fd3e8
...
@@ -44,6 +44,7 @@ type EventBuildOptimized = {
...
@@ -44,6 +44,7 @@ type EventBuildOptimized = {
hasDunderPages
:
boolean
hasDunderPages
:
boolean
hasTestPages
:
boolean
hasTestPages
:
boolean
hasStatic404
:
boolean
hasStatic404
:
boolean
hasReportWebVitals
:
boolean
}
}
export
function
eventBuildOptimize
(
export
function
eventBuildOptimize
(
...
...
test/integration/telemetry/pages/_app_withoutreportwebvitals.empty
0 → 100644
View file @
7c7fd3e8
import App from 'next/app'
export default App
test/integration/telemetry/pages/_app_withreportwebvitals.empty
0 → 100644
View file @
7c7fd3e8
import App from 'next/app'
export default App
export function reportWebVitals(metric) {
console.log(metric)
}
test/integration/telemetry/test/index.test.js
View file @
7c7fd3e8
...
@@ -369,4 +369,55 @@ describe('Telemetry CLI', () => {
...
@@ -369,4 +369,55 @@ describe('Telemetry CLI', () => {
expect
(
stderr
).
toMatch
(
/isSrcDir.*
?
true/
)
expect
(
stderr
).
toMatch
(
/isSrcDir.*
?
true/
)
})
})
it
(
'detect reportWebVitals correctly for `next build`'
,
async
()
=>
{
// Case 1: When _app.js does not exist.
let
build
=
await
nextBuild
(
appDir
,
[],
{
stderr
:
true
,
env
:
{
NEXT_TELEMETRY_DEBUG
:
1
},
})
let
event1
=
/NEXT_BUILD_OPTIMIZED
[\s\S]
+
?
{
([\s\S]
+
?)
}/
.
exec
(
build
.
stderr
)
.
pop
()
expect
(
event1
).
toMatch
(
/hasReportWebVitals.*
?
false/
)
// Case 2: When _app.js exist with reportWebVitals function.
await
fs
.
rename
(
path
.
join
(
appDir
,
'pages'
,
'_app_withreportwebvitals.empty'
),
path
.
join
(
appDir
,
'pages'
,
'_app.js'
)
)
build
=
await
nextBuild
(
appDir
,
[],
{
stderr
:
true
,
env
:
{
NEXT_TELEMETRY_DEBUG
:
1
},
})
await
fs
.
rename
(
path
.
join
(
appDir
,
'pages'
,
'_app.js'
),
path
.
join
(
appDir
,
'pages'
,
'_app_withreportwebvitals.empty'
)
)
event1
=
/NEXT_BUILD_OPTIMIZED
[\s\S]
+
?
{
([\s\S]
+
?)
}/
.
exec
(
build
.
stderr
).
pop
()
expect
(
event1
).
toMatch
(
/hasReportWebVitals.*
?
true/
)
// Case 3: When _app.js exist without reportWebVitals function.
await
fs
.
rename
(
path
.
join
(
appDir
,
'pages'
,
'_app_withoutreportwebvitals.empty'
),
path
.
join
(
appDir
,
'pages'
,
'_app.js'
)
)
build
=
await
nextBuild
(
appDir
,
[],
{
stderr
:
true
,
env
:
{
NEXT_TELEMETRY_DEBUG
:
1
},
})
await
fs
.
rename
(
path
.
join
(
appDir
,
'pages'
,
'_app.js'
),
path
.
join
(
appDir
,
'pages'
,
'_app_withoutreportwebvitals.empty'
)
)
event1
=
/NEXT_BUILD_OPTIMIZED
[\s\S]
+
?
{
([\s\S]
+
?)
}/
.
exec
(
build
.
stderr
).
pop
()
expect
(
event1
).
toMatch
(
/hasReportWebVitals.*
?
false/
)
})
})
})
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