create project

This commit is contained in:
ismailsosic
2022-12-27 12:05:56 +01:00
parent 2a33a2d3de
commit cd2143287c
16035 changed files with 2489703 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
/**
* 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`
*
* @param filepath Absolute path to the page.
* @param opts.pagesDir Absolute path to the pages folder.
* @param opts.extensions Extensions allowed for the page.
* @param opts.keepIndex When true the trailing `index` kept in the path.
*/
export declare function absolutePathToPage(pagePath: string, options: {
extensions: string[];
keepIndex?: boolean;
pagesDir: string;
}): string;

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.absolutePathToPage = absolutePathToPage;
var _ensureLeadingSlash = require("./ensure-leading-slash");
var _normalizePathSep = require("./normalize-path-sep");
var _path = require("../isomorphic/path");
var _removePagePathTail = require("./remove-page-path-tail");
function absolutePathToPage(pagePath, options) {
return (0, _removePagePathTail).removePagePathTail((0, _normalizePathSep).normalizePathSep((0, _ensureLeadingSlash).ensureLeadingSlash((0, _path).relative(options.pagesDir, pagePath))), {
extensions: options.extensions,
keepIndex: options.keepIndex
});
}
//# sourceMappingURL=absolute-path-to-page.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../shared/lib/page-path/absolute-path-to-page.ts"],"names":["absolutePathToPage","pagePath","options","removePagePathTail","normalizePathSep","ensureLeadingSlash","relative","pagesDir","extensions","keepIndex"],"mappings":"AAAA;;;;QAgBgBA,kBAAkB,GAAlBA,kBAAkB;AAhBC,IAAA,mBAAwB,WAAxB,wBAAwB,CAAA;AAC1B,IAAA,iBAAsB,WAAtB,sBAAsB,CAAA;AAC9B,IAAA,KAAoB,WAApB,oBAAoB,CAAA;AACV,IAAA,mBAAyB,WAAzB,yBAAyB,CAAA;AAarD,SAASA,kBAAkB,CAChCC,QAAgB,EAChBC,OAIC,EACD;IACA,OAAOC,CAAAA,GAAAA,mBAAkB,AAMxB,CAAA,mBANwB,CACvBC,CAAAA,GAAAA,iBAAgB,AAA0D,CAAA,iBAA1D,CAACC,CAAAA,GAAAA,mBAAkB,AAAsC,CAAA,mBAAtC,CAACC,CAAAA,GAAAA,KAAQ,AAA4B,CAAA,SAA5B,CAACJ,OAAO,CAACK,QAAQ,EAAEN,QAAQ,CAAC,CAAC,CAAC,EAC1E;QACEO,UAAU,EAAEN,OAAO,CAACM,UAAU;QAC9BC,SAAS,EAAEP,OAAO,CAACO,SAAS;KAC7B,CACF,CAAA;CACF"}

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,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.denormalizePagePath = denormalizePagePath;
var _utils = require("../router/utils");
var _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":["../../../../shared/lib/page-path/denormalize-page-path.ts"],"names":["denormalizePagePath","page","_page","normalizePathSep","startsWith","isDynamicRoute","slice"],"mappings":"AAAA;;;;QAWgBA,mBAAmB,GAAnBA,mBAAmB;AAXJ,IAAA,MAAiB,WAAjB,iBAAiB,CAAA;AACf,IAAA,iBAAsB,WAAtB,sBAAsB,CAAA;AAUhD,SAASA,mBAAmB,CAACC,IAAY,EAAE;IAChD,IAAIC,KAAK,GAAGC,CAAAA,GAAAA,iBAAgB,AAAM,CAAA,iBAAN,CAACF,IAAI,CAAC;IAClC,OAAOC,KAAK,CAACE,UAAU,CAAC,SAAS,CAAC,IAAI,CAACC,CAAAA,GAAAA,MAAc,AAAO,CAAA,eAAP,CAACH,KAAK,CAAC,GACxDA,KAAK,CAACI,KAAK,CAAC,CAAC,CAAC,GACdJ,KAAK,KAAK,QAAQ,GAClBA,KAAK,GACL,GAAG,CAAA;CACR"}

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,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ensureLeadingSlash = ensureLeadingSlash;
function ensureLeadingSlash(path) {
return path.startsWith('/') ? path : `/${path}`;
}
//# sourceMappingURL=ensure-leading-slash.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../shared/lib/page-path/ensure-leading-slash.ts"],"names":["ensureLeadingSlash","path","startsWith"],"mappings":"AAIA;;;;QAAgBA,kBAAkB,GAAlBA,kBAAkB;AAA3B,SAASA,kBAAkB,CAACC,IAAY,EAAE;IAC/C,OAAOA,IAAI,CAACC,UAAU,CAAC,GAAG,CAAC,GAAGD,IAAI,GAAG,CAAC,CAAC,EAAEA,IAAI,CAAC,CAAC,CAAA;CAChD"}

