{"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":["BUILTIN_PREFIX","nextInternalPrefixRegex","normalizeFilePath","projectDir","filePath","cwd","process","env","NEXT_RUNTIME","relativeProjectRoot","replace","relativePath","startsWith","slice","length","includes","projectDirName","split","pop","projectDirWithSlash","idx","indexOf","normalizeConventionFilePath","conventionPath","test","isNextjsBuiltinFilePath","BOUNDARY_SUFFIX","normalizeBoundaryFilename","filename","RegExp","BOUNDARY_PREFIX","isBoundaryFile","fileType","isBuiltinBoundaryFile","getBoundaryOriginFileType","getConventionPathByType","tree","dir","conventionType","modules","undefined"],"mappings":"AAEA,OAAO,MAAMA,iBAAiB,mBAAkB;AAEhD,MAAMC,0BACJ;AAEF;;;CAGC,GACD,OAAO,SAASC,kBACdC,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,EAChCJ,OAAO,CAAC,OAAO;IACpB;IAEA,mEAAmE;IACnE,yEAAyE;IACzE,6CAA6C;IAC7C,IAAIC,aAAaI,QAAQ,CAAC,MAAM;QAC9B,MAAMC,iBAAiBb,WAAWc,KAAK,CAAC,SAASC,GAAG,MAAM;QAC1D,IAAIF,gBAAgB;YAClB,MAAMG,sBAAsBH,iBAAiB;YAC7C,MAAMI,MAAMT,aAAaU,O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