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
ae542b85
Unverified
Commit
ae542b85
authored
Jun 26, 2020
by
Tim Neutkens
Committed by
GitHub
Jun 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use entry option instead of custom make hook (#14527)
Simplifies on-demand-entries a bit.
parent
c6dc34e4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
229 additions
and
443 deletions
+229
-443
webpack-config.ts
packages/next/build/webpack-config.ts
+17
-21
build-manifest-plugin.ts
packages/next/build/webpack/plugins/build-manifest-plugin.ts
+2
-1
unlink-removed-pages-plugin.ts
...next/build/webpack/plugins/unlink-removed-pages-plugin.ts
+0
-36
LICENSE
packages/next/compiled/webpack-dev-middleware/LICENSE
+0
-20
index.js
packages/next/compiled/webpack-dev-middleware/index.js
+0
-1
package.json
packages/next/compiled/webpack-dev-middleware/package.json
+0
-1
package.json
packages/next/package.json
+0
-2
hot-reloader.ts
packages/next/server/hot-reloader.ts
+94
-135
next-dev-server.ts
packages/next/server/next-dev-server.ts
+2
-0
on-demand-entry-handler.ts
packages/next/server/on-demand-entry-handler.ts
+26
-91
taskfile.js
packages/next/taskfile.js
+56
-69
misc.d.ts
packages/next/types/misc.d.ts
+2
-4
middleware.ts
packages/react-dev-overlay/src/middleware.ts
+15
-3
index.test.js
test/integration/ondemand/test/index.test.js
+13
-15
yarn.lock
yarn.lock
+2
-44
No files found.
packages/next/build/webpack-config.ts
View file @
ae542b85
...
...
@@ -694,11 +694,15 @@ export default async function getBaseWebpackConfig(
:
{}),
}
},
watchOptions
:
{
ignored
:
[
'.git/**'
,
'node_modules/**'
,
'.git/**'
],
},
output
:
{
path
:
outputPath
,
// On the server we don't use the chunkhash
filename
:
dev
||
isServer
?
'[name].js'
:
'[name]-[chunkhash].js'
,
libraryTarget
:
isServer
?
'commonjs2'
:
'var'
,
library
:
isServer
?
undefined
:
'_N_E'
,
libraryTarget
:
isServer
?
'commonjs2'
:
'assign'
,
hotUpdateChunkFilename
:
isWebpack5
?
'static/webpack/[id].[fullhash].hot-update.js'
:
'static/webpack/[id].[hash].hot-update.js'
,
...
...
@@ -894,16 +898,9 @@ export default async function getBaseWebpackConfig(
const
{
NextJsRequireCacheHotReloader
,
}
=
require
(
'./webpack/plugins/nextjs-require-cache-hot-reloader'
)
const
{
UnlinkRemovedPagesPlugin
,
}
=
require
(
'./webpack/plugins/unlink-removed-pages-plugin'
)
const
devPlugins
=
[
new
UnlinkRemovedPagesPlugin
(),
new
NextJsRequireCacheHotReloader
(),
]
const
devPlugins
=
[
new
NextJsRequireCacheHotReloader
()]
// Webpack 5 enables HMR automatically in the development mode
if
(
!
isServer
&&
!
isWebpack5
)
{
if
(
!
isServer
)
{
devPlugins
.
push
(
new
webpack
.
HotModuleReplacementPlugin
())
}
...
...
@@ -1038,6 +1035,16 @@ export default async function getBaseWebpackConfig(
}
}
// Backwards compat with webpack-dev-middleware options object
if
(
typeof
config
.
webpackDevMiddleware
===
'function'
)
{
const
options
=
config
.
webpackDevMiddleware
({
watchOptions
:
webpackConfig
.
watchOptions
,
})
if
(
options
.
watchOptions
)
{
webpackConfig
.
watchOptions
=
options
.
watchOptions
}
}
function
canMatchCss
(
rule
:
webpack
.
RuleSetCondition
|
undefined
):
boolean
{
if
(
!
rule
)
{
return
false
...
...
@@ -1262,16 +1269,5 @@ export default async function getBaseWebpackConfig(
webpackConfig
.
entry
=
await
(
webpackConfig
.
entry
as
webpack
.
EntryFunc
)()
}
// In webpack 5, the 'var' libraryTarget output requires a name.
// TODO: this should be revisited as 'var' was only used to not have the
// initial variable exposed. In webpack 4, not setting the library option
// would result in the bundle being a self-executing function without the
// variable.
if
(
isWebpack5
&&
!
isServer
)
{
webpackConfig
.
output
!
.
library
=
webpackConfig
.
output
?.
library
?
webpackConfig
.
output
.
library
:
'INTERNAL_NEXT_APP'
}
return
webpackConfig
}
packages/next/build/webpack/plugins/build-manifest-plugin.ts
View file @
ae542b85
...
...
@@ -41,7 +41,8 @@ function generateClientManifest(
}
function
isJsFile
(
file
:
string
):
boolean
{
return
file
.
endsWith
(
'.js'
)
// We don't want to include `.hot-update.js` files into the initial page
return
!
file
.
endsWith
(
'.hot-update.js'
)
&&
file
.
endsWith
(
'.js'
)
}
// This plugin creates a build-manifest.json for all assets that are being output
...
...
packages/next/build/webpack/plugins/unlink-removed-pages-plugin.ts
deleted
100644 → 0
View file @
c6dc34e4
import
{
join
}
from
'path'
import
{
promises
}
from
'fs'
import
{
Compiler
}
from
'webpack'
import
getRouteFromEntrypoint
from
'../../../next-server/server/get-route-from-entrypoint'
// Makes sure removed pages are removed from `.next` in development
export
class
UnlinkRemovedPagesPlugin
{
prevAssets
:
any
constructor
()
{
this
.
prevAssets
=
{}
}
apply
(
compiler
:
Compiler
)
{
compiler
.
hooks
.
afterEmit
.
tapAsync
(
'NextJsUnlinkRemovedPages'
,
(
compilation
,
callback
)
=>
{
const
removed
=
Object
.
keys
(
this
.
prevAssets
).
filter
(
(
a
)
=>
getRouteFromEntrypoint
(
a
)
&&
!
compilation
.
assets
[
a
]
)
this
.
prevAssets
=
compilation
.
assets
Promise
.
all
(
removed
.
map
(
async
(
f
)
=>
{
const
path
=
join
((
compiler
as
any
).
outputPath
,
f
)
try
{
await
promises
.
unlink
(
path
)
}
catch
(
err
)
{
if
(
err
.
code
===
'ENOENT'
)
return
throw
err
}
})
).
then
(()
=>
callback
(),
callback
)
}
)
}
}
packages/next/compiled/webpack-dev-middleware/LICENSE
deleted
100644 → 0
View file @
c6dc34e4
Copyright JS Foundation and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
packages/next/compiled/webpack-dev-middleware/index.js
deleted
100644 → 0
View file @
c6dc34e4
This diff is collapsed.
Click to expand it.
packages/next/compiled/webpack-dev-middleware/package.json
deleted
100644 → 0
View file @
c6dc34e4
{
"name"
:
"webpack-dev-middleware"
,
"main"
:
"index.js"
,
"author"
:
"Tobias Koppers @sokra"
,
"license"
:
"MIT"
}
packages/next/package.json
View file @
ae542b85
...
...
@@ -151,7 +151,6 @@
"@types/styled-jsx"
:
"2.2.8"
,
"@types/terser-webpack-plugin"
:
"2.2.0"
,
"@types/text-table"
:
"0.2.1"
,
"@types/webpack-dev-middleware"
:
"2.0.3"
,
"@types/webpack-hot-middleware"
:
"2.16.5"
,
"@types/webpack-sources"
:
"0.1.5"
,
"@zeit/ncc"
:
"0.22.0"
,
...
...
@@ -213,7 +212,6 @@
"typescript"
:
"3.8.3"
,
"unfetch"
:
"4.1.0"
,
"unistore"
:
"3.4.1"
,
"webpack-dev-middleware"
:
"3.7.0"
,
"webpack-hot-middleware"
:
"2.25.0"
},
"engines"
:
{
...
...
packages/next/server/hot-reloader.ts
View file @
ae542b85
This diff is collapsed.
Click to expand it.
packages/next/server/next-dev-server.ts
View file @
ae542b85
...
...
@@ -471,6 +471,7 @@ export default class DevServer extends Server {
pathname
:
string
,
query
:
{
[
key
:
string
]:
string
}
):
Promise
<
string
|
null
>
{
await
this
.
devReady
const
compilationErr
=
await
this
.
getCompilationError
(
pathname
)
if
(
compilationErr
)
{
res
.
statusCode
=
500
...
...
@@ -520,6 +521,7 @@ export default class DevServer extends Server {
pathname
:
string
,
query
:
{
[
key
:
string
]:
string
}
):
Promise
<
string
|
null
>
{
await
this
.
devReady
if
(
res
.
statusCode
===
404
&&
(
await
this
.
hasPage
(
'/404'
)))
{
await
this
.
hotReloader
!
.
ensurePage
(
'/404'
)
}
else
{
...
...
packages/next/server/on-demand-entry-handler.ts
View file @
ae542b85
import
{
EventEmitter
}
from
'events'
import
{
IncomingMessage
,
ServerResponse
}
from
'http'
import
WebpackDevMiddleware
from
'next/dist/compiled/webpack-dev-middleware'
import
{
join
,
posix
}
from
'path'
import
{
stringify
}
from
'querystring'
import
{
parse
}
from
'url'
import
webpack
from
'webpack'
import
DynamicEntryPlugin
from
'webpack/lib/DynamicEntryPlugin'
import
{
isWriteable
}
from
'../build/is-writeable'
import
*
as
Log
from
'../build/output/log'
import
{
ClientPagesLoaderOptions
}
from
'../build/webpack/loaders/next-client-pages-loader'
import
{
API_ROUTE
}
from
'../lib/constants'
import
{
normalizePagePath
,
normalizePathSep
,
...
...
@@ -18,28 +12,22 @@ import { pageNotFoundError } from '../next-server/server/require'
import
{
findPageFile
}
from
'./lib/find-page-file'
import
getRouteFromEntrypoint
from
'../next-server/server/get-route-from-entrypoint'
const
ADDED
=
Symbol
(
'added'
)
const
BUILDING
=
Symbol
(
'building'
)
const
BUILT
=
Symbol
(
'built'
)
// Based on https://github.com/webpack/webpack/blob/master/lib/DynamicEntryPlugin.js#L29-L37
function
addEntry
(
compilation
:
webpack
.
compilation
.
Compilation
,
context
:
string
,
name
:
string
,
entry
:
string
[]
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
dep
=
DynamicEntryPlugin
.
createDependency
(
entry
,
name
)
compilation
.
addEntry
(
context
,
dep
,
name
,
(
err
:
Error
)
=>
{
if
(
err
)
return
reject
(
err
)
resolve
()
})
})
}
export
const
ADDED
=
Symbol
(
'added'
)
export
const
BUILDING
=
Symbol
(
'building'
)
export
const
BUILT
=
Symbol
(
'built'
)
export
let
entries
:
{
[
page
:
string
]:
{
serverBundlePath
:
string
clientBundlePath
:
string
absolutePagePath
:
string
status
?:
typeof
ADDED
|
typeof
BUILDING
|
typeof
BUILT
lastActiveTime
?:
number
}
}
=
{}
export
default
function
onDemandEntryHandler
(
devMiddleware
:
WebpackDevMiddleware
.
WebpackDevMiddleware
,
watcher
:
any
,
multiCompiler
:
webpack
.
MultiCompiler
,
{
pagesDir
,
...
...
@@ -54,60 +42,16 @@ export default function onDemandEntryHandler(
}
)
{
const
{
compilers
}
=
multiCompiler
const
invalidator
=
new
Invalidator
(
devMiddleware
,
multiCompiler
)
let
entries
:
{
[
page
:
string
]:
{
serverBundlePath
:
string
clientBundlePath
:
string
absolutePagePath
:
string
status
?:
typeof
ADDED
|
typeof
BUILDING
|
typeof
BUILT
lastActiveTime
?:
number
}
}
=
{}
const
invalidator
=
new
Invalidator
(
watcher
,
multiCompiler
)
let
lastAccessPages
=
[
''
]
let
doneCallbacks
:
EventEmitter
|
null
=
new
EventEmitter
()
for
(
const
compiler
of
compilers
)
{
compiler
.
hooks
.
make
.
tap
Promise
(
compiler
.
hooks
.
make
.
tap
(
'NextJsOnDemandEntries'
,
(
compilation
:
webpack
.
compilation
.
Compilation
)
=>
{
(
_
compilation
:
webpack
.
compilation
.
Compilation
)
=>
{
invalidator
.
startBuilding
()
const
isClientCompilation
=
compiler
.
name
===
'client'
const
allEntries
=
Object
.
keys
(
entries
).
map
(
async
(
page
)
=>
{
if
(
isClientCompilation
&&
page
.
match
(
API_ROUTE
))
{
return
}
const
{
serverBundlePath
,
clientBundlePath
,
absolutePagePath
,
}
=
entries
[
page
]
const
pageExists
=
await
isWriteable
(
absolutePagePath
)
if
(
!
pageExists
)
{
// page was removed
delete
entries
[
page
]
return
}
entries
[
page
].
status
=
BUILDING
const
pageLoaderOpts
:
ClientPagesLoaderOptions
=
{
page
,
absolutePagePath
,
}
return
addEntry
(
compilation
,
compiler
.
context
,
isClientCompilation
?
clientBundlePath
:
serverBundlePath
,
[
isClientCompilation
?
`next-client-pages-loader?
${
stringify
(
pageLoaderOpts
)}
!`
:
absolutePagePath
,
]
)
})
return
Promise
.
all
(
allEntries
).
catch
((
err
)
=>
console
.
error
(
err
))
}
)
}
...
...
@@ -150,12 +94,7 @@ export default function onDemandEntryHandler(
})
const
disposeHandler
=
setInterval
(
function
()
{
disposeInactiveEntries
(
devMiddleware
,
entries
,
lastAccessPages
,
maxInactiveAge
)
disposeInactiveEntries
(
watcher
,
lastAccessPages
,
maxInactiveAge
)
},
5000
)
disposeHandler
.
unref
()
...
...
@@ -297,8 +236,7 @@ export default function onDemandEntryHandler(
}
function
disposeInactiveEntries
(
devMiddleware
:
WebpackDevMiddleware
.
WebpackDevMiddleware
,
entries
:
any
,
watcher
:
any
,
lastAccessPages
:
any
,
maxInactiveAge
:
number
)
{
...
...
@@ -316,7 +254,7 @@ function disposeInactiveEntries(
// In that case, we should not dispose the current viewing page
if
(
lastAccessPages
.
includes
(
page
))
return
if
(
Date
.
now
()
-
lastActiveTime
>
maxInactiveAge
)
{
if
(
lastActiveTime
&&
Date
.
now
()
-
lastActiveTime
>
maxInactiveAge
)
{
disposingPages
.
push
(
page
)
}
})
...
...
@@ -326,7 +264,7 @@ function disposeInactiveEntries(
delete
entries
[
page
]
})
// disposing inactive page(s)
devMiddleware
.
invalidate
()
watcher
.
invalidate
()
}
}
...
...
@@ -334,16 +272,13 @@ function disposeInactiveEntries(
// Otherwise, webpack hash gets changed and it'll force the client to reload.
class
Invalidator
{
private
multiCompiler
:
webpack
.
MultiCompiler
private
devMiddleware
:
WebpackDevMiddleware
.
WebpackDevMiddleware
private
watcher
:
any
private
building
:
boolean
private
rebuildAgain
:
boolean
constructor
(
devMiddleware
:
WebpackDevMiddleware
.
WebpackDevMiddleware
,
multiCompiler
:
webpack
.
MultiCompiler
)
{
constructor
(
watcher
:
any
,
multiCompiler
:
webpack
.
MultiCompiler
)
{
this
.
multiCompiler
=
multiCompiler
this
.
devMiddleware
=
devMiddleware
this
.
watcher
=
watcher
// contains an array of types of compilers currently building
this
.
building
=
false
this
.
rebuildAgain
=
false
...
...
@@ -365,7 +300,7 @@ class Invalidator {
for
(
const
compiler
of
this
.
multiCompiler
.
compilers
)
{
compiler
.
hooks
.
invalid
.
call
()
}
this
.
devMiddleware
.
invalidate
()
this
.
watcher
.
invalidate
()
}
startBuilding
()
{
...
...
packages/next/taskfile.js
View file @
ae542b85
...
...
@@ -43,7 +43,6 @@ const externals = {
// Webpack indirect and direct dependencies:
webpack
:
'webpack'
,
'webpack-sources'
:
'webpack-sources'
,
// dependents: webpack-dev-middleware
'webpack/lib/node/NodeOutputFileSystem'
:
'webpack/lib/node/NodeOutputFileSystem'
,
// dependents: terser-webpack-plugin
...
...
@@ -478,17 +477,7 @@ export async function ncc_unistore(task, opts) {
.
ncc
({
packageName
:
'unistore'
,
externals
})
.
target
(
'compiled/unistore'
)
}
// eslint-disable-next-line camelcase
externals
[
'webpack-dev-middleware'
]
=
'next/dist/compiled/webpack-dev-middleware'
export
async
function
ncc_webpack_dev_middleware
(
task
,
opts
)
{
await
task
.
source
(
opts
.
src
||
relative
(
__dirname
,
require
.
resolve
(
'webpack-dev-middleware'
))
)
.
ncc
({
packageName
:
'webpack-dev-middleware'
,
externals
})
.
target
(
'compiled/webpack-dev-middleware'
)
}
// eslint-disable-next-line camelcase
externals
[
'webpack-hot-middleware'
]
=
'next/dist/compiled/webpack-hot-middleware'
...
...
@@ -537,63 +526,61 @@ export async function copy_ncced(task) {
}
export
async
function
ncc
(
task
)
{
await
task
.
clear
(
'compiled'
)
.
parallel
([
'ncc_amphtml_validator'
,
'ncc_arg'
,
'ncc_async_retry'
,
'ncc_async_sema'
,
'ncc_babel_loader'
,
'ncc_cache_loader'
,
'ncc_chalk'
,
'ncc_ci_info'
,
'ncc_compression'
,
'ncc_conf'
,
'ncc_content_type'
,
'ncc_cookie'
,
'ncc_cssnano_simple'
,
'ncc_debug'
,
'ncc_devalue'
,
'ncc_dotenv'
,
'ncc_dotenv_expand'
,
'ncc_escape_string_regexp'
,
'ncc_etag'
,
'ncc_file_loader'
,
'ncc_find_up'
,
'ncc_fresh'
,
'ncc_gzip_size'
,
'ncc_http_proxy'
,
'ncc_ignore_loader'
,
'ncc_is_docker'
,
'ncc_is_wsl'
,
'ncc_json5'
,
'ncc_jsonwebtoken'
,
'ncc_launch_editor'
,
'ncc_lodash_curry'
,
'ncc_lru_cache'
,
'ncc_nanoid'
,
'ncc_node_fetch'
,
'ncc_ora'
,
'ncc_postcss_flexbugs_fixes'
,
'ncc_postcss_loader'
,
'ncc_postcss_preset_env'
,
'ncc_raw_body'
,
'ncc_recast'
,
'ncc_resolve'
,
'ncc_send'
,
'ncc_source_map'
,
'ncc_string_hash'
,
'ncc_strip_ansi'
,
'ncc_terser'
,
'ncc_text_table'
,
'ncc_thread_loader'
,
'ncc_unistore'
,
'ncc_webpack_dev_middleware'
,
'ncc_webpack_hot_middleware'
,
'ncc_terser_webpack_plugin'
,
'ncc_comment_json'
,
])
await
task
.
clear
(
'compiled'
).
parallel
([
'ncc_amphtml_validator'
,
'ncc_arg'
,
'ncc_async_retry'
,
'ncc_async_sema'
,
'ncc_babel_loader'
,
'ncc_cache_loader'
,
'ncc_chalk'
,
'ncc_ci_info'
,
'ncc_compression'
,
'ncc_conf'
,
'ncc_content_type'
,
'ncc_cookie'
,
'ncc_cssnano_simple'
,
'ncc_debug'
,
'ncc_devalue'
,
'ncc_dotenv'
,
'ncc_dotenv_expand'
,
'ncc_escape_string_regexp'
,
'ncc_etag'
,
'ncc_file_loader'
,
'ncc_find_up'
,
'ncc_fresh'
,
'ncc_gzip_size'
,
'ncc_http_proxy'
,
'ncc_ignore_loader'
,
'ncc_is_docker'
,
'ncc_is_wsl'
,
'ncc_json5'
,
'ncc_jsonwebtoken'
,
'ncc_launch_editor'
,
'ncc_lodash_curry'
,
'ncc_lru_cache'
,
'ncc_nanoid'
,
'ncc_node_fetch'
,
'ncc_ora'
,
'ncc_postcss_flexbugs_fixes'
,
'ncc_postcss_loader'
,
'ncc_postcss_preset_env'
,
'ncc_raw_body'
,
'ncc_recast'
,
'ncc_resolve'
,
'ncc_send'
,
'ncc_source_map'
,
'ncc_string_hash'
,
'ncc_strip_ansi'
,
'ncc_terser'
,
'ncc_text_table'
,
'ncc_thread_loader'
,
'ncc_unistore'
,
// 'ncc_webpack_dev_middleware',
'ncc_webpack_hot_middleware'
,
'ncc_terser_webpack_plugin'
,
'ncc_comment_json'
,
])
}
export
async
function
compile
(
task
)
{
...
...
packages/next/types/misc.d.ts
View file @
ae542b85
...
...
@@ -210,10 +210,7 @@ declare module 'next/dist/compiled/unistore' {
import
m
from
'unistore'
export
=
m
}
declare
module
'next/dist/compiled/webpack-dev-middleware'
{
import
m
from
'webpack-dev-middleware'
export
=
m
}
declare
module
'next/dist/compiled/webpack-hot-middleware'
{
import
m
from
'webpack-hot-middleware'
export
=
m
...
...
@@ -248,6 +245,7 @@ declare module 'watchpack' {
import
{
EventEmitter
}
from
'events'
class
Watchpack
extends
EventEmitter
{
constructor
(
options
?:
any
)
watch
(
files
:
string
[],
directories
:
string
[],
startTime
?:
number
):
void
close
():
void
...
...
packages/react-dev-overlay/src/middleware.ts
View file @
ae542b85
...
...
@@ -27,6 +27,20 @@ export type OriginalStackFrameResponse = {
type
Source
=
{
map
:
()
=>
RawSourceMap
}
|
null
function
getSourcePath
(
source
:
string
)
{
// Webpack prefixes certain source paths with this path
if
(
source
.
startsWith
(
'webpack:///'
))
{
return
source
.
substring
(
11
)
}
// Make sure library name is filtered out as well
if
(
source
.
startsWith
(
'webpack://_N_E/'
))
{
return
source
.
substring
(
15
)
}
return
source
}
function
getOverlayMiddleware
(
options
:
OverlayMiddlewareOptions
)
{
async
function
getSourceById
(
isServerSide
:
boolean
,
...
...
@@ -162,9 +176,7 @@ function getOverlayMiddleware(options: OverlayMiddlewareOptions) {
const
filePath
=
path
.
resolve
(
options
.
rootDirectory
,
pos
.
source
.
startsWith
(
'webpack:///'
)
?
pos
.
source
.
substring
(
11
)
:
pos
.
source
getSourcePath
(
pos
.
source
)
)
const
originalFrame
:
StackFrame
=
{
...
...
test/integration/ondemand/test/index.test.js
View file @
ae542b85
/* eslint-env jest */
import
webdriver
from
'next-webdriver'
import
{
join
,
resolve
}
from
'path'
import
{
existsSync
}
from
'fs'
import
{
join
}
from
'path'
import
AbortController
from
'abort-controller'
import
{
renderViaHTTP
,
...
...
@@ -14,6 +13,7 @@ import {
check
,
getBrowserBodyText
,
getPageFileFromBuildManifest
,
getBuildManifest
,
}
from
'next-test-utils'
const
appDir
=
join
(
__dirname
,
'../'
)
...
...
@@ -72,30 +72,28 @@ describe('On Demand Entries', () => {
it
(
'should dispose inactive pages'
,
async
()
=>
{
await
renderViaHTTP
(
context
.
appPort
,
'/'
)
await
doPing
(
'/'
)
const
indexPage
=
getPageFileFromBuildManifest
(
appDir
,
'/'
)
const
indexPagePath
=
resolve
(
__dirname
,
join
(
'../.next'
,
indexPage
))
expect
(
existsSync
(
indexPagePath
)).
toBeTruthy
()
// Render two pages after the index, since the server keeps at least two pages
await
renderViaHTTP
(
context
.
appPort
,
'/about'
)
await
doPing
(
'/about'
)
const
aboutPage
=
getPageFileFromBuildManifest
(
appDir
,
'/about'
)
const
aboutPagePath
=
resolve
(
__dirname
,
join
(
'../.next'
,
aboutPage
))
await
renderViaHTTP
(
context
.
appPort
,
'/third'
)
await
doPing
(
'/third'
)
const
thirdPage
=
getPageFileFromBuildManifest
(
appDir
,
'/third'
)
const
thirdPagePath
=
resolve
(
__dirname
,
join
(
'../.next'
,
thirdPage
))
// Wait maximum of jest.setTimeout checking
// for disposing /about
while
(
true
)
{
for
(
let
i
=
0
;
i
<
30
;
++
i
)
{
await
waitFor
(
1000
*
1
)
// Assert that the two lastly demanded page are not disposed
expect
(
existsSync
(
aboutPagePath
)).
toBeTruthy
()
expect
(
existsSync
(
thirdPagePath
)).
toBeTruthy
()
if
(
!
existsSync
(
indexPagePath
))
return
try
{
const
buildManifest
=
getBuildManifest
(
appDir
)
// Assert that the two lastly demanded page are not disposed
expect
(
buildManifest
.
pages
[
'/'
]).
toBeUndefined
()
expect
(
buildManifest
.
pages
[
'/about'
]).
toBeDefined
()
expect
(
buildManifest
.
pages
[
'/third'
]).
toBeDefined
()
return
}
catch
(
err
)
{
continue
}
}
})
...
...
yarn.lock
View file @
ae542b85
...
...
@@ -2770,12 +2770,6 @@
version "5.1.0"
resolved "https://registry.yarnpkg.com/@types/lru-cache/-/lru-cache-5.1.0.tgz#57f228f2b80c046b4a1bd5cac031f81f207f4f03"
"@types/memory-fs@*":
version "0.3.2"
resolved "https://registry.yarnpkg.com/@types/memory-fs/-/memory-fs-0.3.2.tgz#5d4753f9b390cb077c8c8af97bc96463399ceccd"
dependencies:
"@types/node" "*"
"@types/mime@*":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-2.0.1.tgz#dc488842312a7f075149312905b5e3c0b054c79d"
...
...
@@ -2980,15 +2974,6 @@
"@types/unist" "*"
"@types/vfile-message" "*"
"@types/webpack-dev-middleware@2.0.3":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@types/webpack-dev-middleware/-/webpack-dev-middleware-2.0.3.tgz#aefb145281b3326a052325d583d2339debbf1be3"
dependencies:
"@types/connect" "*"
"@types/memory-fs" "*"
"@types/webpack" "*"
loglevel "^1.6.2"
"@types/webpack-hot-middleware@2.16.5":
version "2.16.5"
resolved "https://registry.yarnpkg.com/@types/webpack-hot-middleware/-/webpack-hot-middleware-2.16.5.tgz#5271eada42f34670a7ae79ddb6f1c419a19c985f"
...
...
@@ -3430,10 +3415,6 @@ anser@1.4.9:
version "1.4.9"
resolved "https://registry.yarnpkg.com/anser/-/anser-1.4.9.tgz#1f85423a5dcf8da4631a341665ff675b96845760"
ansi-colors@^3.0.0:
version "3.2.4"
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-3.2.4.tgz#e3a3da4bfbae6c86a9c285625de124a234026fbf"
ansi-escapes@^3.0.0, ansi-escapes@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.2.0.tgz#8780b98ff9dbf5638152d1f1fe5c1d7b4442976b"
...
...
@@ -10006,10 +9987,6 @@ log-update@^2.3.0:
cli-cursor "^2.0.0"
wrap-ansi "^3.0.1"
loglevel@^1.6.2:
version "1.6.6"
resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.6.6.tgz#0ee6300cc058db6b3551fa1c4bf73b83bb771312"
lolex@1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/lolex/-/lolex-1.3.2.tgz#7c3da62ffcb30f0f5a80a2566ca24e45d8a01f31"
...
...
@@ -10442,10 +10419,6 @@ mime@1.6.0, mime@^1.4.1:
version "1.6.0"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"
mime@^2.4.2:
version "2.4.4"
resolved "https://registry.yarnpkg.com/mime/-/mime-2.4.4.tgz#bd7b91135fc6b01cde3e9bae33d659b63d8857e5"
mimic-fn@^1.0.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
...
...
@@ -13071,7 +13044,7 @@ randomfill@^1.0.3:
randombytes "^2.0.5"
safe-buffer "^5.1.0"
range-parser@
^1.2.1, range-parser@
~1.2.1:
range-parser@~1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031"
...
...
@@ -15982,15 +15955,6 @@ webpack-bundle-analyzer@3.6.1:
opener "^1.5.1"
ws "^6.0.0"
webpack-dev-middleware@3.7.0:
version "3.7.0"
resolved "https://registry.yarnpkg.com/webpack-dev-middleware/-/webpack-dev-middleware-3.7.0.tgz#ef751d25f4e9a5c8a35da600c5fda3582b5c6cff"
dependencies:
memory-fs "^0.4.1"
mime "^2.4.2"
range-parser "^1.2.1"
webpack-log "^2.0.0"
webpack-hot-middleware@2.25.0:
version "2.25.0"
resolved "https://registry.yarnpkg.com/webpack-hot-middleware/-/webpack-hot-middleware-2.25.0.tgz#4528a0a63ec37f8f8ef565cf9e534d57d09fe706"
...
...
@@ -16000,13 +15964,6 @@ webpack-hot-middleware@2.25.0:
querystring "^0.2.0"
strip-ansi "^3.0.0"
webpack-log@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/webpack-log/-/webpack-log-2.0.0.tgz#5b7928e0637593f119d32f6227c1e0ac31e1b47f"
dependencies:
ansi-colors "^3.0.0"
uuid "^3.3.2"
webpack-sources@1.4.3, webpack-sources@^1.1.0, webpack-sources@^1.4.0, webpack-sources@^1.4.1, webpack-sources@^1.4.3:
version "1.4.3"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.4.3.tgz#eedd8ec0b928fbf1cbfe994e22d2d890f330a933"
...
...
@@ -16017,6 +15974,7 @@ webpack-sources@1.4.3, webpack-sources@^1.1.0, webpack-sources@^1.4.0, webpack-s
webpack@4.43.0, webpack@^4.42.1:
version "4.43.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.43.0.tgz#c48547b11d563224c561dad1172c8aa0b8a678e6"
integrity sha512-GW1LjnPipFW2Y78OOab8NJlCflB7EFskMih2AHdvjbpKMeDJqEgSx24cXXXiPS65+WSwVyxtDsJH6jGX2czy+g==
dependencies:
"@webassemblyjs/ast" "1.9.0"
"@webassemblyjs/helper-module-context" "1.9.0"
...
...
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