Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename app paths folder #37146

Merged
merged 5 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"dev2": "while true; do yarn --check-files && yarn dev; done",
"test-types": "yarn tsc",
"test-unit": "yarn jest test/unit/",
"test-dev": "cross-env NEXT_TEST_MODE=dev yarn testheadless",
"test-start": "cross-env NEXT_TEST_MODE=start yarn testheadless",
"test-deploy": "cross-env NEXT_TEST_MODE=deploy yarn testheadless",
"testonly": "yarn jest --runInBand",
"testheadless": "cross-env HEADLESS=true yarn testonly",
"genstats": "cross-env LOCAL_STATS=true node .github/actions/next-stats-action/src/index.js",
Expand Down
44 changes: 22 additions & 22 deletions packages/next/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
MIDDLEWARE_FILENAME,
PAGES_DIR_ALIAS,
ROOT_DIR_ALIAS,
VIEWS_DIR_ALIAS,
APP_DIR_ALIAS,
} from '../lib/constants'
import {
CLIENT_STATIC_FILES_RUNTIME_AMP,
Expand Down Expand Up @@ -60,7 +60,7 @@ export function createPagesMapping({
isDev: boolean
pageExtensions: string[]
pagePaths: string[]
pagesType: 'pages' | 'root' | 'views'
pagesType: 'pages' | 'root' | 'app'
}): { [page: string]: string } {
const previousPages: { [key: string]: string } = {}
const pages = pagePaths.reduce<{ [key: string]: string }>(
Expand Down Expand Up @@ -95,8 +95,8 @@ export function createPagesMapping({
join(
pagesType === 'pages'
? PAGES_DIR_ALIAS
: pagesType === 'views'
? VIEWS_DIR_ALIAS
: pagesType === 'app'
? APP_DIR_ALIAS
: ROOT_DIR_ALIAS,
pagePath
)
Expand Down Expand Up @@ -140,8 +140,8 @@ interface CreateEntrypointsParams {
rootDir: string
rootPaths?: Record<string, string>
target: 'server' | 'serverless' | 'experimental-serverless-trace'
viewsDir?: string
viewPaths?: Record<string, string>
appDir?: string
appPaths?: Record<string, string>
pageExtensions: string[]
}

Expand Down Expand Up @@ -186,14 +186,14 @@ export function getEdgeServerEntry(opts: {
}
}

export function getViewsEntry(opts: {
export function getAppEntry(opts: {
name: string
pagePath: string
viewsDir: string
appDir: string
pageExtensions: string[]
}) {
return {
import: `next-view-loader?${stringify(opts)}!`,
import: `next-app-loader?${stringify(opts)}!`,
layer: 'sc_server',
}
}
Expand Down Expand Up @@ -269,24 +269,24 @@ export async function createEntrypoints(params: CreateEntrypointsParams) {
rootDir,
rootPaths,
target,
viewsDir,
viewPaths,
appDir,
appPaths,
pageExtensions,
} = params
const edgeServer: webpack5.EntryObject = {}
const server: webpack5.EntryObject = {}
const client: webpack5.EntryObject = {}

const getEntryHandler =
(mappings: Record<string, string>, pagesType: 'views' | 'pages' | 'root') =>
(mappings: Record<string, string>, pagesType: 'app' | 'pages' | 'root') =>
async (page: string) => {
const bundleFile = normalizePagePath(page)
const clientBundlePath = posix.join('pages', bundleFile)
const serverBundlePath =
pagesType === 'pages'
? posix.join('pages', bundleFile)
: pagesType === 'views'
? posix.join('views', bundleFile)
: pagesType === 'app'
? posix.join('app', bundleFile)
: bundleFile.slice(1)
const absolutePagePath = mappings[page]

Expand All @@ -296,8 +296,8 @@ export async function createEntrypoints(params: CreateEntrypointsParams) {
return absolutePagePath.replace(PAGES_DIR_ALIAS, pagesDir)
}

if (absolutePagePath.startsWith(VIEWS_DIR_ALIAS) && viewsDir) {
return absolutePagePath.replace(VIEWS_DIR_ALIAS, viewsDir)
if (absolutePagePath.startsWith(APP_DIR_ALIAS) && appDir) {
return absolutePagePath.replace(APP_DIR_ALIAS, appDir)
}

if (absolutePagePath.startsWith(ROOT_DIR_ALIAS)) {
Expand Down Expand Up @@ -344,11 +344,11 @@ export async function createEntrypoints(params: CreateEntrypointsParams) {
}
},
onServer: () => {
if (pagesType === 'views' && viewsDir) {
server[serverBundlePath] = getViewsEntry({
if (pagesType === 'app' && appDir) {
server[serverBundlePath] = getAppEntry({
name: serverBundlePath,
pagePath: mappings[page],
viewsDir,
appDir,
pageExtensions,
})
} else if (isTargetLikeServerless(target)) {
Expand Down Expand Up @@ -381,9 +381,9 @@ export async function createEntrypoints(params: CreateEntrypointsParams) {
})
}

if (viewsDir && viewPaths) {
const entryHandler = getEntryHandler(viewPaths, 'views')
await Promise.all(Object.keys(viewPaths).map(entryHandler))
if (appDir && appPaths) {
const entryHandler = getEntryHandler(appPaths, 'app')
await Promise.all(Object.keys(appPaths).map(entryHandler))
}
if (rootPaths) {
await Promise.all(
Expand Down
34 changes: 17 additions & 17 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ export default async function build(
setGlobal('telemetry', telemetry)

const publicDir = path.join(dir, 'public')
const { pages: pagesDir, views: viewsDir } = findPagesDir(
const { pages: pagesDir, appDir } = findPagesDir(
dir,
config.experimental.viewsDir
config.experimental.appDir
)

const hasPublicDir = await fileExists(publicDir)
Expand Down Expand Up @@ -270,7 +270,7 @@ export default async function build(
nextBuildSpan.traceChild('verify-typescript-setup').traceAsyncFn(() =>
verifyTypeScriptSetup(
dir,
[pagesDir, viewsDir].filter(Boolean) as string[],
[pagesDir, appDir].filter(Boolean) as string[],
!ignoreTypeScriptErrors,
config.typescript.tsconfigPath,
config.images.disableStaticImages,
Expand Down Expand Up @@ -333,14 +333,14 @@ export default async function build(
)
)

let viewPaths: string[] | undefined
let appPaths: string[] | undefined

if (viewsDir) {
viewPaths = await nextBuildSpan
.traceChild('collect-view-paths')
if (appDir) {
appPaths = await nextBuildSpan
.traceChild('collect-app-paths')
.traceAsyncFn(() =>
recursiveReadDir(
viewsDir,
appDir,
new RegExp(`page\\.(?:${config.pageExtensions.join('|')})$`)
)
)
Expand Down Expand Up @@ -377,17 +377,17 @@ export default async function build(
})
)

let mappedViewPaths: { [page: string]: string } | undefined
let mappedappPaths: { [page: string]: string } | undefined

if (viewPaths && viewsDir) {
mappedViewPaths = nextBuildSpan
.traceChild('create-views-mapping')
if (appPaths && appDir) {
mappedappPaths = nextBuildSpan
.traceChild('create-app-mapping')
.traceFn(() =>
createPagesMapping({
pagePaths: viewPaths!,
pagePaths: appPaths!,
hasServerComponents,
isDev: false,
pagesType: 'views',
pagesType: 'app',
pageExtensions: config.pageExtensions,
})
)
Expand Down Expand Up @@ -418,8 +418,8 @@ export default async function build(
target,
rootDir: dir,
rootPaths: mappedRootPaths,
viewsDir,
viewPaths: mappedViewPaths,
appDir,
appPaths: mappedappPaths,
pageExtensions: config.pageExtensions,
})
)
Expand Down Expand Up @@ -719,7 +719,7 @@ export default async function build(
rewrites,
runWebpackSpan,
target,
viewsDir,
appDir,
}

const configs = await runWebpackSpan
Expand Down
24 changes: 12 additions & 12 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
NEXT_PROJECT_ROOT_DIST_CLIENT,
PAGES_DIR_ALIAS,
ROOT_DIR_ALIAS,
VIEWS_DIR_ALIAS,
APP_DIR_ALIAS,
} from '../lib/constants'
import { fileExists } from '../lib/file-exists'
import { CustomRoutes } from '../lib/load-custom-routes.js'
Expand Down Expand Up @@ -333,7 +333,7 @@ export default async function getBaseWebpackConfig(
rewrites,
runWebpackSpan,
target = 'server',
viewsDir,
appDir,
}: {
buildId: string
config: NextConfigComplete
Expand All @@ -347,7 +347,7 @@ export default async function getBaseWebpackConfig(
rewrites: CustomRoutes['rewrites']
runWebpackSpan: Span
target?: string
viewsDir?: string
appDir?: string
}
): Promise<webpack.Configuration> {
const isClient = compilerType === 'client'
Expand Down Expand Up @@ -569,14 +569,14 @@ export default async function getBaseWebpackConfig(
)
)
.replace(/\\/g, '/'),
...(config.experimental.viewsDir
...(config.experimental.appDir
? {
[CLIENT_STATIC_FILES_RUNTIME_MAIN_ROOT]:
`./` +
path
.relative(
dir,
path.join(NEXT_PROJECT_ROOT_DIST_CLIENT, 'views-next.js')
path.join(NEXT_PROJECT_ROOT_DIST_CLIENT, 'app-next.js')
)
.replace(/\\/g, '/'),
}
Expand Down Expand Up @@ -661,9 +661,9 @@ export default async function getBaseWebpackConfig(
...customRootAliases,

[PAGES_DIR_ALIAS]: pagesDir,
...(viewsDir
...(appDir
? {
[VIEWS_DIR_ALIAS]: viewsDir,
[APP_DIR_ALIAS]: appDir,
}
: {}),
[ROOT_DIR_ALIAS]: dir,
Expand Down Expand Up @@ -1183,7 +1183,7 @@ export default async function getBaseWebpackConfig(
? `[name].js`
: `../[name].js`
: `static/chunks/${isDevFallback ? 'fallback/' : ''}[name]${
dev ? '' : viewsDir ? '-[chunkhash]' : '-[contenthash]'
dev ? '' : appDir ? '-[chunkhash]' : '-[contenthash]'
}.js`,
library: isClient || isEdgeServer ? '_N_E' : undefined,
libraryTarget: isClient || isEdgeServer ? 'assign' : 'commonjs2',
Expand Down Expand Up @@ -1221,7 +1221,7 @@ export default async function getBaseWebpackConfig(
'next-middleware-loader',
'next-middleware-ssr-loader',
'next-middleware-wasm-loader',
'next-view-loader',
'next-app-loader',
].reduce((alias, loader) => {
// using multiple aliases to replace `resolveLoader.modules`
alias[loader] = path.join(__dirname, 'webpack', 'loaders', loader)
Expand Down Expand Up @@ -1602,7 +1602,7 @@ export default async function getBaseWebpackConfig(
serverless: isLikeServerless,
dev,
isEdgeRuntime: isEdgeServer,
rootEnabled: !!config.experimental.viewsDir,
appDirEnabled: !!config.experimental.appDir,
}),
// MiddlewarePlugin should be after DefinePlugin so NEXT_PUBLIC_*
// replacement is done before its process.env.* handling
Expand All @@ -1613,7 +1613,7 @@ export default async function getBaseWebpackConfig(
rewrites,
isDevFallback,
exportRuntime: hasConcurrentFeatures,
rootEnabled: !!config.experimental.viewsDir,
appDirEnabled: !!config.experimental.appDir,
}),
new ProfilingPlugin({ runWebpackSpan }),
config.optimizeFonts &&
Expand Down Expand Up @@ -1645,7 +1645,7 @@ export default async function getBaseWebpackConfig(
(isClient
? new FlightManifestPlugin({
dev,
viewsDir: !!config.experimental.viewsDir,
appDir: !!config.experimental.appDir,
pageExtensions: rawPageExtensions,
})
: new ClientEntryPlugin({
Expand Down
Loading