03eb4b1d61
Check `pagesDir` to bypass empty pages folder when appDir is enabled * Output empty loadable manifest for now if there's no `pagesDir` * No custom aliases with all page extensions for `/_app`, `_document` if pagesDir is empty, only keep the built-in ones * Check pagesDir in build/dev-server/eslint * Type safe: change arguments of some APIs from optional to required, so that we won't mess up with default arguments
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { denormalizePagePath } from './denormalize-page-path'
|
|
import { flatten } from '../flatten'
|
|
import { join } from '../isomorphic/path'
|
|
|
|
/**
|
|
* Calculate all possible pagePaths for a given normalized pagePath along with
|
|
* allowed extensions. This can be used to check which one of the files exists
|
|
* and to debug inspected locations.
|
|
*
|
|
* For pages, map `/route` to [`/route.[ext]`, `/route/index.[ext]`]
|
|
* For app paths, map `/route/page` to [`/route/page.[ext]`]
|
|
*
|
|
* @param normalizedPagePath Normalized page path (it will denormalize).
|
|
* @param extensions Allowed extensions.
|
|
*/
|
|
export function getPagePaths(
|
|
normalizedPagePath: string,
|
|
extensions: string[],
|
|
isAppDir: boolean
|
|
) {
|
|
const page = denormalizePagePath(normalizedPagePath)
|
|
|
|
return flatten(
|
|
extensions.map((extension) => {
|
|
const appPage = `${page}.${extension}`
|
|
const folderIndexPage = join(page, `index.${extension}`)
|
|
|
|
if (!normalizedPagePath.endsWith('/index')) {
|
|
return isAppDir ? [appPage] : [`${page}.${extension}`, folderIndexPage]
|
|
}
|
|
return [isAppDir ? appPage : folderIndexPage]
|
|
})
|
|
)
|
|
}
|