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
de670b38
Unverified
Commit
de670b38
authored
Oct 10, 2019
by
Joe Haddad
Committed by
GitHub
Oct 10, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do Not Rely on Module State (#8968)
* Do Not Rely on Module State * Update storage.ts
parent
ac42beae
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
251 additions
and
252 deletions
+251
-252
index.ts
packages/next/build/index.ts
+24
-18
next-telemetry.ts
packages/next/cli/next-telemetry.ts
+6
-4
index.ts
packages/next/export/index.ts
+4
-4
next-dev-server.ts
packages/next/server/next-dev-server.ts
+4
-4
build.ts
packages/next/telemetry/events/build.ts
+10
-8
plugins.ts
packages/next/telemetry/events/plugins.ts
+24
-23
version.ts
packages/next/telemetry/events/version.ts
+13
-13
project-id.ts
packages/next/telemetry/project-id.ts
+2
-10
storage.ts
packages/next/telemetry/storage.ts
+164
-168
No files found.
packages/next/build/index.ts
View file @
de670b38
...
...
@@ -25,12 +25,12 @@ import loadConfig, {
isTargetLikeServerless
,
}
from
'../next-server/server/config'
import
{
record
BuildDuration
,
record
BuildOptimize
,
record
NextPlugins
,
record
Version
,
event
BuildDuration
,
event
BuildOptimize
,
event
NextPlugins
,
event
Version
,
}
from
'../telemetry/events'
import
{
setDistDir
as
setTelemetryDir
}
from
'../telemetry/storage'
import
{
Telemetry
}
from
'../telemetry/storage'
import
{
CompilerResult
,
runCompiler
}
from
'./compiler'
import
{
createEntrypoints
,
createPagesMapping
}
from
'./entries'
import
{
generateBuildId
}
from
'./generate-build-id'
...
...
@@ -91,7 +91,9 @@ export default async function build(dir: string, conf = null): Promise<void> {
const
{
target
}
=
config
const
buildId
=
await
generateBuildId
(
config
.
generateBuildId
,
nanoid
)
const
distDir
=
path
.
join
(
dir
,
config
.
distDir
)
setTelemetryDir
(
distDir
)
const
telemetry
=
new
Telemetry
({
distDir
})
const
publicDir
=
path
.
join
(
dir
,
'public'
)
const
pagesDir
=
findPagesDir
(
dir
)
let
publicFiles
:
string
[]
=
[]
...
...
@@ -99,8 +101,8 @@ export default async function build(dir: string, conf = null): Promise<void> {
let
backgroundWork
:
(
Promise
<
any
>
|
undefined
)[]
=
[]
backgroundWork
.
push
(
recordVersion
({
cliCommand
:
'build'
}
),
recordNextPlugins
(
path
.
resolve
(
dir
))
telemetry
.
record
(
eventVersion
({
cliCommand
:
'build'
})
),
eventNextPlugins
(
path
.
resolve
(
dir
)).
then
(
events
=>
telemetry
.
record
(
events
))
)
await
verifyTypeScriptSetup
(
dir
,
pagesDir
)
...
...
@@ -273,10 +275,12 @@ export default async function build(dir: string, conf = null): Promise<void> {
}
else
{
console
.
log
(
chalk
.
green
(
'Compiled successfully.
\
n'
))
backgroundWork
.
push
(
recordBuildDuration
({
totalPageCount
:
pagePaths
.
length
,
durationInSeconds
:
webpackBuildEnd
[
0
],
})
telemetry
.
record
(
eventBuildDuration
({
totalPageCount
:
pagePaths
.
length
,
durationInSeconds
:
webpackBuildEnd
[
0
],
})
)
)
}
...
...
@@ -572,12 +576,14 @@ export default async function build(dir: string, conf = null): Promise<void> {
const
analysisEnd
=
process
.
hrtime
(
analysisBegin
)
backgroundWork
.
push
(
recordBuildOptimize
({
durationInSeconds
:
analysisEnd
[
0
],
totalPageCount
:
pagePaths
.
length
,
staticPageCount
:
staticPages
.
size
,
ssrPageCount
:
pagePaths
.
length
-
staticPages
.
size
,
})
telemetry
.
record
(
eventBuildOptimize
({
durationInSeconds
:
analysisEnd
[
0
],
totalPageCount
:
pagePaths
.
length
,
staticPageCount
:
staticPages
.
size
,
ssrPageCount
:
pagePaths
.
length
-
staticPages
.
size
,
})
)
)
if
(
sprPages
.
size
>
0
)
{
...
...
packages/next/cli/next-telemetry.ts
View file @
de670b38
...
...
@@ -3,7 +3,7 @@ import chalk from 'chalk'
import
arg
from
'next/dist/compiled/arg/index.js'
import
{
cliCommand
}
from
'../bin/next'
import
{
setTelemetryEnabled
,
isTelemetryEnabled
}
from
'../telemetry/storage'
import
{
Telemetry
}
from
'../telemetry/storage'
const
nextTelemetry
:
cliCommand
=
argv
=>
{
const
args
=
arg
(
...
...
@@ -35,16 +35,18 @@ const nextTelemetry: cliCommand = argv => {
return
}
let
isEnabled
=
isTelemetryEnabled
()
const
telemetry
=
new
Telemetry
({
distDir
:
process
.
cwd
()
})
let
isEnabled
=
telemetry
.
isEnabled
if
(
args
[
'--enable'
]
||
args
.
_
[
0
]
===
'enable'
)
{
setTelemetry
Enabled
(
true
)
telemetry
.
set
Enabled
(
true
)
console
.
log
(
chalk
.
cyan
(
'Success!'
))
console
.
log
()
isEnabled
=
true
}
else
if
(
args
[
'--disable'
]
||
args
.
_
[
0
]
===
'disable'
)
{
setTelemetry
Enabled
(
false
)
telemetry
.
set
Enabled
(
false
)
if
(
isEnabled
)
{
console
.
log
(
chalk
.
cyan
(
'Your preference has been saved.'
))
}
else
{
...
...
packages/next/export/index.ts
View file @
de670b38
...
...
@@ -25,8 +25,8 @@ import {
import
loadConfig
,
{
isTargetLikeServerless
,
}
from
'../next-server/server/config'
import
{
record
Version
}
from
'../telemetry/events'
import
{
setDistDir
as
setTelemetryDir
}
from
'../telemetry/storage'
import
{
event
Version
}
from
'../telemetry/events'
import
{
Telemetry
}
from
'../telemetry/storage'
const
mkdirp
=
promisify
(
mkdirpModule
)
const
copyFile
=
promisify
(
copyFileOrig
)
...
...
@@ -94,8 +94,8 @@ export default async function(
const
threads
=
options
.
threads
||
Math
.
max
(
cpus
().
length
-
1
,
1
)
const
distDir
=
join
(
dir
,
nextConfig
.
distDir
)
if
(
!
options
.
buildExport
)
{
setTelemetryDir
(
distDir
)
recordVersion
({
cliCommand
:
'export'
}
)
const
telemetry
=
new
Telemetry
({
distDir
}
)
telemetry
.
record
(
eventVersion
({
cliCommand
:
'export'
})
)
}
const
subFolders
=
nextConfig
.
exportTrailingSlash
...
...
packages/next/server/next-dev-server.ts
View file @
de670b38
...
...
@@ -22,8 +22,8 @@ import {
import
Server
,
{
ServerConstructor
}
from
'../next-server/server/next-server'
import
{
normalizePagePath
}
from
'../next-server/server/normalize-page-path'
import
{
route
}
from
'../next-server/server/router'
import
{
record
Version
}
from
'../telemetry/events'
import
{
setDistDir
as
setTelemetryDir
}
from
'../telemetry/storage'
import
{
event
Version
}
from
'../telemetry/events'
import
{
Telemetry
}
from
'../telemetry/storage'
import
ErrorDebug
from
'./error-debug'
import
HotReloader
from
'./hot-reloader'
import
{
findPageFile
}
from
'./lib/find-page-file'
...
...
@@ -206,8 +206,8 @@ export default class DevServer extends Server {
await
this
.
startWatcher
()
this
.
setDevReady
!
()
setTelemetryDir
(
this
.
distDir
)
recordVersion
({
cliCommand
:
'dev'
}
)
const
telemetry
=
new
Telemetry
({
distDir
:
this
.
distDir
}
)
telemetry
.
record
(
eventVersion
({
cliCommand
:
'dev'
})
)
}
protected
async
close
()
{
...
...
packages/next/telemetry/events/build.ts
View file @
de670b38
import
{
record
}
from
'../storage'
const
EVENT_BUILD_DURATION
=
'NEXT_BUILD_COMPLETED'
type
EventBuildCompleted
=
{
durationInSeconds
:
number
totalPageCount
:
number
}
export
function
recordBuildDuration
(
event
:
EventBuildCompleted
)
{
return
record
({
export
function
eventBuildDuration
(
event
:
EventBuildCompleted
):
{
eventName
:
string
;
payload
:
EventBuildCompleted
}
{
return
{
eventName
:
EVENT_BUILD_DURATION
,
payload
:
event
,
}
)
}
}
const
EVENT_BUILD_OPTIMIZE
=
'NEXT_BUILD_OPTIMIZED'
...
...
@@ -21,9 +21,11 @@ type EventBuildOptimized = {
ssrPageCount
:
number
}
export
function
recordBuildOptimize
(
event
:
EventBuildOptimized
)
{
return
record
({
export
function
eventBuildOptimize
(
event
:
EventBuildOptimized
):
{
eventName
:
string
;
payload
:
EventBuildOptimized
}
{
return
{
eventName
:
EVENT_BUILD_OPTIMIZE
,
payload
:
event
,
}
)
}
}
packages/next/telemetry/events/plugins.ts
View file @
de670b38
import
{
record
}
from
'../storage'
import
findUp
from
'find-up'
const
EVENT_PLUGIN_PRESENT
=
'NEXT_PACKAGE_DETECTED'
...
...
@@ -159,32 +158,34 @@ const plugins = [
'@apollo/react-ssr'
,
]
export
async
function
recordNextPlugins
(
dir
:
string
)
{
export
async
function
eventNextPlugins
(
dir
:
string
):
Promise
<
Array
<
{
eventName
:
string
;
payload
:
EventPackageDetected
}
>>
{
try
{
const
packageJsonPath
=
await
findUp
(
'package.json'
,
{
cwd
:
dir
})
if
(
!
packageJsonPath
)
{
return
return
[]
}
const
{
dependencies
=
{},
devDependencies
=
{}
}
=
require
(
packageJsonPath
)
return
record
(
(
plugins
.
map
(
plugin
=>
{
const
version
=
dependencies
[
plugin
]
||
devDependencies
[
plugin
]
if
(
version
)
{
return
{
pluginName
:
plugin
,
pluginVersion
:
version
}
}
})
.
filter
(
Boolean
)
as
{
pluginName
:
string
pluginVersion
:
string
}[]).
map
(({
pluginName
,
pluginVersion
})
=>
({
eventName
:
EVENT_PLUGIN_PRESENT
,
pa
yload
:
{
packageName
:
pluginName
,
packageVersion
:
pluginVersion
,
}
as
EventPackageDetected
,
}))
)
}
catch
(
_
)
{}
return
(
plugins
.
map
(
plugin
=>
{
const
version
=
dependencies
[
plugin
]
||
devDependencies
[
plugin
]
if
(
version
)
{
return
{
pluginName
:
plugin
,
pluginVersion
:
version
}
}
})
.
filter
(
Boolean
)
as
{
pluginName
:
string
pluginVersion
:
string
}[]).
map
(({
pluginName
,
pluginVersion
})
=>
({
eventName
:
EVENT_PLUGIN_PRESENT
,
payload
:
{
pa
ckageName
:
pluginName
,
packageVersion
:
pluginVersion
,
}
as
EventPackageDetected
,
}))
}
catch
(
_
)
{
return
[]
}
}
packages/next/telemetry/events/version.ts
View file @
de670b38
import
{
record
}
from
'../storage'
const
EVENT_VERSION
=
'NEXT_CLI_SESSION_STARTED'
type
EventCliSessionStarted
=
{
...
...
@@ -8,20 +6,22 @@ type EventCliSessionStarted = {
cliCommand
:
string
}
export
function
record
Version
(
export
function
event
Version
(
event
:
Omit
<
EventCliSessionStarted
,
'nextVersion'
|
'nodeVersion'
>
)
{
)
:
{
eventName
:
string
;
payload
:
EventCliSessionStarted
}[]
{
// This should be an invariant, if it fails our build tooling is broken.
if
(
typeof
process
.
env
.
__NEXT_VERSION
!==
'string'
)
{
return
Promise
.
resolve
()
return
[]
}
return
record
({
eventName
:
EVENT_VERSION
,
payload
:
{
nextVersion
:
process
.
env
.
__NEXT_VERSION
,
nodeVersion
:
process
.
version
,
cliCommand
:
event
.
cliCommand
,
}
as
EventCliSessionStarted
,
})
return
[
{
eventName
:
EVENT_VERSION
,
payload
:
{
nextVersion
:
process
.
env
.
__NEXT_VERSION
,
nodeVersion
:
process
.
version
,
cliCommand
:
event
.
cliCommand
,
}
as
EventCliSessionStarted
,
},
]
}
packages/next/telemetry/project-id.ts
View file @
de670b38
import
{
execSync
}
from
'child_process'
import
{
computeHash
}
from
'./storage'
// Q: Why does Next.js need a project ID? Why is it looking at my git remote?
// A:
...
...
@@ -28,13 +27,6 @@ function _getProjectIdByGit() {
}
}
export
function
getProjectId
():
string
{
const
projectId
=
_getProjectIdByGit
()
||
process
.
env
.
REPOSITORY_URL
||
process
.
cwd
()
// Compute a one-way, salted hash of the project ID. This value cannot be
// reversed.
// See the top of the file for a more detailed reason why we ask for this
// data.
return
computeHash
(
projectId
.
trim
().
toLowerCase
())
||
''
export
function
getRawProjectId
():
string
{
return
_getProjectIdByGit
()
||
process
.
env
.
REPOSITORY_URL
||
process
.
cwd
()
}
packages/next/telemetry/storage.ts
View file @
de670b38
This diff is collapsed.
Click to expand it.
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