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,22 @@
import { ensureLeadingSlash } from './ensure-leading-slash';
import { normalizePathSep } from './normalize-path-sep';
import { relative } from '../isomorphic/path';
import { removePagePathTail } from './remove-page-path-tail';
/**
* 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 function absolutePathToPage(pagePath, options) {
return removePagePathTail(normalizePathSep(ensureLeadingSlash(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":["ensureLeadingSlash","normalizePathSep","relative","removePagePathTail","absolutePathToPage","pagePath","options","pagesDir","extensions","keepIndex"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,wBAAwB,CAAA;AAC3D,SAASC,gBAAgB,QAAQ,sBAAsB,CAAA;AACvD,SAASC,QAAQ,QAAQ,oBAAoB,CAAA;AAC7C,SAASC,kBAAkB,QAAQ,yBAAyB,CAAA;AAE5D;;;;;;;;;;GAUG,CACH,OAAO,SAASC,kBAAkB,CAChCC,QAAgB,EAChBC,OAIC,EACD;IACA,OAAOH,kBAAkB,CACvBF,gBAAgB,CAACD,kBAAkB,CAACE,QAAQ,CAACI,OAAO,CAACC,QAAQ,EAAEF,QAAQ,CAAC,CAAC,CAAC,EAC1E;QACEG,UAAU,EAAEF,OAAO,CAACE,UAAU;QAC9BC,SAAS,EAAEH,OAAO,CAACG,SAAS;KAC7B,CACF,CAAA;CACF"}

View File

@@ -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

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../shared/lib/page-path/denormalize-page-path.ts"],"names":["isDynamicRoute","normalizePathSep","denormalizePagePath","page","_page","startsWith","slice"],"mappings":"AAAA,SAASA,cAAc,QAAQ,iBAAiB,CAAA;AAChD,SAASC,gBAAgB,QAAQ,sBAAsB,CAAA;AAEvD;;;;;;;GAOG,CACH,OAAO,SAASC,mBAAmB,CAACC,IAAY,EAAE;IAChD,IAAIC,KAAK,GAAGH,gBAAgB,CAACE,IAAI,CAAC;IAClC,OAAOC,KAAK,CAACC,UAAU,CAAC,SAAS,CAAC,IAAI,CAACL,cAAc,CAACI,KAAK,CAAC,GACxDA,KAAK,CAACE,KAAK,CAAC,CAAC,CAAC,GACdF,KAAK,KAAK,QAAQ,GAClBA,KAAK,GACL,GAAG,CAAA;CACR"}

View File

@@ -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

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../shared/lib/page-path/ensure-leading-slash.ts"],"names":["ensureLeadingSlash","path","startsWith"],"mappings":"AAAA;;;GAGG,CACH,OAAO,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,33 @@
import { denormalizePagePath } from './denormalize-page-path';
import { flatten } from '../flatten';
import { join } 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]`]
*
* @param normalizedPagePath Normalized page path (it will denormalize).
* @param extensions Allowed extensions.
*/ export function getPagePaths(normalizedPagePath, extensions, isAppDir) {
const page = denormalizePagePath(normalizedPagePath);
return flatten(extensions.map((extension)=>{
const appPage = `${page}.${extension}`;
const folderIndexPage = 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":["denormalizePagePath","flatten","join","getPagePaths","normalizedPagePath","extensions","isAppDir","page","map","extension","appPage","folderIndexPage","endsWith"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,yBAAyB,CAAA;AAC7D,SAASC,OAAO,QAAQ,YAAY,CAAA;AACpC,SAASC,IAAI,QAAQ,oBAAoB,CAAA;AAEzC;;;;;;;;;;GAUG,CACH,OAAO,SAASC,YAAY,CAC1BC,kBAA0B,EAC1BC,UAAoB,EACpBC,QAAiB,EACjB;IACA,MAAMC,IAAI,GAAGP,mBAAmB,CAACI,kBAAkB,CAAC;IAEpD,OAAOH,OAAO,CACZI,UAAU,CAACG,GAAG,CAAC,CAACC,SAAS,GAAK;QAC5B,MAAMC,OAAO,GAAG,CAAC,EAAEH,IAAI,CAAC,CAAC,EAAEE,SAAS,CAAC,CAAC;QACtC,MAAME,eAAe,GAAGT,IAAI,CAACK,IAAI,EAAE,CAAC,MAAM,EAAEE,SAAS,CAAC,CAAC,CAAC;QAExD,IAAI,CAACL,kBAAkB,CAACQ,QAAQ,CAAC,QAAQ,CAAC,EAAE;YAC1C,OAAON,QAAQ,GAAG;gBAACI,OAAO;aAAC,GAAG;gBAAC,CAAC,EAAEH,IAAI,CAAC,CAAC,EAAEE,SAAS,CAAC,CAAC;gBAAEE,eAAe;aAAC,CAAA;SACxE;QACD,OAAO;YAACL,QAAQ,GAAGI,OAAO,GAAGC,eAAe;SAAC,CAAA;KAC9C,CAAC,CACH,CAAA;CACF"}

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 = ensureLeadingSlash(/^\/index(\/|$)/.test(page) && !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 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":["ensureLeadingSlash","isDynamicRoute","NormalizeError","normalizePagePath","page","normalized","test","process","env","NEXT_RUNTIME","posix","require","resolvedPage","normalize"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,wBAAwB,CAAA;AAC3D,SAASC,cAAc,QAAQ,iBAAiB,CAAA;AAChD,SAASC,cAAc,QAAQ,UAAU,CAAA;AAEzC;;;;;;;;GAQG,CACH,OAAO,SAASC,iBAAiB,CAACC,IAAY,EAAU;IACtD,MAAMC,UAAU,GAAGL,kBAAkB,CACnC,iBAAiBM,IAAI,CAACF,IAAI,CAAC,IAAI,CAACH,cAAc,CAACG,IAAI,CAAC,GAChD,CAAC,MAAM,EAAEA,IAAI,CAAC,CAAC,GACfA,IAAI,KAAK,GAAG,GACZ,QAAQ,GACRA,IAAI,CACT;IAED,IAAIG,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,CAACR,UAAU,CAAC;QAChD,IAAIO,YAAY,KAAKP,UAAU,EAAE;YAC/B,MAAM,IAAIH,cAAc,CACtB,CAAC,sCAAsC,EAAEG,UAAU,CAAC,CAAC,EAAEO,YAAY,CAAC,CAAC,CACtE,CAAA;SACF;KACF;IAED,OAAOP,UAAU,CAAA;CAClB"}

View File

@@ -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

View File

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

View File

@@ -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

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../shared/lib/page-path/remove-page-path-tail.ts"],"names":["normalizePathSep","removePagePathTail","pagePath","options","replace","RegExp","extensions","join","keepIndex"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,sBAAsB,CAAA;AAEvD;;;;;;;;;;GAUG,CACH,OAAO,SAASC,kBAAkB,CAChCC,QAAgB,EAChBC,OAGC,EACD;IACAD,QAAQ,GAAGF,gBAAgB,CAACE,QAAQ,CAAC,CAACE,OAAO,CAC3C,IAAIC,MAAM,CAAC,CAAC,OAAO,EAAEF,OAAO,CAACG,UAAU,CAACC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EACtD,EAAE,CACH;IAED,IAAIJ,OAAO,CAACK,SAAS,KAAK,IAAI,EAAE;QAC9BN,QAAQ,GAAGA,QAAQ,CAACE,OAAO,aAAa,EAAE,CAAC,IAAI,GAAG;KACnD;IAED,OAAOF,QAAQ,CAAA;CAChB"}