Next.js website for Rocky Mountain Vending company featuring: - Product catalog with Stripe integration - Service areas and parts pages - Admin dashboard with Clerk authentication - SEO optimized pages with JSON-LD structured data Co-authored-by: Cursor <cursoragent@cursor.com>
1 line
No EOL
9.3 KiB
Text
1 line
No EOL
9.3 KiB
Text
{"version":3,"sources":["../../../src/server/lib/find-page-file.ts"],"sourcesContent":["import { fileExists } from '../../lib/file-exists'\nimport { getPagePaths } from '../../shared/lib/page-path/get-page-paths'\nimport { nonNullable } from '../../lib/non-nullable'\nimport { join, sep, normalize } from 'path'\nimport { promises as fsPromises } from 'fs'\nimport { warn } from '../../build/output/log'\nimport { cyan } from '../../lib/picocolors'\nimport { isMetadataRouteFile } from '../../lib/metadata/is-metadata-route'\nimport type { PageExtensions } from '../../build/page-extensions-type'\n\nasync function isTrueCasePagePath(pagePath: string, pagesDir: string) {\n const pageSegments = normalize(pagePath).split(sep).filter(Boolean)\n const segmentExistsPromises = pageSegments.map(async (segment, i) => {\n const segmentParentDir = join(pagesDir, ...pageSegments.slice(0, i))\n const parentDirEntries = await fsPromises.readdir(segmentParentDir)\n return parentDirEntries.includes(segment)\n })\n\n return (await Promise.all(segmentExistsPromises)).every(Boolean)\n}\n\n/**\n * Finds a page file with the given parameters. If the page is duplicated with\n * multiple extensions it will throw, otherwise it will return the *relative*\n * path to the page file or null if it is not found.\n *\n * @param pagesDir Absolute path to the pages folder with trailing `/pages`.\n * @param normalizedPagePath The page normalized (it will be denormalized).\n * @param pageExtensions Array of page extensions.\n */\nexport async function findPageFile(\n pagesDir: string,\n normalizedPagePath: string,\n pageExtensions: PageExtensions,\n isAppDir: boolean\n): Promise<string | null> {\n const pagePaths = getPagePaths(normalizedPagePath, pageExtensions, isAppDir)\n const [existingPath, ...others] = (\n await Promise.all(\n pagePaths.map(async (path) => {\n const filePath = join(pagesDir, path)\n try {\n return (await fileExists(filePath)) ? path : null\n } catch (err: any) {\n if (!err?.code?.includes('ENOTDIR')) throw err\n }\n return null\n })\n )\n ).filter(nonNullable)\n\n if (!existingPath) {\n return null\n }\n\n if (!(await isTrueCasePagePath(existingPath, pagesDir))) {\n return null\n }\n\n if (others.length > 0) {\n warn(\n `Duplicate page detected. ${cyan(join('pages', existingPath))} and ${cyan(\n join('pages', others[0])\n )} both resolve to ${cyan(normalizedPagePath)}.`\n )\n }\n\n return existingPath\n}\n\n/**\n *\n * createValidFileMatcher receives configured page extensions and return helpers to determine:\n * `isLayoutsLeafPage`: if a file is a valid page file or routes file under app directory\n * `isTrackedFiles`: if it's a tracked file for webpack watcher\n *\n */\nexport function createValidFileMatcher(\n pageExtensions: PageExtensions,\n appDirPath: string | undefined\n) {\n const getExtensionRegexString = (extensions: string[]) =>\n `(?:${extensions.join('|')})`\n\n const validExtensionFileRegex = new RegExp(\n '\\\\.' + getExtensionRegexString(pageExtensions) + '$'\n )\n const leafOnlyPageFileRegex = new RegExp(\n `(^(page|route)|[\\\\\\\\/](page|route))\\\\.${getExtensionRegexString(\n pageExtensions\n )}$`\n )\n\n const leafOnlyRouteFileRegex = new RegExp(\n `(^route|[\\\\\\\\/]route)\\\\.${getExtensionRegexString(pageExtensions)}$`\n )\n const leafOnlyLayoutFileRegex = new RegExp(\n `(^(layout)|[\\\\\\\\/](layout))\\\\.${getExtensionRegexString(pageExtensions)}$`\n )\n const rootNotFoundFileRegex = new RegExp(\n `^not-found\\\\.${getExtensionRegexString(pageExtensions)}$`\n )\n const leafOnlyDefaultFileRegex = new RegExp(\n `(^(default)|[\\\\\\\\/](default))\\\\.${getExtensionRegexString(pageExtensions)}$`\n )\n /** TODO-METADATA: support other metadata routes\n * regex for:\n *\n * /robots.txt|<ext>\n * /sitemap.xml|<ext>\n * /favicon.ico\n * /manifest.json|<ext>\n * <route>/icon.png|jpg|<ext>\n * <route>/apple-touch-icon.png|jpg|<ext>\n *\n */\n\n /**\n * Match the file if it's a metadata route file, static: if the file is a static metadata file.\n * It needs to be a file which doesn't match the custom metadata routes e.g. `app/robots.txt/route.js`\n */\n function isMetadataFile(filePath: string) {\n const appDirRelativePath = appDirPath\n ? filePath.replace(appDirPath, '')\n : filePath\n\n return isMetadataRouteFile(appDirRelativePath, pageExtensions, true)\n }\n\n // Determine if the file is leaf node page file or route file under layouts,\n // 'page.<extension>' | 'route.<extension>'\n function isAppRouterPage(filePath: string) {\n return leafOnlyPageFileRegex.test(filePath) || isMetadataFile(filePath)\n }\n\n // Determine if the file is leaf node route file under app directory\n function isAppRouterRoute(filePath: string) {\n return leafOnlyRouteFileRegex.test(filePath)\n }\n\n function isAppLayoutPage(filePath: string) {\n return leafOnlyLayoutFileRegex.test(filePath)\n }\n\n function isAppDefaultPage(filePath: string) {\n return leafOnlyDefaultFileRegex.test(filePath)\n }\n\n function isPageFile(filePath: string) {\n return validExtensionFileRegex.test(filePath) || isMetadataFile(filePath)\n }\n\n function isRootNotFound(filePath: string) {\n if (!appDirPath) {\n return false\n }\n if (!filePath.startsWith(appDirPath + sep)) {\n return false\n }\n const rest = filePath.slice(appDirPath.length + 1)\n return rootNotFoundFileRegex.test(rest)\n }\n\n return {\n isPageFile,\n isAppRouterPage,\n isAppRouterRoute,\n isAppLayoutPage,\n isAppDefaultPage,\n isMetadataFile,\n isRootNotFound,\n }\n}\n"],"names":["fileExists","getPagePaths","nonNullable","join","sep","normalize","promises","fsPromises","warn","cyan","isMetadataRouteFile","isTrueCasePagePath","pagePath","pagesDir","pageSegments","split","filter","Boolean","segmentExistsPromises","map","segment","i","segmentParentDir","slice","parentDirEntries","readdir","includes","Promise","all","every","findPageFile","normalizedPagePath","pageExtensions","isAppDir","pagePaths","existingPath","others","path","filePath","err","code","length","createValidFileMatcher","appDirPath","getExtensionRegexString","extensions","validExtensionFileRegex","RegExp","leafOnlyPageFileRegex","leafOnlyRouteFileRegex","leafOnlyLayoutFileRegex","rootNotFoundFileRegex","leafOnlyDefaultFileRegex","isMetadataFile","appDirRelativePath","replace","isAppRouterPage","test","isAppRouterRoute","isAppLayoutPage","isAppDefaultPage","isPageFile","isRootNotFound","startsWith","r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