main repo

This commit is contained in:
Basilosaurusrex
2025-11-24 18:09:40 +01:00
parent b636ee5e70
commit f027651f9b
34146 changed files with 4436636 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
/**
* 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 declare function absolutePathToPage(pagePath: string, options: {
extensions: string[] | readonly string[];
keepIndex: boolean;
dir: string;
pagesType: 'pages' | 'app' | 'root';
}): string;

View File

@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "absolutePathToPage", {
enumerable: true,
get: function() {
return absolutePathToPage;
}
});
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
const _ensureleadingslash = require("./ensure-leading-slash");
const _normalizepathsep = require("./normalize-path-sep");
const _path = /*#__PURE__*/ _interop_require_default._(require("../isomorphic/path"));
const _removepagepathtail = require("./remove-page-path-tail");
const _getmetadataroute = require("../../../lib/metadata/get-metadata-route");
function absolutePathToPage(pagePath, options) {
const isAppDir = options.pagesType === "app";
const page = (0, _removepagepathtail.removePagePathTail)((0, _normalizepathsep.normalizePathSep)((0, _ensureleadingslash.ensureLeadingSlash)(_path.default.relative(options.dir, pagePath))), {
extensions: options.extensions,
keepIndex: options.keepIndex
});
return isAppDir ? (0, _getmetadataroute.normalizeMetadataRoute)(page) : page;
}
//# sourceMappingURL=absolute-path-to-page.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/shared/lib/page-path/absolute-path-to-page.ts"],"names":["absolutePathToPage","pagePath","options","isAppDir","pagesType","page","removePagePathTail","normalizePathSep","ensureLeadingSlash","path","relative","dir","extensions","keepIndex","normalizeMetadataRoute"],"mappings":";;;;+BAqBgBA;;;eAAAA;;;;oCArBmB;kCACF;+DAChB;oCACkB;kCACI;AAiBhC,SAASA,mBACdC,QAAgB,EAChBC,OAKC;IAED,MAAMC,WAAWD,QAAQE,SAAS,KAAK;IACvC,MAAMC,OAAOC,IAAAA,sCAAkB,EAC7BC,IAAAA,kCAAgB,EAACC,IAAAA,sCAAkB,EAACC,aAAI,CAACC,QAAQ,CAACR,QAAQS,GAAG,EAAEV,aAC/D;QACEW,YAAYV,QAAQU,UAAU;QAC9BC,WAAWX,QAAQW,SAAS;IAC9B;IAEF,OAAOV,WAAWW,IAAAA,wCAAsB,EAACT,QAAQA;AACnD"}

View File

@@ -0,0 +1 @@
export declare function denormalizeAppPagePath(page: string): string;

View File

@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "denormalizeAppPagePath", {
enumerable: true,
get: function() {
return denormalizeAppPagePath;
}
});
function denormalizeAppPagePath(page) {
// `/` is normalized to `/index`
if (page === "/index") {
return "/";
}
return page;
}
//# sourceMappingURL=denormalize-app-path.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/shared/lib/page-path/denormalize-app-path.ts"],"names":["denormalizeAppPagePath","page"],"mappings":";;;;+BAAgBA;;;eAAAA;;;AAAT,SAASA,uBAAuBC,IAAY;IACjD,gCAAgC;IAChC,IAAIA,SAAS,UAAU;QACrB,OAAO;IACT;IAEA,OAAOA;AACT"}

View File

