{"version":3,"sources":["../../../src/server/app-render/segment-explorer-path.ts"],"sourcesContent":["import type { LoaderTree } from '../lib/app-dir-module'\n\nexport const BUILTIN_PREFIX = '__next_builtin__'\n\nconst nextInternalPrefixRegex =\n  /^(.*[\\\\/])?next[\\\\/]dist[\\\\/]client[\\\\/]components[\\\\/]builtin[\\\\/]/\n\n/**\n * Normalize a file path to be relative to the project directory.\n * Handles Turbopack [project] prefix and monorepo setups.\n */\nexport function normalizeFilePath(\n  projectDir: string,\n  filePath: string | undefined\n): string {\n  // Turbopack project path is formed as: \"<project root>/<cwd>\".\n  // When project root is not the working directory, we can extract the relative project root path.\n  // This is mostly used for running Next.js inside a monorepo.\n  const cwd = process.env.NEXT_RUNTIME === 'edge' ? '' : process.cwd()\n  const relativeProjectRoot = projectDir.replace(cwd, '').replace(/^[\\\\/]/, '')\n\n  let relativePath = (filePath || '')\n    // remove turbopack [project] prefix\n    .replace(/^\\[project\\][\\\\/]?/, '')\n    // remove the project root from the path (absolute)\n    .replace(projectDir, '')\n    // remove cwd prefix (absolute)\n    .replace(cwd, '')\n    // normalize path separators and remove leading slash\n    .replace(/\\\\/g, '/')\n    .replace(/^\\//, '')\n\n  // remove relative project path prefix (e.g., \"test/e2e/app-dir/actions/\")\n  if (relativeProjectRoot && relativePath.startsWith(relativeProjectRoot)) {\n    relativePath = relativePath\n      .slice(relativeProjectRoot.length)\n      .replace(/^\\//, '')\n  }\n\n  // Handle case where filename is relative to a parent of projectDir\n  // (e.g., in tests where filename is \"test/tmp/next-test-XXX/app/page.js\"\n  // but projectDir is the test temp directory)\n  if (relativePath.includes('/')) {\n    const projectDirName = projectDir.split(/[\\\\/]/).pop() || ''\n    if (projectDirName) {\n      const projectDirWithSlash = projectDirName + '/'\n      const idx = relativePath.indexOf(projectDirWithSlash)\n      if (idx >= 0) {\n        relativePath = relativePath.slice(idx + projectDirWithSlash.length)\n      }\n    }\n  }\n\n  return relativePath\n}\n\nexport function normalizeConventionFilePath(\n  projectDir: string,\n  conventionPath: string | undefined\n) {\n  let relativePath = normalizeFilePath(projectDir, conventionPath)\n    // remove /(src/)?app/ dir prefix\n    .replace(/^(src\\/)?app\\//, '')\n\n  // If it's internal file only keep the filename, strip nextjs internal prefix\n  if (nextInternalPrefixRegex.test(relativePath)) {\n    relativePath = relativePath.replace(nextInternalPrefixRegex, '')\n    // Add a special prefix to let segment explorer know it's a built-in component\n    relativePath = `${BUILTIN_PREFIX}${relativePath}`\n  }\n\n  return relativePath\n}\n\n// if a filepath is a builtin file. e.g.\n// .../project/node_modules/next/dist/client/components/builtin/global-error.js -> true\n// .../project/app/global-error.js -> false\nexport const isNextjsBuiltinFilePath = (filePath: string) => {\n  return nextInternalPrefixRegex.test(filePath)\n}\n\nexport const BOUNDARY_SUFFIX = '@boundary'\nexport function normalizeBoundaryFilename(filename: string) {\n  return filename\n    .replace(new RegExp(`^${BUILTIN_PREFIX}`), '')\n    .replace(new RegExp(`${BOUNDARY_SUFFIX}$`), '')\n}\n\nexport const BOUNDARY_PREFIX = 'boundary:'\nexport function isBoundaryFile(fileType: string) {\n  return fileType.startsWith(BOUNDARY_PREFIX)\n}\n\n// if a filename is a builtin file.\n// __next_builtin__global-error.js -> true\n// page.js -> false\nexport function isBuiltinBoundaryFile(fileType: string) {\n  return fileType.startsWith(BUILTIN_PREFIX)\n}\n\nexport function getBoundaryOriginFileType(fileType: string) {\n  return fileType.replace(BOUNDARY_PREFIX, '')\n}\n\nexport function getConventionPathByType(\n  tree: LoaderTree,\n  dir: string,\n  conventionType:\n    | 'layout'\n    | 'template'\n    | 'page'\n    | 'not-found'\n    | 'error'\n    | 'loading'\n    | 'forbidden'\n    | 'unauthorized'\n    | 'defaultPage'\n    | 'global-error'\n) {\n  const modules = tree[2]\n  const conventionPath = modules[conventionType]\n    ? modules[conventionType][1]\n    : undefined\n  if (conventionPath) {\n    return normalizeConventionFilePath(dir, conventionPath)\n  }\n  return undefined\n}\n"],"names":["BOUNDARY_PREFIX","BOUNDARY_SUFFIX","BUILTIN_PREFIX","getBoundaryOriginFileType","getConventionPathByType","isBoundaryFile","isBuiltinBoundaryFile","isNextjsBuiltinFilePath","normalizeBoundaryFilename","normalizeConventionFilePath","normalizeFilePath","nextInternalPrefixRegex","projectDir","filePath","cwd","process","env","NEXT_RUNTIME","relativeProjectRoot","replace","relativePath","startsWith","slice","length","includes","projectDirName","split","pop","projectDirWithSlash","idx","indexOf","conventionPath","test","filename","RegExp","fileType","tree","dir","conventionType","modules","undefined"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;IAwFaA,eAAe;eAAfA;;IAPAC,eAAe;eAAfA;;IA/EAC,cAAc;eAAdA;;IAkGGC,yBAAyB;eAAzBA;;IAIAC,uBAAuB;eAAvBA;;IAfAC,cAAc;eAAdA;;IAOAC,qBAAqB;eAArBA;;IAnBHC,uBAAuB;eAAvBA;;IAKGC,yBAAyB;eAAzBA;;IA1BAC,2BAA2B;eAA3BA;;IA7CAC,iBAAiB;eAAjBA;;;AATT,MAAMR,iBAAiB;AAE9B,MAAMS,0BACJ;AAMK,SAASD,kBACdE,UAAkB,EAClBC,QAA4B;IAE5B,+DAA+D;IAC/D,iGAAiG;IACjG,6DAA6D;IAC7D,MAAMC,MAAMC,QAAQC,GAAG,CAACC,YAAY,KAAK,SAAS,KAAKF,QAAQD,GAAG;IAClE,MAAMI,sBAAsBN,WAAWO,OAAO,CAACL,KAAK,IAAIK,OAAO,CAAC,UAAU;IAE1E,IAAIC,eAAe,AAACP,CAAAA,YAAY,EAAC,CAC/B,oCAAoC;KACnCM,OAAO,CAAC,sBAAsB,GAC/B,mDAAmD;KAClDA,OAAO,CAACP,YAAY,GACrB,+BAA+B;KAC9BO,OAAO,CAACL,KAAK,GACd,qDAAqD;KACpDK,OAAO,CAAC,OAAO,KACfA,OAAO,CAAC,OAAO;IAElB,0EAA0E;IAC1E,IAAID,uBAAuBE,aAAaC,UAAU,CAACH,sBAAsB;QACvEE,eAAeA,aACZE,KAAK,CAACJ,oBAAoBK,MAAM,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