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
1c247b5c
Unverified
Commit
1c247b5c
authored
Feb 14, 2020
by
Joe Haddad
Committed by
GitHub
Feb 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check next.config.js settings (#10425)
* Check next.config.js settings * Add tests * test package.json case too
parent
ecfa7f7d
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
308 additions
and
22 deletions
+308
-22
index.ts
packages/next/build/index.ts
+2
-2
index.ts
packages/next/export/index.ts
+2
-2
config.ts
packages/next/next-server/server/config.ts
+1
-1
next-dev-server.ts
packages/next/server/next-dev-server.ts
+2
-2
version.ts
packages/next/telemetry/events/version.ts
+90
-15
.babelrc.default
test/integration/telemetry/.babelrc.default
+3
-0
.babelrc.plugin
test/integration/telemetry/.babelrc.plugin
+4
-0
.babelrc.preset
test/integration/telemetry/.babelrc.preset
+3
-0
next.config.target
test/integration/telemetry/next.config.target
+10
-0
next.config.webpack
test/integration/telemetry/next.config.webpack
+5
-0
package.babel
test/integration/telemetry/package.babel
+10
-0
index.test.js
test/integration/telemetry/test/index.test.js
+176
-0
No files found.
packages/next/build/index.ts
View file @
1c247b5c
...
...
@@ -50,8 +50,8 @@ import { normalizePagePath } from '../next-server/server/normalize-page-path'
import
{
eventBuildCompleted
,
eventBuildOptimize
,
eventCliSession
,
eventNextPlugins
,
eventVersion
,
}
from
'../telemetry/events'
import
{
Telemetry
}
from
'../telemetry/storage'
import
{
CompilerResult
,
runCompiler
}
from
'./compiler'
...
...
@@ -161,7 +161,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
let
hasPublicDir
=
false
telemetry
.
record
(
event
Version
(
{
event
CliSession
(
PHASE_PRODUCTION_BUILD
,
dir
,
{
cliCommand
:
'build'
,
isSrcDir
:
path
.
relative
(
dir
,
pagesDir
!
).
startsWith
(
'src'
),
hasNowJson
:
!!
(
await
findUp
(
'now.json'
,
{
cwd
:
dir
})),
...
...
packages/next/export/index.ts
View file @
1c247b5c
...
...
@@ -31,7 +31,7 @@ import {
import
loadConfig
,
{
isTargetLikeServerless
,
}
from
'../next-server/server/config'
import
{
event
Ver
sion
}
from
'../telemetry/events'
import
{
event
CliSes
sion
}
from
'../telemetry/events'
import
{
Telemetry
}
from
'../telemetry/storage'
import
{
normalizePagePath
}
from
'../next-server/server/normalize-page-path'
...
...
@@ -105,7 +105,7 @@ export default async function(
if
(
telemetry
)
{
telemetry
.
record
(
event
Version
(
{
event
CliSession
(
PHASE_EXPORT
,
distDir
,
{
cliCommand
:
'export'
,
isSrcDir
:
null
,
hasNowJson
:
!!
(
await
findUp
(
'now.json'
,
{
cwd
:
dir
})),
...
...
packages/next/next-server/server/config.ts
View file @
1c247b5c
...
...
@@ -198,7 +198,7 @@ function assignDefaults(userConfig: { [key: string]: any }) {
return
result
}
function
normalizeConfig
(
phase
:
string
,
config
:
any
)
{
export
function
normalizeConfig
(
phase
:
string
,
config
:
any
)
{
if
(
typeof
config
===
'function'
)
{
config
=
config
(
phase
,
{
defaultConfig
})
...
...
packages/next/server/next-dev-server.ts
View file @
1c247b5c
...
...
@@ -25,7 +25,7 @@ import { __ApiPreviewProps } from '../next-server/server/api-utils'
import
Server
,
{
ServerConstructor
}
from
'../next-server/server/next-server'
import
{
normalizePagePath
}
from
'../next-server/server/normalize-page-path'
import
Router
,
{
Params
,
route
}
from
'../next-server/server/router'
import
{
event
Ver
sion
}
from
'../telemetry/events'
import
{
event
CliSes
sion
}
from
'../telemetry/events'
import
{
Telemetry
}
from
'../telemetry/storage'
import
ErrorDebug
from
'./error-debug'
import
HotReloader
from
'./hot-reloader'
...
...
@@ -233,7 +233,7 @@ export default class DevServer extends Server {
const
telemetry
=
new
Telemetry
({
distDir
:
this
.
distDir
})
telemetry
.
record
(
event
Version
(
{
event
CliSession
(
PHASE_DEVELOPMENT_SERVER
,
this
.
distDir
,
{
cliCommand
:
'dev'
,
isSrcDir
:
relative
(
this
.
dir
,
this
.
pagesDir
!
).
startsWith
(
'src'
),
hasNowJson
:
!!
(
await
findUp
(
'now.json'
,
{
cwd
:
this
.
dir
})),
...
...
packages/next/telemetry/events/version.ts
View file @
1c247b5c
import
findUp
from
'find-up'
import
path
from
'path'
import
{
CONFIG_FILE
,
PHASE_DEVELOPMENT_SERVER
,
PHASE_EXPORT
,
PHASE_PRODUCTION_BUILD
,
}
from
'../../next-server/lib/constants'
import
{
normalizeConfig
}
from
'../../next-server/server/config'
const
EVENT_VERSION
=
'NEXT_CLI_SESSION_STARTED'
type
EventCliSessionStarted
=
{
...
...
@@ -7,27 +17,92 @@ type EventCliSessionStarted = {
isSrcDir
:
boolean
|
null
hasNowJson
:
boolean
isCustomServer
:
boolean
|
null
hasNextConfig
:
boolean
buildTarget
:
string
hasWebpackConfig
:
boolean
hasBabelConfig
:
boolean
}
function
hasBabelConfig
(
dir
:
string
):
boolean
{
try
{
const
noopFile
=
path
.
join
(
dir
,
'noop.js'
)
const
res
=
require
(
'@babel/core'
).
loadPartialConfig
({
cwd
:
dir
,
filename
:
noopFile
,
sourceFileName
:
noopFile
,
})
as
any
const
isForTooling
=
res
.
options
?.
presets
?.
every
(
(
e
:
any
)
=>
e
?.
file
?.
request
===
'next/babel'
)
&&
res
.
options
?.
plugins
?.
length
===
0
return
res
.
hasFilesystemConfig
()
&&
!
isForTooling
}
catch
{
return
false
}
}
type
NextConfigurationPhase
=
|
typeof
PHASE_DEVELOPMENT_SERVER
|
typeof
PHASE_PRODUCTION_BUILD
|
typeof
PHASE_EXPORT
function
getNextConfig
(
phase
:
NextConfigurationPhase
,
dir
:
string
):
{
[
key
:
string
]:
any
}
|
null
{
try
{
const
configurationPath
=
findUp
.
sync
(
CONFIG_FILE
,
{
cwd
:
dir
,
})
if
(
configurationPath
)
{
// This should've already been loaded, and thus should be cached / won't
// be re-evaluated.
const
configurationModule
=
require
(
configurationPath
)
// Re-normalize the configuration.
return
normalizeConfig
(
phase
,
configurationModule
.
default
||
configurationModule
)
}
}
catch
{
// ignored
}
return
null
}
export
function
eventVersion
(
event
:
Omit
<
EventCliSessionStarted
,
'nextVersion'
|
'nodeVersion'
>
export
function
eventCliSession
(
phase
:
NextConfigurationPhase
,
dir
:
string
,
event
:
Omit
<
EventCliSessionStarted
,
|
'nextVersion'
|
'nodeVersion'
|
'hasNextConfig'
|
'buildTarget'
|
'hasWebpackConfig'
|
'hasBabelConfig'
>
):
{
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
[]
}
return
[
{
eventName
:
EVENT_VERSION
,
payload
:
{
nextVersion
:
process
.
env
.
__NEXT_VERSION
,
nodeVersion
:
process
.
version
,
cliCommand
:
event
.
cliCommand
,
isSrcDir
:
event
.
isSrcDir
,
hasNowJson
:
event
.
hasNowJson
,
isCustomServer
:
event
.
isCustomServer
,
}
as
EventCliSessionStarted
,
},
]
const
userConfiguration
=
getNextConfig
(
phase
,
dir
)
const
payload
:
EventCliSessionStarted
=
{
nextVersion
:
process
.
env
.
__NEXT_VERSION
,
nodeVersion
:
process
.
version
,
cliCommand
:
event
.
cliCommand
,
isSrcDir
:
event
.
isSrcDir
,
hasNowJson
:
event
.
hasNowJson
,
isCustomServer
:
event
.
isCustomServer
,
hasNextConfig
:
!!
userConfiguration
,
buildTarget
:
userConfiguration
?.
target
??
'default'
,
hasWebpackConfig
:
typeof
userConfiguration
?.
webpack
===
'function'
,
hasBabelConfig
:
hasBabelConfig
(
dir
),
}
return
[{
eventName
:
EVENT_VERSION
,
payload
}]
}
test/integration/telemetry/.babelrc.default
0 → 100644
View file @
1c247b5c
{
"presets": ["next/babel"]
}
test/integration/telemetry/.babelrc.plugin
0 → 100644
View file @
1c247b5c
{
"presets": ["next/babel"],
"plugins": ["@babel/plugin-proposal-object-rest-spread"]
}
test/integration/telemetry/.babelrc.preset
0 → 100644
View file @
1c247b5c
{
"presets": ["next/babel", "@babel/preset-flow"]
}
test/integration/telemetry/next.config.target
0 → 100644
View file @
1c247b5c
const { PHASE_PRODUCTION_BUILD } = require('next/constants')
module.exports = phase => {
if (phase === PHASE_PRODUCTION_BUILD) {
return {
target: 'experimental-serverless-trace',
}
}
return {}
}
test/integration/telemetry/next.config.webpack
0 → 100644
View file @
1c247b5c
module.exports = {
webpack(config) {
return config
},
}
test/integration/telemetry/package.babel
0 → 100644
View file @
1c247b5c
{
"babel": {
"presets": [
"next/babel"
],
"plugins": [
"@babel/plugin-proposal-object-rest-spread"
]
}
}
test/integration/telemetry/test/index.test.js
View file @
1c247b5c
...
...
@@ -138,6 +138,182 @@ describe('Telemetry CLI', () => {
expect
(
event2
).
toMatch
(
/hasTestPages.*
?
true/
)
})
it
(
'detects correct cli session defaults'
,
async
()
=>
{
const
{
stderr
}
=
await
runNextCommand
([
'build'
,
appDir
],
{
stderr
:
true
,
env
:
{
NEXT_TELEMETRY_DEBUG
:
1
,
},
})
const
event
=
/NEXT_CLI_SESSION_STARTED
[\s\S]
+
?
{
([\s\S]
+
?)
}/
.
exec
(
stderr
)
.
pop
()
expect
(
event
).
toMatch
(
/"hasNextConfig": false/
)
expect
(
event
).
toMatch
(
/"buildTarget": "default"/
)
expect
(
event
).
toMatch
(
/"hasWebpackConfig": false/
)
expect
(
event
).
toMatch
(
/"hasBabelConfig": false/
)
})
it
(
'cli session: babel tooling config'
,
async
()
=>
{
await
fs
.
rename
(
path
.
join
(
appDir
,
'.babelrc.default'
),
path
.
join
(
appDir
,
'.babelrc'
)
)
const
{
stderr
}
=
await
runNextCommand
([
'build'
,
appDir
],
{
stderr
:
true
,
env
:
{
NEXT_TELEMETRY_DEBUG
:
1
,
},
})
await
fs
.
rename
(
path
.
join
(
appDir
,
'.babelrc'
),
path
.
join
(
appDir
,
'.babelrc.default'
)
)
const
event
=
/NEXT_CLI_SESSION_STARTED
[\s\S]
+
?
{
([\s\S]
+
?)
}/
.
exec
(
stderr
)
.
pop
()
expect
(
event
).
toMatch
(
/"hasNextConfig": false/
)
expect
(
event
).
toMatch
(
/"buildTarget": "default"/
)
expect
(
event
).
toMatch
(
/"hasWebpackConfig": false/
)
expect
(
event
).
toMatch
(
/"hasBabelConfig": false/
)
})
it
(
'cli session: custom babel config (plugin)'
,
async
()
=>
{
await
fs
.
rename
(
path
.
join
(
appDir
,
'.babelrc.plugin'
),
path
.
join
(
appDir
,
'.babelrc'
)
)
const
{
stderr
}
=
await
runNextCommand
([
'build'
,
appDir
],
{
stderr
:
true
,
env
:
{
NEXT_TELEMETRY_DEBUG
:
1
,
},
})
await
fs
.
rename
(
path
.
join
(
appDir
,
'.babelrc'
),
path
.
join
(
appDir
,
'.babelrc.plugin'
)
)
const
event
=
/NEXT_CLI_SESSION_STARTED
[\s\S]
+
?
{
([\s\S]
+
?)
}/
.
exec
(
stderr
)
.
pop
()
expect
(
event
).
toMatch
(
/"hasNextConfig": false/
)
expect
(
event
).
toMatch
(
/"buildTarget": "default"/
)
expect
(
event
).
toMatch
(
/"hasWebpackConfig": false/
)
expect
(
event
).
toMatch
(
/"hasBabelConfig": true/
)
})
it
(
'cli session: package.json custom babel config (plugin)'
,
async
()
=>
{
await
fs
.
rename
(
path
.
join
(
appDir
,
'package.babel'
),
path
.
join
(
appDir
,
'package.json'
)
)
const
{
stderr
}
=
await
runNextCommand
([
'build'
,
appDir
],
{
stderr
:
true
,
env
:
{
NEXT_TELEMETRY_DEBUG
:
1
,
},
})
await
fs
.
rename
(
path
.
join
(
appDir
,
'package.json'
),
path
.
join
(
appDir
,
'package.babel'
)
)
console
.
log
(
stderr
)
const
event
=
/NEXT_CLI_SESSION_STARTED
[\s\S]
+
?
{
([\s\S]
+
?)
}/
.
exec
(
stderr
)
.
pop
()
expect
(
event
).
toMatch
(
/"hasNextConfig": false/
)
expect
(
event
).
toMatch
(
/"buildTarget": "default"/
)
expect
(
event
).
toMatch
(
/"hasWebpackConfig": false/
)
expect
(
event
).
toMatch
(
/"hasBabelConfig": true/
)
})
it
(
'cli session: custom babel config (preset)'
,
async
()
=>
{
await
fs
.
rename
(
path
.
join
(
appDir
,
'.babelrc.preset'
),
path
.
join
(
appDir
,
'.babelrc'
)
)
const
{
stderr
}
=
await
runNextCommand
([
'build'
,
appDir
],
{
stderr
:
true
,
env
:
{
NEXT_TELEMETRY_DEBUG
:
1
,
},
})
await
fs
.
rename
(
path
.
join
(
appDir
,
'.babelrc'
),
path
.
join
(
appDir
,
'.babelrc.preset'
)
)
const
event
=
/NEXT_CLI_SESSION_STARTED
[\s\S]
+
?
{
([\s\S]
+
?)
}/
.
exec
(
stderr
)
.
pop
()
expect
(
event
).
toMatch
(
/"hasNextConfig": false/
)
expect
(
event
).
toMatch
(
/"buildTarget": "default"/
)
expect
(
event
).
toMatch
(
/"hasWebpackConfig": false/
)
expect
(
event
).
toMatch
(
/"hasBabelConfig": true/
)
})
it
(
'cli session: next config with target'
,
async
()
=>
{
await
fs
.
rename
(
path
.
join
(
appDir
,
'next.config.target'
),
path
.
join
(
appDir
,
'next.config.js'
)
)
const
{
stderr
}
=
await
runNextCommand
([
'build'
,
appDir
],
{
stderr
:
true
,
env
:
{
NEXT_TELEMETRY_DEBUG
:
1
,
},
})
await
fs
.
rename
(
path
.
join
(
appDir
,
'next.config.js'
),
path
.
join
(
appDir
,
'next.config.target'
)
)
const
event
=
/NEXT_CLI_SESSION_STARTED
[\s\S]
+
?
{
([\s\S]
+
?)
}/
.
exec
(
stderr
)
.
pop
()
expect
(
event
).
toMatch
(
/"hasNextConfig": true/
)
expect
(
event
).
toMatch
(
/"buildTarget": "experimental-serverless-trace"/
)
expect
(
event
).
toMatch
(
/"hasWebpackConfig": false/
)
expect
(
event
).
toMatch
(
/"hasBabelConfig": false/
)
})
it
(
'cli session: next config with webpack'
,
async
()
=>
{
await
fs
.
rename
(
path
.
join
(
appDir
,
'next.config.webpack'
),
path
.
join
(
appDir
,
'next.config.js'
)
)
const
{
stderr
}
=
await
runNextCommand
([
'build'
,
appDir
],
{
stderr
:
true
,
env
:
{
NEXT_TELEMETRY_DEBUG
:
1
,
},
})
await
fs
.
rename
(
path
.
join
(
appDir
,
'next.config.js'
),
path
.
join
(
appDir
,
'next.config.webpack'
)
)
const
event
=
/NEXT_CLI_SESSION_STARTED
[\s\S]
+
?
{
([\s\S]
+
?)
}/
.
exec
(
stderr
)
.
pop
()
expect
(
event
).
toMatch
(
/"hasNextConfig": true/
)
expect
(
event
).
toMatch
(
/"buildTarget": "default"/
)
expect
(
event
).
toMatch
(
/"hasWebpackConfig": true/
)
expect
(
event
).
toMatch
(
/"hasBabelConfig": false/
)
})
it
(
'detect static 404 correctly for `next build`'
,
async
()
=>
{
const
{
stderr
}
=
await
nextBuild
(
appDir
,
[],
{
stderr
:
true
,
...
...
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