Unverified Commit b68d9eaf authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Rename app paths folder (#37146)

parent 1cd34dd6
......@@ -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",
......
......@@ -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,
......@@ -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 }>(
......@@ -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
)
......@@ -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[]
}
......@@ -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',
}
}
......@@ -269,8 +269,8 @@ export async function createEntrypoints(params: CreateEntrypointsParams) {
rootDir,
rootPaths,
target,
viewsDir,
viewPaths,
appDir,
appPaths,
pageExtensions,
} = params
const edgeServer: webpack5.EntryObject = {}
......@@ -278,15 +278,15 @@ export async function createEntrypoints(params: CreateEntrypointsParams) {
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]
......@@ -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)) {
......@@ -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)) {
......@@ -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(
......
......@@ -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)
......@@ -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,
......@@ -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('|')})$`)
)
)
......@@ -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,
})
)
......@@ -418,8 +418,8 @@ export default async function build(
target,
rootDir: dir,
rootPaths: mappedRootPaths,
viewsDir,
viewPaths: mappedViewPaths,
appDir,
appPaths: mappedappPaths,
pageExtensions: config.pageExtensions,
})
)
......@@ -719,7 +719,7 @@ export default async function build(
rewrites,
runWebpackSpan,
target,
viewsDir,
appDir,
}
const configs = await runWebpackSpan
......
......@@ -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'
......@@ -333,7 +333,7 @@ export default async function getBaseWebpackConfig(
rewrites,
runWebpackSpan,
target = 'server',
viewsDir,
appDir,
}: {
buildId: string
config: NextConfigComplete
......@@ -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'
......@@ -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, '/'),
}
......@@ -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,
......@@ -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',
......@@ -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)
......@@ -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
......@@ -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 &&
......@@ -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({
......
......@@ -4,9 +4,9 @@ import { NODE_RESOLVE_OPTIONS } from '../../webpack-config'
import { getModuleBuildInfo } from './get-module-build-info'
function pathToUrlPath(pathname: string) {
let urlPath = pathname.replace(/^private-next-views-dir/, '')
let urlPath = pathname.replace(/^private-next-app-dir/, '')
// For `views/layout.js`
// For `app/layout.js`
if (urlPath === '') {
urlPath = '/'
}
......@@ -36,17 +36,17 @@ async function resolveLayoutPathsByPage({
let resolvedLayoutPath = await resolve(layoutPath)
let urlPath = pathToUrlPath(pathWithoutSlashLayout)
// if we are in a new root views/(root) and a custom root layout was
// not provided or a root layout views/layout is not present, we use
// if we are in a new root app/(root) and a custom root layout was
// not provided or a root layout app/layout is not present, we use
// a default root layout to provide the html/body tags
const isCustomRootLayout = isNewRootLayout && i === 2
if ((isCustomRootLayout || i === 1) && !resolvedLayoutPath) {
resolvedLayoutPath = await resolve('next/dist/lib/views-layout')
resolvedLayoutPath = await resolve('next/dist/lib/app-layout')
}
layoutPaths.set(urlPath, resolvedLayoutPath)
// if we're in a new root layout don't add the top-level view/layout
// if we're in a new root layout don't add the top-level app/layout
if (isCustomRootLayout) {
break
}
......@@ -54,19 +54,18 @@ async function resolveLayoutPathsByPage({
return layoutPaths
}
const nextViewLoader: webpack.LoaderDefinitionFunction<{
const nextAppLoader: webpack.LoaderDefinitionFunction<{
name: string
pagePath: string
viewsDir: string
appDir: string
pageExtensions: string[]
}> = async function nextViewLoader() {
const { name, viewsDir, pagePath, pageExtensions } = this.getOptions() || {}
}> = async function nextAppLoader() {
const { name, appDir, pagePath, pageExtensions } = this.getOptions() || {}
const buildInfo = getModuleBuildInfo((this as any)._module)
buildInfo.route = {
page: name.replace(/^views/, ''),
absolutePagePath:
viewsDir + pagePath.replace(/^private-next-views-dir/, ''),
page: name.replace(/^app/, ''),
absolutePagePath: appDir + pagePath.replace(/^private-next-app-dir/, ''),
}
const extensions = pageExtensions.map((extension) => `.${extension}`)
......@@ -99,9 +98,7 @@ const nextViewLoader: webpack.LoaderDefinitionFunction<{
componentsCode.push(codeLine)
} else {
for (const ext of extensions) {
this.addMissingDependency(
path.join(viewsDir, layoutPath, `layout${ext}`)
)
this.addMissingDependency(path.join(appDir, layoutPath, `layout${ext}`))
}
}
}
......@@ -120,9 +117,9 @@ const nextViewLoader: webpack.LoaderDefinitionFunction<{
${componentsCode.join(',\n')}
};
export const __next_view_webpack_require__ = __webpack_require__
export const __next_app_webpack_require__ = __webpack_require__
`
return result
}
export default nextViewLoader
export default nextAppLoader
......@@ -96,14 +96,14 @@ export default class BuildManifestPlugin {
private rewrites: CustomRoutes['rewrites']
private isDevFallback: boolean
private exportRuntime: boolean
private rootEnabled: boolean
private appDirEnabled: boolean
constructor(options: {
buildId: string
rewrites: CustomRoutes['rewrites']
isDevFallback?: boolean
exportRuntime?: boolean
rootEnabled: boolean
appDirEnabled: boolean
}) {
this.buildId = options.buildId
this.isDevFallback = !!options.isDevFallback
......@@ -112,7 +112,7 @@ export default class BuildManifestPlugin {
afterFiles: [],
fallback: [],
}
this.rootEnabled = options.rootEnabled
this.appDirEnabled = options.appDirEnabled
this.rewrites.beforeFiles = options.rewrites.beforeFiles.map(processRoute)
this.rewrites.afterFiles = options.rewrites.afterFiles.map(processRoute)
this.rewrites.fallback = options.rewrites.fallback.map(processRoute)
......@@ -152,7 +152,7 @@ export default class BuildManifestPlugin {
getEntrypointFiles(entrypoints.get(CLIENT_STATIC_FILES_RUNTIME_MAIN))
)
if (this.rootEnabled) {
if (this.appDirEnabled) {
assetMap.rootMainFiles = [
...new Set(
getEntrypointFiles(
......@@ -193,7 +193,7 @@ export default class BuildManifestPlugin {
CLIENT_STATIC_FILES_RUNTIME_MAIN,
CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH,
CLIENT_STATIC_FILES_RUNTIME_AMP,
...(this.rootEnabled ? [CLIENT_STATIC_FILES_RUNTIME_MAIN_ROOT] : []),
...(this.appDirEnabled ? [CLIENT_STATIC_FILES_RUNTIME_MAIN_ROOT] : []),
])
for (const entrypoint of compilation.entrypoints.values()) {
......
......@@ -18,7 +18,7 @@ import { clientComponentRegex } from '../loaders/utils'
type Options = {
dev: boolean
viewsDir: boolean
appDir: boolean
pageExtensions: string[]
}
......@@ -27,13 +27,13 @@ const PLUGIN_NAME = 'FlightManifestPlugin'
export class FlightManifestPlugin {
dev: boolean = false
pageExtensions: string[]
viewsDir: boolean = false
appDir: boolean = false
constructor(options: Options) {
if (typeof options.dev === 'boolean') {
this.dev = options.dev
}
this.viewsDir = options.viewsDir
this.appDir = options.appDir
this.pageExtensions = options.pageExtensions
}
......@@ -66,7 +66,7 @@ export class FlightManifestPlugin {
createAsset(assets: any, compilation: any) {
const manifest: any = {}
const viewsDir = this.viewsDir
const appDir = this.appDir
const dev = this.dev
compilation.chunkGroups.forEach((chunkGroup: any) => {
......@@ -103,7 +103,7 @@ export class FlightManifestPlugin {
moduleExports[name] = {
id: id.replace(/^\(sc_server\)\//, ''),
name,
chunks: viewsDir
chunks: appDir
? chunk.ids.map((chunkId: string) => {
return (
chunkId + ':' + chunk.name + (dev ? '' : '-' + chunk.hash)
......
import { webpack, sources } from 'next/dist/compiled/webpack/webpack'
import {
PAGES_MANIFEST,
VIEW_PATHS_MANIFEST,
APP_PATHS_MANIFEST,
} from '../../../shared/lib/constants'
import getRouteFromEntrypoint from '../../../server/get-route-from-entrypoint'
import { normalizePathSep } from '../../../shared/lib/page-path/normalize-path-sep'
......@@ -20,23 +20,23 @@ export default class PagesManifestPlugin implements webpack.Plugin {
serverless: boolean
dev: boolean
isEdgeRuntime: boolean
rootEnabled: boolean
appDirEnabled: boolean
constructor({
serverless,
dev,
isEdgeRuntime,
rootEnabled,
appDirEnabled,
}: {
serverless: boolean
dev: boolean
isEdgeRuntime: boolean
rootEnabled: boolean
appDirEnabled: boolean
}) {
this.serverless = serverless
this.dev = dev
this.isEdgeRuntime = isEdgeRuntime
this.rootEnabled = rootEnabled
this.appDirEnabled = appDirEnabled
}
createAssets(compilation: any, assets: any) {
......@@ -45,7 +45,10 @@ export default class PagesManifestPlugin implements webpack.Plugin {
const rootPaths: PagesManifest = {}
for (const entrypoint of entrypoints.values()) {
const pagePath = getRouteFromEntrypoint(entrypoint.name, this.rootEnabled)
const pagePath = getRouteFromEntrypoint(
entrypoint.name,
this.appDirEnabled
)
if (!pagePath) {
continue
......@@ -74,7 +77,7 @@ export default class PagesManifestPlugin implements webpack.Plugin {
}
file = normalizePathSep(file)
if (entrypoint.name.startsWith('views/')) {
if (entrypoint.name.startsWith('app/')) {
rootPaths[pagePath] = file
} else {
pages[pagePath] = file
......@@ -104,9 +107,9 @@ export default class PagesManifestPlugin implements webpack.Plugin {
)
)
if (this.rootEnabled) {
if (this.appDirEnabled) {
assets[
`${!this.dev && !this.isEdgeRuntime ? '../' : ''}` + VIEW_PATHS_MANIFEST
`${!this.dev && !this.isEdgeRuntime ? '../' : ''}` + APP_PATHS_MANIFEST
] = new sources.RawSource(
JSON.stringify(
{
......
......@@ -194,17 +194,17 @@ const RSCComponent = (props: any) => {
)
}
const ViewRouterContext = React.createContext({})
const AppRouterContext = React.createContext({})
// TODO: move to client component when handling is implemented
function ViewRouter({ initialUrl, children }: any) {
function AppRouter({ initialUrl, children }: any) {
const initialState = {
url: initialUrl,
}
const previousUrlRef = React.useRef(initialState)
const [current, setCurrent] = React.useState(initialState)
const viewRouter = React.useMemo(() => {
const appRouter = React.useMemo(() => {
return {
push: (url: string) => {
previousUrlRef.current = current
......@@ -217,10 +217,10 @@ function ViewRouter({ initialUrl, children }: any) {
}, [current])
// @ts-ignore TODO: for testing
window.viewRouter = viewRouter
window.appRouter = appRouter
console.log({
viewRouter,
appRouter,
previous: previousUrlRef.current,
current,
})
......@@ -233,9 +233,9 @@ function ViewRouter({ initialUrl, children }: any) {
}
return (
<ViewRouterContext.Provider value={viewRouter}>
<AppRouterContext.Provider value={appRouter}>
{root ? root : children}
</ViewRouterContext.Provider>
</AppRouterContext.Provider>
)
}
......@@ -243,9 +243,9 @@ export function hydrate() {
renderReactElement(appElement!, () => (
<React.StrictMode>
<Root>
<ViewRouter initialUrl={location.pathname}>
<AppRouter initialUrl={location.pathname}>
<RSCComponent />
</ViewRouter>
</AppRouter>
</Root>
</React.StrictMode>
))
......
import { hydrate, version } from './views-index'
import { hydrate, version } from './app-index'
window.next = {
version,
......
......@@ -583,7 +583,7 @@ export default async function exportApp(
outDir,
pagesDataDir,
renderOpts,
viewsDir: nextConfig.experimental.viewsDir,
appDir: nextConfig.experimental.appDir,
serverRuntimeConfig,
subFolders,
buildExport: options.buildExport,
......
......@@ -60,7 +60,7 @@ interface ExportPageInput {
parentSpanId: any
httpAgentOptions: NextConfigComplete['httpAgentOptions']
serverComponents?: boolean
viewsDir?: boolean
appDir?: boolean
}
interface ExportPageResults {
......@@ -85,7 +85,7 @@ interface RenderOpts {
locale?: string
defaultLocale?: string
trailingSlash?: boolean
viewsDir?: boolean
appDir?: boolean
}
type ComponentModule = ComponentType<{}> & {
......@@ -99,7 +99,7 @@ export default async function exportPage({
pathMap,
distDir,
outDir,
viewsDir,
appDir,
pagesDataDir,
renderOpts,
buildExport,
......@@ -275,7 +275,7 @@ export default async function exportPage({
page,
serverless,
serverComponents,
viewsDir
appDir
)
const ampState = {
ampFirst: pageConfig?.amp === true,
......
......@@ -4,7 +4,7 @@ export type LayoutProps = {
children: any
}
export default function ViewsLayout({ children }: LayoutProps) {
export default function AppLayout({ children }: LayoutProps) {
return (
<html>
<head>
......
......@@ -28,7 +28,7 @@ export const MIDDLEWARE_FILE = `/${MIDDLEWARE_FILENAME}`
export const PAGES_DIR_ALIAS = 'private-next-pages'
export const DOT_NEXT_ALIAS = 'private-dot-next'
export const ROOT_DIR_ALIAS = 'private-next-root-dir'
export const VIEWS_DIR_ALIAS = 'private-next-views-dir'
export const APP_DIR_ALIAS = 'private-next-app-dir'
export const PUBLIC_DIR_MIDDLEWARE_CONFLICT = `You can not have a '_next' folder inside of your public folder. This conflicts with the internal '/_next' route. https://nextjs.org/docs/messages/public-next-folder-conflict`
......
......@@ -10,7 +10,7 @@ export const existsSync = (f: string): boolean => {
}
}
function findDir(dir: string, name: 'pages' | 'views'): string | null {
function findDir(dir: string, name: 'pages' | 'app'): string | null {
// prioritize ./${name} over ./src/${name}
let curDir = path.join(dir, name)
if (existsSync(curDir)) return curDir
......@@ -23,13 +23,13 @@ function findDir(dir: string, name: 'pages' | 'views'): string | null {
export function findPagesDir(
dir: string,
views?: boolean
): { pages: string; views?: string } {
appDirEnabled?: boolean
): { pages: string; appDir?: string } {
const pagesDir = findDir(dir, 'pages')
let viewsDir: undefined | string
let appDir: undefined | string
if (views) {
viewsDir = findDir(dir, 'views') || undefined
if (appDirEnabled) {
appDir = findDir(dir, 'app') || undefined
}
// TODO: allow "root" dir without pages dir
......@@ -41,6 +41,6 @@ export function findPagesDir(
return {
pages: pagesDir,
views: viewsDir,
appDir,
}
}
......@@ -161,10 +161,10 @@ function createServerComponentRenderer(
) {
// We need to expose the `__webpack_require__` API globally for
// react-server-dom-webpack. This is a hack until we find a better way.
if (ComponentMod.__next_view_webpack_require__ || ComponentMod.__next_rsc__) {
if (ComponentMod.__next_app_webpack_require__ || ComponentMod.__next_rsc__) {
// @ts-ignore
globalThis.__webpack_require__ = ComponentMod.__next_view_webpack_require__
? ComponentMod.__next_view_webpack_require__
globalThis.__webpack_require__ = ComponentMod.__next_app_webpack_require__
? ComponentMod.__next_app_webpack_require__
: ComponentMod.__next_rsc__.__webpack_require__
// @ts-ignore
......
......@@ -65,7 +65,7 @@ import { createHeaderRoute, createRedirectRoute } from './server-route-utils'
import { PrerenderManifest } from '../build'
import { ImageConfigComplete } from '../shared/lib/image-config'
import { replaceBasePath } from './router-utils'
import { normalizeViewPath } from '../shared/lib/router/utils/view-paths'
import { normalizeAppPath } from '../shared/lib/router/utils/app-paths'
import { getRouteMatcher } from '../shared/lib/router/utils/route-matcher'
import { getRouteRegex } from '../shared/lib/router/utils/route-regex'
......@@ -139,7 +139,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
protected publicDir: string
protected hasStaticDir: boolean
protected pagesManifest?: PagesManifest
protected viewPathsManifest?: PagesManifest
protected appPathsManifest?: PagesManifest
protected buildId: string
protected minimalMode: boolean
protected renderOpts: {
......@@ -179,7 +179,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
private responseCache: ResponseCache
protected router: Router
protected dynamicRoutes?: DynamicRoutes
protected viewPathRoutes?: Record<string, string>
protected appPathRoutes?: Record<string, string>
protected customRoutes: CustomRoutes
protected serverComponentManifest?: any
public readonly hostname?: string
......@@ -188,7 +188,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
protected abstract getPublicDir(): string
protected abstract getHasStaticDir(): boolean
protected abstract getPagesManifest(): PagesManifest | undefined
protected abstract getViewPathsManifest(): PagesManifest | undefined
protected abstract getAppPathsManifest(): PagesManifest | undefined
protected abstract getBuildId(): string
protected abstract generatePublicRoutes(): Route[]
protected abstract generateImageRoutes(): Route[]
......@@ -338,7 +338,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
})
this.pagesManifest = this.getPagesManifest()
this.viewPathsManifest = this.getViewPathsManifest()
this.appPathsManifest = this.getAppPathsManifest()
this.customRoutes = this.getCustomRoutes()
this.router = new Router(this.generateRoutes())
......@@ -851,7 +851,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
const { useFileSystemPublicRoutes } = this.nextConfig
if (useFileSystemPublicRoutes) {
this.viewPathRoutes = this.getViewPathRoutes()
this.appPathRoutes = this.getappPathRoutes()
this.dynamicRoutes = this.getDynamicRoutes()
}
......@@ -943,7 +943,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
return getSortedRoutes(
[
...Object.keys(this.viewPathRoutes || {}),
...Object.keys(this.appPathRoutes || {}),
...Object.keys(this.pagesManifest!),
].map(
(page) =>
......@@ -961,20 +961,20 @@ export default abstract class Server<ServerOptions extends Options = Options> {
.filter((item): item is RoutingItem => Boolean(item))
}
protected getViewPathRoutes(): Record<string, string> {
const viewPathRoutes: Record<string, string> = {}
protected getappPathRoutes(): Record<string, string> {
const appPathRoutes: Record<string, string> = {}
Object.keys(this.viewPathsManifest || {}).forEach((entry) => {
viewPathRoutes[normalizeViewPath(entry)] = entry
Object.keys(this.appPathsManifest || {}).forEach((entry) => {
appPathRoutes[normalizeAppPath(entry)] = entry
})
return viewPathRoutes
return appPathRoutes
}
protected getViewPathLayouts(pathname: string): string[] {
protected getappPathLayouts(pathname: string): string[] {
const layoutPaths: string[] = []
if (this.viewPathRoutes) {
const paths = Object.values(this.viewPathRoutes)
if (this.appPathRoutes) {
const paths = Object.values(this.appPathRoutes)
const parts = pathname.split('/').filter(Boolean)
for (let i = 1; i < parts.length; i++) {
......@@ -985,7 +985,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
}
}
if (this.viewPathRoutes['/layout']) {
if (this.appPathRoutes['/layout']) {
layoutPaths.unshift('/layout')
}
}
......@@ -1705,17 +1705,17 @@ export default abstract class Server<ServerOptions extends Options = Options> {
delete query._nextBubbleNoFallback
// map the route to the actual bundle name e.g.
// `/dashboard/rootonly/hello` -> `/dashboard+rootonly/hello`
const getOriginalViewPath = (viewPath: string) => {
if (this.nextConfig.experimental.viewsDir) {
const originalViewPath =
this.viewPathRoutes?.[`${viewPath}/index`] ||
this.viewPathRoutes?.[`${viewPath}`]
const getOriginalappPath = (appPath: string) => {
if (this.nextConfig.experimental.appDir) {
const originalappPath =
this.appPathRoutes?.[`${appPath}/index`] ||
this.appPathRoutes?.[`${appPath}`]
if (!originalViewPath) {
if (!originalappPath) {
return null
}
return originalViewPath
return originalappPath
}
return null
}
......@@ -1724,10 +1724,10 @@ export default abstract class Server<ServerOptions extends Options = Options> {
// Ensure a request to the URL /accounts/[id] will be treated as a dynamic
// route correctly and not loaded immediately without parsing params.
if (!isDynamicRoute(pathname)) {
const viewPath = getOriginalViewPath(pathname)
const appPath = getOriginalappPath(pathname)
if (typeof viewPath === 'string') {
page = viewPath
if (typeof appPath === 'string') {
page = appPath
}
const result = await this.findPageComponents(page, query)
if (result) {
......@@ -1750,10 +1750,10 @@ export default abstract class Server<ServerOptions extends Options = Options> {
continue
}
page = dynamicRoute.page
const viewPath = getOriginalViewPath(page)
const appPath = getOriginalappPath(page)
if (typeof viewPath === 'string') {
page = viewPath
if (typeof appPath === 'string') {
page = appPath
}
const dynamicRouteResult = await this.findPageComponents(
......
......@@ -99,7 +99,7 @@ export interface ExperimentalConfig {
scrollRestoration?: boolean
externalDir?: boolean
conformance?: boolean
viewsDir?: boolean
appDir?: boolean
amp?: {
optimizer?: any
validator?: string
......@@ -501,7 +501,7 @@ export const defaultConfig: NextConfig = {
swcFileReading: true,
craCompat: false,
esmExternals: true,
viewsDir: false,
appDir: false,
// default to 50MB limit
isrMemoryCacheSize: 50 * 1024 * 1024,
serverComponents: false,
......
......@@ -11,7 +11,7 @@ import {
finalizeEntrypoint,
getClientEntry,
getEdgeServerEntry,
getViewsEntry,
getAppEntry,
runDependingOnPageType,
} from '../../build/entries'
import { watchCompilers } from '../../build/output'
......@@ -19,7 +19,7 @@ import getBaseWebpackConfig from '../../build/webpack-config'
import {
API_ROUTE,
MIDDLEWARE_FILENAME,
VIEWS_DIR_ALIAS,
APP_DIR_ALIAS,
} from '../../lib/constants'
import { recursiveDelete } from '../../lib/recursive-delete'
import { BLOCKED_PAGES } from '../../shared/lib/constants'
......@@ -175,7 +175,7 @@ export default class HotReloader {
private fallbackWatcher: any
private hotReloaderSpan: Span
private pagesMapping: { [key: string]: string } = {}
private viewsDir?: string
private appDir?: string
constructor(
dir: string,
......@@ -186,7 +186,7 @@ export default class HotReloader {
buildId,
previewProps,
rewrites,
viewsDir,
appDir,
}: {
config: NextConfigComplete
pagesDir: string
......@@ -194,14 +194,14 @@ export default class HotReloader {
buildId: string
previewProps: __ApiPreviewProps
rewrites: CustomRoutes['rewrites']
viewsDir?: string
appDir?: string
}
) {
this.buildId = buildId
this.dir = dir
this.middlewares = []
this.pagesDir = pagesDir
this.viewsDir = viewsDir
this.appDir = appDir
this.distDir = distDir
this.clientStats = null
this.serverStats = null
......@@ -437,7 +437,7 @@ export default class HotReloader {
pagesDir: this.pagesDir,
rewrites: this.rewrites,
runWebpackSpan: this.hotReloaderSpan,
viewsDir: this.viewsDir,
appDir: this.appDir,
}
return webpackConfigSpan
......@@ -633,14 +633,14 @@ export default class HotReloader {
name: bundlePath,
isServerComponent,
value:
this.viewsDir && bundlePath.startsWith('views/')
? getViewsEntry({
this.appDir && bundlePath.startsWith('app/')
? getAppEntry({
name: bundlePath,
pagePath: join(
VIEWS_DIR_ALIAS,
relative(this.viewsDir!, absolutePagePath)
APP_DIR_ALIAS,
relative(this.appDir!, absolutePagePath)
),
viewsDir: this.viewsDir!,
appDir: this.appDir!,
pageExtensions: this.config.pageExtensions,
})
: request,
......@@ -889,7 +889,7 @@ export default class HotReloader {
multiCompiler,
watcher: this.watcher,
pagesDir: this.pagesDir,
viewsDir: this.viewsDir,
appDir: this.appDir,
rootDir: this.dir,
nextConfig: this.config,
...(this.config.onDemandEntries as {
......
......@@ -67,7 +67,7 @@ import { runDependingOnPageType } from '../../build/entries'
import { NodeNextResponse, NodeNextRequest } from '../base-http/node'
import { getPageStaticInfo } from '../../build/analysis/get-page-static-info'
import { normalizePathSep } from '../../shared/lib/page-path/normalize-path-sep'
import { normalizeViewPath } from '../../shared/lib/router/utils/view-paths'
import { normalizeAppPath } from '../../shared/lib/router/utils/app-paths'
import { MIDDLEWARE_FILE } from '../../lib/constants'
// Load ReactDevOverlay only when needed
......@@ -100,7 +100,7 @@ export default class DevServer extends Server {
protected sortedRoutes?: string[]
private addedUpgradeListener = false
private pagesDir: string
private viewsDir?: string
private appDir?: string
/**
* Since the dev server is stateful and middleware routes can be added and
......@@ -188,12 +188,12 @@ export default class DevServer extends Server {
this.isCustomServer = !options.isNextDevCommand
// TODO: hot-reload root/pages dirs?
const { pages: pagesDir, views: viewsDir } = findPagesDir(
const { pages: pagesDir, appDir } = findPagesDir(
this.dir,
this.nextConfig.experimental.viewsDir
this.nextConfig.experimental.appDir
)
this.pagesDir = pagesDir
this.viewsDir = viewsDir
this.appDir = appDir
}
protected getBuildId(): string {
......@@ -271,8 +271,8 @@ export default class DevServer extends Server {
let wp = (this.webpackWatcher = new Watchpack())
const pages = [this.pagesDir]
const views = this.viewsDir ? [this.viewsDir] : []
const directories = [...pages, ...views]
const app = this.appDir ? [this.appDir] : []
const directories = [...pages, ...app]
const files = this.nextConfig.pageExtensions.map((extension) =>
pathJoin(this.dir, `${MIDDLEWARE_FILENAME}.${extension}`)
)
......@@ -283,7 +283,7 @@ export default class DevServer extends Server {
const routedMiddleware: string[] = []
const routedPages: string[] = []
const knownFiles = wp.getTimeInfoEntries()
const viewPaths: Record<string, string> = {}
const appPaths: Record<string, string> = {}
const ssrMiddleware = new Set<string>()
for (const [fileName, meta] of knownFiles) {
......@@ -294,10 +294,10 @@ export default class DevServer extends Server {
continue
}
const isViewPath = Boolean(
this.viewsDir &&
const isAppPath = Boolean(
this.appDir &&
normalizePathSep(fileName).startsWith(
normalizePathSep(this.viewsDir)
normalizePathSep(this.appDir)
)
)
......@@ -312,16 +312,16 @@ export default class DevServer extends Server {
}
let pageName = absolutePathToPage(fileName, {
pagesDir: isViewPath ? this.viewsDir! : this.pagesDir,
pagesDir: isAppPath ? this.appDir! : this.pagesDir,
extensions: this.nextConfig.pageExtensions,
keepIndex: isViewPath,
keepIndex: isAppPath,
})
if (isViewPath) {
if (isAppPath) {
// TODO: should only routes ending in /index.js be route-able?
const originalPageName = pageName
pageName = normalizeViewPath(pageName)
viewPaths[pageName] = originalPageName
pageName = normalizeAppPath(pageName)
appPaths[pageName] = originalPageName
if (routedPages.includes(pageName)) {
continue
......@@ -360,7 +360,7 @@ export default class DevServer extends Server {
routedPages.push(pageName)
}
this.viewPathRoutes = viewPaths
this.appPathRoutes = appPaths
this.middleware = getSortedRoutes(routedMiddleware).map((page) => ({
match: getRouteMatcher(
getMiddlewareRegex(page, { catchAll: !ssrMiddleware.has(page) })
......@@ -422,7 +422,7 @@ export default class DevServer extends Server {
setGlobal('phase', PHASE_DEVELOPMENT_SERVER)
await verifyTypeScriptSetup(
this.dir,
[this.pagesDir!, this.viewsDir].filter(Boolean) as string[],
[this.pagesDir!, this.appDir].filter(Boolean) as string[],
false,
this.nextConfig.typescript.tsconfigPath,
this.nextConfig.images.disableStaticImages
......@@ -450,7 +450,7 @@ export default class DevServer extends Server {
previewProps: this.getPreviewProps(),
buildId: this.buildId,
rewrites,
viewsDir: this.viewsDir,
appDir: this.appDir,
})
await super.prepare()
await this.addExportPathMapRoutes()
......@@ -516,10 +516,10 @@ export default class DevServer extends Server {
).then(Boolean)
}
// check viewsDir first if enabled
if (this.viewsDir) {
// check appDir first if enabled
if (this.appDir) {
const pageFile = await findPageFile(
this.viewsDir,
this.appDir,
normalizedPath,
this.nextConfig.pageExtensions
)
......@@ -810,7 +810,7 @@ export default class DevServer extends Server {
return undefined
}
protected getViewPathsManifest(): undefined {
protected getAppPathsManifest(): undefined {
return undefined
}
......
......@@ -65,7 +65,7 @@ export function onDemandEntryHandler({
pagesBufferLength,
pagesDir,
rootDir,
viewsDir,
appDir,
watcher,
}: {
maxInactiveAge: number
......@@ -74,7 +74,7 @@ export function onDemandEntryHandler({
pagesBufferLength: number
pagesDir: string
rootDir: string
viewsDir?: string
appDir?: string
watcher: any
}) {
invalidator = new Invalidator(watcher)
......@@ -113,7 +113,7 @@ export function onDemandEntryHandler({
return invalidator.doneBuilding()
}
const [clientStats, serverStats, edgeServerStats] = multiStats.stats
const root = !!viewsDir
const root = !!appDir
const pagePaths = [
...getPagePathsFromEntrypoints(
'client',
......@@ -195,7 +195,7 @@ export function onDemandEntryHandler({
pagesDir,
page,
nextConfig.pageExtensions,
viewsDir
appDir
)
let entryAdded = false
......@@ -366,7 +366,7 @@ async function findPagePathData(
pagesDir: string,
page: string,
extensions: string[],
viewsDir?: string
appDir?: string
) {
const normalizedPagePath = tryToNormalizePagePath(page)
let pagePath: string | null = null
......@@ -391,9 +391,9 @@ async function findPagePathData(
}
}
// Check viewsDir first falling back to pagesDir
if (viewsDir) {
pagePath = await findPageFile(viewsDir, normalizedPagePath, extensions)
// Check appDir first falling back to pagesDir
if (appDir) {
pagePath = await findPageFile(appDir, normalizedPagePath, extensions)
if (pagePath) {
const pageUrl = ensureLeadingSlash(
removePagePathTail(normalizePathSep(pagePath), {
......@@ -403,8 +403,8 @@ async function findPagePathData(
)
return {
absolutePagePath: join(viewsDir, pagePath),
bundlePath: posix.join('views', normalizePagePath(pageUrl)),
absolutePagePath: join(appDir, pagePath),
bundlePath: posix.join('app', normalizePagePath(pageUrl)),
page: posix.normalize(pageUrl),
}
}
......
......@@ -2,8 +2,8 @@ import getRouteFromAssetPath from '../shared/lib/router/utils/get-route-from-ass
// matches pages/:page*.js
const SERVER_ROUTE_NAME_REGEX = /^pages[/\\](.*)$/
// matches root/:path*.js
const ROOT_ROUTE_NAME_REGEX = /^views[/\\](.*)$/
// matches app/:path*.js
const APP_ROUTE_NAME_REGEX = /^app[/\\](.*)$/
// matches static/pages/:page*.js
const BROWSER_ROUTE_NAME_REGEX = /^static[/\\]pages[/\\](.*)$/
......@@ -19,7 +19,7 @@ function matchBundle(regex: RegExp, input: string): string | null {
export default function getRouteFromEntrypoint(
entryFile: string,
root?: boolean
app?: boolean
): string | null {
let pagePath = matchBundle(SERVER_ROUTE_NAME_REGEX, entryFile)
......@@ -27,8 +27,8 @@ export default function getRouteFromEntrypoint(
return pagePath
}
if (root) {
pagePath = matchBundle(ROOT_ROUTE_NAME_REGEX, entryFile)
if (app) {
pagePath = matchBundle(APP_ROUTE_NAME_REGEX, entryFile)
if (pagePath) return pagePath
}
......
......@@ -40,7 +40,7 @@ export type LoadComponentsReturnType = {
getStaticPaths?: GetStaticPaths
getServerSideProps?: GetServerSideProps
ComponentMod: any
isViewPath?: boolean
isAppPath?: boolean
}
export async function loadDefaultErrorComponents(distDir: string) {
......@@ -66,7 +66,7 @@ export async function loadComponents(
pathname: string,
serverless: boolean,
hasServerComponents?: boolean,
rootEnabled?: boolean
appDirEnabled?: boolean
): Promise<LoadComponentsReturnType> {
if (serverless) {
const ComponentMod = await requirePage(pathname, distDir, serverless)
......@@ -103,13 +103,13 @@ export async function loadComponents(
const [DocumentMod, AppMod, ComponentMod] = await Promise.all([
Promise.resolve().then(() =>
requirePage('/_document', distDir, serverless, rootEnabled)
requirePage('/_document', distDir, serverless, appDirEnabled)
),
Promise.resolve().then(() =>
requirePage('/_app', distDir, serverless, rootEnabled)
requirePage('/_app', distDir, serverless, appDirEnabled)
),
Promise.resolve().then(() =>
requirePage(pathname, distDir, serverless, rootEnabled)
requirePage(pathname, distDir, serverless, appDirEnabled)
),
])
......@@ -129,7 +129,7 @@ export async function loadComponents(
normalizePagePath(pathname) + NEXT_CLIENT_SSR_ENTRY_SUFFIX,
distDir,
serverless,
rootEnabled
appDirEnabled
)
} catch (_) {
// This page might not be a server component page, so there is no
......@@ -143,18 +143,18 @@ export async function loadComponents(
const { getServerSideProps, getStaticProps, getStaticPaths } = ComponentMod
let isViewPath = false
let isAppPath = false
if (rootEnabled) {
if (appDirEnabled) {
const pagePath = getPagePath(
pathname,
distDir,
serverless,
false,
undefined,
rootEnabled
appDirEnabled
)
isViewPath = !!pagePath?.match(/server[/\\]views[/\\]/)
isAppPath = !!pagePath?.match(/server[/\\]app[/\\]/)
}
return {
......@@ -169,6 +169,6 @@ export async function loadComponents(
getStaticProps,
getStaticPaths,
serverComponentManifest,
isViewPath,
isAppPath,
}
}
......@@ -30,7 +30,7 @@ import {
ROUTES_MANIFEST,
MIDDLEWARE_FLIGHT_MANIFEST,
CLIENT_PUBLIC_FILES_PATH,
VIEW_PATHS_MANIFEST,
APP_PATHS_MANIFEST,
} from '../shared/lib/constants'
import { recursiveReadDirSync } from './lib/recursive-readdir-sync'
import { format as formatUrl, UrlWithParsedQuery } from 'url'
......@@ -45,7 +45,7 @@ import { getExtension, serveStatic } from './serve-static'
import { ParsedUrlQuery } from 'querystring'
import { apiResolver } from './api-utils/node'
import { RenderOpts, renderToHTML } from './render'
import { renderToHTML as viewRenderToHTML } from './view-render'
import { renderToHTML as appRenderToHTML } from './app-render'
import { ParsedUrl, parseUrl } from '../shared/lib/router/utils/parse-url'
import * as Log from '../build/output/log'
......@@ -167,13 +167,10 @@ export default class NextNodeServer extends BaseServer {
return require(join(this.serverDistDir, PAGES_MANIFEST))
}
protected getViewPathsManifest(): PagesManifest | undefined {
if (this.nextConfig.experimental.viewsDir) {
const viewPathsManifestPath = join(
this.serverDistDir,
VIEW_PATHS_MANIFEST
)
return require(viewPathsManifestPath)
protected getAppPathsManifest(): PagesManifest | undefined {
if (this.nextConfig.experimental.appDir) {
const appPathsManifestPath = join(this.serverDistDir, APP_PATHS_MANIFEST)
return require(appPathsManifestPath)
}
}
......@@ -592,8 +589,8 @@ export default class NextNodeServer extends BaseServer {
// https://github.com/vercel/next.js/blob/df7cbd904c3bd85f399d1ce90680c0ecf92d2752/packages/next/server/render.tsx#L947-L952
renderOpts.serverComponentManifest = this.serverComponentManifest
if (renderOpts.isViewPath) {
return viewRenderToHTML(
if (renderOpts.isAppPath) {
return appRenderToHTML(
req.originalRequest,
res.originalResponse,
pathname,
......@@ -650,7 +647,7 @@ export default class NextNodeServer extends BaseServer {
this._isLikeServerless,
this.renderOpts.dev,
locales,
this.nextConfig.experimental.viewsDir
this.nextConfig.experimental.appDir
)
}
......@@ -681,7 +678,7 @@ export default class NextNodeServer extends BaseServer {
pagePath!,
!this.renderOpts.dev && this._isLikeServerless,
this.renderOpts.serverComponents,
this.nextConfig.experimental.viewsDir
this.nextConfig.experimental.appDir
)
if (
......
......@@ -5,7 +5,7 @@ import {
PAGES_MANIFEST,
SERVER_DIRECTORY,
SERVERLESS_DIRECTORY,
VIEW_PATHS_MANIFEST,
APP_PATHS_MANIFEST,
} from '../shared/lib/constants'
import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path'
import { normalizePagePath } from '../shared/lib/page-path/normalize-page-path'
......@@ -24,7 +24,7 @@ export function getPagePath(
serverless: boolean,
dev?: boolean,
locales?: string[],
rootEnabled?: boolean
appDirEnabled?: boolean
): string {
const serverBuildPath = join(
distDir,
......@@ -32,11 +32,11 @@ export function getPagePath(
)
let rootPathsManifest: undefined | PagesManifest
if (rootEnabled) {
if (appDirEnabled) {
if (page === '/_root') {
return join(serverBuildPath, 'root.js')
}
rootPathsManifest = require(join(serverBuildPath, VIEW_PATHS_MANIFEST))
rootPathsManifest = require(join(serverBuildPath, APP_PATHS_MANIFEST))
}
const pagesManifest = require(join(
serverBuildPath,
......@@ -84,7 +84,7 @@ export function requirePage(
page: string,
distDir: string,
serverless: boolean,
rootEnabled?: boolean
appDirEnabled?: boolean
): any {
const pagePath = getPagePath(
page,
......@@ -92,7 +92,7 @@ export function requirePage(
serverless,
false,
undefined,
rootEnabled
appDirEnabled
)
if (pagePath.endsWith('.html')) {
return promises.readFile(pagePath, 'utf8')
......
......@@ -94,7 +94,7 @@ export default class NextWebServer extends BaseServer<WebServerOptions> {
[this.serverOptions.webServerConfig.page]: '',
}
}
protected getViewPathsManifest() {
protected getAppPathsManifest() {
return {
[this.serverOptions.webServerConfig.page]: '',
}
......
......@@ -4,7 +4,7 @@ export const PHASE_PRODUCTION_SERVER = 'phase-production-server'
export const PHASE_DEVELOPMENT_SERVER = 'phase-development-server'
export const PHASE_TEST = 'phase-test'
export const PAGES_MANIFEST = 'pages-manifest.json'
export const VIEW_PATHS_MANIFEST = 'view-paths-manifest.json'
export const APP_PATHS_MANIFEST = 'app-paths-manifest.json'
export const BUILD_MANIFEST = 'build-manifest.json'
export const EXPORT_MARKER = 'export-marker.json'
export const EXPORT_DETAIL = 'export-detail.json'
......
// remove (name) from pathname as it's not considered for routing
export function normalizeViewPath(pathname: string) {
export function normalizeAppPath(pathname: string) {
let normalized = ''
const segments = pathname.split('/')
......
module.exports = {
experimental: {
viewsDir: true,
appDir: true,
runtime: 'nodejs',
reactRoot: true,
serverComponents: true,
......
module.exports = {
experimental: {
viewsDir: true,
appDir: true,
runtime: 'nodejs',
reactRoot: true,
serverComponents: true,
......
......@@ -22,7 +22,7 @@ describe('views dir', () => {
files: {
public: new FileRef(path.join(__dirname, 'app/public')),
pages: new FileRef(path.join(__dirname, 'app/pages')),
views: new FileRef(path.join(__dirname, 'app/views')),
app: new FileRef(path.join(__dirname, 'app/app')),
'next.config.js': new FileRef(
path.join(__dirname, 'app/next.config.js')
),
......
......@@ -21,7 +21,7 @@ describe('views dir rendering', () => {
beforeAll(async () => {
next = await createNext({
files: {
views: new FileRef(path.join(__dirname, 'app-rendering/views')),
app: new FileRef(path.join(__dirname, 'app-rendering/app')),
pages: new FileRef(path.join(__dirname, 'app-rendering/pages')),
'next.config.js': new FileRef(
path.join(__dirname, 'app-rendering/next.config.js')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment