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*
test/**/next-env.d.ts
.DS_Store
/e2e-tests
test/tmp/**
# Editors
**/.idea
...
...
packages/next/build/webpack-config.ts
View file @
38ac55dd
...
...
@@ -1296,7 +1296,6 @@ export default async function getBaseWebpackConfig(
isWebpack5
&&
new
TraceEntryPointsPlugin
({
appDir
:
dir
,
esmExternals
:
config
.
experimental
.
esmExternals
,
}),
// 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
...
...
packages/next/build/webpack/plugins/next-trace-entrypoints-plugin.ts
View file @
38ac55dd
...
...
@@ -9,11 +9,6 @@ import {
isWebpack5
,
sources
,
}
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
TRACE_IGNORES
=
[
...
...
@@ -38,20 +33,16 @@ export class TraceEntryPointsPlugin implements webpack.Plugin {
private
appDir
:
string
private
entryTraces
:
Map
<
string
,
string
[]
>
private
excludeFiles
:
string
[]
private
esmExternals
:
NextConfigComplete
[
'experimental'
][
'esmExternals'
]
constructor
({
appDir
,
excludeFiles
,
esmExternals
,
}:
{
appDir
:
string
excludeFiles
?:
string
[]
esmExternals
?:
NextConfigComplete
[
'experimental'
][
'esmExternals'
]
})
{
this
.
appDir
=
appDir
this
.
entryTraces
=
new
Map
()
this
.
esmExternals
=
esmExternals
this
.
excludeFiles
=
excludeFiles
||
[]
}
...
...
@@ -308,10 +299,18 @@ export class TraceEntryPointsPlugin implements webpack.Plugin {
const
tracedDeps
:
string
[]
=
[]
for
(
const
file
of
result
.
fileList
)
{
// don't include the entry itself
if
(
result
.
reasons
[
file
].
type
===
'initial'
)
{
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 = {
...
...
@@ -354,80 +353,32 @@ export class TraceEntryPointsPlugin implements webpack.Plugin {
}
)
const
resolver
=
compilation
.
resolverFactory
.
get
(
'normal'
)
const
looseEsmExternals
=
this
.
esmExternals
===
'loose'
const
doResolve
=
async
(
request
:
string
,
context
:
string
,
isEsmRequested
?:
boolean
_
isEsmRequested
?:
boolean
):
Promise
<
string
>
=>
{
const
preferEsm
=
isEsmRequested
&&
this
.
esmExternals
const
curResolver
=
resolver
.
withOptions
(
preferEsm
?
NODE_ESM_RESOLVE_OPTIONS
:
NODE_RESOLVE_OPTIONS
)
let
res
:
string
=
''
try
{
res
=
await
new
Promise
((
resolve
,
reject
)
=>
{
curResolver
.
resolve
(
{},
context
,
request
,
{
fileDependencies
:
compilation
.
fileDependencies
,
missingDependencies
:
compilation
.
missingDependencies
,
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
)
return
new
Promise
((
resolve
,
reject
)
=>
{
resolver
.
resolve
(
{},
context
,
request
,
{
fileDependencies
:
compilation
.
fileDependencies
,
missingDependencies
:
compilation
.
missingDependencies
,
contextDependencies
:
compilation
.
contextDependencies
,
},
(
err
:
any
,
result
:
string
)
=>
{
if
(
err
)
return
reject
(
err
)
if
(
!
result
)
{
return
reject
(
new
Error
(
'module not found'
))
}
)
})
}
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
,
})
resolve
(
result
)
}
)
}
return
res
})
}
this
.
tapfinishModules
(
...
...
test/integration/production/test/index.test.js
View file @
38ac55dd
...
...
@@ -118,8 +118,6 @@ describe('Production Usage', () => {
/node_modules
\/
react
\/
index
\.
js/
,
/node_modules
\/
react
\/
package
\.
json/
,
/node_modules
\/
react
\/
cjs
\/
react
\.
production
\.
min
\.
js/
,
/next
\/
link
\.
js/
,
/next
\/
dist
\/
client
\/
link
\.
js/
,
],
notTests
:
[
/node_modules
\/
react
\/
cjs
\/
react
\.
development
\.
js/
],
},
...
...
@@ -131,8 +129,6 @@ describe('Production Usage', () => {
/node_modules
\/
react
\/
index
\.
js/
,
/node_modules
\/
react
\/
package
\.
json/
,
/node_modules
\/
react
\/
cjs
\/
react
\.
production
\.
min
\.
js/
,
/next
\/
router
\.
js/
,
/next
\/
dist
\/
client
\/
router
\.
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: {
nextConfig
?:
NextConfig
skipStart
?:
boolean
}):
Promise
<
NextInstance
>
{
if
(
nextInstance
)
{
throw
new
Error
(
`createNext called without destroying previous instance`
)
}
try
{
if
(
nextInstance
)
{
throw
new
Error
(
`createNext called without destroying previous instance`
)
}
if
(
testMode
===
'dev'
)
{
// next dev
nextInstance
=
new
NextDevInstance
(
opts
)
}
else
if
(
testMode
===
'deploy'
)
{
// Vercel
throw
new
Error
(
'to-implement'
)
}
else
{
// next build + next start
nextInstance
=
new
NextStartInstance
(
opts
)
}
if
(
testMode
===
'dev'
)
{
// next dev
nextInstance
=
new
NextDevInstance
(
opts
)
}
else
if
(
testMode
===
'deploy'
)
{
// Vercel
throw
new
Error
(
'to-implement'
)
}
else
{
// next build + next start
nextInstance
=
new
NextStartInstance
(
opts
)
}
nextInstance
.
on
(
'destroy'
,
()
=>
{
nextInstance
=
undefined
})
nextInstance
.
on
(
'destroy'
,
()
=>
{
nextInstance
=
undefined
})
await
nextInstance
.
setup
()
await
nextInstance
.
setup
()
if
(
!
opts
.
skipStart
)
{
await
nextInstance
.
start
()
if
(
!
opts
.
skipStart
)
{
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 {
}
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
()}
`
)
if
(
process
.
env
.
NEXT_TEST_STARTER
&&
!
this
.
dependencies
)
{
await
fs
.
copy
(
process
.
env
.
NEXT_TEST_STARTER
,
this
.
testDir
)
}
else
{
}
else
if
(
!
skipIsolatedNext
)
{
this
.
testDir
=
await
createNextInstall
({
react
:
'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
{
NextInstance
}
from
'./base'
...
...
@@ -22,7 +24,9 @@ export class NextDevInstance extends NextInstance {
}
// we don't use yarn next here as yarn detaches itself from the
// 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
,
stdio
:
[
'ignore'
,
'pipe'
,
'pipe'
],
shell
:
false
,
...
...
test/lib/next-modes/next-start.ts
View file @
38ac55dd
import
path
from
'path'
import
fs
from
'fs-extra'
import
resolveFrom
from
'resolve-from'
import
{
spawn
,
SpawnOptions
}
from
'child_process'
import
{
NextInstance
}
from
'./base'
...
...
@@ -48,10 +49,11 @@ export class NextStartInstance extends NextInstance {
this
.
emit
(
'stderr'
,
[
msg
])
})
}
const
nextDir
=
path
.
dirname
(
resolveFrom
(
this
.
testDir
,
'next/package.json'
))
this
.
childProcess
=
spawn
(
'node'
,
[
'node_modules/next/dist/bin/next'
,
'build'
],
[
path
.
join
(
nextDir
,
'/dist/bin/next'
)
,
'build'
],
spawnOpts
)
handleStdio
()
...
...
@@ -59,7 +61,7 @@ export class NextStartInstance extends NextInstance {
await
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
this
.
childProcess
.
on
(
'exit'
,
(
code
)
=>
{
if
(
code
)
reject
(
new
Error
(
`next build failed with code
${
code
}
`
))
resolve
()
else
resolve
()
})
})
this
.
_buildId
=
(
...
...
@@ -76,7 +78,7 @@ export class NextStartInstance extends NextInstance {
// child process making it harder to kill all processes
this
.
childProcess
=
spawn
(
'node'
,
[
'node_modules/next/dist/bin/next'
,
'start'
],
[
path
.
join
(
nextDir
,
'/dist/bin/next'
)
,
'start'
],
spawnOpts
)
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