View File

@@ -0,0 +1,12 @@
/**
* 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]`]
*
* @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,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getPagePaths = getPagePaths;
var _denormalizePagePath = require("./denormalize-page-path");
var _flatten = require("../flatten");
var _path = require("../isomorphic/path");
function getPagePaths(normalizedPagePath, extensions, isAppDir) {
const page = (0, _denormalizePagePath).denormalizePagePath(normalizedPagePath);
return (0, _flatten).flatten(extensions.map((extension)=>{
const appPage = `${page}.${extension}`;
const folderIndexPage = (0, _path).join(page, `index.${extension}`);
if (!normalizedPagePath.endsWith('/index')) {
return isAppDir ? [
appPage
] : [
`${page}.${extension}`,
folderIndexPage
];
}
return [
isAppDir ? appPage : folderIndexPage
];
}));
}
//# sourceMappingURL=get-page-paths.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../shared/lib/page-path/get-page-paths.ts"],"names":["getPagePaths","normalizedPagePath","extensions","isAppDir","page","denormalizePagePath","flatten","map","extension","appPage","folderIndexPage","join","endsWith"],"mappings":"AAAA;;;;QAegBA,YAAY,GAAZA,YAAY;AAfQ,IAAA,oBAAyB,WAAzB,yBAAyB,CAAA;AACrC,IAAA,QAAY,WAAZ,YAAY,CAAA;AACf,IAAA,KAAoB,WAApB,oBAAoB,CAAA;AAalC,SAASA,YAAY,CAC1BC,kBAA0B,EAC1BC,UAAoB,EACpBC,QAAiB,EACjB;IACA,MAAMC,IAAI,GAAGC,CAAAA,GAAAA,oBAAmB,AAAoB,CAAA,oBAApB,CAACJ,kBAAkB,CAAC;IAEpD,OAAOK,CAAAA,GAAAA,QAAO,AAUb,CAAA,QAVa,CACZJ,UAAU,CAACK,GAAG,CAAC,CAACC,SAAS,GAAK;QAC5B,MAAMC,OAAO,GAAG,CAAC,EAAEL,IAAI,CAAC,CAAC,EAAEI,SAAS,CAAC,CAAC;QACtC,MAAME,eAAe,GAAGC,CAAAA,GAAAA,KAAI,AAA4B,CAAA,KAA5B,CAACP,IAAI,EAAE,CAAC,MAAM,EAAEI,SAAS,CAAC,CAAC,CAAC;QAExD,IAAI,CAACP,kBAAkB,CAACW,QAAQ,CAAC,QAAQ,CAAC,EAAE;YAC1C,OAAOT,QAAQ,GAAG;gBAACM,OAAO;aAAC,GAAG;gBAAC,CAAC,EAAEL,IAAI,CAAC,CAAC,EAAEI,SAAS,CAAC,CAAC;gBAAEE,eAAe;aAAC,CAAA;SACxE;QACD,OAAO;YAACP,QAAQ,GAAGM,OAAO,GAAGC,eAAe;SAAC,CAAA;KAC9C,CAAC,CACH,CAAA;CACF"}

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,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.normalizePagePath = normalizePagePath;
var _ensureLeadingSlash = require("./ensure-leading-slash");
var _utils = require("../router/utils");
var _utils1 = require("../utils");
function normalizePagePath(page) {
const normalized = (0, _ensureLeadingSlash).ensureLeadingSlash(/^\/index(\/|$)/.test(page) && !(0, _utils).isDynamicRoute(page) ? `/index${page}` : page === '/' ? '/index' : 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":["../../../../shared/lib/page-path/normalize-page-path.ts"],"names":["normalizePagePath","page","normalized","ensureLeadingSlash","test","isDynamicRoute","process","env","NEXT_RUNTIME","posix","require","resolvedPage","normalize","NormalizeError"],"mappings":"AAAA;;;;QAagBA,iBAAiB,GAAjBA,iBAAiB;AAbE,IAAA,mBAAwB,WAAxB,wBAAwB,CAAA;AAC5B,IAAA,MAAiB,WAAjB,iBAAiB,CAAA;AACjB,IAAA,OAAU,WAAV,UAAU,CAAA;AAWlC,SAASA,iBAAiB,CAACC,IAAY,EAAU;IACtD,MAAMC,UAAU,GAAGC,CAAAA,GAAAA,mBAAkB,AAMpC,CAAA,mBANoC,CACnC,iBAAiBC,IAAI,CAACH,IAAI,CAAC,IAAI,CAACI,CAAAA,GAAAA,MAAc,AAAM,CAAA,eAAN,CAACJ,IAAI,CAAC,GAChD,CAAC,MAAM,EAAEA,IAAI,CAAC,CAAC,GACfA,IAAI,KAAK,GAAG,GACZ,QAAQ,GACRA,IAAI,CACT;IAED,IAAIK,OAAO,CAACC,GAAG,CAACC,YAAY,KAAK,MAAM,EAAE;QACvC,MAAM,EAAEC,KAAK,CAAA,EAAE,GAAGC,OAAO,CAAC,MAAM,CAAC;QACjC,MAAMC,YAAY,GAAGF,KAAK,CAACG,SAAS,CAACV,UAAU,CAAC;QAChD,IAAIS,YAAY,KAAKT,UAAU,EAAE;YAC/B,MAAM,IAAIW,OAAc,eAAA,CACtB,CAAC,sCAAsC,EAAEX,UAAU,CAAC,CAAC,EAAES,YAAY,CAAC,CAAC,CACtE,CAAA;SACF;KACF;IAED,OAAOT,UAAU,CAAA;CAClB"}

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

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../shared/lib/page-path/normalize-path-sep.ts"],"names":["normalizePathSep","path","replace"],"mappings":"AAKA;;;;QAAgBA,gBAAgB,GAAhBA,gBAAgB;AAAzB,SAASA,gBAAgB,CAACC,IAAY,EAAU;IACrD,OAAOA,IAAI,CAACC,OAAO,QAAQ,GAAG,CAAC,CAAA;CAChC"}

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: string[];
keepIndex?: boolean;
}): string;

View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.removePagePathTail = removePagePathTail;
var _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":["../../../../shared/lib/page-path/remove-page-path-tail.ts"],"names":["removePagePathTail","pagePath","options","normalizePathSep","replace","RegExp","extensions","join","keepIndex"],"mappings":"AAAA;;;;QAagBA,kBAAkB,GAAlBA,kBAAkB;AAbD,IAAA,iBAAsB,WAAtB,sBAAsB,CAAA;AAahD,SAASA,kBAAkB,CAChCC,QAAgB,EAChBC,OAGC,EACD;IACAD,QAAQ,GAAGE,CAAAA,GAAAA,iBAAgB,AAAU,CAAA,iBAAV,CAACF,QAAQ,CAAC,CAACG,OAAO,CAC3C,IAAIC,MAAM,CAAC,CAAC,OAAO,EAAEH,OAAO,CAACI,UAAU,CAACC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EACtD,EAAE,CACH;IAED,IAAIL,OAAO,CAACM,SAAS,KAAK,IAAI,EAAE;QAC9BP,QAAQ,GAAGA,QAAQ,CAACG,OAAO,aAAa,EAAE,CAAC,IAAI,GAAG;KACnD;IAED,OAAOH,QAAQ,CAAA;CAChB"}