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
38ac55dd
Unverified
Commit
38ac55dd
authored
Sep 29, 2021
by
JJ Kasper
Committed by
GitHub
Sep 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update output tracing resolving (#29473)
parent
e5960dc6
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
72 additions
and
108 deletions
+72
-108
.gitignore
.gitignore
+1
-0
webpack-config.ts
packages/next/build/webpack-config.ts
+0
-1
next-trace-entrypoints-plugin.ts
...xt/build/webpack/plugins/next-trace-entrypoints-plugin.ts
+28
-77
index.test.js
test/integration/production/test/index.test.js
+0
-4
e2e-utils.ts
test/lib/e2e-utils.ts
+28
-20
base.ts
test/lib/next-modes/base.ts
+5
-2
next-dev.ts
test/lib/next-modes/next-dev.ts
+5
-1
next-start.ts
test/lib/next-modes/next-start.ts
+5
-3
No files found.
.gitignore
View file @
38ac55dd
...
@@ -23,6 +23,7 @@ test/**/out*
...
@@ -23,6 +23,7 @@ test/**/out*
test/**/next-env.d.ts
test/**/next-env.d.ts
.DS_Store
.DS_Store
/e2e-tests
/e2e-tests
test/tmp/**
# Editors
# Editors
**/.idea
**/.idea
...
...
packages/next/build/webpack-config.ts
View file @
38ac55dd
...
@@ -1296,7 +1296,6 @@ export default async function getBaseWebpackConfig(
...
@@ -1296,7 +1296,6 @@ export default async function getBaseWebpackConfig(
isWebpack5
&&
isWebpack5
&&
new
TraceEntryPointsPlugin
({
new
TraceEntryPointsPlugin
({
appDir
:
dir
,
appDir
:
dir
,
esmExternals
:
config
.
experimental
.
esmExternals
,
}),
}),
// Moment.js is an extremely popular library that bundles large locale files
// Moment.js is an extremely popular library that bundles large locale files
// by default due to how Webpack interprets its code. This is a practical
// by default due to how Webpack interprets its code. This is a practical
...
...
packages/next/build/webpack/plugins/next-trace-entrypoints-plugin.ts
View file @
38ac55dd
...
@@ -9,11 +9,6 @@ import {
...
@@ -9,11 +9,6 @@ import {
isWebpack5
,
isWebpack5
,
sources
,
sources
,
}
from
'next/dist/compiled/webpack/webpack'
}
from
'next/dist/compiled/webpack/webpack'
import
{
NODE_ESM_RESOLVE_OPTIONS
,
NODE_RESOLVE_OPTIONS
,
}
from
'../../webpack-config'
import
{
NextConfigComplete
}
from
'../../../server/config-shared'
const
PLUGIN_NAME
=
'TraceEntryPointsPlugin'
const
PLUGIN_NAME
=
'TraceEntryPointsPlugin'
const
TRACE_IGNORES
=
[
const
TRACE_IGNORES
=
[
...
@@ -38,20 +33,16 @@ export class TraceEntryPointsPlugin implements webpack.Plugin {
...
@@ -38,20 +33,16 @@ export class TraceEntryPointsPlugin implements webpack.Plugin {
private
appDir
:
string
private
appDir
:
string
private
entryTraces
:
Map
<
string
,
string
[]
>
private
entryTraces
:
Map
<
string
,
string
[]
>
private
excludeFiles
:
string
[]
private
excludeFiles
:
string
[]
private
esmExternals
:
NextConfigComplete
[
'experimental'
][
'esmExternals'
]
constructor
({
constructor
({
appDir
,
appDir
,
excludeFiles
,
excludeFiles
,
esmExternals
,
}:
{
}:
{
appDir
:
string
appDir
:
string
excludeFiles
?:
string
[]
excludeFiles
?:
string
[]
esmExternals
?:
NextConfigComplete
[
'experimental'
][
'esmExternals'
]
})
{
})
{
this
.
appDir
=
appDir
this
.
appDir
=
appDir
this
.
entryTraces
=
new
Map
()
this
.
entryTraces
=
new
Map
()
this
.
esmExternals
=
esmExternals
this
.
excludeFiles
=
excludeFiles
||
[]
this
.
excludeFiles
=
excludeFiles
||
[]
}
}
...
@@ -308,10 +299,18 @@ export class TraceEntryPointsPlugin implements webpack.Plugin {
...
@@ -308,10 +299,18 @@ export class TraceEntryPointsPlugin implements webpack.Plugin {
const
tracedDeps
:
string
[]
=
[]
const
tracedDeps
:
string
[]
=
[]
for
(
const
file
of
result
.
fileList
)
{
for
(
const
file
of
result
.
fileList
)
{
// don't include the entry itself
if
(
result
.
reasons
[
file
].
type
===
'initial'
)
{
if
(
result
.
reasons
[
file
].
type
===
'initial'
)
{
continue
continue
}
}
tracedDeps
.
push
(
nodePath
.
join
(
root
,
file
))
const
filepath
=
nodePath
.
join
(
root
,
file
)
// don't include transpiled files as they are included
// in the webpack output (e.g. chunks or the entry itself)
if
(
depModMap
.
get
(
filepath
)?.
originalSource
?.())
{
continue
}
tracedDeps
.
push
(
filepath
)
}
}
// entryMod.buildInfo.cachedNextEntryTrace = {
// entryMod.buildInfo.cachedNextEntryTrace = {
...
@@ -354,80 +353,32 @@ export class TraceEntryPointsPlugin implements webpack.Plugin {
...
@@ -354,80 +353,32 @@ export class TraceEntryPointsPlugin implements webpack.Plugin {
}
}
)
)
const
resolver
=
compilation
.
resolverFactory
.
get
(
'normal'
)
const
resolver
=
compilation
.
resolverFactory
.
get
(
'normal'
)
const
looseEsmExternals
=
this
.
esmExternals
===
'loose'
const
doResolve
=
async
(
const
doResolve
=
async
(
request
:
string
,
request
:
string
,
context
:
string
,
context
:
string
,
isEsmRequested
?:
boolean
_
isEsmRequested
?:
boolean
):
Promise
<
string
>
=>
{
):
Promise
<
string
>
=>
{
const
preferEsm
=
isEsmRequested
&&
this
.
esmExternals
return
new
Promise
((
resolve
,
reject
)
=>
{
const
curResolver
=
resolver
.
withOptions
(
resolver
.
resolve
(
preferEsm
?
NODE_ESM_RESOLVE_OPTIONS
:
NODE_RESOLVE_OPTIONS
{},
)
context
,
request
,
let
res
:
string
=
''
{
try
{
fileDependencies
:
compilation
.
fileDependencies
,
res
=
await
new
Promise
((
resolve
,
reject
)
=>
{
missingDependencies
:
compilation
.
missingDependencies
,
curResolver
.
resolve
(
contextDependencies
:
compilation
.
contextDependencies
,
{},
},
context
,
(
err
:
any
,
result
:
string
)
=>
{
request
,
if
(
err
)
return
reject
(
err
)
{
fileDependencies
:
compilation
.
fileDependencies
,
if
(
!
result
)
{
missingDependencies
:
compilation
.
missingDependencies
,
return
reject
(
new
Error
(
'module not found'
))
contextDependencies
:
compilation
.
contextDependencies
,
},
(
err
:
any
,
result
:
string
)
=>
{
if
(
err
)
reject
(
err
)
else
resolve
(
result
)
}
)
})
}
catch
(
err
)
{
if
(
!
(
isEsmRequested
&&
looseEsmExternals
))
{
throw
err
}
// continue to attempt alternative resolving
}
if
(
!
res
&&
isEsmRequested
&&
looseEsmExternals
)
{
const
altResolver
=
resolver
.
withOptions
(
preferEsm
?
NODE_RESOLVE_OPTIONS
:
NODE_ESM_RESOLVE_OPTIONS
)
res
=
await
new
Promise
((
resolve
,
reject
)
=>
{
altResolver
.
resolve
(
{},
context
,
request
,
{
fileDependencies
:
compilation
.
fileDependencies
,
missingDependencies
:
compilation
.
missingDependencies
,
contextDependencies
:
compilation
.
contextDependencies
,
},
(
err
:
any
,
result
:
string
)
=>
{
if
(
err
)
reject
(
err
)
else
resolve
(
result
)
}
}
)
resolve
(
result
)
})
}
}
if
(
!
res
)
{
// we should not get here as one of the two above resolves should
// have thrown but this is here as a safeguard
throw
new
Error
(
'invariant: failed to resolve '
+
JSON
.
stringify
({
isEsmRequested
,
looseEsmExternals
,
request
,
res
,
})
)
)
}
})
return
res
}
}
this
.
tapfinishModules
(
this
.
tapfinishModules
(
...
...
test/integration/production/test/index.test.js
View file @
38ac55dd
...
@@ -118,8 +118,6 @@ describe('Production Usage', () => {
...
@@ -118,8 +118,6 @@ describe('Production Usage', () => {
/node_modules
\/
react
\/
index
\.
js/
,
/node_modules
\/
react
\/
index
\.
js/
,
/node_modules
\/
react
\/
package
\.
json/
,
/node_modules
\/
react
\/
package
\.
json/
,
/node_modules
\/
react
\/
cjs
\/
react
\.
production
\.
min
\.
js/
,
/node_modules
\/
react
\/
cjs
\/
react
\.
production
\.
min
\.
js/
,
/next
\/
link
\.
js/
,
/next
\/
dist
\/
client
\/
link
\.
js/
,
],
],
notTests
:
[
/node_modules
\/
react
\/
cjs
\/
react
\.
development
\.
js/
],
notTests
:
[
/node_modules
\/
react
\/
cjs
\/
react
\.
development
\.
js/
],
},
},
...
@@ -131,8 +129,6 @@ describe('Production Usage', () => {
...
@@ -131,8 +129,6 @@ describe('Production Usage', () => {
/node_modules
\/
react
\/
index
\.
js/
,
/node_modules
\/
react
\/
index
\.
js/
,
/node_modules
\/
react
\/
package
\.
json/
,
/node_modules
\/
react
\/
package
\.
json/
,
/node_modules
\/
react
\/
cjs
\/
react
\.
production
\.
min
\.
js/
,
/node_modules
\/
react
\/
cjs
\/
react
\.
production
\.
min
\.
js/
,
/next
\/
router
\.
js/
,
/next
\/
dist
\/
client
\/
router
\.
js/
,
],
],
notTests
:
[
/node_modules
\/
react
\/
cjs
\/
react
\.
development
\.
js/
],
notTests
:
[
/node_modules
\/
react
\/
cjs
\/
react
\.
development
\.
js/
],
},
},
...
...
test/lib/e2e-utils.ts
View file @
38ac55dd
...
@@ -96,29 +96,37 @@ export async function createNext(opts: {
...
@@ -96,29 +96,37 @@ export async function createNext(opts: {
nextConfig
?:
NextConfig
nextConfig
?:
NextConfig
skipStart
?:
boolean
skipStart
?:
boolean
}):
Promise
<
NextInstance
>
{
}):
Promise
<
NextInstance
>
{
if
(
nextInstance
)
{
try
{
throw
new
Error
(
`createNext called without destroying previous instance`
)
if
(
nextInstance
)
{
}
throw
new
Error
(
`createNext called without destroying previous instance`
)
}
if
(
testMode
===
'dev'
)
{
if
(
testMode
===
'dev'
)
{
// next dev
// next dev
nextInstance
=
new
NextDevInstance
(
opts
)
nextInstance
=
new
NextDevInstance
(
opts
)
}
else
if
(
testMode
===
'deploy'
)
{
}
else
if
(
testMode
===
'deploy'
)
{
// Vercel
// Vercel
throw
new
Error
(
'to-implement'
)
throw
new
Error
(
'to-implement'
)
}
else
{
}
else
{
// next build + next start
// next build + next start
nextInstance
=
new
NextStartInstance
(
opts
)
nextInstance
=
new
NextStartInstance
(
opts
)
}
}
nextInstance
.
on
(
'destroy'
,
()
=>
{
nextInstance
.
on
(
'destroy'
,
()
=>
{
nextInstance
=
undefined
nextInstance
=
undefined
})
})
await
nextInstance
.
setup
()
await
nextInstance
.
setup
()
if
(
!
opts
.
skipStart
)
{
if
(
!
opts
.
skipStart
)
{
await
nextInstance
.
start
()
await
nextInstance
.
start
()
}
return
nextInstance
!
}
catch
(
err
)
{
console
.
error
(
'Failed to create next instance'
,
err
)
try
{
await
nextInstance
.
destroy
()
}
catch
(
_
)
{}
process
.
exit
(
1
)
}
}
return
nextInstance
!
}
}
test/lib/next-modes/base.ts
View file @
38ac55dd
...
@@ -50,12 +50,15 @@ export class NextInstance {
...
@@ -50,12 +50,15 @@ export class NextInstance {
}
}
console
.
log
(
`Creating test directory with isolated next...`
)
console
.
log
(
`Creating test directory with isolated next...`
)
const
tmpDir
=
process
.
env
.
NEXT_TEST_DIR
||
(
await
fs
.
realpath
(
os
.
tmpdir
()))
const
skipIsolatedNext
=
!!
process
.
env
.
NEXT_SKIP_ISOLATE
const
tmpDir
=
skipIsolatedNext
?
path
.
join
(
__dirname
,
'../../tmp'
)
:
process
.
env
.
NEXT_TEST_DIR
||
(
await
fs
.
realpath
(
os
.
tmpdir
()))
this
.
testDir
=
path
.
join
(
tmpDir
,
`next-test-
${
Date
.
now
()}
`
)
this
.
testDir
=
path
.
join
(
tmpDir
,
`next-test-
${
Date
.
now
()}
`
)
if
(
process
.
env
.
NEXT_TEST_STARTER
&&
!
this
.
dependencies
)
{
if
(
process
.
env
.
NEXT_TEST_STARTER
&&
!
this
.
dependencies
)
{
await
fs
.
copy
(
process
.
env
.
NEXT_TEST_STARTER
,
this
.
testDir
)
await
fs
.
copy
(
process
.
env
.
NEXT_TEST_STARTER
,
this
.
testDir
)
}
else
{
}
else
if
(
!
skipIsolatedNext
)
{
this
.
testDir
=
await
createNextInstall
({
this
.
testDir
=
await
createNextInstall
({
react
:
'latest'
,
react
:
'latest'
,
'react-dom'
:
'latest'
,
'react-dom'
:
'latest'
,
...
...
test/lib/next-modes/next-dev.ts
View file @
38ac55dd
import
path
from
'path'
import
resolveFrom
from
'resolve-from'
import
{
spawn
}
from
'child_process'
import
{
spawn
}
from
'child_process'
import
{
NextInstance
}
from
'./base'
import
{
NextInstance
}
from
'./base'
...
@@ -22,7 +24,9 @@ export class NextDevInstance extends NextInstance {
...
@@ -22,7 +24,9 @@ export class NextDevInstance extends NextInstance {
}
}
// we don't use yarn next here as yarn detaches itself from the
// we don't use yarn next here as yarn detaches itself from the
// child process making it harder to kill all processes
// child process making it harder to kill all processes
this
.
childProcess
=
spawn
(
'node'
,
[
'node_modules/next/dist/bin/next'
],
{
const
nextDir
=
path
.
dirname
(
resolveFrom
(
this
.
testDir
,
'next/package.json'
))
this
.
childProcess
=
spawn
(
'node'
,
[
path
.
join
(
nextDir
,
'/dist/bin/next'
)],
{
cwd
:
this
.
testDir
,
cwd
:
this
.
testDir
,
stdio
:
[
'ignore'
,
'pipe'
,
'pipe'
],
stdio
:
[
'ignore'
,
'pipe'
,
'pipe'
],
shell
:
false
,
shell
:
false
,
...
...
test/lib/next-modes/next-start.ts
View file @
38ac55dd
import
path
from
'path'
import
path
from
'path'
import
fs
from
'fs-extra'
import
fs
from
'fs-extra'
import
resolveFrom
from
'resolve-from'
import
{
spawn
,
SpawnOptions
}
from
'child_process'
import
{
spawn
,
SpawnOptions
}
from
'child_process'
import
{
NextInstance
}
from
'./base'
import
{
NextInstance
}
from
'./base'
...
@@ -48,10 +49,11 @@ export class NextStartInstance extends NextInstance {
...
@@ -48,10 +49,11 @@ export class NextStartInstance extends NextInstance {
this
.
emit
(
'stderr'
,
[
msg
])
this
.
emit
(
'stderr'
,
[
msg
])
})
})
}
}
const
nextDir
=
path
.
dirname
(
resolveFrom
(
this
.
testDir
,
'next/package.json'
))
this
.
childProcess
=
spawn
(
this
.
childProcess
=
spawn
(
'node'
,
'node'
,
[
'node_modules/next/dist/bin/next'
,
'build'
],
[
path
.
join
(
nextDir
,
'/dist/bin/next'
)
,
'build'
],
spawnOpts
spawnOpts
)
)
handleStdio
()
handleStdio
()
...
@@ -59,7 +61,7 @@ export class NextStartInstance extends NextInstance {
...
@@ -59,7 +61,7 @@ export class NextStartInstance extends NextInstance {
await
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
await
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
this
.
childProcess
.
on
(
'exit'
,
(
code
)
=>
{
this
.
childProcess
.
on
(
'exit'
,
(
code
)
=>
{
if
(
code
)
reject
(
new
Error
(
`next build failed with code
${
code
}
`
))
if
(
code
)
reject
(
new
Error
(
`next build failed with code
${
code
}
`
))
resolve
()
else
resolve
()
})
})
})
})
this
.
_buildId
=
(
this
.
_buildId
=
(
...
@@ -76,7 +78,7 @@ export class NextStartInstance extends NextInstance {
...
@@ -76,7 +78,7 @@ export class NextStartInstance extends NextInstance {
// child process making it harder to kill all processes
// child process making it harder to kill all processes
this
.
childProcess
=
spawn
(
this
.
childProcess
=
spawn
(
'node'
,
'node'
,
[
'node_modules/next/dist/bin/next'
,
'start'
],
[
path
.
join
(
nextDir
,
'/dist/bin/next'
)
,
'start'
],
spawnOpts
spawnOpts
)
)
handleStdio
()
handleStdio
()
...
...
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