@@ -0,0 +1,9 @@
/**
* 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 declare function denormalizePagePath(page: string): string;

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "denormalizePagePath", {
enumerable: true,
get: function() {
return denormalizePagePath;
}
});
const _utils = require("../router/utils");
const _normalizepathsep = require("./normalize-path-sep");
function denormalizePagePath(page) {
let _page = (0, _normalizepathsep.normalizePathSep)(page);
return _page.startsWith("/index/") && !(0, _utils.isDynamicRoute)(_page) ? _page.slice(6) : _page !== "/index" ? _page : "/";
}
//# sourceMappingURL=denormalize-page-path.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/shared/lib/page-path/denormalize-page-path.ts"],"names":["denormalizePagePath","page","_page","normalizePathSep","startsWith","isDynamicRoute","slice"],"mappings":";;;;+BAWgBA;;;eAAAA;;;uBAXe;kCACE;AAU1B,SAASA,oBAAoBC,IAAY;IAC9C,IAAIC,QAAQC,IAAAA,kCAAgB,EAACF;IAC7B,OAAOC,MAAME,UAAU,CAAC,cAAc,CAACC,IAAAA,qBAAc,EAACH,SAClDA,MAAMI,KAAK,CAAC,KACZJ,UAAU,WACVA,QACA;AACN"}

View File

@@ -0,0 +1,5 @@
/**
* 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 declare function ensureLeadingSlash(path: string): string;

View File

@@ -0,0 +1,18 @@
/**
* 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.
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "ensureLeadingSlash", {
enumerable: true,
get: function() {
return ensureLeadingSlash;
}
});
function ensureLeadingSlash(path) {
return path.startsWith("/") ? path : "/" + path;
}
//# sourceMappingURL=ensure-leading-slash.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/shared/lib/page-path/ensure-leading-slash.ts"],"names":["ensureLeadingSlash","path","startsWith"],"mappings":"AAAA;;;CAGC;;;;+BACeA;;;eAAAA;;;AAAT,SAASA,mBAAmBC,IAAY;IAC7C,OAAOA,KAAKC,UAAU,CAAC,OAAOD,OAAO,AAAC,MAAGA;AAC3C"}

View File

@@ -0,0 +1,13 @@
/**
* 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 declare function getPagePaths(normalizedPagePath: string, extensions: string[], isAppDir: boolean): string[];

View File

@@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "getPagePaths", {
enumerable: true,
get: function() {
return getPagePaths;
}
});
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
const _denormalizepagepath = require("./denormalize-page-path");
const _path = /*#__PURE__*/ _interop_require_default._(require("../isomorphic/path"));
function getPagePaths(normalizedPagePath, extensions, isAppDir) {
const page = (0, _denormalizepagepath.denormalizePagePath)(normalizedPagePath);
let prefixes;
if (isAppDir) {
prefixes = [
page
];
} else if (normalizedPagePath.endsWith("/index")) {
prefixes = [
_path.default.join(page, "index")
];
} else {
prefixes = [
page,
_path.default.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

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/shared/lib/page-path/get-page-paths.ts"],"names":["getPagePaths","normalizedPagePath","extensions","isAppDir","page","denormalizePagePath","prefixes","endsWith","path","join","paths","extension","prefix","push"],"mappings":";;;;+BAegBA;;;eAAAA;;;;qCAfoB;+DACnB;AAcV,SAASA,aACdC,kBAA0B,EAC1BC,UAAoB,EACpBC,QAAiB;IAEjB,MAAMC,OAAOC,IAAAA,wCAAmB,EAACJ;IAEjC,IAAIK;IACJ,IAAIH,UAAU;QACZG,WAAW;YAACF;SAAK;IACnB,OAAO,IAAIH,mBAAmBM,QAAQ,CAAC,WAAW;QAChDD,WAAW;YAACE,aAAI,CAACC,IAAI,CAACL,MAAM;SAAS;IACvC,OAAO;QACLE,WAAW;YAACF;YAAMI,aAAI,CAACC,IAAI,CAACL,MAAM;SAAS;IAC7C;IAEA,MAAMM,QAAkB,EAAE;IAC1B,KAAK,MAAMC,aAAaT,WAAY;QAClC,KAAK,MAAMU,UAAUN,SAAU;YAC7BI,MAAMG,IAAI,CAAC,AAAGD,SAAO,MAAGD;QAC1B;IACF;IAEA,OAAOD;AACT"}

View File

@@ -0,0 +1,10 @@
/**
* 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 declare function normalizePagePath(page: string): string;

View File

@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "normalizePagePath", {
enumerable: true,
get: function() {
return normalizePagePath;
}
});
const _ensureleadingslash = require("./ensure-leading-slash");
const _utils = require("../router/utils");
const _utils1 = require("../utils");
function normalizePagePath(page) {
const normalized = /^\/index(\/|$)/.test(page) && !(0, _utils.isDynamicRoute)(page) ? "/index" + page : page === "/" ? "/index" : (0, _ensureleadingslash.ensureLeadingSlash)(page);
if (process.env.NEXT_RUNTIME !== "edge") {
const { posix } = require("path");
const resolvedPage = posix.normalize(normalized);
if (resolvedPage !== normalized) {
throw new _utils1.NormalizeError("Requested and resolved page mismatch: " + normalized + " " + resolvedPage);
}
}
return normalized;
}
//# sourceMappingURL=normalize-page-path.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/shared/lib/page-path/normalize-page-path.ts"],"names":["normalizePagePath","page","normalized","test","isDynamicRoute","ensureLeadingSlash","process","env","NEXT_RUNTIME","posix","require","resolvedPage","normalize","NormalizeError"],"mappings":";;;;+BAagBA;;;eAAAA;;;oCAbmB;uBACJ;wBACA;AAWxB,SAASA,kBAAkBC,IAAY;IAC5C,MAAMC,aACJ,iBAAiBC,IAAI,CAACF,SAAS,CAACG,IAAAA,qBAAc,EAACH,QAC3C,AAAC,WAAQA,OACTA,SAAS,MACT,WACAI,IAAAA,sCAAkB,EAACJ;IAEzB,IAAIK,QAAQC,GAAG,CAACC,YAAY,KAAK,QAAQ;QACvC,MAAM,EAAEC,KAAK,EAAE,GAAGC,QAAQ;QAC1B,MAAMC,eAAeF,MAAMG,SAAS,CAACV;QACrC,IAAIS,iBAAiBT,YAAY;YAC/B,MAAM,IAAIW,sBAAc,CACtB,AAAC,2CAAwCX,aAAW,MAAGS;QAE3D;IACF;IAEA,OAAOT;AACT"}

View File

@@ -0,0 +1,6 @@
/**
* 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 declare function normalizePathSep(path: string): string;

View File

@@ -0,0 +1,19 @@
/**
* 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`
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "normalizePathSep", {
enumerable: true,
get: function() {
return normalizePathSep;
}
});
function normalizePathSep(path) {
return path.replace(/\\/g, "/");
}
//# sourceMappingURL=normalize-path-sep.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/shared/lib/page-path/normalize-path-sep.ts"],"names":["normalizePathSep","path","replace"],"mappings":"AAAA;;;;CAIC;;;;+BACeA;;;eAAAA;;;AAAT,SAASA,iBAAiBC,IAAY;IAC3C,OAAOA,KAAKC,OAAO,CAAC,OAAO;AAC7B"}

View File

@@ -0,0 +1,15 @@
/**
* 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 declare function removePagePathTail(pagePath: string, options: {
extensions: ReadonlyArray<string>;
keepIndex?: boolean;
}): string;

View File

@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "removePagePathTail", {
enumerable: true,
get: function() {
return removePagePathTail;
}
});
const _normalizepathsep = require("./normalize-path-sep");
function removePagePathTail(pagePath, options) {
pagePath = (0, _normalizepathsep.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

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/shared/lib/page-path/remove-page-path-tail.ts"],"names":["removePagePathTail","pagePath","options","normalizePathSep","replace","RegExp","extensions","join","keepIndex"],"mappings":";;;;+BAagBA;;;eAAAA;;;kCAbiB;AAa1B,SAASA,mBACdC,QAAgB,EAChBC,OAGC;IAEDD,WAAWE,IAAAA,kCAAgB,EAACF,UAAUG,OAAO,CAC3C,IAAIC,OAAO,AAAC,YAASH,QAAQI,UAAU,CAACC,IAAI,CAAC,OAAK,OAClD;IAGF,IAAIL,QAAQM,SAAS,KAAK,MAAM;QAC9BP,WAAWA,SAASG,OAAO,CAAC,YAAY,OAAO;IACjD;IAEA,OAAOH;AACT"}