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
5f2e44d4
Unverified
Commit
5f2e44d4
authored
Oct 04, 2022
by
Jiachi Liu
Committed by
GitHub
Oct 04, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor app dir related flags (#41166)
simplify the `appDir` passing down
parent
d2efbc88
Hide whitespace changes
Inline
Side-by-side
Showing
29 changed files
with
132 additions
and
93 deletions
+132
-93
preset.js
packages/next-plugin-storybook/preset.js
+1
-1
entries.ts
packages/next/build/entries.ts
+4
-4
index.ts
packages/next/build/index.ts
+4
-6
jest.ts
packages/next/build/jest/jest.ts
+6
-1
jest-transformer.js
packages/next/build/swc/jest-transformer.js
+1
-0
options.js
packages/next/build/swc/options.js
+6
-1
webpack-config.ts
packages/next/build/webpack-config.ts
+18
-15
index.ts
packages/next/build/webpack/config/blocks/css/index.ts
+6
-6
client.ts
...es/next/build/webpack/config/blocks/css/loaders/client.ts
+3
-3
font-loader.ts
...xt/build/webpack/config/blocks/css/loaders/font-loader.ts
+1
-1
global.ts
...es/next/build/webpack/config/blocks/css/loaders/global.ts
+1
-1
modules.ts
...s/next/build/webpack/config/blocks/css/loaders/modules.ts
+1
-1
index.ts
packages/next/build/webpack/config/index.ts
+6
-2
utils.ts
packages/next/build/webpack/config/utils.ts
+1
-0
index.ts
.../next/build/webpack/loaders/next-edge-ssr-loader/index.ts
+1
-1
render.ts
...next/build/webpack/loaders/next-edge-ssr-loader/render.ts
+2
-1
next-swc-loader.js
packages/next/build/webpack/loaders/next-swc-loader.js
+2
-0
middleware-plugin.ts
packages/next/build/webpack/plugins/middleware-plugin.ts
+1
-1
next-lint.ts
packages/next/cli/next-lint.ts
+2
-2
index.ts
packages/next/export/index.ts
+4
-3
runLintCheck.ts
packages/next/lib/eslint/runLintCheck.ts
+2
-3
find-pages-dir.ts
packages/next/lib/find-pages-dir.ts
+16
-10
verifyAndLint.ts
packages/next/lib/verifyAndLint.ts
+10
-6
base-server.ts
packages/next/server/base-server.ts
+5
-2
config-schema.ts
packages/next/server/config-schema.ts
+0
-3
hot-reloader.ts
packages/next/server/dev/hot-reloader.ts
+8
-7
next-dev-server.ts
packages/next/server/dev/next-dev-server.ts
+3
-6
next-server.ts
packages/next/server/next-server.ts
+13
-6
web-server.ts
packages/next/server/web-server.ts
+4
-0
No files found.
packages/next-plugin-storybook/preset.js
View file @
5f2e44d4
...
@@ -6,8 +6,8 @@ const getWebpackConfig = require('next/dist/build/webpack-config').default
...
@@ -6,8 +6,8 @@ const getWebpackConfig = require('next/dist/build/webpack-config').default
const
CWD
=
process
.
cwd
()
const
CWD
=
process
.
cwd
()
async
function
webpackFinal
(
config
)
{
async
function
webpackFinal
(
config
)
{
const
pagesDir
=
findPagesDir
(
CWD
)
const
nextConfig
=
await
loadConfig
(
PHASE_PRODUCTION_BUILD
,
CWD
)
const
nextConfig
=
await
loadConfig
(
PHASE_PRODUCTION_BUILD
,
CWD
)
const
pagesDir
=
findPagesDir
(
CWD
,
!!
nextConfig
.
experimental
.
appDir
)
const
nextWebpackConfig
=
await
getWebpackConfig
(
CWD
,
{
const
nextWebpackConfig
=
await
getWebpackConfig
(
CWD
,
{
pagesDir
,
pagesDir
,
entrypoints
:
{},
entrypoints
:
{},
...
...
packages/next/build/entries.ts
View file @
5f2e44d4
...
@@ -164,7 +164,7 @@ export function getEdgeServerEntry(opts: {
...
@@ -164,7 +164,7 @@ export function getEdgeServerEntry(opts: {
page
:
string
page
:
string
pages
:
{
[
page
:
string
]:
string
}
pages
:
{
[
page
:
string
]:
string
}
middleware
?:
Partial
<
MiddlewareConfig
>
middleware
?:
Partial
<
MiddlewareConfig
>
pagesType
?
:
'app'
|
'pages'
|
'root'
pagesType
:
'app'
|
'pages'
|
'root'
appDirLoader
?:
string
appDirLoader
?:
string
})
{
})
{
if
(
isMiddlewareFile
(
opts
.
page
))
{
if
(
isMiddlewareFile
(
opts
.
page
))
{
...
@@ -526,13 +526,13 @@ export function finalizeEntrypoint({
...
@@ -526,13 +526,13 @@ export function finalizeEntrypoint({
compilerType
,
compilerType
,
value
,
value
,
isServerComponent
,
isServerComponent
,
a
ppDir
,
hasA
ppDir
,
}:
{
}:
{
compilerType
?:
CompilerNameValues
compilerType
?:
CompilerNameValues
name
:
string
name
:
string
value
:
ObjectValue
<
webpack
.
EntryObject
>
value
:
ObjectValue
<
webpack
.
EntryObject
>
isServerComponent
?:
boolean
isServerComponent
?:
boolean
a
ppDir
?:
boolean
hasA
ppDir
?:
boolean
}):
ObjectValue
<
webpack
.
EntryObject
>
{
}):
ObjectValue
<
webpack
.
EntryObject
>
{
const
entry
=
const
entry
=
typeof
value
!==
'object'
||
Array
.
isArray
(
value
)
typeof
value
!==
'object'
||
Array
.
isArray
(
value
)
...
@@ -575,7 +575,7 @@ export function finalizeEntrypoint({
...
@@ -575,7 +575,7 @@ export function finalizeEntrypoint({
name
!==
CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH
name
!==
CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH
)
{
)
{
// TODO-APP: this is a temporary fix. @shuding is going to change the handling of server components
// TODO-APP: this is a temporary fix. @shuding is going to change the handling of server components
if
(
a
ppDir
&&
entry
.
import
.
includes
(
'flight'
))
{
if
(
hasA
ppDir
&&
entry
.
import
.
includes
(
'flight'
))
{
return
{
return
{
dependOn
:
CLIENT_STATIC_FILES_RUNTIME_MAIN_APP
,
dependOn
:
CLIENT_STATIC_FILES_RUNTIME_MAIN_APP
,
...
entry
,
...
entry
,
...
...
packages/next/build/index.ts
View file @
5f2e44d4
...
@@ -301,10 +301,8 @@ export default async function build(
...
@@ -301,10 +301,8 @@ export default async function build(
setGlobal
(
'telemetry'
,
telemetry
)
setGlobal
(
'telemetry'
,
telemetry
)
const
publicDir
=
path
.
join
(
dir
,
'public'
)
const
publicDir
=
path
.
join
(
dir
,
'public'
)
const
{
pages
:
pagesDir
,
appDir
}
=
findPagesDir
(
const
hasAppDir
=
!!
config
.
experimental
.
appDir
dir
,
const
{
pagesDir
,
appDir
}
=
findPagesDir
(
dir
,
hasAppDir
)
config
.
experimental
.
appDir
)
const
hasPublicDir
=
await
fileExists
(
publicDir
)
const
hasPublicDir
=
await
fileExists
(
publicDir
)
...
@@ -396,7 +394,7 @@ export default async function build(
...
@@ -396,7 +394,7 @@ export default async function build(
config
.
experimental
.
cpus
,
config
.
experimental
.
cpus
,
config
.
experimental
.
workerThreads
,
config
.
experimental
.
workerThreads
,
telemetry
,
telemetry
,
!!
config
.
experimental
.
a
ppDir
hasA
ppDir
)
)
}),
}),
])
])
...
@@ -1990,7 +1988,7 @@ export default async function build(
...
@@ -1990,7 +1988,7 @@ export default async function build(
combinedPages
.
length
>
0
||
combinedPages
.
length
>
0
||
useStatic404
||
useStatic404
||
useDefaultStatic500
||
useDefaultStatic500
||
config
.
experimental
.
a
ppDir
hasA
ppDir
)
{
)
{
const
staticGenerationSpan
=
const
staticGenerationSpan
=
nextBuildSpan
.
traceChild
(
'static-generation'
)
nextBuildSpan
.
traceChild
(
'static-generation'
)
...
...
packages/next/build/jest/jest.ts
View file @
5f2e44d4
...
@@ -64,14 +64,18 @@ export default function nextJest(options: { dir?: string } = {}) {
...
@@ -64,14 +64,18 @@ export default function nextJest(options: { dir?: string } = {}) {
let
resolvedBaseUrl
let
resolvedBaseUrl
let
isEsmProject
=
false
let
isEsmProject
=
false
let
pagesDir
:
string
|
undefined
let
pagesDir
:
string
|
undefined
let
hasServerComponents
:
boolean
|
undefined
if
(
options
.
dir
)
{
if
(
options
.
dir
)
{
const
resolvedDir
=
resolve
(
options
.
dir
)
const
resolvedDir
=
resolve
(
options
.
dir
)
pagesDir
=
findPagesDir
(
resolvedDir
).
pages
const
packageConfig
=
loadClosestPackageJson
(
resolvedDir
)
const
packageConfig
=
loadClosestPackageJson
(
resolvedDir
)
isEsmProject
=
packageConfig
.
type
===
'module'
isEsmProject
=
packageConfig
.
type
===
'module'
nextConfig
=
await
getConfig
(
resolvedDir
)
nextConfig
=
await
getConfig
(
resolvedDir
)
const
hasAppDir
=
!!
nextConfig
.
experimental
.
appDir
const
findPagesDirResult
=
findPagesDir
(
resolvedDir
,
hasAppDir
)
hasServerComponents
=
!!
findPagesDirResult
.
appDir
pagesDir
=
findPagesDirResult
.
pagesDir
setUpEnv
(
resolvedDir
,
nextConfig
)
setUpEnv
(
resolvedDir
,
nextConfig
)
// TODO: revisit when bug in SWC is fixed that strips `.css`
// TODO: revisit when bug in SWC is fixed that strips `.css`
const
result
=
await
loadJsConfig
(
resolvedDir
,
nextConfig
)
const
result
=
await
loadJsConfig
(
resolvedDir
,
nextConfig
)
...
@@ -134,6 +138,7 @@ export default function nextJest(options: { dir?: string } = {}) {
...
@@ -134,6 +138,7 @@ export default function nextJest(options: { dir?: string } = {}) {
nextConfig
,
nextConfig
,
jsConfig
,
jsConfig
,
resolvedBaseUrl
,
resolvedBaseUrl
,
hasServerComponents
,
isEsmProject
,
isEsmProject
,
pagesDir
,
pagesDir
,
},
},
...
...
packages/next/build/swc/jest-transformer.js
View file @
5f2e44d4
...
@@ -48,6 +48,7 @@ module.exports = {
...
@@ -48,6 +48,7 @@ module.exports = {
jsConfig
:
inputOptions
.
jsConfig
,
jsConfig
:
inputOptions
.
jsConfig
,
resolvedBaseUrl
:
inputOptions
.
resolvedBaseUrl
,
resolvedBaseUrl
:
inputOptions
.
resolvedBaseUrl
,
pagesDir
:
inputOptions
.
pagesDir
,
pagesDir
:
inputOptions
.
pagesDir
,
hasServerComponents
:
inputOptions
.
hasServerComponents
,
esm
:
esm
:
isSupportEsm
&&
isSupportEsm
&&
isEsm
(
Boolean
(
inputOptions
.
isEsmProject
),
filename
,
jestConfig
),
isEsm
(
Boolean
(
inputOptions
.
isEsmProject
),
filename
,
jestConfig
),
...
...
packages/next/build/swc/options.js
View file @
5f2e44d4
...
@@ -34,6 +34,7 @@ function getBaseSWCOptions({
...
@@ -34,6 +34,7 @@ function getBaseSWCOptions({
swcCacheDir
,
swcCacheDir
,
isServerLayer
,
isServerLayer
,
relativeFilePathFromRoot
,
relativeFilePathFromRoot
,
hasServerComponents
,
})
{
})
{
const
parserConfig
=
getParserOptions
({
filename
,
jsConfig
})
const
parserConfig
=
getParserOptions
({
filename
,
jsConfig
})
const
paths
=
jsConfig
?.
compilerOptions
?.
paths
const
paths
=
jsConfig
?.
compilerOptions
?.
paths
...
@@ -119,7 +120,7 @@ function getBaseSWCOptions({
...
@@ -119,7 +120,7 @@ function getBaseSWCOptions({
modularizeImports
:
nextConfig
?.
experimental
?.
modularizeImports
,
modularizeImports
:
nextConfig
?.
experimental
?.
modularizeImports
,
relay
:
nextConfig
?.
compiler
?.
relay
,
relay
:
nextConfig
?.
compiler
?.
relay
,
emotion
:
getEmotionOptions
(
nextConfig
,
development
),
emotion
:
getEmotionOptions
(
nextConfig
,
development
),
serverComponents
:
nextConfig
?.
experimental
?.
appDir
serverComponents
:
hasServerComponents
?
{
?
{
isServer
:
!!
isServerLayer
,
isServer
:
!!
isServerLayer
,
}
}
...
@@ -180,6 +181,7 @@ export function getJestSWCOptions({
...
@@ -180,6 +181,7 @@ export function getJestSWCOptions({
nextConfig
,
nextConfig
,
jsConfig
,
jsConfig
,
pagesDir
,
pagesDir
,
hasServerComponents
,
// This is not passed yet as "paths" resolving needs a test first
// This is not passed yet as "paths" resolving needs a test first
// resolvedBaseUrl,
// resolvedBaseUrl,
})
{
})
{
...
@@ -191,6 +193,7 @@ export function getJestSWCOptions({
...
@@ -191,6 +193,7 @@ export function getJestSWCOptions({
globalWindow
:
!
isServer
,
globalWindow
:
!
isServer
,
nextConfig
,
nextConfig
,
jsConfig
,
jsConfig
,
hasServerComponents
,
// resolvedBaseUrl,
// resolvedBaseUrl,
})
})
...
@@ -226,6 +229,7 @@ export function getLoaderSWCOptions({
...
@@ -226,6 +229,7 @@ export function getLoaderSWCOptions({
supportedBrowsers
,
supportedBrowsers
,
swcCacheDir
,
swcCacheDir
,
relativeFilePathFromRoot
,
relativeFilePathFromRoot
,
hasServerComponents
,
// This is not passed yet as "paths" resolving is handled by webpack currently.
// This is not passed yet as "paths" resolving is handled by webpack currently.
// resolvedBaseUrl,
// resolvedBaseUrl,
})
{
})
{
...
@@ -240,6 +244,7 @@ export function getLoaderSWCOptions({
...
@@ -240,6 +244,7 @@ export function getLoaderSWCOptions({
swcCacheDir
,
swcCacheDir
,
isServerLayer
,
isServerLayer
,
relativeFilePathFromRoot
,
relativeFilePathFromRoot
,
hasServerComponents
,
})
})
const
isNextDist
=
nextDistPath
.
test
(
filename
)
const
isNextDist
=
nextDistPath
.
test
(
filename
)
...
...
packages/next/build/webpack-config.ts
View file @
5f2e44d4
...
@@ -33,9 +33,9 @@ import { execOnce } from '../shared/lib/utils'
...
@@ -33,9 +33,9 @@ import { execOnce } from '../shared/lib/utils'
import
{
NextConfigComplete
}
from
'../server/config-shared'
import
{
NextConfigComplete
}
from
'../server/config-shared'
import
{
finalizeEntrypoint
}
from
'./entries'
import
{
finalizeEntrypoint
}
from
'./entries'
import
*
as
Log
from
'./output/log'
import
*
as
Log
from
'./output/log'
import
{
build
as
build
Configuration
}
from
'./webpack/config'
import
{
buildConfiguration
}
from
'./webpack/config'
import
MiddlewarePlugin
,
{
import
MiddlewarePlugin
,
{
handleWebpackExtenalForEdgeRuntime
,
handleWebpackExte
r
nalForEdgeRuntime
,
}
from
'./webpack/plugins/middleware-plugin'
}
from
'./webpack/plugins/middleware-plugin'
import
BuildManifestPlugin
from
'./webpack/plugins/build-manifest-plugin'
import
BuildManifestPlugin
from
'./webpack/plugins/build-manifest-plugin'
import
{
JsConfigPathsPlugin
}
from
'./webpack/plugins/jsconfig-paths-plugin'
import
{
JsConfigPathsPlugin
}
from
'./webpack/plugins/jsconfig-paths-plugin'
...
@@ -563,6 +563,10 @@ export default async function getBaseWebpackConfig(
...
@@ -563,6 +563,10 @@ export default async function getBaseWebpackConfig(
rewrites
.
afterFiles
.
length
>
0
||
rewrites
.
afterFiles
.
length
>
0
||
rewrites
.
fallback
.
length
>
0
rewrites
.
fallback
.
length
>
0
const
hasAppDir
=
!!
config
.
experimental
.
appDir
const
hasConcurrentFeatures
=
hasReactRoot
const
hasServerComponents
=
hasAppDir
// Only error in first one compiler (client) once
// Only error in first one compiler (client) once
if
(
isClient
)
{
if
(
isClient
)
{
if
(
!
hasReactRoot
)
{
if
(
!
hasReactRoot
)
{
...
@@ -571,7 +575,7 @@ export default async function getBaseWebpackConfig(
...
@@ -571,7 +575,7 @@ export default async function getBaseWebpackConfig(
'`experimental.runtime` requires React 18 to be installed.'
'`experimental.runtime` requires React 18 to be installed.'
)
)
}
}
if
(
config
.
experimental
.
a
ppDir
)
{
if
(
hasA
ppDir
)
{
throw
new
Error
(
throw
new
Error
(
'`experimental.appDir` requires React 18 to be installed.'
'`experimental.appDir` requires React 18 to be installed.'
)
)
...
@@ -579,8 +583,6 @@ export default async function getBaseWebpackConfig(
...
@@ -579,8 +583,6 @@ export default async function getBaseWebpackConfig(
}
}
}
}
const
hasConcurrentFeatures
=
hasReactRoot
const
hasServerComponents
=
!!
config
.
experimental
.
appDir
const
disableOptimizedLoading
=
hasConcurrentFeatures
const
disableOptimizedLoading
=
hasConcurrentFeatures
?
true
?
true
:
config
.
experimental
.
disableOptimizedLoading
:
config
.
experimental
.
disableOptimizedLoading
...
@@ -654,6 +656,7 @@ export default async function getBaseWebpackConfig(
...
@@ -654,6 +656,7 @@ export default async function getBaseWebpackConfig(
pagesDir
,
pagesDir
,
cwd
:
dir
,
cwd
:
dir
,
development
:
dev
,
development
:
dev
,
hasServerComponents
,
hasReactRefresh
:
dev
&&
isClient
,
hasReactRefresh
:
dev
&&
isClient
,
hasJsxRuntime
:
true
,
hasJsxRuntime
:
true
,
},
},
...
@@ -682,6 +685,7 @@ export default async function getBaseWebpackConfig(
...
@@ -682,6 +685,7 @@ export default async function getBaseWebpackConfig(
isServer
:
isNodeServer
||
isEdgeServer
,
isServer
:
isNodeServer
||
isEdgeServer
,
rootDir
:
dir
,
rootDir
:
dir
,
pagesDir
,
pagesDir
,
hasServerComponents
,
hasReactRefresh
:
dev
&&
isClient
,
hasReactRefresh
:
dev
&&
isClient
,
fileReading
:
config
.
experimental
.
swcFileReading
,
fileReading
:
config
.
experimental
.
swcFileReading
,
nextConfig
:
config
,
nextConfig
:
config
,
...
@@ -745,7 +749,7 @@ export default async function getBaseWebpackConfig(
...
@@ -745,7 +749,7 @@ export default async function getBaseWebpackConfig(
)
)
)
)
.
replace
(
/
\\
/g
,
'/'
),
.
replace
(
/
\\
/g
,
'/'
),
...(
config
.
experimental
.
a
ppDir
...(
hasA
ppDir
?
{
?
{
[
CLIENT_STATIC_FILES_RUNTIME_MAIN_APP
]:
dev
[
CLIENT_STATIC_FILES_RUNTIME_MAIN_APP
]:
dev
?
[
?
[
...
@@ -1215,7 +1219,7 @@ export default async function getBaseWebpackConfig(
...
@@ -1215,7 +1219,7 @@ export default async function getBaseWebpackConfig(
'{}'
,
'{}'
,
'react-dom'
:
'{}'
,
'react-dom'
:
'{}'
,
},
},
handleWebpackExtenalForEdgeRuntime
,
handleWebpackExte
r
nalForEdgeRuntime
,
]
]
:
[]),
:
[]),
]
]
...
@@ -1520,7 +1524,7 @@ export default async function getBaseWebpackConfig(
...
@@ -1520,7 +1524,7 @@ export default async function getBaseWebpackConfig(
},
},
module
:
{
module
:
{
rules
:
[
rules
:
[
...(
config
.
experimental
.
a
ppDir
&&
!
isClient
&&
!
isEdgeServer
...(
hasA
ppDir
&&
!
isClient
&&
!
isEdgeServer
?
[
?
[
{
{
issuerLayer
:
WEBPACK_LAYERS
.
server
,
issuerLayer
:
WEBPACK_LAYERS
.
server
,
...
@@ -1827,7 +1831,7 @@ export default async function getBaseWebpackConfig(
...
@@ -1827,7 +1831,7 @@ export default async function getBaseWebpackConfig(
appDir
:
dir
,
appDir
:
dir
,
esmExternals
:
config
.
experimental
.
esmExternals
,
esmExternals
:
config
.
experimental
.
esmExternals
,
outputFileTracingRoot
:
config
.
experimental
.
outputFileTracingRoot
,
outputFileTracingRoot
:
config
.
experimental
.
outputFileTracingRoot
,
appDirEnabled
:
!!
config
.
experimental
.
a
ppDir
,
appDirEnabled
:
hasA
ppDir
,
}
}
),
),
// Moment.js is an extremely popular library that bundles large locale files
// Moment.js is an extremely popular library that bundles large locale files
...
@@ -1872,7 +1876,7 @@ export default async function getBaseWebpackConfig(
...
@@ -1872,7 +1876,7 @@ export default async function getBaseWebpackConfig(
serverless
:
isLikeServerless
,
serverless
:
isLikeServerless
,
dev
,
dev
,
isEdgeRuntime
:
isEdgeServer
,
isEdgeRuntime
:
isEdgeServer
,
appDirEnabled
:
!!
config
.
experimental
.
a
ppDir
,
appDirEnabled
:
hasA
ppDir
,
}),
}),
// MiddlewarePlugin should be after DefinePlugin so NEXT_PUBLIC_*
// MiddlewarePlugin should be after DefinePlugin so NEXT_PUBLIC_*
// replacement is done before its process.env.* handling
// replacement is done before its process.env.* handling
...
@@ -1888,7 +1892,7 @@ export default async function getBaseWebpackConfig(
...
@@ -1888,7 +1892,7 @@ export default async function getBaseWebpackConfig(
rewrites
,
rewrites
,
isDevFallback
,
isDevFallback
,
exportRuntime
:
hasConcurrentFeatures
,
exportRuntime
:
hasConcurrentFeatures
,
appDirEnabled
:
!!
config
.
experimental
.
a
ppDir
,
appDirEnabled
:
hasA
ppDir
,
}),
}),
new
ProfilingPlugin
({
runWebpackSpan
}),
new
ProfilingPlugin
({
runWebpackSpan
}),
config
.
optimizeFonts
&&
config
.
optimizeFonts
&&
...
@@ -1919,9 +1923,7 @@ export default async function getBaseWebpackConfig(
...
@@ -1919,9 +1923,7 @@ export default async function getBaseWebpackConfig(
minimized
:
true
,
minimized
:
true
,
},
},
}),
}),
!!
config
.
experimental
.
appDir
&&
hasAppDir
&&
isClient
&&
new
AppBuildManifestPlugin
({
dev
}),
isClient
&&
new
AppBuildManifestPlugin
({
dev
}),
hasServerComponents
&&
hasServerComponents
&&
(
isClient
(
isClient
?
new
FlightManifestPlugin
({
?
new
FlightManifestPlugin
({
...
@@ -2200,6 +2202,7 @@ export default async function getBaseWebpackConfig(
...
@@ -2200,6 +2202,7 @@ export default async function getBaseWebpackConfig(
customAppFile
:
pagesDir
customAppFile
:
pagesDir
?
new
RegExp
(
escapeStringRegexp
(
path
.
join
(
pagesDir
,
`_app`
)))
?
new
RegExp
(
escapeStringRegexp
(
path
.
join
(
pagesDir
,
`_app`
)))
:
undefined
,
:
undefined
,
hasAppDir
,
isDevelopment
:
dev
,
isDevelopment
:
dev
,
isServer
:
isNodeServer
||
isEdgeServer
,
isServer
:
isNodeServer
||
isEdgeServer
,
isEdgeRuntime
:
isEdgeServer
,
isEdgeRuntime
:
isEdgeServer
,
...
@@ -2588,7 +2591,7 @@ export default async function getBaseWebpackConfig(
...
@@ -2588,7 +2591,7 @@ export default async function getBaseWebpackConfig(
value
:
entry
[
name
],
value
:
entry
[
name
],
compilerType
,
compilerType
,
name
,
name
,
appDir
:
config
.
experimental
.
a
ppDir
,
hasA
ppDir
,
})
})
}
}
...
...
packages/next/build/webpack/config/blocks/css/index.ts
View file @
5f2e44d4
...
@@ -257,7 +257,7 @@ export const css = curry(async function css(
...
@@ -257,7 +257,7 @@ export const css = curry(async function css(
// CSS Modules support must be enabled on the server and client so the class
// CSS Modules support must be enabled on the server and client so the class
// names are available for SSR or Prerendering.
// names are available for SSR or Prerendering.
if
(
ctx
.
experimental
.
a
ppDir
&&
!
ctx
.
isProduction
)
{
if
(
ctx
.
hasA
ppDir
&&
!
ctx
.
isProduction
)
{
fns
.
push
(
fns
.
push
(
loader
({
loader
({
oneOf
:
[
oneOf
:
[
...
@@ -373,7 +373,7 @@ export const css = curry(async function css(
...
@@ -373,7 +373,7 @@ export const css = curry(async function css(
)
)
}
}
if
(
!
ctx
.
experimental
.
a
ppDir
)
{
if
(
!
ctx
.
hasA
ppDir
)
{
// Throw an error for CSS Modules used outside their supported scope
// Throw an error for CSS Modules used outside their supported scope
fns
.
push
(
fns
.
push
(
loader
({
loader
({
...
@@ -393,7 +393,7 @@ export const css = curry(async function css(
...
@@ -393,7 +393,7 @@ export const css = curry(async function css(
}
}
if
(
ctx
.
isServer
)
{
if
(
ctx
.
isServer
)
{
if
(
ctx
.
experimental
.
a
ppDir
&&
!
ctx
.
isProduction
)
{
if
(
ctx
.
hasA
ppDir
&&
!
ctx
.
isProduction
)
{
fns
.
push
(
fns
.
push
(
loader
({
loader
({
oneOf
:
[
oneOf
:
[
...
@@ -420,7 +420,7 @@ export const css = curry(async function css(
...
@@ -420,7 +420,7 @@ export const css = curry(async function css(
)
)
}
}
}
else
{
}
else
{
if
(
ctx
.
experimental
.
a
ppDir
)
{
if
(
ctx
.
hasA
ppDir
)
{
fns
.
push
(
fns
.
push
(
loader
({
loader
({
oneOf
:
[
oneOf
:
[
...
@@ -552,7 +552,7 @@ export const css = curry(async function css(
...
@@ -552,7 +552,7 @@ export const css = curry(async function css(
oneOf
:
[
oneOf
:
[
markRemovable
({
markRemovable
({
test
:
[
regexCssGlobal
,
regexSassGlobal
],
test
:
[
regexCssGlobal
,
regexSassGlobal
],
issuer
:
ctx
.
experimental
.
a
ppDir
issuer
:
ctx
.
hasA
ppDir
?
{
?
{
// If it's inside the app dir, but not importing from a layout file,
// If it's inside the app dir, but not importing from a layout file,
// throw an error.
// throw an error.
...
@@ -597,7 +597,7 @@ export const css = curry(async function css(
...
@@ -597,7 +597,7 @@ export const css = curry(async function css(
}
}
// Enable full mini-css-extract-plugin hmr for prod mode pages or app dir
// Enable full mini-css-extract-plugin hmr for prod mode pages or app dir
if
(
ctx
.
isClient
&&
(
ctx
.
isProduction
||
ctx
.
experimental
.
a
ppDir
))
{
if
(
ctx
.
isClient
&&
(
ctx
.
isProduction
||
ctx
.
hasA
ppDir
))
{
// Extract CSS as CSS file(s) in the client-side production bundle.
// Extract CSS as CSS file(s) in the client-side production bundle.
const
MiniCssExtractPlugin
=
const
MiniCssExtractPlugin
=
require
(
'../../../plugins/mini-css-extract-plugin'
).
default
require
(
'../../../plugins/mini-css-extract-plugin'
).
default
...
...
packages/next/build/webpack/config/blocks/css/loaders/client.ts
View file @
5f2e44d4
import
type
{
webpack
}
from
'next/dist/compiled/webpack/webpack'
import
type
{
webpack
}
from
'next/dist/compiled/webpack/webpack'
export
function
getClientStyleLoader
({
export
function
getClientStyleLoader
({
i
sAppDir
,
ha
sAppDir
,
isDevelopment
,
isDevelopment
,
assetPrefix
,
assetPrefix
,
}:
{
}:
{
i
sAppDir
:
boolean
ha
sAppDir
:
boolean
isDevelopment
:
boolean
isDevelopment
:
boolean
assetPrefix
:
string
assetPrefix
:
string
}):
webpack
.
RuleSetUseItem
{
}):
webpack
.
RuleSetUseItem
{
// Keep next-style-loader for development mode in `pages/`
// Keep next-style-loader for development mode in `pages/`
if
(
isDevelopment
&&
!
i
sAppDir
)
{
if
(
isDevelopment
&&
!
ha
sAppDir
)
{
return
{
return
{
loader
:
'next-style-loader'
,
loader
:
'next-style-loader'
,
options
:
{
options
:
{
...
...
packages/next/build/webpack/config/blocks/css/loaders/font-loader.ts
View file @
5f2e44d4
...
@@ -15,7 +15,7 @@ export function getFontLoader(
...
@@ -15,7 +15,7 @@ export function getFontLoader(
// loader
// loader
loaders
.
push
(
loaders
.
push
(
getClientStyleLoader
({
getClientStyleLoader
({
isAppDir
:
!!
ctx
.
experimental
.
a
ppDir
,
hasAppDir
:
ctx
.
hasA
ppDir
,
isDevelopment
:
ctx
.
isDevelopment
,
isDevelopment
:
ctx
.
isDevelopment
,
assetPrefix
:
ctx
.
assetPrefix
,
assetPrefix
:
ctx
.
assetPrefix
,
})
})
...
...
packages/next/build/webpack/config/blocks/css/loaders/global.ts
View file @
5f2e44d4
...
@@ -16,7 +16,7 @@ export function getGlobalCssLoader(
...
@@ -16,7 +16,7 @@ export function getGlobalCssLoader(
// loader
// loader
loaders
.
push
(
loaders
.
push
(
getClientStyleLoader
({
getClientStyleLoader
({
isAppDir
:
!!
ctx
.
experimental
.
a
ppDir
,
hasAppDir
:
ctx
.
hasA
ppDir
,
isDevelopment
:
ctx
.
isDevelopment
,
isDevelopment
:
ctx
.
isDevelopment
,
assetPrefix
:
ctx
.
assetPrefix
,
assetPrefix
:
ctx
.
assetPrefix
,
})
})
...
...
packages/next/build/webpack/config/blocks/css/loaders/modules.ts
View file @
5f2e44d4
...
@@ -16,7 +16,7 @@ export function getCssModuleLoader(
...
@@ -16,7 +16,7 @@ export function getCssModuleLoader(
// loader
// loader
loaders
.
push
(
loaders
.
push
(
getClientStyleLoader
({
getClientStyleLoader
({
isAppDir
:
!!
ctx
.
experimental
.
a
ppDir
,
hasAppDir
:
ctx
.
hasA
ppDir
,
isDevelopment
:
ctx
.
isDevelopment
,
isDevelopment
:
ctx
.
isDevelopment
,
assetPrefix
:
ctx
.
assetPrefix
,
assetPrefix
:
ctx
.
assetPrefix
,
})
})
...
...
packages/next/build/webpack/config/index.ts
View file @
5f2e44d4
import
type
{
webpack
}
from
'next/dist/compiled/webpack/webpack'
import
type
{
webpack
}
from
'next/dist/compiled/webpack/webpack'
import
type
{
NextConfigComplete
}
from
'../../../server/config-shared'
import
type
{
NextConfigComplete
}
from
'../../../server/config-shared'
import
type
{
ConfigurationContext
}
from
'./utils'
import
{
base
}
from
'./blocks/base'
import
{
base
}
from
'./blocks/base'
import
{
css
}
from
'./blocks/css'
import
{
css
}
from
'./blocks/css'
import
{
images
}
from
'./blocks/images'
import
{
images
}
from
'./blocks/images'
import
{
ConfigurationContext
,
pipe
}
from
'./utils'
import
{
pipe
}
from
'./utils'
export
async
function
build
(
export
async
function
build
Configuration
(
config
:
webpack
.
Configuration
,
config
:
webpack
.
Configuration
,
{
{
hasAppDir
,
supportedBrowsers
,
supportedBrowsers
,
rootDirectory
,
rootDirectory
,
customAppFile
,
customAppFile
,
...
@@ -23,6 +25,7 @@ export async function build(
...
@@ -23,6 +25,7 @@ export async function build(
experimental
,
experimental
,
disableStaticImages
,
disableStaticImages
,
}:
{
}:
{
hasAppDir
:
boolean
supportedBrowsers
:
string
[]
|
undefined
supportedBrowsers
:
string
[]
|
undefined
rootDirectory
:
string
rootDirectory
:
string
customAppFile
:
RegExp
|
undefined
customAppFile
:
RegExp
|
undefined
...
@@ -39,6 +42,7 @@ export async function build(
...
@@ -39,6 +42,7 @@ export async function build(
}
}
):
Promise
<
webpack
.
Configuration
>
{
):
Promise
<
webpack
.
Configuration
>
{
const
ctx
:
ConfigurationContext
=
{
const
ctx
:
ConfigurationContext
=
{
hasAppDir
,
supportedBrowsers
,
supportedBrowsers
,
rootDirectory
,
rootDirectory
,
customAppFile
,
customAppFile
,
...
...
packages/next/build/webpack/config/utils.ts
View file @
5f2e44d4
...
@@ -2,6 +2,7 @@ import type { webpack } from 'next/dist/compiled/webpack/webpack'
...
@@ -2,6 +2,7 @@ import type { webpack } from 'next/dist/compiled/webpack/webpack'
import
type
{
NextConfigComplete
}
from
'../../../server/config-shared'
import
type
{
NextConfigComplete
}
from
'../../../server/config-shared'
export
type
ConfigurationContext
=
{
export
type
ConfigurationContext
=
{
hasAppDir
:
boolean
supportedBrowsers
:
string
[]
|
undefined
supportedBrowsers
:
string
[]
|
undefined
rootDirectory
:
string
rootDirectory
:
string
customAppFile
:
RegExp
|
undefined
customAppFile
:
RegExp
|
undefined
...
...
packages/next/build/webpack/loaders/next-edge-ssr-loader/index.ts
View file @
5f2e44d4
...
@@ -13,7 +13,7 @@ export type EdgeSSRLoaderQuery = {
...
@@ -13,7 +13,7 @@ export type EdgeSSRLoaderQuery = {
page
:
string
page
:
string
stringifiedConfig
:
string
stringifiedConfig
:
string
appDirLoader
?:
string
appDirLoader
?:
string
pagesType
?
:
'app'
|
'pages'
|
'root'
pagesType
:
'app'
|
'pages'
|
'root'
sriEnabled
:
boolean
sriEnabled
:
boolean
hasFontLoaders
:
boolean
hasFontLoaders
:
boolean
}
}
...
...
packages/next/build/webpack/loaders/next-edge-ssr-loader/render.ts
View file @
5f2e44d4
...
@@ -32,7 +32,7 @@ export function getRender({
...
@@ -32,7 +32,7 @@ export function getRender({
buildId
,
buildId
,
fontLoaderManifest
,
fontLoaderManifest
,
}:
{
}:
{
pagesType
?
:
'app'
|
'pages'
|
'root'
pagesType
:
'app'
|
'pages'
|
'root'
dev
:
boolean
dev
:
boolean
page
:
string
page
:
string
appMod
:
any
appMod
:
any
...
@@ -69,6 +69,7 @@ export function getRender({
...
@@ -69,6 +69,7 @@ export function getRender({
minimalMode
:
true
,
minimalMode
:
true
,
webServerConfig
:
{
webServerConfig
:
{
page
,
page
,
pagesType
,
extendRenderOpts
:
{
extendRenderOpts
:
{
buildId
,
buildId
,
runtime
:
SERVER_RUNTIME
.
edge
,
runtime
:
SERVER_RUNTIME
.
edge
,
...
...
packages/next/build/webpack/loaders/next-swc-loader.js
View file @
5f2e44d4
...
@@ -46,6 +46,7 @@ async function loaderTransform(parentTrace, source, inputSourceMap) {
...
@@ -46,6 +46,7 @@ async function loaderTransform(parentTrace, source, inputSourceMap) {
jsConfig
,
jsConfig
,
supportedBrowsers
,
supportedBrowsers
,
swcCacheDir
,
swcCacheDir
,
hasServerComponents
,
}
=
loaderOptions
}
=
loaderOptions
const
isPageFile
=
filename
.
startsWith
(
pagesDir
)
const
isPageFile
=
filename
.
startsWith
(
pagesDir
)
const
relativeFilePathFromRoot
=
path
.
relative
(
rootDir
,
filename
)
const
relativeFilePathFromRoot
=
path
.
relative
(
rootDir
,
filename
)
...
@@ -63,6 +64,7 @@ async function loaderTransform(parentTrace, source, inputSourceMap) {
...
@@ -63,6 +64,7 @@ async function loaderTransform(parentTrace, source, inputSourceMap) {
supportedBrowsers
,
supportedBrowsers
,
swcCacheDir
,
swcCacheDir
,
relativeFilePathFromRoot
,
relativeFilePathFromRoot
,
hasServerComponents
,
})
})
const
programmaticOptions
=
{
const
programmaticOptions
=
{
...
...
packages/next/build/webpack/plugins/middleware-plugin.ts
View file @
5f2e44d4
...
@@ -868,7 +868,7 @@ export default class MiddlewarePlugin {
...
@@ -868,7 +868,7 @@ export default class MiddlewarePlugin {
}
}
}
}
export
async
function
handleWebpackExtenalForEdgeRuntime
({
export
async
function
handleWebpackExte
r
nalForEdgeRuntime
({
request
,
request
,
context
,
context
,
contextInfo
,
contextInfo
,
...
...
packages/next/cli/next-lint.ts
View file @
5f2e44d4
...
@@ -187,8 +187,9 @@ const nextLint: cliCommand = async (argv) => {
...
@@ -187,8 +187,9 @@ const nextLint: cliCommand = async (argv) => {
const
distDir
=
join
(
baseDir
,
nextConfig
.
distDir
)
const
distDir
=
join
(
baseDir
,
nextConfig
.
distDir
)
const
defaultCacheLocation
=
join
(
distDir
,
'cache'
,
'eslint/'
)
const
defaultCacheLocation
=
join
(
distDir
,
'cache'
,
'eslint/'
)
const
hasAppDir
=
!!
nextConfig
.
experimental
.
appDir
runLintCheck
(
baseDir
,
pathsToLint
,
{
runLintCheck
(
baseDir
,
pathsToLint
,
hasAppDir
,
{
lintDuringBuild
:
false
,
lintDuringBuild
:
false
,
eslintOptions
:
eslintOptions
(
args
,
defaultCacheLocation
),
eslintOptions
:
eslintOptions
(
args
,
defaultCacheLocation
),
reportErrorsOnly
:
reportErrorsOnly
,
reportErrorsOnly
:
reportErrorsOnly
,
...
@@ -196,7 +197,6 @@ const nextLint: cliCommand = async (argv) => {
...
@@ -196,7 +197,6 @@ const nextLint: cliCommand = async (argv) => {
formatter
,
formatter
,
outputFile
,
outputFile
,
strict
,
strict
,
hasAppDir
:
!!
nextConfig
.
experimental
.
appDir
,
})
})
.
then
(
async
(
lintResults
)
=>
{
.
then
(
async
(
lintResults
)
=>
{
const
lintOutput
=
const
lintOutput
=
...
...
packages/next/export/index.ts
View file @
5f2e44d4
...
@@ -147,6 +147,7 @@ export default async function exportApp(
...
@@ -147,6 +147,7 @@ export default async function exportApp(
configuration
?:
NextConfigComplete
configuration
?:
NextConfigComplete
):
Promise
<
void
>
{
):
Promise
<
void
>
{
const
nextExportSpan
=
span
.
traceChild
(
'next-export'
)
const
nextExportSpan
=
span
.
traceChild
(
'next-export'
)
const
hasAppDir
=
!!
options
.
appPaths
return
nextExportSpan
.
traceAsyncFn
(
async
()
=>
{
return
nextExportSpan
.
traceAsyncFn
(
async
()
=>
{
dir
=
resolve
(
dir
)
dir
=
resolve
(
dir
)
...
@@ -389,7 +390,7 @@ export default async function exportApp(
...
@@ -389,7 +390,7 @@ export default async function exportApp(
nextScriptWorkers
:
nextConfig
.
experimental
.
nextScriptWorkers
,
nextScriptWorkers
:
nextConfig
.
experimental
.
nextScriptWorkers
,
optimizeFonts
:
nextConfig
.
optimizeFonts
as
FontConfig
,
optimizeFonts
:
nextConfig
.
optimizeFonts
as
FontConfig
,
largePageDataBytes
:
nextConfig
.
experimental
.
largePageDataBytes
,
largePageDataBytes
:
nextConfig
.
experimental
.
largePageDataBytes
,
serverComponents
:
!!
nextConfig
.
experimental
.
a
ppDir
,
serverComponents
:
hasA
ppDir
,
fontLoaderManifest
:
nextConfig
.
experimental
.
fontLoaders
fontLoaderManifest
:
nextConfig
.
experimental
.
fontLoaders
?
require
(
join
(
distDir
,
'server'
,
`
${
FONT_LOADER_MANIFEST
}
.json`
))
?
require
(
join
(
distDir
,
'server'
,
`
${
FONT_LOADER_MANIFEST
}
.json`
))
:
undefined
,
:
undefined
,
...
@@ -422,7 +423,7 @@ export default async function exportApp(
...
@@ -422,7 +423,7 @@ export default async function exportApp(
return
exportMap
return
exportMap
})
})
if
(
options
.
buildExport
&&
nextConfig
.
experimental
.
a
ppDir
)
{
if
(
options
.
buildExport
&&
hasA
ppDir
)
{
// @ts-expect-error untyped
// @ts-expect-error untyped
renderOpts
.
serverComponentManifest
=
require
(
join
(
renderOpts
.
serverComponentManifest
=
require
(
join
(
distDir
,
distDir
,
...
@@ -617,7 +618,7 @@ export default async function exportApp(
...
@@ -617,7 +618,7 @@ export default async function exportApp(
nextConfig
.
experimental
.
disableOptimizedLoading
,
nextConfig
.
experimental
.
disableOptimizedLoading
,
parentSpanId
:
pageExportSpan
.
id
,
parentSpanId
:
pageExportSpan
.
id
,
httpAgentOptions
:
nextConfig
.
httpAgentOptions
,
httpAgentOptions
:
nextConfig
.
httpAgentOptions
,
serverComponents
:
!!
nextConfig
.
experimental
.
a
ppDir
,
serverComponents
:
hasA
ppDir
,
appPaths
:
options
.
appPaths
||
[],
appPaths
:
options
.
appPaths
||
[],
enableUndici
:
nextConfig
.
experimental
.
enableUndici
,
enableUndici
:
nextConfig
.
experimental
.
enableUndici
,
})
})
...
...
packages/next/lib/eslint/runLintCheck.ts
View file @
5f2e44d4
...
@@ -185,7 +185,7 @@ async function lint(
...
@@ -185,7 +185,7 @@ async function lint(
}
}
}
}
const
pagesDir
=
findPagesDir
(
baseDir
,
hasAppDir
).
pages
const
pagesDir
=
findPagesDir
(
baseDir
,
hasAppDir
).
pages
Dir
const
pagesDirRules
=
pagesDir
?
[
'@next/next/no-html-link-for-pages'
]
:
[]
const
pagesDirRules
=
pagesDir
?
[
'@next/next/no-html-link-for-pages'
]
:
[]
if
(
nextEslintPluginIsEnabled
)
{
if
(
nextEslintPluginIsEnabled
)
{
...
@@ -277,6 +277,7 @@ async function lint(
...
@@ -277,6 +277,7 @@ async function lint(
export
async
function
runLintCheck
(
export
async
function
runLintCheck
(
baseDir
:
string
,
baseDir
:
string
,
lintDirs
:
string
[],
lintDirs
:
string
[],
hasAppDir
:
boolean
,
opts
:
{
opts
:
{
lintDuringBuild
?:
boolean
lintDuringBuild
?:
boolean
eslintOptions
?:
any
eslintOptions
?:
any
...
@@ -285,7 +286,6 @@ export async function runLintCheck(
...
@@ -285,7 +286,6 @@ export async function runLintCheck(
formatter
?:
string
|
null
formatter
?:
string
|
null
outputFile
?:
string
|
null
outputFile
?:
string
|
null
strict
?:
boolean
strict
?:
boolean
hasAppDir
:
boolean
}
}
):
ReturnType
<
typeof
lint
>
{
):
ReturnType
<
typeof
lint
>
{
const
{
const
{
...
@@ -296,7 +296,6 @@ export async function runLintCheck(
...
@@ -296,7 +296,6 @@ export async function runLintCheck(
formatter
=
null
,
formatter
=
null
,
outputFile
=
null
,
outputFile
=
null
,
strict
=
false
,
strict
=
false
,
hasAppDir
,
}
=
opts
}
=
opts
try
{
try
{
// Find user's .eslintrc file
// Find user's .eslintrc file
...
...
packages/next/lib/find-pages-dir.ts
View file @
5f2e44d4
...
@@ -23,21 +23,27 @@ function findDir(dir: string, name: 'pages' | 'app'): string | null {
...
@@ -23,21 +23,27 @@ function findDir(dir: string, name: 'pages' | 'app'): string | null {
export
function
findPagesDir
(
export
function
findPagesDir
(
dir
:
string
,
dir
:
string
,
appDirEnabled
?:
boolean
isAppDirEnabled
:
boolean
):
{
pages
:
string
|
undefined
;
appDir
:
string
|
undefined
}
{
):
{
pagesDir
:
string
|
undefined
appDir
:
string
|
undefined
}
{
const
pagesDir
=
findDir
(
dir
,
'pages'
)
||
undefined
const
pagesDir
=
findDir
(
dir
,
'pages'
)
||
undefined
let
appDir
:
undefined
|
string
let
appDir
:
undefined
|
string
if
(
a
ppDirEnabled
)
{
if
(
isA
ppDirEnabled
)
{
appDir
=
findDir
(
dir
,
'app'
)
||
undefined
appDir
=
findDir
(
dir
,
'app'
)
||
undefined
if
(
appDirEnabled
==
null
&&
pagesDir
==
null
)
{
}
throw
new
Error
(
const
hasAppDir
=
"> Couldn't find any `pages` or `app` directory. Please create one under the project root"
!!
appDir
&&
fs
.
existsSync
(
appDir
)
&&
fs
.
statSync
(
appDir
).
isDirectory
()
)
}
if
(
hasAppDir
&&
appDir
==
null
&&
pagesDir
==
null
)
{
throw
new
Error
(
"> Couldn't find any `pages` or `app` directory. Please create one under the project root"
)
}
}
if
(
!
a
ppDirEnabled
)
{
if
(
!
isA
ppDirEnabled
)
{
if
(
pagesDir
==
null
)
{
if
(
pagesDir
==
null
)
{
throw
new
Error
(
throw
new
Error
(
"> Couldn't find a `pages` directory. Please create one under the project root"
"> Couldn't find a `pages` directory. Please create one under the project root"
...
@@ -46,7 +52,7 @@ export function findPagesDir(
...
@@ -46,7 +52,7 @@ export function findPagesDir(
}
}
return
{
return
{
pages
:
pages
Dir
,
pagesDir
,
appDir
,
appDir
,
}
}
}
}
packages/next/lib/verifyAndLint.ts
View file @
5f2e44d4
...
@@ -39,13 +39,17 @@ export async function verifyAndLint(
...
@@ -39,13 +39,17 @@ export async function verifyAndLint(
[]
[]
)
)
const
lintResults
=
await
lintWorkers
.
runLintCheck
(
dir
,
lintDirs
,
{
const
lintResults
=
await
lintWorkers
.
runLintCheck
(
dir
,
lintDirs
,
hasAppDir
,
hasAppDir
,
lintDuringBuild
:
true
,
{
eslintOptions
:
{
lintDuringBuild
:
true
,
cacheLocation
,
eslintOptions
:
{
},
cacheLocation
,
})
},
}
)
const
lintOutput
=
const
lintOutput
=
typeof
lintResults
===
'string'
?
lintResults
:
lintResults
?.
output
typeof
lintResults
===
'string'
?
lintResults
:
lintResults
?.
output
...
...
packages/next/server/base-server.ts
View file @
5f2e44d4
...
@@ -185,6 +185,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
...
@@ -185,6 +185,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
protected
distDir
:
string
protected
distDir
:
string
protected
publicDir
:
string
protected
publicDir
:
string
protected
hasStaticDir
:
boolean
protected
hasStaticDir
:
boolean
protected
hasAppDir
:
boolean
protected
pagesManifest
?:
PagesManifest
protected
pagesManifest
?:
PagesManifest
protected
appPathsManifest
?:
PagesManifest
protected
appPathsManifest
?:
PagesManifest
protected
buildId
:
string
protected
buildId
:
string
...
@@ -237,6 +238,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
...
@@ -237,6 +238,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
protected
abstract
getPublicDir
():
string
protected
abstract
getPublicDir
():
string
protected
abstract
getHasStaticDir
():
boolean
protected
abstract
getHasStaticDir
():
boolean
protected
abstract
getHasAppDir
():
boolean
protected
abstract
getPagesManifest
():
PagesManifest
|
undefined
protected
abstract
getPagesManifest
():
PagesManifest
|
undefined
protected
abstract
getAppPathsManifest
():
PagesManifest
|
undefined
protected
abstract
getAppPathsManifest
():
PagesManifest
|
undefined
protected
abstract
getBuildId
():
string
protected
abstract
getBuildId
():
string
...
@@ -353,6 +355,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
...
@@ -353,6 +355,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
:
require
(
'path'
).
join
(
this
.
dir
,
this
.
nextConfig
.
distDir
)
:
require
(
'path'
).
join
(
this
.
dir
,
this
.
nextConfig
.
distDir
)
this
.
publicDir
=
this
.
getPublicDir
()
this
.
publicDir
=
this
.
getPublicDir
()
this
.
hasStaticDir
=
!
minimalMode
&&
this
.
getHasStaticDir
()
this
.
hasStaticDir
=
!
minimalMode
&&
this
.
getHasStaticDir
()
this
.
hasAppDir
=
this
.
getHasAppDir
()
// Only serverRuntimeConfig needs the default
// Only serverRuntimeConfig needs the default
// publicRuntimeConfig gets it's default in client/index.js
// publicRuntimeConfig gets it's default in client/index.js
...
@@ -366,7 +369,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
...
@@ -366,7 +369,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
this
.
buildId
=
this
.
getBuildId
()
this
.
buildId
=
this
.
getBuildId
()
this
.
minimalMode
=
minimalMode
||
!!
process
.
env
.
NEXT_PRIVATE_MINIMAL_MODE
this
.
minimalMode
=
minimalMode
||
!!
process
.
env
.
NEXT_PRIVATE_MINIMAL_MODE
const
serverComponents
=
!!
this
.
nextConfig
.
experimental
.
a
ppDir
const
serverComponents
=
this
.
hasA
ppDir
this
.
serverComponentManifest
=
serverComponents
this
.
serverComponentManifest
=
serverComponents
?
this
.
getServerComponentManifest
()
?
this
.
getServerComponentManifest
()
:
undefined
:
undefined
...
@@ -1588,7 +1591,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
...
@@ -1588,7 +1591,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
// map the route to the actual bundle name
// map the route to the actual bundle name
protected
getOriginalAppPaths
(
route
:
string
)
{
protected
getOriginalAppPaths
(
route
:
string
)
{
if
(
this
.
nextConfig
.
experimental
.
a
ppDir
)
{
if
(
this
.
hasA
ppDir
)
{
const
originalAppPath
=
this
.
appPathRoutes
?.[
route
]
const
originalAppPath
=
this
.
appPathRoutes
?.[
route
]
if
(
!
originalAppPath
)
{
if
(
!
originalAppPath
)
{
...
...
packages/next/server/config-schema.ts
View file @
5f2e44d4
...
@@ -240,9 +240,6 @@ const configSchema = {
...
@@ -240,9 +240,6 @@ const configSchema = {
},
},
type
:
'object'
,
type
:
'object'
,
},
},
appDir
:
{
type
:
'boolean'
,
},
browsersListForSwc
:
{
browsersListForSwc
:
{
type
:
'boolean'
,
type
:
'boolean'
,
},
},
...
...
packages/next/server/dev/hot-reloader.ts
View file @
5f2e44d4
...
@@ -217,7 +217,7 @@ export default class HotReloader {
...
@@ -217,7 +217,7 @@ export default class HotReloader {
this
.
config
=
config
this
.
config
=
config
this
.
hasReactRoot
=
!!
process
.
env
.
__NEXT_REACT_ROOT
this
.
hasReactRoot
=
!!
process
.
env
.
__NEXT_REACT_ROOT
this
.
hasServerComponents
=
this
.
hasReactRoot
&&
!!
config
.
experimental
.
appDir
this
.
hasServerComponents
=
this
.
hasReactRoot
&&
!!
this
.
appDir
this
.
previewProps
=
previewProps
this
.
previewProps
=
previewProps
this
.
rewrites
=
rewrites
this
.
rewrites
=
rewrites
this
.
hotReloaderSpan
=
trace
(
'hot-reloader'
,
undefined
,
{
this
.
hotReloaderSpan
=
trace
(
'hot-reloader'
,
undefined
,
{
...
@@ -595,7 +595,8 @@ export default class HotReloader {
...
@@ -595,7 +595,8 @@ export default class HotReloader {
}
}
}
}
const
isAppPath
=
!!
this
.
appDir
&&
bundlePath
.
startsWith
(
'app/'
)
const
hasAppDir
=
!!
this
.
appDir
const
isAppPath
=
hasAppDir
&&
bundlePath
.
startsWith
(
'app/'
)
const
staticInfo
=
isEntry
const
staticInfo
=
isEntry
?
await
getPageStaticInfo
({
?
await
getPageStaticInfo
({
pageFilePath
:
entryData
.
absolutePagePath
,
pageFilePath
:
entryData
.
absolutePagePath
,
...
@@ -643,9 +644,9 @@ export default class HotReloader {
...
@@ -643,9 +644,9 @@ export default class HotReloader {
pages
:
this
.
pagesMapping
,
pages
:
this
.
pagesMapping
,
isServerComponent
,
isServerComponent
,
appDirLoader
,
appDirLoader
,
pagesType
:
isAppPath
?
'app'
:
undefined
,
pagesType
:
isAppPath
?
'app'
:
'pages'
,
}),
}),
appDir
:
this
.
config
.
experimental
.
a
ppDir
,
hasA
ppDir
,
})
})
},
},
onClient
:
()
=>
{
onClient
:
()
=>
{
...
@@ -656,7 +657,7 @@ export default class HotReloader {
...
@@ -656,7 +657,7 @@ export default class HotReloader {
name
:
bundlePath
,
name
:
bundlePath
,
compilerType
:
COMPILER_NAMES
.
client
,
compilerType
:
COMPILER_NAMES
.
client
,
value
:
entryData
.
request
,
value
:
entryData
.
request
,
appDir
:
this
.
config
.
experimental
.
a
ppDir
,
hasA
ppDir
,
})
})
}
else
{
}
else
{
entries
[
entryKey
].
status
=
BUILDING
entries
[
entryKey
].
status
=
BUILDING
...
@@ -667,7 +668,7 @@ export default class HotReloader {
...
@@ -667,7 +668,7 @@ export default class HotReloader {
absolutePagePath
:
entryData
.
absolutePagePath
,
absolutePagePath
:
entryData
.
absolutePagePath
,
page
,
page
,
}),
}),
appDir
:
this
.
config
.
experimental
.
a
ppDir
,
hasA
ppDir
,
})
})
}
}
},
},
...
@@ -705,7 +706,7 @@ export default class HotReloader {
...
@@ -705,7 +706,7 @@ export default class HotReloader {
pageExtensions
:
this
.
config
.
pageExtensions
,
pageExtensions
:
this
.
config
.
pageExtensions
,
})
})
:
relativeRequest
,
:
relativeRequest
,
appDir
:
this
.
config
.
experimental
.
a
ppDir
,
hasA
ppDir
,
})
})
},
},
})
})
...
...
packages/next/server/dev/next-dev-server.ts
View file @
5f2e44d4
...
@@ -190,11 +190,8 @@ export default class DevServer extends Server {
...
@@ -190,11 +190,8 @@ export default class DevServer extends Server {
}
}
this
.
isCustomServer
=
!
options
.
isNextDevCommand
this
.
isCustomServer
=
!
options
.
isNextDevCommand
// TODO: hot-reload root/pages dirs?
const
{
pages
:
pagesDir
,
appDir
}
=
findPagesDir
(
const
{
pagesDir
,
appDir
}
=
findPagesDir
(
this
.
dir
,
this
.
hasAppDir
)
this
.
dir
,
this
.
nextConfig
.
experimental
.
appDir
)
this
.
pagesDir
=
pagesDir
this
.
pagesDir
=
pagesDir
this
.
appDir
=
appDir
this
.
appDir
=
appDir
}
}
...
@@ -1355,7 +1352,7 @@ export default class DevServer extends Server {
...
@@ -1355,7 +1352,7 @@ export default class DevServer extends Server {
// When the new page is compiled, we need to reload the server component
// When the new page is compiled, we need to reload the server component
// manifest.
// manifest.
if
(
this
.
nextConfig
.
experimental
.
appDir
)
{
if
(
!!
this
.
appDir
)
{
this
.
serverComponentManifest
=
super
.
getServerComponentManifest
()
this
.
serverComponentManifest
=
super
.
getServerComponentManifest
()
this
.
serverCSSManifest
=
super
.
getServerCSSManifest
()
this
.
serverCSSManifest
=
super
.
getServerCSSManifest
()
}
}
...
...
packages/next/server/next-server.ts
View file @
5f2e44d4
...
@@ -286,7 +286,7 @@ export default class NextNodeServer extends BaseServer {
...
@@ -286,7 +286,7 @@ export default class NextNodeServer extends BaseServer {
fs
:
this
.
getCacheFilesystem
(),
fs
:
this
.
getCacheFilesystem
(),
dev
,
dev
,
serverDistDir
:
this
.
serverDistDir
,
serverDistDir
:
this
.
serverDistDir
,
appDir
:
this
.
nextConfig
.
experimental
.
a
ppDir
,
appDir
:
this
.
hasA
ppDir
,
maxMemoryCacheSize
:
this
.
nextConfig
.
experimental
.
isrMemoryCacheSize
,
maxMemoryCacheSize
:
this
.
nextConfig
.
experimental
.
isrMemoryCacheSize
,
flushToDisk
:
flushToDisk
:
!
this
.
minimalMode
&&
this
.
nextConfig
.
experimental
.
isrFlushToDisk
,
!
this
.
minimalMode
&&
this
.
nextConfig
.
experimental
.
isrFlushToDisk
,
...
@@ -323,7 +323,7 @@ export default class NextNodeServer extends BaseServer {
...
@@ -323,7 +323,7 @@ export default class NextNodeServer extends BaseServer {
}
}
protected
getAppPathsManifest
():
PagesManifest
|
undefined
{
protected
getAppPathsManifest
():
PagesManifest
|
undefined
{
if
(
this
.
nextConfig
.
experimental
.
a
ppDir
)
{
if
(
this
.
hasA
ppDir
)
{
const
appPathsManifestPath
=
join
(
this
.
serverDistDir
,
APP_PATHS_MANIFEST
)
const
appPathsManifestPath
=
join
(
this
.
serverDistDir
,
APP_PATHS_MANIFEST
)
return
require
(
appPathsManifestPath
)
return
require
(
appPathsManifestPath
)
}
}
...
@@ -474,6 +474,13 @@ export default class NextNodeServer extends BaseServer {
...
@@ -474,6 +474,13 @@ export default class NextNodeServer extends BaseServer {
]
]
}
}
protected
getHasAppDir
():
boolean
{
const
appDirectory
=
join
(
this
.
dir
,
'app'
)
return
(
fs
.
existsSync
(
appDirectory
)
&&
fs
.
statSync
(
appDirectory
).
isDirectory
()
)
}
protected
generateStaticRoutes
():
Route
[]
{
protected
generateStaticRoutes
():
Route
[]
{
return
this
.
hasStaticDir
return
this
.
hasStaticDir
?
[
?
[
...
@@ -823,7 +830,7 @@ export default class NextNodeServer extends BaseServer {
...
@@ -823,7 +830,7 @@ export default class NextNodeServer extends BaseServer {
renderOpts
.
serverCSSManifest
=
this
.
serverCSSManifest
renderOpts
.
serverCSSManifest
=
this
.
serverCSSManifest
renderOpts
.
fontLoaderManifest
=
this
.
fontLoaderManifest
renderOpts
.
fontLoaderManifest
=
this
.
fontLoaderManifest
if
(
this
.
nextConfig
.
experimental
.
a
ppDir
&&
renderOpts
.
isAppPath
)
{
if
(
this
.
hasA
ppDir
&&
renderOpts
.
isAppPath
)
{
return
appRenderToHTMLOrFlight
(
return
appRenderToHTMLOrFlight
(
req
.
originalRequest
,
req
.
originalRequest
,
res
.
originalResponse
,
res
.
originalResponse
,
...
@@ -882,7 +889,7 @@ export default class NextNodeServer extends BaseServer {
...
@@ -882,7 +889,7 @@ export default class NextNodeServer extends BaseServer {
this
.
_isLikeServerless
,
this
.
_isLikeServerless
,
this
.
renderOpts
.
dev
,
this
.
renderOpts
.
dev
,
locales
,
locales
,
this
.
nextConfig
.
experimental
.
a
ppDir
this
.
hasA
ppDir
)
)
}
}
...
@@ -998,12 +1005,12 @@ export default class NextNodeServer extends BaseServer {
...
@@ -998,12 +1005,12 @@ export default class NextNodeServer extends BaseServer {
}
}
protected
getServerComponentManifest
()
{
protected
getServerComponentManifest
()
{
if
(
!
this
.
nextConfig
.
experimental
.
a
ppDir
)
return
undefined
if
(
!
this
.
hasA
ppDir
)
return
undefined
return
require
(
join
(
this
.
distDir
,
'server'
,
FLIGHT_MANIFEST
+
'.json'
))
return
require
(
join
(
this
.
distDir
,
'server'
,
FLIGHT_MANIFEST
+
'.json'
))
}
}
protected
getServerCSSManifest
()
{
protected
getServerCSSManifest
()
{
if
(
!
this
.
nextConfig
.
experimental
.
a
ppDir
)
return
undefined
if
(
!
this
.
hasA
ppDir
)
return
undefined
return
require
(
join
(
return
require
(
join
(
this
.
distDir
,
this
.
distDir
,
'server'
,
'server'
,
...
...
packages/next/server/web-server.ts
View file @
5f2e44d4
...
@@ -31,6 +31,7 @@ import { getNamedRouteRegex } from '../shared/lib/router/utils/route-regex'
...
@@ -31,6 +31,7 @@ import { getNamedRouteRegex } from '../shared/lib/router/utils/route-regex'
interface
WebServerOptions
extends
Options
{
interface
WebServerOptions
extends
Options
{
webServerConfig
:
{
webServerConfig
:
{
page
:
string
page
:
string
pagesType
:
'app'
|
'pages'
|
'root'
loadComponent
:
(
loadComponent
:
(
pathname
:
string
pathname
:
string
)
=>
Promise
<
LoadComponentsReturnType
|
null
>
)
=>
Promise
<
LoadComponentsReturnType
|
null
>
...
@@ -88,6 +89,9 @@ export default class NextWebServer extends BaseServer<WebServerOptions> {
...
@@ -88,6 +89,9 @@ export default class NextWebServer extends BaseServer<WebServerOptions> {
// The web server does not need to load the env config. This is done by the
// The web server does not need to load the env config. This is done by the
// runtime already.
// runtime already.
}
}
protected
getHasAppDir
()
{
return
this
.
serverOptions
.
webServerConfig
.
pagesType
===
'app'
}
protected
getHasStaticDir
()
{
protected
getHasStaticDir
()
{
return
false
return
false
}
}
...
...
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