including-modules

This commit is contained in:
Kismet Hasanaj
2026-05-03 00:14:08 +02:00
parent ec83a0d879
commit 39a8a128be
20434 changed files with 3906546 additions and 3 deletions
@@ -0,0 +1,29 @@
import { ensureLeadingSlash } from './ensure-leading-slash';
import { normalizePathSep } from './normalize-path-sep';
import path from '../isomorphic/path';
import { removePagePathTail } from './remove-page-path-tail';
import { normalizeMetadataRoute } from '../../../lib/metadata/get-metadata-route';
/**
* Given the absolute path to the pages folder, an absolute file path for a
* page and the page extensions, this function will return the page path
* relative to the pages folder. It doesn't consider index tail. Example:
* - `/Users/rick/my-project/pages/foo/bar/baz.js` -> `/foo/bar/baz`
*
* It also handles special metadata routes mapping. Example:
* - `/Users/rick/my-project/app/sitemap.js` -> `/sitemap/route`
*
* @param filepath Absolute path to the page.
* @param opts.dir Absolute path to the pages/app folder.
* @param opts.extensions Extensions allowed for the page.
* @param opts.keepIndex When true the trailing `index` kept in the path.
* @param opts.pagesType Whether the page is in the pages or app directory.
*/ export function absolutePathToPage(pagePath, options) {
const isAppDir = options.pagesType === 'app';
const page = removePagePathTail(normalizePathSep(ensureLeadingSlash(path.relative(options.dir, pagePath))), {
extensions: options.extensions,
keepIndex: options.keepIndex
});
return isAppDir ? normalizeMetadataRoute(page) : page;
}
//# sourceMappingURL=absolute-path-to-page.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/shared/lib/page-path/absolute-path-to-page.ts"],"sourcesContent":["import { ensureLeadingSlash } from './ensure-leading-slash'\nimport { normalizePathSep } from './normalize-path-sep'\nimport path from '../isomorphic/path'\nimport { removePagePathTail } from './remove-page-path-tail'\nimport { normalizeMetadataRoute } from '../../../lib/metadata/get-metadata-route'\nimport type { PAGE_TYPES } from '../../../lib/page-types'\n\n/**\n * Given the absolute path to the pages folder, an absolute file path for a\n * page and the page extensions, this function will return the page path\n * relative to the pages folder. It doesn't consider index tail. Example:\n * - `/Users/rick/my-project/pages/foo/bar/baz.js` -> `/foo/bar/baz`\n *\n * It also handles special metadata routes mapping. Example:\n * - `/Users/rick/my-project/app/sitemap.js` -> `/sitemap/route`\n *\n * @param filepath Absolute path to the page.\n * @param opts.dir Absolute path to the pages/app folder.\n * @param opts.extensions Extensions allowed for the page.\n * @param opts.keepIndex When true the trailing `index` kept in the path.\n * @param opts.pagesType Whether the page is in the pages or app directory.\n */\nexport function absolutePathToPage(\n pagePath: string,\n options: {\n extensions: string[] | readonly string[]\n keepIndex: boolean\n dir: string\n pagesType: PAGE_TYPES\n }\n) {\n const isAppDir = options.pagesType === 'app'\n const page = removePagePathTail(\n normalizePathSep(ensureLeadingSlash(path.relative(options.dir, pagePath))),\n {\n extensions: options.extensions,\n keepIndex: options.keepIndex,\n }\n )\n return isAppDir ? normalizeMetadataRoute(page) : page\n}\n"],"names":["ensureLeadingSlash","normalizePathSep","path","removePagePathTail","normalizeMetadataRoute","absolutePathToPage","pagePath","options","isAppDir","pagesType","page","relative","dir","extensions","keepIndex"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,yBAAwB;AAC3D,SAASC,gBAAgB,QAAQ,uBAAsB;AACvD,OAAOC,UAAU,qBAAoB;AACrC,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,sBAAsB,QAAQ,2CAA0C;AAGjF;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASC,mBACdC,QAAgB,EAChBC,OAKC;IAED,MAAMC,WAAWD,QAAQE,SAAS,KAAK;IACvC,MAAMC,OAAOP,mBACXF,iBAAiBD,mBAAmBE,KAAKS,QAAQ,CAACJ,QAAQK,GAAG,EAAEN,aAC/D;QACEO,YAAYN,QAAQM,UAAU;QAC9BC,WAAWP,QAAQO,SAAS;IAC9B;IAEF,OAAON,WAAWJ,uBAAuBM,QAAQA;AACnD","ignoreList":[0]}
@@ -0,0 +1,9 @@
export function denormalizeAppPagePath(page) {
// `/` is normalized to `/index`
if (page === '/index') {
return '/';
}
return page;
}
//# sourceMappingURL=denormalize-app-path.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/shared/lib/page-path/denormalize-app-path.ts"],"sourcesContent":["export function denormalizeAppPagePath(page: string): string {\n // `/` is normalized to `/index`\n if (page === '/index') {\n return '/'\n }\n\n return page\n}\n"],"names":["denormalizeAppPagePath","page"],"mappings":"AAAA,OAAO,SAASA,uBAAuBC,IAAY;IACjD,gCAAgC;IAChC,IAAIA,SAAS,UAAU;QACrB,OAAO;IACT;IAEA,OAAOA;AACT","ignoreList":[0]}
@@ -0,0 +1,15 @@
import { isDynamicRoute } from '../router/utils';
import { normalizePathSep } from './normalize-path-sep';
/**
* Performs the opposite transformation of `normalizePagePath`. Note that
* this function is not idempotent either in cases where there are multiple
* leading `/index` for the page. Examples:
* - `/index` -> `/`
* - `/index/foo` -> `/foo`
* - `/index/index` -> `/index`
*/ export function denormalizePagePath(page) {
let _page = normalizePathSep(page);
return _page.startsWith('/index/') && !isDynamicRoute(_page) ? _page.slice(6) : _page !== '/index' ? _page : '/';
}
//# sourceMappingURL=denormalize-page-path.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/shared/lib/page-path/denormalize-page-path.ts"],"sourcesContent":["import { isDynamicRoute } from '../router/utils'\nimport { normalizePathSep } from './normalize-path-sep'\n\n/**\n * Performs the opposite transformation of `normalizePagePath`. Note that\n * this function is not idempotent either in cases where there are multiple\n * leading `/index` for the page. Examples:\n * - `/index` -> `/`\n * - `/index/foo` -> `/foo`\n * - `/index/index` -> `/index`\n */\nexport function denormalizePagePath(page: string) {\n let _page = normalizePathSep(page)\n return _page.startsWith('/index/') && !isDynamicRoute(_page)\n ? _page.slice(6)\n : _page !== '/index'\n ? _page\n : '/'\n}\n"],"names":["isDynamicRoute","normalizePathSep","denormalizePagePath","page","_page","startsWith","slice"],"mappings":"AAAA,SAASA,cAAc,QAAQ,kBAAiB;AAChD,SAASC,gBAAgB,QAAQ,uBAAsB;AAEvD;;;;;;;CAOC,GACD,OAAO,SAASC,oBAAoBC,IAAY;IAC9C,IAAIC,QAAQH,iBAAiBE;IAC7B,OAAOC,MAAMC,UAAU,CAAC,cAAc,CAACL,eAAeI,SAClDA,MAAME,KAAK,CAAC,KACZF,UAAU,WACRA,QACA;AACR","ignoreList":[0]}
@@ -0,0 +1,8 @@
/**
* For a given page path, this function ensures that there is a leading slash.
* If there is not a leading slash, one is added, otherwise it is noop.
*/ export function ensureLeadingSlash(path) {
return path.startsWith('/') ? path : `/${path}`;
}
//# sourceMappingURL=ensure-leading-slash.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/shared/lib/page-path/ensure-leading-slash.ts"],"sourcesContent":["/**\n * For a given page path, this function ensures that there is a leading slash.\n * If there is not a leading slash, one is added, otherwise it is noop.\n */\nexport function ensureLeadingSlash(path: string) {\n return path.startsWith('/') ? path : `/${path}`\n}\n"],"names":["ensureLeadingSlash","path","startsWith"],"mappings":"AAAA;;;CAGC,GACD,OAAO,SAASA,mBAAmBC,IAAY;IAC7C,OAAOA,KAAKC,UAAU,CAAC,OAAOD,OAAO,CAAC,CAAC,EAAEA,MAAM;AACjD","ignoreList":[0]}
+40
View File
@@ -0,0 +1,40 @@
import { denormalizePagePath } from './denormalize-page-path';
import path 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]`] or `/route/route`
* to [`/route/route.[ext]`]
*
* @param normalizedPagePath Normalized page path (it will denormalize).
* @param extensions Allowed extensions.
*/ export function getPagePaths(normalizedPagePath, extensions, isAppDir) {
const page = denormalizePagePath(normalizedPagePath);
let prefixes;
if (isAppDir) {
prefixes = [
page
];
} else if (normalizedPagePath.endsWith('/index')) {
prefixes = [
path.join(page, 'index')
];
} else {
prefixes = [
page,
path.join(page, 'index')
];
}
const paths = [];
for (const extension of extensions){
for (const prefix of prefixes){
paths.push(`${prefix}.${extension}`);
}
}
return paths;
}
//# sourceMappingURL=get-page-paths.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/shared/lib/page-path/get-page-paths.ts"],"sourcesContent":["import { denormalizePagePath } from './denormalize-page-path'\nimport path from '../isomorphic/path'\n\n/**\n * Calculate all possible pagePaths for a given normalized pagePath along with\n * allowed extensions. This can be used to check which one of the files exists\n * and to debug inspected locations.\n *\n * For pages, map `/route` to [`/route.[ext]`, `/route/index.[ext]`]\n * For app paths, map `/route/page` to [`/route/page.[ext]`] or `/route/route`\n * to [`/route/route.[ext]`]\n *\n * @param normalizedPagePath Normalized page path (it will denormalize).\n * @param extensions Allowed extensions.\n */\nexport function getPagePaths(\n normalizedPagePath: string,\n extensions: string[],\n isAppDir: boolean\n) {\n const page = denormalizePagePath(normalizedPagePath)\n\n let prefixes: string[]\n if (isAppDir) {\n prefixes = [page]\n } else if (normalizedPagePath.endsWith('/index')) {\n prefixes = [path.join(page, 'index')]\n } else {\n prefixes = [page, path.join(page, 'index')]\n }\n\n const paths: string[] = []\n for (const extension of extensions) {\n for (const prefix of prefixes) {\n paths.push(`${prefix}.${extension}`)\n }\n }\n\n return paths\n}\n"],"names":["denormalizePagePath","path","getPagePaths","normalizedPagePath","extensions","isAppDir","page","prefixes","endsWith","join","paths","extension","prefix","push"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,0BAAyB;AAC7D,OAAOC,UAAU,qBAAoB;AAErC;;;;;;;;;;;CAWC,GACD,OAAO,SAASC,aACdC,kBAA0B,EAC1BC,UAAoB,EACpBC,QAAiB;IAEjB,MAAMC,OAAON,oBAAoBG;IAEjC,IAAII;IACJ,IAAIF,UAAU;QACZE,WAAW;YAACD;SAAK;IACnB,OAAO,IAAIH,mBAAmBK,QAAQ,CAAC,WAAW;QAChDD,WAAW;YAACN,KAAKQ,IAAI,CAACH,MAAM;SAAS;IACvC,OAAO;QACLC,WAAW;YAACD;YAAML,KAAKQ,IAAI,CAACH,MAAM;SAAS;IAC7C;IAEA,MAAMI,QAAkB,EAAE;IAC1B,KAAK,MAAMC,aAAaP,WAAY;QAClC,KAAK,MAAMQ,UAAUL,SAAU;YAC7BG,MAAMG,IAAI,CAAC,GAAGD,OAAO,CAAC,EAAED,WAAW;QACrC;IACF;IAEA,OAAOD;AACT","ignoreList":[0]}
+15
View File
@@ -0,0 +1,15 @@
import { pathHasPrefix } from '../router/utils/path-has-prefix';
/**
* strip _next/data/<build-id>/ prefix and .json suffix
*/ export function normalizeDataPath(pathname) {
if (!pathHasPrefix(pathname || '/', '/_next/data')) {
return pathname;
}
pathname = pathname.replace(/\/_next\/data\/[^/]{1,}/, '').replace(/\.json$/, '');
if (pathname === '/index') {
return '/';
}
return pathname;
}
//# sourceMappingURL=normalize-data-path.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/shared/lib/page-path/normalize-data-path.ts"],"sourcesContent":["import { pathHasPrefix } from '../router/utils/path-has-prefix'\n\n/**\n * strip _next/data/<build-id>/ prefix and .json suffix\n */\nexport function normalizeDataPath(pathname: string) {\n if (!pathHasPrefix(pathname || '/', '/_next/data')) {\n return pathname\n }\n pathname = pathname\n .replace(/\\/_next\\/data\\/[^/]{1,}/, '')\n .replace(/\\.json$/, '')\n\n if (pathname === '/index') {\n return '/'\n }\n return pathname\n}\n"],"names":["pathHasPrefix","normalizeDataPath","pathname","replace"],"mappings":"AAAA,SAASA,aAAa,QAAQ,kCAAiC;AAE/D;;CAEC,GACD,OAAO,SAASC,kBAAkBC,QAAgB;IAChD,IAAI,CAACF,cAAcE,YAAY,KAAK,gBAAgB;QAClD,OAAOA;IACT;IACAA,WAAWA,SACRC,OAAO,CAAC,2BAA2B,IACnCA,OAAO,CAAC,WAAW;IAEtB,IAAID,aAAa,UAAU;QACzB,OAAO;IACT;IACA,OAAOA;AACT","ignoreList":[0]}
+24
View File
@@ -0,0 +1,24 @@
import { ensureLeadingSlash } from './ensure-leading-slash';
import { isDynamicRoute } from '../router/utils';
import { NormalizeError } from '../utils';
/**
* Takes a page and transforms it into its file counterpart ensuring that the
* output is normalized. Note this function is not idempotent because a page
* `/index` can be referencing `/index/index.js` and `/index/index` could be
* referencing `/index/index/index.js`. Examples:
* - `/` -> `/index`
* - `/index/foo` -> `/index/index/foo`
* - `/index` -> `/index/index`
*/ export function normalizePagePath(page) {
const normalized = /^\/index(\/|$)/.test(page) && !isDynamicRoute(page) ? `/index${page}` : page === '/' ? '/index' : ensureLeadingSlash(page);
if (process.env.NEXT_RUNTIME !== 'edge') {
const { posix } = require('path');
const resolvedPage = posix.normalize(normalized);
if (resolvedPage !== normalized) {
throw new NormalizeError(`Requested and resolved page mismatch: ${normalized} ${resolvedPage}`);
}
}
return normalized;
}
//# sourceMappingURL=normalize-page-path.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/shared/lib/page-path/normalize-page-path.ts"],"sourcesContent":["import { ensureLeadingSlash } from './ensure-leading-slash'\nimport { isDynamicRoute } from '../router/utils'\nimport { NormalizeError } from '../utils'\n\n/**\n * Takes a page and transforms it into its file counterpart ensuring that the\n * output is normalized. Note this function is not idempotent because a page\n * `/index` can be referencing `/index/index.js` and `/index/index` could be\n * referencing `/index/index/index.js`. Examples:\n * - `/` -> `/index`\n * - `/index/foo` -> `/index/index/foo`\n * - `/index` -> `/index/index`\n */\nexport function normalizePagePath(page: string): string {\n const normalized =\n /^\\/index(\\/|$)/.test(page) && !isDynamicRoute(page)\n ? `/index${page}`\n : page === '/'\n ? '/index'\n : ensureLeadingSlash(page)\n\n if (process.env.NEXT_RUNTIME !== 'edge') {\n const { posix } = require('path') as typeof import('path')\n const resolvedPage = posix.normalize(normalized)\n if (resolvedPage !== normalized) {\n throw new NormalizeError(\n `Requested and resolved page mismatch: ${normalized} ${resolvedPage}`\n )\n }\n }\n\n return normalized\n}\n"],"names":["ensureLeadingSlash","isDynamicRoute","NormalizeError","normalizePagePath","page","normalized","test","process","env","NEXT_RUNTIME","posix","require","resolvedPage","normalize"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,yBAAwB;AAC3D,SAASC,cAAc,QAAQ,kBAAiB;AAChD,SAASC,cAAc,QAAQ,WAAU;AAEzC;;;;;;;;CAQC,GACD,OAAO,SAASC,kBAAkBC,IAAY;IAC5C,MAAMC,aACJ,iBAAiBC,IAAI,CAACF,SAAS,CAACH,eAAeG,QAC3C,CAAC,MAAM,EAAEA,MAAM,GACfA,SAAS,MACP,WACAJ,mBAAmBI;IAE3B,IAAIG,QAAQC,GAAG,CAACC,YAAY,KAAK,QAAQ;QACvC,MAAM,EAAEC,KAAK,EAAE,GAAGC,QAAQ;QAC1B,MAAMC,eAAeF,MAAMG,SAAS,CAACR;QACrC,IAAIO,iBAAiBP,YAAY;YAC/B,MAAM,IAAIH,eACR,CAAC,sCAAsC,EAAEG,WAAW,CAAC,EAAEO,cAAc;QAEzE;IACF;IAEA,OAAOP;AACT","ignoreList":[0]}
@@ -0,0 +1,9 @@
/**
* For a given page path, this function ensures that there is no backslash
* escaping slashes in the path. Example:
* - `foo\/bar\/baz` -> `foo/bar/baz`
*/ export function normalizePathSep(path) {
return path.replace(/\\/g, '/');
}
//# sourceMappingURL=normalize-path-sep.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/shared/lib/page-path/normalize-path-sep.ts"],"sourcesContent":["/**\n * For a given page path, this function ensures that there is no backslash\n * escaping slashes in the path. Example:\n * - `foo\\/bar\\/baz` -> `foo/bar/baz`\n */\nexport function normalizePathSep(path: string): string {\n return path.replace(/\\\\/g, '/')\n}\n"],"names":["normalizePathSep","path","replace"],"mappings":"AAAA;;;;CAIC,GACD,OAAO,SAASA,iBAAiBC,IAAY;IAC3C,OAAOA,KAAKC,OAAO,CAAC,OAAO;AAC7B","ignoreList":[0]}
@@ -0,0 +1,20 @@
import { normalizePathSep } from './normalize-path-sep';
/**
* Removes the file extension for a page and the trailing `index` if it exists
* making sure to not return an empty string. The page head is not touched
* and returned as it is passed. Examples:
* - `/foo/bar/baz/index.js` -> `/foo/bar/baz`
* - `/foo/bar/baz.js` -> `/foo/bar/baz`
*
* @param pagePath A page to a page file (absolute or relative)
* @param options.extensions Extensions allowed for the page.
* @param options.keepIndex When true the trailing `index` is _not_ removed.
*/ export function removePagePathTail(pagePath, options) {
pagePath = normalizePathSep(pagePath).replace(new RegExp(`\\.+(?:${options.extensions.join('|')})$`), '');
if (options.keepIndex !== true) {
pagePath = pagePath.replace(/\/index$/, '') || '/';
}
return pagePath;
}
//# sourceMappingURL=remove-page-path-tail.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/shared/lib/page-path/remove-page-path-tail.ts"],"sourcesContent":["import { normalizePathSep } from './normalize-path-sep'\n\n/**\n * Removes the file extension for a page and the trailing `index` if it exists\n * making sure to not return an empty string. The page head is not touched\n * and returned as it is passed. Examples:\n * - `/foo/bar/baz/index.js` -> `/foo/bar/baz`\n * - `/foo/bar/baz.js` -> `/foo/bar/baz`\n *\n * @param pagePath A page to a page file (absolute or relative)\n * @param options.extensions Extensions allowed for the page.\n * @param options.keepIndex When true the trailing `index` is _not_ removed.\n */\nexport function removePagePathTail(\n pagePath: string,\n options: {\n extensions: ReadonlyArray<string>\n keepIndex?: boolean\n }\n) {\n pagePath = normalizePathSep(pagePath).replace(\n new RegExp(`\\\\.+(?:${options.extensions.join('|')})$`),\n ''\n )\n\n if (options.keepIndex !== true) {\n pagePath = pagePath.replace(/\\/index$/, '') || '/'\n }\n\n return pagePath\n}\n"],"names":["normalizePathSep","removePagePathTail","pagePath","options","replace","RegExp","extensions","join","keepIndex"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,uBAAsB;AAEvD;;;;;;;;;;CAUC,GACD,OAAO,SAASC,mBACdC,QAAgB,EAChBC,OAGC;IAEDD,WAAWF,iBAAiBE,UAAUE,OAAO,CAC3C,IAAIC,OAAO,CAAC,OAAO,EAAEF,QAAQG,UAAU,CAACC,IAAI,CAAC,KAAK,EAAE,CAAC,GACrD;IAGF,IAAIJ,QAAQK,SAAS,KAAK,MAAM;QAC9BN,WAAWA,SAASE,OAAO,CAAC,YAAY,OAAO;IACjD;IAEA,OAAOF;AACT","ignoreList":[0]}