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,65 @@
import type { DomainLocale, I18NConfig } from '../../config-shared';
import type { NextParsedUrlQuery } from '../../request-meta';
/**
* The result of matching a locale aware route.
*/
export interface LocaleAnalysisResult {
/**
* The pathname without the locale prefix (if any).
*/
pathname: string;
/**
* The detected locale. If no locale was detected, this will be `undefined`.
*/
detectedLocale?: string;
/**
* True if the locale was inferred from the default locale.
*/
inferredFromDefault: boolean;
}
type LocaleAnalysisOptions = {
/**
* When provided, it will be used as the default locale if the locale
* cannot be inferred from the pathname.
*/
defaultLocale?: string;
};
/**
* The I18NProvider is used to match locale aware routes, detect the locale from
* the pathname and hostname and normalize the pathname by removing the locale
* prefix.
*/
export declare class I18NProvider {
readonly config: Readonly<I18NConfig>;
private readonly lowerCaseLocales;
private readonly lowerCaseDomains?;
constructor(config: Readonly<I18NConfig>);
/**
* Detects the domain locale from the hostname and the detected locale if
* provided.
*
* @param hostname The hostname to detect the domain locale from, this must be lowercased.
* @param detectedLocale The detected locale to use if the hostname does not match.
* @returns The domain locale if found, `undefined` otherwise.
*/
detectDomainLocale(hostname?: string, detectedLocale?: string): DomainLocale | undefined;
/**
* Pulls the pre-computed locale and inference results from the query
* object.
*
* @param pathname the pathname that could contain a locale prefix
* @param query the query object
* @returns the locale analysis result
*/
fromQuery(pathname: string, query: NextParsedUrlQuery): LocaleAnalysisResult;
/**
* Analyzes the pathname for a locale and returns the pathname without it.
*
* @param pathname The pathname that could contain a locale prefix.
* @param options The options to use when matching the locale.
* @returns The matched locale and the pathname without the locale prefix
* (if any).
*/
analyze(pathname: string, options?: LocaleAnalysisOptions): LocaleAnalysisResult;
}
export {};

View File

@@ -0,0 +1,124 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "I18NProvider", {
enumerable: true,
get: function() {
return I18NProvider;
}
});
class I18NProvider {
constructor(config){
var _config_domains;
this.config = config;
if (!config.locales.length) {
throw new Error("Invariant: No locales provided");
}
this.lowerCaseLocales = config.locales.map((locale)=>locale.toLowerCase());
this.lowerCaseDomains = (_config_domains = config.domains) == null ? void 0 : _config_domains.map((domainLocale)=>{
var _domainLocale_locales;
const domain = domainLocale.domain.toLowerCase();
return {
defaultLocale: domainLocale.defaultLocale.toLowerCase(),
hostname: domain.split(":")[0],
domain,
locales: (_domainLocale_locales = domainLocale.locales) == null ? void 0 : _domainLocale_locales.map((locale)=>locale.toLowerCase()),
http: domainLocale.http
};
});
}
/**
* Detects the domain locale from the hostname and the detected locale if
* provided.
*
* @param hostname The hostname to detect the domain locale from, this must be lowercased.
* @param detectedLocale The detected locale to use if the hostname does not match.
* @returns The domain locale if found, `undefined` otherwise.
*/ detectDomainLocale(hostname, detectedLocale) {
if (!hostname || !this.lowerCaseDomains || !this.config.domains) return;
if (detectedLocale) detectedLocale = detectedLocale.toLowerCase();
for(let i = 0; i < this.lowerCaseDomains.length; i++){
var // Configuration validation ensures that the locale is not repeated in
// other domains locales.
_domainLocale_locales;
const domainLocale = this.lowerCaseDomains[i];
if (// We assume that the hostname is already lowercased.
domainLocale.hostname === hostname || ((_domainLocale_locales = domainLocale.locales) == null ? void 0 : _domainLocale_locales.some((locale)=>locale === detectedLocale))) {
return this.config.domains[i];
}
}
return;
}
/**
* Pulls the pre-computed locale and inference results from the query
* object.
*
* @param pathname the pathname that could contain a locale prefix
* @param query the query object
* @returns the locale analysis result
*/ fromQuery(pathname, query) {
const detectedLocale = query.__nextLocale;
// If a locale was detected on the query, analyze the pathname to ensure
// that the locale matches.
if (detectedLocale) {
const analysis = this.analyze(pathname);
// If the analysis contained a locale we should validate it against the
// query and strip it from the pathname.
if (analysis.detectedLocale) {
if (analysis.detectedLocale !== detectedLocale) {
throw new Error(`Invariant: The detected locale does not match the locale in the query. Expected to find '${detectedLocale}' in '${pathname}' but found '${analysis.detectedLocale}'}`);
}
pathname = analysis.pathname;
}
}
return {
pathname,
detectedLocale,
inferredFromDefault: query.__nextInferredLocaleFromDefault === "1"
};
}
/**
* Analyzes the pathname for a locale and returns the pathname without it.
*
* @param pathname The pathname that could contain a locale prefix.
* @param options The options to use when matching the locale.
* @returns The matched locale and the pathname without the locale prefix
* (if any).
*/ analyze(pathname, options = {}) {
let detectedLocale = options.defaultLocale;
// By default, we assume that the default locale was inferred if there was
// no detected locale.
let inferredFromDefault = typeof detectedLocale === "string";
// The first segment will be empty, because it has a leading `/`. If
// there is no further segment, there is no locale (or it's the default).
const segments = pathname.split("/");
if (!segments[1]) return {
detectedLocale,
pathname,
inferredFromDefault
};
// The second segment will contain the locale part if any.
const segment = segments[1].toLowerCase();
// See if the segment matches one of the locales. If it doesn't, there is
// no locale (or it's the default).
const index = this.lowerCaseLocales.indexOf(segment);
if (index < 0) return {
detectedLocale,
pathname,
inferredFromDefault
};
// Return the case-sensitive locale.
detectedLocale = this.config.locales[index];
inferredFromDefault = false;
// Remove the `/${locale}` part of the pathname.
pathname = pathname.slice(detectedLocale.length + 1) || "/";
return {
detectedLocale,
pathname,
inferredFromDefault
};
}
}
//# sourceMappingURL=i18n-provider.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/future/helpers/i18n-provider.ts"],"names":["I18NProvider","constructor","config","locales","length","Error","lowerCaseLocales","map","locale","toLowerCase","lowerCaseDomains","domains","domainLocale","domain","defaultLocale","hostname","split","http","detectDomainLocale","detectedLocale","i","some","fromQuery","pathname","query","__nextLocale","analysis","analyze","inferredFromDefault","__nextInferredLocaleFromDefault","options","segments","segment","index","indexOf","slice"],"mappings":";;;;+BAoCaA;;;eAAAA;;;AAAN,MAAMA;IAWXC,YAA4BC,OAA8B;YAMhCA;sBANEA;QAC1B,IAAI,CAACA,OAAOC,OAAO,CAACC,MAAM,EAAE;YAC1B,MAAM,IAAIC,MAAM;QAClB;QAEA,IAAI,CAACC,gBAAgB,GAAGJ,OAAOC,OAAO,CAACI,GAAG,CAAC,CAACC,SAAWA,OAAOC,WAAW;QACzE,IAAI,CAACC,gBAAgB,IAAGR,kBAAAA,OAAOS,OAAO,qBAAdT,gBAAgBK,GAAG,CAAC,CAACK;gBAMhCA;YALX,MAAMC,SAASD,aAAaC,MAAM,CAACJ,WAAW;YAC9C,OAAO;gBACLK,eAAeF,aAAaE,aAAa,CAACL,WAAW;gBACrDM,UAAUF,OAAOG,KAAK,CAAC,IAAI,CAAC,EAAE;gBAC9BH;gBACAV,OAAO,GAAES,wBAAAA,aAAaT,OAAO,qBAApBS,sBAAsBL,GAAG,CAAC,CAACC,SAAWA,OAAOC,WAAW;gBACjEQ,MAAML,aAAaK,IAAI;YACzB;QACF;IACF;IAEA;;;;;;;GAOC,GACD,AAAOC,mBACLH,QAAiB,EACjBI,cAAuB,EACG;QAC1B,IAAI,CAACJ,YAAY,CAAC,IAAI,CAACL,gBAAgB,IAAI,CAAC,IAAI,CAACR,MAAM,CAACS,OAAO,EAAE;QAEjE,IAAIQ,gBAAgBA,iBAAiBA,eAAeV,WAAW;QAE/D,IAAK,IAAIW,IAAI,GAAGA,IAAI,IAAI,CAACV,gBAAgB,CAACN,MAAM,EAAEgB,IAAK;gBAKnD,sEAAsE;YACtE,yBAAyB;YACzBR;YANF,MAAMA,eAAe,IAAI,CAACF,gBAAgB,CAACU,EAAE;YAC7C,IACE,qDAAqD;YACrDR,aAAaG,QAAQ,KAAKA,cAG1BH,wBAAAA,aAAaT,OAAO,qBAApBS,sBAAsBS,IAAI,CAAC,CAACb,SAAWA,WAAWW,kBAClD;gBACA,OAAO,IAAI,CAACjB,MAAM,CAACS,OAAO,CAACS,EAAE;YAC/B;QACF;QAEA;IACF;IAEA;;;;;;;GAOC,GACD,AAAOE,UACLC,QAAgB,EAChBC,KAAyB,EACH;QACtB,MAAML,iBAAiBK,MAAMC,YAAY;QAEzC,wEAAwE;QACxE,2BAA2B;QAC3B,IAAIN,gBAAgB;YAClB,MAAMO,WAAW,IAAI,CAACC,OAAO,CAACJ;YAE9B,uEAAuE;YACvE,wCAAwC;YACxC,IAAIG,SAASP,cAAc,EAAE;gBAC3B,IAAIO,SAASP,cAAc,KAAKA,gBAAgB;oBAC9C,MAAM,IAAId,MACR,CAAC,yFAAyF,EAAEc,eAAe,MAAM,EAAEI,SAAS,aAAa,EAAEG,SAASP,cAAc,CAAC,EAAE,CAAC;gBAE1K;gBAEAI,WAAWG,SAASH,QAAQ;YAC9B;QACF;QAEA,OAAO;YACLA;YACAJ;YACAS,qBAAqBJ,MAAMK,+BAA+B,KAAK;QACjE;IACF;IAEA;;;;;;;GAOC,GACD,AAAOF,QACLJ,QAAgB,EAChBO,UAAiC,CAAC,CAAC,EACb;QACtB,IAAIX,iBAAqCW,QAAQhB,aAAa;QAE9D,0EAA0E;QAC1E,sBAAsB;QACtB,IAAIc,sBAAsB,OAAOT,mBAAmB;QAEpD,oEAAoE;QACpE,yEAAyE;QACzE,MAAMY,WAAWR,SAASP,KAAK,CAAC;QAChC,IAAI,CAACe,QAAQ,CAAC,EAAE,EACd,OAAO;YACLZ;YACAI;YACAK;QACF;QAEF,0DAA0D;QAC1D,MAAMI,UAAUD,QAAQ,CAAC,EAAE,CAACtB,WAAW;QAEvC,yEAAyE;QACzE,mCAAmC;QACnC,MAAMwB,QAAQ,IAAI,CAAC3B,gBAAgB,CAAC4B,OAAO,CAACF;QAC5C,IAAIC,QAAQ,GACV,OAAO;YACLd;YACAI;YACAK;QACF;QAEF,oCAAoC;QACpCT,iBAAiB,IAAI,CAACjB,MAAM,CAACC,OAAO,CAAC8B,MAAM;QAC3CL,sBAAsB;QAEtB,gDAAgD;QAChDL,WAAWA,SAASY,KAAK,CAAChB,eAAef,MAAM,GAAG,MAAM;QAExD,OAAO;YACLe;YACAI;YACAK;QACF;IACF;AACF"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,6 @@
export declare const INTERCEPTION_ROUTE_MARKERS: readonly ["(..)(..)", "(.)", "(..)", "(...)"];
export declare function isInterceptionRouteAppPath(path: string): boolean;
export declare function extractInterceptionRouteInformation(path: string): {
interceptingRoute: string;
interceptedRoute: string;
};

View File

@@ -0,0 +1,89 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
INTERCEPTION_ROUTE_MARKERS: null,
isInterceptionRouteAppPath: null,
extractInterceptionRouteInformation: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
INTERCEPTION_ROUTE_MARKERS: function() {
return INTERCEPTION_ROUTE_MARKERS;
},
isInterceptionRouteAppPath: function() {
return isInterceptionRouteAppPath;
},
extractInterceptionRouteInformation: function() {
return extractInterceptionRouteInformation;
}
});
const _apppaths = require("../../../shared/lib/router/utils/app-paths");
const INTERCEPTION_ROUTE_MARKERS = [
"(..)(..)",
"(.)",
"(..)",
"(...)"
];
function isInterceptionRouteAppPath(path) {
// TODO-APP: add more serious validation
return path.split("/").find((segment)=>INTERCEPTION_ROUTE_MARKERS.find((m)=>segment.startsWith(m))) !== undefined;
}
function extractInterceptionRouteInformation(path) {
let interceptingRoute, marker, interceptedRoute;
for (const segment of path.split("/")){
marker = INTERCEPTION_ROUTE_MARKERS.find((m)=>segment.startsWith(m));
if (marker) {
[interceptingRoute, interceptedRoute] = path.split(marker, 2);
break;
}
}
if (!interceptingRoute || !marker || !interceptedRoute) {
throw new Error(`Invalid interception route: ${path}. Must be in the format /<intercepting route>/(..|...|..)(..)/<intercepted route>`);
}
interceptingRoute = (0, _apppaths.normalizeAppPath)(interceptingRoute) // normalize the path, e.g. /(blog)/feed -> /feed
;
switch(marker){
case "(.)":
// (.) indicates that we should match with sibling routes, so we just need to append the intercepted route to the intercepting route
if (interceptingRoute === "/") {
interceptedRoute = `/${interceptedRoute}`;
} else {
interceptedRoute = interceptingRoute + "/" + interceptedRoute;
}
break;
case "(..)":
// (..) indicates that we should match at one level up, so we need to remove the last segment of the intercepting route
if (interceptingRoute === "/") {
throw new Error(`Invalid interception route: ${path}. Cannot use (..) marker at the root level, use (.) instead.`);
}
interceptedRoute = interceptingRoute.split("/").slice(0, -1).concat(interceptedRoute).join("/");
break;
case "(...)":
// (...) will match the route segment in the root directory, so we need to use the root directory to prepend the intercepted route
interceptedRoute = "/" + interceptedRoute;
break;
case "(..)(..)":
// (..)(..) indicates that we should match at two levels up, so we need to remove the last two segments of the intercepting route
const splitInterceptingRoute = interceptingRoute.split("/");
if (splitInterceptingRoute.length <= 2) {
throw new Error(`Invalid interception route: ${path}. Cannot use (..)(..) marker at the root level or one level up.`);
}
interceptedRoute = splitInterceptingRoute.slice(0, -2).concat(interceptedRoute).join("/");
break;
default:
throw new Error("Invariant: unexpected marker");
}
return {
interceptingRoute,
interceptedRoute
};
}
//# sourceMappingURL=interception-routes.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/future/helpers/interception-routes.ts"],"names":["INTERCEPTION_ROUTE_MARKERS","isInterceptionRouteAppPath","extractInterceptionRouteInformation","path","split","find","segment","m","startsWith","undefined","interceptingRoute","marker","interceptedRoute","Error","normalizeAppPath","slice","concat","join","splitInterceptingRoute","length"],"mappings":";;;;;;;;;;;;;;;;IAGaA,0BAA0B;eAA1BA;;IAOGC,0BAA0B;eAA1BA;;IAWAC,mCAAmC;eAAnCA;;;0BArBiB;AAG1B,MAAMF,6BAA6B;IACxC;IACA;IACA;IACA;CACD;AAEM,SAASC,2BAA2BE,IAAY;IACrD,wCAAwC;IACxC,OACEA,KACGC,KAAK,CAAC,KACNC,IAAI,CAAC,CAACC,UACLN,2BAA2BK,IAAI,CAAC,CAACE,IAAMD,QAAQE,UAAU,CAACD,SACtDE;AAEZ;AAEO,SAASP,oCAAoCC,IAAY;IAC9D,IAAIO,mBACFC,QACAC;IAEF,KAAK,MAAMN,WAAWH,KAAKC,KAAK,CAAC,KAAM;QACrCO,SAASX,2BAA2BK,IAAI,CAAC,CAACE,IAAMD,QAAQE,UAAU,CAACD;QACnE,IAAII,QAAQ;YACT,CAACD,mBAAmBE,iBAAiB,GAAGT,KAAKC,KAAK,CAACO,QAAQ;YAC5D;QACF;IACF;IAEA,IAAI,CAACD,qBAAqB,CAACC,UAAU,CAACC,kBAAkB;QACtD,MAAM,IAAIC,MACR,CAAC,4BAA4B,EAAEV,KAAK,iFAAiF,CAAC;IAE1H;IAEAO,oBAAoBI,IAAAA,0BAAgB,EAACJ,mBAAmB,iDAAiD;;IAEzG,OAAQC;QACN,KAAK;YACH,oIAAoI;YACpI,IAAID,sBAAsB,KAAK;gBAC7BE,mBAAmB,CAAC,CAAC,EAAEA,iBAAiB,CAAC;YAC3C,OAAO;gBACLA,mBAAmBF,oBAAoB,MAAME;YAC/C;YACA;QACF,KAAK;YACH,uHAAuH;YACvH,IAAIF,sBAAsB,KAAK;gBAC7B,MAAM,IAAIG,MACR,CAAC,4BAA4B,EAAEV,KAAK,4DAA4D,CAAC;YAErG;YACAS,mBAAmBF,kBAChBN,KAAK,CAAC,KACNW,KAAK,CAAC,GAAG,CAAC,GACVC,MAAM,CAACJ,kBACPK,IAAI,CAAC;YACR;QACF,KAAK;YACH,kIAAkI;YAClIL,mBAAmB,MAAMA;YACzB;QACF,KAAK;YACH,iIAAiI;YAEjI,MAAMM,yBAAyBR,kBAAkBN,KAAK,CAAC;YACvD,IAAIc,uBAAuBC,MAAM,IAAI,GAAG;gBACtC,MAAM,IAAIN,MACR,CAAC,4BAA4B,EAAEV,KAAK,+DAA+D,CAAC;YAExG;YAEAS,mBAAmBM,uBAChBH,KAAK,CAAC,GAAG,CAAC,GACVC,MAAM,CAACJ,kBACPK,IAAI,CAAC;YACR;QACF;YACE,MAAM,IAAIJ,MAAM;IACpB;IAEA,OAAO;QAAEH;QAAmBE;IAAiB;AAC/C"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,6 @@
/**
* Loads a given module for a given ID.
*/
export interface ModuleLoader {
load<M = any>(id: string): Promise<M>;
}

View File

@@ -0,0 +1,8 @@
/**
* Loads a given module for a given ID.
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=module-loader.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/server/future/helpers/module-loader/module-loader.ts"],"names":[],"mappings":"AAAA;;CAEC"}

View File

@@ -0,0 +1,7 @@
import { ModuleLoader } from './module-loader';
/**
* Loads a module using `await require(id)`.
*/
export declare class NodeModuleLoader implements ModuleLoader {
load<M>(id: string): Promise<M>;
}

View File

@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "NodeModuleLoader", {
enumerable: true,
get: function() {
return NodeModuleLoader;
}
});
class NodeModuleLoader {
async load(id) {
if (process.env.NEXT_RUNTIME !== "edge") {
// Need to `await` to cover the case that route is marked ESM modules by ESM escalation.
return await (process.env.NEXT_MINIMAL ? __non_webpack_require__(id) : require(id));
}
throw new Error("NodeModuleLoader is not supported in edge runtime.");
}
}
//# sourceMappingURL=node-module-loader.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/server/future/helpers/module-loader/node-module-loader.ts"],"names":["NodeModuleLoader","load","id","process","env","NEXT_RUNTIME","NEXT_MINIMAL","__non_webpack_require__","require","Error"],"mappings":";;;;+BAKaA;;;eAAAA;;;AAAN,MAAMA;IACX,MAAaC,KAAQC,EAAU,EAAc;QAC3C,IAAIC,QAAQC,GAAG,CAACC,YAAY,KAAK,QAAQ;YACvC,wFAAwF;YACxF,OAAO,MAAOF,CAAAA,QAAQC,GAAG,CAACE,YAAY,GAElCC,wBAAwBL,MACxBM,QAAQN,GAAE;QAChB;QAEA,MAAM,IAAIO,MAAM;IAClB;AACF"}

View File

@@ -0,0 +1,8 @@
import type { RouteModule } from '../../route-modules/route-module';
import type { ModuleLoader } from './module-loader';
export interface AppLoaderModule<M extends RouteModule = RouteModule> {
routeModule: M;
}
export declare class RouteModuleLoader {
static load<M extends RouteModule>(id: string, loader?: ModuleLoader): Promise<M>;
}

View File

@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "RouteModuleLoader", {
enumerable: true,
get: function() {
return RouteModuleLoader;
}
});
const _nodemoduleloader = require("./node-module-loader");
class RouteModuleLoader {
static async load(id, loader = new _nodemoduleloader.NodeModuleLoader()) {
const module = await loader.load(id);
if ("routeModule" in module) {
return module.routeModule;
}
throw new Error(`Module "${id}" does not export a routeModule.`);
}
}
//# sourceMappingURL=route-module-loader.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/server/future/helpers/module-loader/route-module-loader.ts"],"names":["RouteModuleLoader","load","id","loader","NodeModuleLoader","module","routeModule","Error"],"mappings":";;;;+BASaA;;;eAAAA;;;kCANoB;AAM1B,MAAMA;IACX,aAAaC,KACXC,EAAU,EACVC,SAAuB,IAAIC,kCAAgB,EAAE,EACjC;QACZ,MAAMC,SAA6B,MAAMF,OAAOF,IAAI,CAACC;QACrD,IAAI,iBAAiBG,QAAQ;YAC3B,OAAOA,OAAOC,WAAW;QAC3B;QAEA,MAAM,IAAIC,MAAM,CAAC,QAAQ,EAAEL,GAAG,gCAAgC,CAAC;IACjE;AACF"}

View File

@@ -0,0 +1,18 @@
import { Normalizer } from './normalizer';
/**
* Normalizes a given filename so that it's relative to the provided directory.
* It will also strip the extension (if provided) and the trailing `/index`.
*/
export declare class AbsoluteFilenameNormalizer implements Normalizer {
private readonly dir;
private readonly extensions;
private readonly pagesType;
/**
*
* @param dir the directory for which the files should be made relative to
* @param extensions the extensions the file could have
* @param keepIndex when `true` the trailing `/index` is _not_ removed
*/
constructor(dir: string, extensions: ReadonlyArray<string>, pagesType: 'pages' | 'app' | 'root');
normalize(filename: string): string;
}

View File

@@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "AbsoluteFilenameNormalizer", {
enumerable: true,
get: function() {
return AbsoluteFilenameNormalizer;
}
});
const _absolutepathtopage = require("../../../shared/lib/page-path/absolute-path-to-page");
class AbsoluteFilenameNormalizer {
/**
*
* @param dir the directory for which the files should be made relative to
* @param extensions the extensions the file could have
* @param keepIndex when `true` the trailing `/index` is _not_ removed
*/ constructor(dir, extensions, pagesType){
this.dir = dir;
this.extensions = extensions;
this.pagesType = pagesType;
}
normalize(filename) {
return (0, _absolutepathtopage.absolutePathToPage)(filename, {
extensions: this.extensions,
keepIndex: false,
dir: this.dir,
pagesType: this.pagesType
});
}
}
//# sourceMappingURL=absolute-filename-normalizer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/future/normalizers/absolute-filename-normalizer.ts"],"names":["AbsoluteFilenameNormalizer","constructor","dir","extensions","pagesType","normalize","filename","absolutePathToPage","keepIndex"],"mappings":";;;;+BAOaA;;;eAAAA;;;oCAPsB;AAO5B,MAAMA;IACX;;;;;GAKC,GACDC,YACmBC,KACAC,YACAC,UACjB;mBAHiBF;0BACAC;yBACAC;IAChB;IAEIC,UAAUC,QAAgB,EAAU;QACzC,OAAOC,IAAAA,sCAAkB,EAACD,UAAU;YAClCH,YAAY,IAAI,CAACA,UAAU;YAC3BK,WAAW;YACXN,KAAK,IAAI,CAACA,GAAG;YACbE,WAAW,IAAI,CAACA,SAAS;QAC3B;IACF;AACF"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,11 @@
import { Normalizers } from '../../normalizers';
import { Normalizer } from '../../normalizer';
import { PrefixingNormalizer } from '../../prefixing-normalizer';
export declare class AppBundlePathNormalizer extends PrefixingNormalizer {
constructor();
normalize(page: string): string;
}
export declare class DevAppBundlePathNormalizer extends Normalizers {
constructor(pageNormalizer: Normalizer);
normalize(filename: string): string;
}

View File

@@ -0,0 +1,48 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
AppBundlePathNormalizer: null,
DevAppBundlePathNormalizer: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
AppBundlePathNormalizer: function() {
return AppBundlePathNormalizer;
},
DevAppBundlePathNormalizer: function() {
return DevAppBundlePathNormalizer;
}
});
const _normalizers = require("../../normalizers");
const _prefixingnormalizer = require("../../prefixing-normalizer");
const _normalizepagepath = require("../../../../../shared/lib/page-path/normalize-page-path");
class AppBundlePathNormalizer extends _prefixingnormalizer.PrefixingNormalizer {
constructor(){
super("app");
}
normalize(page) {
return super.normalize((0, _normalizepagepath.normalizePagePath)(page));
}
}
class DevAppBundlePathNormalizer extends _normalizers.Normalizers {
constructor(pageNormalizer){
super([
// This should normalize the filename to a page.
pageNormalizer,
// Normalize the app page to a pathname.
new AppBundlePathNormalizer()
]);
}
normalize(filename) {
return super.normalize(filename);
}
}
//# sourceMappingURL=app-bundle-path-normalizer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../../src/server/future/normalizers/built/app/app-bundle-path-normalizer.ts"],"names":["AppBundlePathNormalizer","DevAppBundlePathNormalizer","PrefixingNormalizer","constructor","normalize","page","normalizePagePath","Normalizers","pageNormalizer","filename"],"mappings":";;;;;;;;;;;;;;;IAKaA,uBAAuB;eAAvBA;;IAUAC,0BAA0B;eAA1BA;;;6BAfe;qCAEQ;mCACF;AAE3B,MAAMD,gCAAgCE,wCAAmB;IAC9DC,aAAc;QACZ,KAAK,CAAC;IACR;IAEOC,UAAUC,IAAY,EAAU;QACrC,OAAO,KAAK,CAACD,UAAUE,IAAAA,oCAAiB,EAACD;IAC3C;AACF;AAEO,MAAMJ,mCAAmCM,wBAAW;IACzDJ,YAAYK,cAA0B,CAAE;QACtC,KAAK,CAAC;YACJ,gDAAgD;YAChDA;YACA,wCAAwC;YACxC,IAAIR;SACL;IACH;IAEOI,UAAUK,QAAgB,EAAU;QACzC,OAAO,KAAK,CAACL,UAAUK;IACzB;AACF"}

View File

@@ -0,0 +1,5 @@
import { PrefixingNormalizer } from '../../prefixing-normalizer';
export declare class AppFilenameNormalizer extends PrefixingNormalizer {
constructor(distDir: string);
normalize(manifestFilename: string): string;
}

View File

@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "AppFilenameNormalizer", {
enumerable: true,
get: function() {
return AppFilenameNormalizer;
}
});
const _constants = require("../../../../../shared/lib/constants");
const _prefixingnormalizer = require("../../prefixing-normalizer");
class AppFilenameNormalizer extends _prefixingnormalizer.PrefixingNormalizer {
constructor(distDir){
super(distDir, _constants.SERVER_DIRECTORY);
}
normalize(manifestFilename) {
return super.normalize(manifestFilename);
}
}
//# sourceMappingURL=app-filename-normalizer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../../src/server/future/normalizers/built/app/app-filename-normalizer.ts"],"names":["AppFilenameNormalizer","PrefixingNormalizer","constructor","distDir","SERVER_DIRECTORY","normalize","manifestFilename"],"mappings":";;;;+BAGaA;;;eAAAA;;;2BAHoB;qCACG;AAE7B,MAAMA,8BAA8BC,wCAAmB;IAC5DC,YAAYC,OAAe,CAAE;QAC3B,KAAK,CAACA,SAASC,2BAAgB;IACjC;IAEOC,UAAUC,gBAAwB,EAAU;QACjD,OAAO,KAAK,CAACD,UAAUC;IACzB;AACF"}

View File

@@ -0,0 +1,8 @@
import { AbsoluteFilenameNormalizer } from '../../absolute-filename-normalizer';
/**
* DevAppPageNormalizer is a normalizer that is used to normalize a pathname
* to a page in the `app` directory.
*/
export declare class DevAppPageNormalizer extends AbsoluteFilenameNormalizer {
constructor(appDir: string, extensions: ReadonlyArray<string>);
}

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "DevAppPageNormalizer", {
enumerable: true,
get: function() {
return DevAppPageNormalizer;
}
});
const _absolutefilenamenormalizer = require("../../absolute-filename-normalizer");
class DevAppPageNormalizer extends _absolutefilenamenormalizer.AbsoluteFilenameNormalizer {
constructor(appDir, extensions){
super(appDir, extensions, "app");
}
}
//# sourceMappingURL=app-page-normalizer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../../src/server/future/normalizers/built/app/app-page-normalizer.ts"],"names":["DevAppPageNormalizer","AbsoluteFilenameNormalizer","constructor","appDir","extensions"],"mappings":";;;;+BAMaA;;;eAAAA;;;4CAN8B;AAMpC,MAAMA,6BAA6BC,sDAA0B;IAClEC,YAAYC,MAAc,EAAEC,UAAiC,CAAE;QAC7D,KAAK,CAACD,QAAQC,YAAY;IAC5B;AACF"}

View File

@@ -0,0 +1,10 @@
import { Normalizers } from '../../normalizers';
import { Normalizer } from '../../normalizer';
export declare class AppPathnameNormalizer extends Normalizers {
constructor();
normalize(page: string): string;
}
export declare class DevAppPathnameNormalizer extends Normalizers {
constructor(pageNormalizer: Normalizer);
normalize(filename: string): string;
}

View File

@@ -0,0 +1,55 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
AppPathnameNormalizer: null,
DevAppPathnameNormalizer: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
AppPathnameNormalizer: function() {
return AppPathnameNormalizer;
},
DevAppPathnameNormalizer: function() {
return DevAppPathnameNormalizer;
}
});
const _apppaths = require("../../../../../shared/lib/router/utils/app-paths");
const _normalizers = require("../../normalizers");
const _wrapnormalizerfn = require("../../wrap-normalizer-fn");
const _underscorenormalizer = require("../../underscore-normalizer");
class AppPathnameNormalizer extends _normalizers.Normalizers {
constructor(){
super([
// The pathname to match should have the trailing `/page` and other route
// group information stripped from it.
(0, _wrapnormalizerfn.wrapNormalizerFn)(_apppaths.normalizeAppPath),
// The page should have the `%5F` characters replaced with `_` characters.
new _underscorenormalizer.UnderscoreNormalizer()
]);
}
normalize(page) {
return super.normalize(page);
}
}
class DevAppPathnameNormalizer extends _normalizers.Normalizers {
constructor(pageNormalizer){
super([
// This should normalize the filename to a page.
pageNormalizer,
// Normalize the app page to a pathname.
new AppPathnameNormalizer()
]);
}
normalize(filename) {
return super.normalize(filename);
}
}
//# sourceMappingURL=app-pathname-normalizer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../../src/server/future/normalizers/built/app/app-pathname-normalizer.ts"],"names":["AppPathnameNormalizer","DevAppPathnameNormalizer","Normalizers","constructor","wrapNormalizerFn","normalizeAppPath","UnderscoreNormalizer","normalize","page","pageNormalizer","filename"],"mappings":";;;;;;;;;;;;;;;IAMaA,qBAAqB;eAArBA;;IAgBAC,wBAAwB;eAAxBA;;;0BAtBoB;6BACL;kCACK;sCACI;AAG9B,MAAMD,8BAA8BE,wBAAW;IACpDC,aAAc;QACZ,KAAK,CAAC;YACJ,yEAAyE;YACzE,sCAAsC;YACtCC,IAAAA,kCAAgB,EAACC,0BAAgB;YACjC,0EAA0E;YAC1E,IAAIC,0CAAoB;SACzB;IACH;IAEOC,UAAUC,IAAY,EAAU;QACrC,OAAO,KAAK,CAACD,UAAUC;IACzB;AACF;AAEO,MAAMP,iCAAiCC,wBAAW;IACvDC,YAAYM,cAA0B,CAAE;QACtC,KAAK,CAAC;YACJ,gDAAgD;YAChDA;YACA,wCAAwC;YACxC,IAAIT;SACL;IACH;IAEOO,UAAUG,QAAgB,EAAU;QACzC,OAAO,KAAK,CAACH,UAAUG;IACzB;AACF"}

View File

@@ -0,0 +1,16 @@
import { AppBundlePathNormalizer, DevAppBundlePathNormalizer } from './app-bundle-path-normalizer';
import { AppFilenameNormalizer } from './app-filename-normalizer';
import { DevAppPageNormalizer } from './app-page-normalizer';
import { AppPathnameNormalizer, DevAppPathnameNormalizer } from './app-pathname-normalizer';
export declare class AppNormalizers {
readonly filename: AppFilenameNormalizer;
readonly pathname: AppPathnameNormalizer;
readonly bundlePath: AppBundlePathNormalizer;
constructor(distDir: string);
}
export declare class DevAppNormalizers {
readonly page: DevAppPageNormalizer;
readonly pathname: DevAppPathnameNormalizer;
readonly bundlePath: DevAppBundlePathNormalizer;
constructor(appDir: string, extensions: ReadonlyArray<string>);
}

View File

@@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
AppNormalizers: null,
DevAppNormalizers: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
AppNormalizers: function() {
return AppNormalizers;
},
DevAppNormalizers: function() {
return DevAppNormalizers;
}
});
const _appbundlepathnormalizer = require("./app-bundle-path-normalizer");
const _appfilenamenormalizer = require("./app-filename-normalizer");
const _apppagenormalizer = require("./app-page-normalizer");
const _apppathnamenormalizer = require("./app-pathname-normalizer");
class AppNormalizers {
constructor(distDir){
this.filename = new _appfilenamenormalizer.AppFilenameNormalizer(distDir);
this.pathname = new _apppathnamenormalizer.AppPathnameNormalizer();
this.bundlePath = new _appbundlepathnormalizer.AppBundlePathNormalizer();
}
}
class DevAppNormalizers {
constructor(appDir, extensions){
this.page = new _apppagenormalizer.DevAppPageNormalizer(appDir, extensions);
this.pathname = new _apppathnamenormalizer.DevAppPathnameNormalizer(this.page);
this.bundlePath = new _appbundlepathnormalizer.DevAppBundlePathNormalizer(this.page);
}
}
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../../src/server/future/normalizers/built/app/index.ts"],"names":["AppNormalizers","DevAppNormalizers","constructor","distDir","filename","AppFilenameNormalizer","pathname","AppPathnameNormalizer","bundlePath","AppBundlePathNormalizer","appDir","extensions","page","DevAppPageNormalizer","DevAppPathnameNormalizer","DevAppBundlePathNormalizer"],"mappings":";;;;;;;;;;;;;;;IAWaA,cAAc;eAAdA;;IAYAC,iBAAiB;eAAjBA;;;yCApBN;uCAC+B;mCACD;uCAI9B;AAEA,MAAMD;IAKXE,YAAYC,OAAe,CAAE;QAC3B,IAAI,CAACC,QAAQ,GAAG,IAAIC,4CAAqB,CAACF;QAC1C,IAAI,CAACG,QAAQ,GAAG,IAAIC,4CAAqB;QACzC,IAAI,CAACC,UAAU,GAAG,IAAIC,gDAAuB;IAC/C;AACF;AAEO,MAAMR;IAKXC,YAAYQ,MAAc,EAAEC,UAAiC,CAAE;QAC7D,IAAI,CAACC,IAAI,GAAG,IAAIC,uCAAoB,CAACH,QAAQC;QAC7C,IAAI,CAACL,QAAQ,GAAG,IAAIQ,+CAAwB,CAAC,IAAI,CAACF,IAAI;QACtD,IAAI,CAACJ,UAAU,GAAG,IAAIO,mDAA0B,CAAC,IAAI,CAACH,IAAI;IAC5D;AACF"}

View File

@@ -0,0 +1,15 @@
import { DevPagesBundlePathNormalizer, PagesBundlePathNormalizer } from './pages-bundle-path-normalizer';
import { PagesFilenameNormalizer } from './pages-filename-normalizer';
import { DevPagesPageNormalizer } from './pages-page-normalizer';
import { DevPagesPathnameNormalizer } from './pages-pathname-normalizer';
export declare class PagesNormalizers {
readonly filename: PagesFilenameNormalizer;
readonly bundlePath: PagesBundlePathNormalizer;
constructor(distDir: string);
}
export declare class DevPagesNormalizers {
readonly page: DevPagesPageNormalizer;
readonly pathname: DevPagesPathnameNormalizer;
readonly bundlePath: DevPagesBundlePathNormalizer;
constructor(pagesDir: string, extensions: ReadonlyArray<string>);
}

View File

@@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
PagesNormalizers: null,
DevPagesNormalizers: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
PagesNormalizers: function() {
return PagesNormalizers;
},
DevPagesNormalizers: function() {
return DevPagesNormalizers;
}
});
const _pagesbundlepathnormalizer = require("./pages-bundle-path-normalizer");
const _pagesfilenamenormalizer = require("./pages-filename-normalizer");
const _pagespagenormalizer = require("./pages-page-normalizer");
const _pagespathnamenormalizer = require("./pages-pathname-normalizer");
class PagesNormalizers {
constructor(distDir){
this.filename = new _pagesfilenamenormalizer.PagesFilenameNormalizer(distDir);
this.bundlePath = new _pagesbundlepathnormalizer.PagesBundlePathNormalizer();
// You'd think that we'd require a `pathname` normalizer here, but for
// `/pages` we have to handle i18n routes, which means that we need to
// analyze the page path to determine the locale prefix and it's locale.
}
}
class DevPagesNormalizers {
constructor(pagesDir, extensions){
this.page = new _pagespagenormalizer.DevPagesPageNormalizer(pagesDir, extensions);
this.pathname = new _pagespathnamenormalizer.DevPagesPathnameNormalizer(pagesDir, extensions);
this.bundlePath = new _pagesbundlepathnormalizer.DevPagesBundlePathNormalizer(this.page);
}
}
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../../src/server/future/normalizers/built/pages/index.ts"],"names":["PagesNormalizers","DevPagesNormalizers","constructor","distDir","filename","PagesFilenameNormalizer","bundlePath","PagesBundlePathNormalizer","pagesDir","extensions","page","DevPagesPageNormalizer","pathname","DevPagesPathnameNormalizer","DevPagesBundlePathNormalizer"],"mappings":";;;;;;;;;;;;;;;IAQaA,gBAAgB;eAAhBA;;IAcAC,mBAAmB;eAAnBA;;;2CAnBN;yCACiC;qCACD;yCACI;AAEpC,MAAMD;IAIXE,YAAYC,OAAe,CAAE;QAC3B,IAAI,CAACC,QAAQ,GAAG,IAAIC,gDAAuB,CAACF;QAC5C,IAAI,CAACG,UAAU,GAAG,IAAIC,oDAAyB;IAE/C,sEAAsE;IACtE,sEAAsE;IACtE,wEAAwE;IAC1E;AACF;AAEO,MAAMN;IAKXC,YAAYM,QAAgB,EAAEC,UAAiC,CAAE;QAC/D,IAAI,CAACC,IAAI,GAAG,IAAIC,2CAAsB,CAACH,UAAUC;QACjD,IAAI,CAACG,QAAQ,GAAG,IAAIC,mDAA0B,CAACL,UAAUC;QACzD,IAAI,CAACH,UAAU,GAAG,IAAIQ,uDAA4B,CAAC,IAAI,CAACJ,IAAI;IAC9D;AACF"}

View File

@@ -0,0 +1,10 @@
import { Normalizer } from '../../normalizer';
import { Normalizers } from '../../normalizers';
export declare class PagesBundlePathNormalizer extends Normalizers {
constructor();
normalize(page: string): string;
}
export declare class DevPagesBundlePathNormalizer extends Normalizers {
constructor(pagesNormalizer: Normalizer);
normalize(filename: string): string;
}

View File

@@ -0,0 +1,55 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
PagesBundlePathNormalizer: null,
DevPagesBundlePathNormalizer: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
PagesBundlePathNormalizer: function() {
return PagesBundlePathNormalizer;
},
DevPagesBundlePathNormalizer: function() {
return DevPagesBundlePathNormalizer;
}
});
const _normalizepagepath = require("../../../../../shared/lib/page-path/normalize-page-path");
const _normalizers = require("../../normalizers");
const _prefixingnormalizer = require("../../prefixing-normalizer");
const _wrapnormalizerfn = require("../../wrap-normalizer-fn");
class PagesBundlePathNormalizer extends _normalizers.Normalizers {
constructor(){
super([
// The bundle path should have the trailing `/index` stripped from
// it.
(0, _wrapnormalizerfn.wrapNormalizerFn)(_normalizepagepath.normalizePagePath),
// The page should prefixed with `pages/`.
new _prefixingnormalizer.PrefixingNormalizer("pages")
]);
}
normalize(page) {
return super.normalize(page);
}
}
class DevPagesBundlePathNormalizer extends _normalizers.Normalizers {
constructor(pagesNormalizer){
super([
// This should normalize the filename to a page.
pagesNormalizer,
// Normalize the app page to a pathname.
new PagesBundlePathNormalizer()
]);
}
normalize(filename) {
return super.normalize(filename);
}
}
//# sourceMappingURL=pages-bundle-path-normalizer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../../src/server/future/normalizers/built/pages/pages-bundle-path-normalizer.ts"],"names":["PagesBundlePathNormalizer","DevPagesBundlePathNormalizer","Normalizers","constructor","wrapNormalizerFn","normalizePagePath","PrefixingNormalizer","normalize","page","pagesNormalizer","filename"],"mappings":";;;;;;;;;;;;;;;IAMaA,yBAAyB;eAAzBA;;IAgBAC,4BAA4B;eAA5BA;;;mCAtBqB;6BAEN;qCACQ;kCACH;AAE1B,MAAMD,kCAAkCE,wBAAW;IACxDC,aAAc;QACZ,KAAK,CAAC;YACJ,kEAAkE;YAClE,MAAM;YACNC,IAAAA,kCAAgB,EAACC,oCAAiB;YAClC,0CAA0C;YAC1C,IAAIC,wCAAmB,CAAC;SACzB;IACH;IAEOC,UAAUC,IAAY,EAAU;QACrC,OAAO,KAAK,CAACD,UAAUC;IACzB;AACF;AAEO,MAAMP,qCAAqCC,wBAAW;IAC3DC,YAAYM,eAA2B,CAAE;QACvC,KAAK,CAAC;YACJ,gDAAgD;YAChDA;YACA,wCAAwC;YACxC,IAAIT;SACL;IACH;IAEOO,UAAUG,QAAgB,EAAU;QACzC,OAAO,KAAK,CAACH,UAAUG;IACzB;AACF"}

View File

@@ -0,0 +1,5 @@
import { PrefixingNormalizer } from '../../prefixing-normalizer';
export declare class PagesFilenameNormalizer extends PrefixingNormalizer {
constructor(distDir: string);
normalize(manifestFilename: string): string;
}

View File

@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "PagesFilenameNormalizer", {
enumerable: true,
get: function() {
return PagesFilenameNormalizer;
}
});
const _constants = require("../../../../../shared/lib/constants");
const _prefixingnormalizer = require("../../prefixing-normalizer");
class PagesFilenameNormalizer extends _prefixingnormalizer.PrefixingNormalizer {
constructor(distDir){
super(distDir, _constants.SERVER_DIRECTORY);
}
normalize(manifestFilename) {
return super.normalize(manifestFilename);
}
}
//# sourceMappingURL=pages-filename-normalizer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../../src/server/future/normalizers/built/pages/pages-filename-normalizer.ts"],"names":["PagesFilenameNormalizer","PrefixingNormalizer","constructor","distDir","SERVER_DIRECTORY","normalize","manifestFilename"],"mappings":";;;;+BAGaA;;;eAAAA;;;2BAHoB;qCACG;AAE7B,MAAMA,gCAAgCC,wCAAmB;IAC9DC,YAAYC,OAAe,CAAE;QAC3B,KAAK,CAACA,SAASC,2BAAgB;IACjC;IAEOC,UAAUC,gBAAwB,EAAU;QACjD,OAAO,KAAK,CAACD,UAAUC;IACzB;AACF"}

View File

@@ -0,0 +1,4 @@
import { AbsoluteFilenameNormalizer } from '../../absolute-filename-normalizer';
export declare class DevPagesPageNormalizer extends AbsoluteFilenameNormalizer {
constructor(pagesDir: string, extensions: ReadonlyArray<string>);
}

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "DevPagesPageNormalizer", {
enumerable: true,
get: function() {
return DevPagesPageNormalizer;
}
});
const _absolutefilenamenormalizer = require("../../absolute-filename-normalizer");
class DevPagesPageNormalizer extends _absolutefilenamenormalizer.AbsoluteFilenameNormalizer {
constructor(pagesDir, extensions){
super(pagesDir, extensions, "pages");
}
}
//# sourceMappingURL=pages-page-normalizer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../../src/server/future/normalizers/built/pages/pages-page-normalizer.ts"],"names":["DevPagesPageNormalizer","AbsoluteFilenameNormalizer","constructor","pagesDir","extensions"],"mappings":";;;;+BAEaA;;;eAAAA;;;4CAF8B;AAEpC,MAAMA,+BAA+BC,sDAA0B;IACpEC,YAAYC,QAAgB,EAAEC,UAAiC,CAAE;QAC/D,KAAK,CAACD,UAAUC,YAAY;IAC9B;AACF"}

View File

@@ -0,0 +1,4 @@
import { AbsoluteFilenameNormalizer } from '../../absolute-filename-normalizer';
export declare class DevPagesPathnameNormalizer extends AbsoluteFilenameNormalizer {
constructor(pagesDir: string, extensions: ReadonlyArray<string>);
}

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "DevPagesPathnameNormalizer", {
enumerable: true,
get: function() {
return DevPagesPathnameNormalizer;
}
});
const _absolutefilenamenormalizer = require("../../absolute-filename-normalizer");
class DevPagesPathnameNormalizer extends _absolutefilenamenormalizer.AbsoluteFilenameNormalizer {
constructor(pagesDir, extensions){
super(pagesDir, extensions, "pages");
}
}
//# sourceMappingURL=pages-pathname-normalizer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../../src/server/future/normalizers/built/pages/pages-pathname-normalizer.ts"],"names":["DevPagesPathnameNormalizer","AbsoluteFilenameNormalizer","constructor","pagesDir","extensions"],"mappings":";;;;+BAEaA;;;eAAAA;;;4CAF8B;AAEpC,MAAMA,mCAAmCC,sDAA0B;IACxEC,YAAYC,QAAgB,EAAEC,UAAiC,CAAE;QAC/D,KAAK,CAACD,UAAUC,YAAY;IAC9B;AACF"}

View File

@@ -0,0 +1,16 @@
import { I18NProvider } from '../helpers/i18n-provider';
import { Normalizer } from './normalizer';
/**
* Normalizes the pathname by removing the locale prefix if any.
*/
export declare class LocaleRouteNormalizer implements Normalizer {
private readonly provider;
constructor(provider: I18NProvider);
/**
* Normalizes the pathname by removing the locale prefix if any.
*
* @param pathname The pathname to normalize.
* @returns The pathname without the locale prefix (if any).
*/
normalize(pathname: string): string;
}

View File

@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "LocaleRouteNormalizer", {
enumerable: true,
get: function() {
return LocaleRouteNormalizer;
}
});
class LocaleRouteNormalizer {
constructor(provider){
this.provider = provider;
}
/**
* Normalizes the pathname by removing the locale prefix if any.
*
* @param pathname The pathname to normalize.
* @returns The pathname without the locale prefix (if any).
*/ normalize(pathname) {
const match = this.provider.analyze(pathname);
return match.pathname;
}
}
//# sourceMappingURL=locale-route-normalizer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/future/normalizers/locale-route-normalizer.ts"],"names":["LocaleRouteNormalizer","constructor","provider","normalize","pathname","match","analyze"],"mappings":";;;;+BAMaA;;;eAAAA;;;AAAN,MAAMA;IACXC,YAA6BC,SAAwB;wBAAxBA;IAAyB;IAEtD;;;;;GAKC,GACD,AAAOC,UAAUC,QAAgB,EAAU;QACzC,MAAMC,QAAQ,IAAI,CAACH,QAAQ,CAACI,OAAO,CAACF;QACpC,OAAOC,MAAMD,QAAQ;IACvB;AACF"}

View File

@@ -0,0 +1,3 @@
export interface Normalizer {
normalize(pathname: string): string;
}

View File

@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=normalizer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,11 @@
import { Normalizer } from './normalizer';
/**
* Normalizers combines many normalizers into a single normalizer interface that
* will normalize the inputted pathname with each normalizer in order.
*/
export declare class Normalizers implements Normalizer {
private readonly normalizers;
constructor(normalizers?: Array<Normalizer>);
push(normalizer: Normalizer): void;
normalize(pathname: string): string;
}

View File

@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "Normalizers", {
enumerable: true,
get: function() {
return Normalizers;
}
});
class Normalizers {
constructor(normalizers = []){
this.normalizers = normalizers;
}
push(normalizer) {
this.normalizers.push(normalizer);
}
normalize(pathname) {
return this.normalizers.reduce((normalized, normalizer)=>normalizer.normalize(normalized), pathname);
}
}
//# sourceMappingURL=normalizers.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/future/normalizers/normalizers.ts"],"names":["Normalizers","constructor","normalizers","push","normalizer","normalize","pathname","reduce","normalized"],"mappings":";;;;+BAMaA;;;eAAAA;;;AAAN,MAAMA;IACXC,YAA6BC,cAAiC,EAAE,CAAE;2BAArCA;IAAsC;IAE5DC,KAAKC,UAAsB,EAAE;QAClC,IAAI,CAACF,WAAW,CAACC,IAAI,CAACC;IACxB;IAEOC,UAAUC,QAAgB,EAAU;QACzC,OAAO,IAAI,CAACJ,WAAW,CAACK,MAAM,CAC5B,CAACC,YAAYJ,aAAeA,WAAWC,SAAS,CAACG,aACjDF;IAEJ;AACF"}

View File

@@ -0,0 +1,6 @@
import { Normalizer } from './normalizer';
export declare class PrefixingNormalizer implements Normalizer {
private readonly prefix;
constructor(...prefixes: ReadonlyArray<string>);
normalize(pathname: string): string;
}

View File

@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "PrefixingNormalizer", {
enumerable: true,
get: function() {
return PrefixingNormalizer;
}
});
const _path = /*#__PURE__*/ _interop_require_default(require("../../../shared/lib/isomorphic/path"));
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
class PrefixingNormalizer {
constructor(...prefixes){
this.prefix = _path.default.posix.join(...prefixes);
}
normalize(pathname) {
return _path.default.posix.join(this.prefix, pathname);
}
}
//# sourceMappingURL=prefixing-normalizer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/future/normalizers/prefixing-normalizer.ts"],"names":["PrefixingNormalizer","constructor","prefixes","prefix","path","posix","join","normalize","pathname"],"mappings":";;;;+BAGaA;;;eAAAA;;;6DAHI;;;;;;AAGV,MAAMA;IAGXC,YAAY,GAAGC,QAA+B,CAAE;QAC9C,IAAI,CAACC,MAAM,GAAGC,aAAI,CAACC,KAAK,CAACC,IAAI,IAAIJ;IACnC;IAEOK,UAAUC,QAAgB,EAAU;QACzC,OAAOJ,aAAI,CAACC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACH,MAAM,EAAEK;IACtC;AACF"}

View File

@@ -0,0 +1,7 @@
import { Normalizer } from './normalizer';
/**
* UnderscoreNormalizer replaces all instances of %5F with _.
*/
export declare class UnderscoreNormalizer implements Normalizer {
normalize(pathname: string): string;
}

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "UnderscoreNormalizer", {
enumerable: true,
get: function() {
return UnderscoreNormalizer;
}
});
class UnderscoreNormalizer {
normalize(pathname) {
return pathname.replace(/%5F/g, "_");
}
}
//# sourceMappingURL=underscore-normalizer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/future/normalizers/underscore-normalizer.ts"],"names":["UnderscoreNormalizer","normalize","pathname","replace"],"mappings":";;;;+BAKaA;;;eAAAA;;;AAAN,MAAMA;IACJC,UAAUC,QAAgB,EAAU;QACzC,OAAOA,SAASC,OAAO,CAAC,QAAQ;IAClC;AACF"}

View File

@@ -0,0 +1,2 @@
import { Normalizer } from './normalizer';
export declare function wrapNormalizerFn(fn: (pathname: string) => string): Normalizer;

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "wrapNormalizerFn", {
enumerable: true,
get: function() {
return wrapNormalizerFn;
}
});
function wrapNormalizerFn(fn) {
return {
normalize: fn
};
}
//# sourceMappingURL=wrap-normalizer-fn.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/future/normalizers/wrap-normalizer-fn.ts"],"names":["wrapNormalizerFn","fn","normalize"],"mappings":";;;;+BAEgBA;;;eAAAA;;;AAAT,SAASA,iBAAiBC,EAAgC;IAC/D,OAAO;QAAEC,WAAWD;IAAG;AACzB"}

View File

@@ -0,0 +1,5 @@
import { RouteKind } from '../route-kind';
import { RouteDefinition } from './route-definition';
export interface AppPageRouteDefinition extends RouteDefinition<RouteKind.APP_PAGE> {
readonly appPaths: ReadonlyArray<string>;
}

View File

@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=app-page-route-definition.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,4 @@
import type { RouteKind } from '../route-kind';
import type { RouteDefinition } from './route-definition';
export interface AppRouteRouteDefinition extends RouteDefinition<RouteKind.APP_ROUTE> {
}

View File

@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=app-route-route-definition.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,15 @@
import { RouteKind } from '../route-kind';
import { RouteDefinition } from './route-definition';
export interface LocaleRouteDefinition<K extends RouteKind = RouteKind> extends RouteDefinition<K> {
/**
* When defined it means that this route is locale aware. When undefined,
* it means no special handling has to occur to process locales.
*/
i18n?: {
/**
* Describes the locale for the route. If this is undefined, then it
* indicates that this route can handle _any_ locale.
*/
locale?: string;
};
}

View File

@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=locale-route-definition.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,4 @@
import { RouteKind } from '../route-kind';
import { LocaleRouteDefinition } from './locale-route-definition';
export interface PagesAPIRouteDefinition extends LocaleRouteDefinition<RouteKind.PAGES_API> {
}

View File

@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=pages-api-route-definition.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,4 @@
import { RouteKind } from '../route-kind';
import { LocaleRouteDefinition } from './locale-route-definition';
export interface PagesRouteDefinition extends LocaleRouteDefinition<RouteKind.PAGES> {
}

View File

@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=pages-route-definition.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,16 @@
import { RouteKind } from '../route-kind';
export interface RouteDefinition<K extends RouteKind = RouteKind> {
readonly kind: K;
readonly bundlePath: string;
readonly filename: string;
/**
* Describes the pathname including all internal modifiers such as
* intercepting routes, parallel routes and route/page suffixes that are not
* part of the pathname.
*/
readonly page: string;
/**
* The pathname (including dynamic placeholders) for a route to resolve.
*/
readonly pathname: string;
}

View File

@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=route-definition.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":[],"names":[],"mappings":""}

20
node_modules/next/dist/server/future/route-kind.d.ts generated vendored Normal file
View File

@@ -0,0 +1,20 @@
export declare const enum RouteKind {
/**
* `PAGES` represents all the React pages that are under `pages/`.
*/
PAGES = "PAGES",
/**
* `PAGES_API` represents all the API routes under `pages/api/`.
*/
PAGES_API = "PAGES_API",
/**
* `APP_PAGE` represents all the React pages that are under `app/` with the
* filename of `page.{j,t}s{,x}`.
*/
APP_PAGE = "APP_PAGE",
/**
* `APP_ROUTE` represents all the API routes and metadata routes that are under `app/` with the
* filename of `route.{j,t}s{,x}`.
*/
APP_ROUTE = "APP_ROUTE"
}

29
node_modules/next/dist/server/future/route-kind.js generated vendored Normal file
View File

@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "RouteKind", {
enumerable: true,
get: function() {
return RouteKind;
}
});
var RouteKind;
(function(RouteKind) {
RouteKind[/**
* `PAGES` represents all the React pages that are under `pages/`.
*/ "PAGES"] = "PAGES";
RouteKind[/**
* `PAGES_API` represents all the API routes under `pages/api/`.
*/ "PAGES_API"] = "PAGES_API";
RouteKind[/**
* `APP_PAGE` represents all the React pages that are under `app/` with the
* filename of `page.{j,t}s{,x}`.
*/ "APP_PAGE"] = "APP_PAGE";
RouteKind[/**
* `APP_ROUTE` represents all the API routes and metadata routes that are under `app/` with the
* filename of `route.{j,t}s{,x}`.
*/ "APP_ROUTE"] = "APP_ROUTE";
})(RouteKind || (RouteKind = {}));
//# sourceMappingURL=route-kind.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/future/route-kind.ts"],"names":["RouteKind","PAGES","PAGES_API","APP_PAGE","APP_ROUTE"],"mappings":";;;;;;;;;;IAAO;UAAWA,SAAS;IAATA,UAChB;;GAEC,GACDC,WAAAA;IAJgBD,UAKhB;;GAEC,GACDE,eAAAA;IARgBF,UAShB;;;GAGC,GACDG,cAAAA;IAbgBH,UAchB;;;GAGC,GACDI,eAAAA;GAlBgBJ,cAAAA"}

View File

@@ -0,0 +1,39 @@
import { RouteKind } from '../route-kind';
import { RouteMatch } from '../route-matches/route-match';
import { RouteDefinition } from '../route-definitions/route-definition';
import { RouteMatcherProvider } from '../route-matcher-providers/route-matcher-provider';
import { RouteMatcher } from '../route-matchers/route-matcher';
import { MatchOptions, RouteMatcherManager } from './route-matcher-manager';
interface RouteMatchers {
static: ReadonlyArray<RouteMatcher>;
dynamic: ReadonlyArray<RouteMatcher>;
duplicates: Record<string, ReadonlyArray<RouteMatcher>>;
}
export declare class DefaultRouteMatcherManager implements RouteMatcherManager {
private readonly providers;
protected readonly matchers: RouteMatchers;
private lastCompilationID;
/**
* When this value changes, it indicates that a change has been introduced
* that requires recompilation.
*/
private get compilationID();
private waitTillReadyPromise?;
waitTillReady(): Promise<void>;
private previousMatchers;
reload(): Promise<void>;
push(provider: RouteMatcherProvider): void;
test(pathname: string, options: MatchOptions): Promise<boolean>;
match(pathname: string, options: MatchOptions): Promise<RouteMatch<RouteDefinition<RouteKind>> | null>;
/**
* This is a point for other managers to override to inject other checking
* behavior like duplicate route checking on a per-request basis.
*
* @param pathname the pathname to validate against
* @param matcher the matcher to validate/test with
* @returns the match if found
*/
protected validate(pathname: string, matcher: RouteMatcher, options: MatchOptions): RouteMatch | null;
matchAll(pathname: string, options: MatchOptions): AsyncGenerator<RouteMatch<RouteDefinition<RouteKind>>, null, undefined>;
}
export {};

View File

@@ -0,0 +1,231 @@
/* eslint-disable @typescript-eslint/no-unused-vars */ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "DefaultRouteMatcherManager", {
enumerable: true,
get: function() {
return DefaultRouteMatcherManager;
}
});
const _utils = require("../../../shared/lib/router/utils");
const _localeroutematcher = require("../route-matchers/locale-route-matcher");
const _ensureleadingslash = require("../../../shared/lib/page-path/ensure-leading-slash");
class DefaultRouteMatcherManager {
/**
* When this value changes, it indicates that a change has been introduced
* that requires recompilation.
*/ get compilationID() {
return this.providers.length;
}
async waitTillReady() {
if (this.waitTillReadyPromise) {
await this.waitTillReadyPromise;
delete this.waitTillReadyPromise;
}
}
async reload() {
let callbacks;
this.waitTillReadyPromise = new Promise((resolve, reject)=>{
callbacks = {
resolve,
reject
};
});
// Grab the compilation ID for this run, we'll verify it at the end to
// ensure that if any routes were added before reloading is finished that
// we error out.
const compilationID = this.compilationID;
try {
// Collect all the matchers from each provider.
const matchers = [];
// Get all the providers matchers.
const providersMatchers = await Promise.all(this.providers.map((provider)=>provider.matchers()));
// Use this to detect duplicate pathnames.
const all = new Map();
const duplicates = {};
for (const providerMatchers of providersMatchers){
for (const matcher of providerMatchers){
// Reset duplicated matches when reloading from pages conflicting state.
if (matcher.duplicated) delete matcher.duplicated;
// Test to see if the matcher being added is a duplicate.
const duplicate = all.get(matcher.definition.pathname);
if (duplicate) {
// This looks a little weird, but essentially if the pathname
// already exists in the duplicates map, then we got that array
// reference. Otherwise, we create a new array with the original
// duplicate first. Then we push the new matcher into the duplicate
// array, and reset it to the duplicates object (which may be a
// no-op if the pathname already existed in the duplicates object).
// Then we set the array of duplicates on both the original
// duplicate object and the new one, so we can keep them in sync.
// If a new duplicate is found, and it matches an existing pathname,
// the retrieval of the `other` will actually return the array
// reference used by all other duplicates. This is why ReadonlyArray
// is so important! Array's are always references!
const others = duplicates[matcher.definition.pathname] ?? [
duplicate
];
others.push(matcher);
duplicates[matcher.definition.pathname] = others;
// Add duplicated details to each route.
duplicate.duplicated = others;
matcher.duplicated = others;
// TODO: see if we should error for duplicates in production?
}
matchers.push(matcher);
// Add the matcher's pathname to the set.
all.set(matcher.definition.pathname, matcher);
}
}
// Update the duplicate matchers. This is used in the development manager
// to warn about duplicates.
this.matchers.duplicates = duplicates;
// If the cache is the same as what we just parsed, we can exit now. We
// can tell by using the `===` which compares object identity, which for
// the manifest matchers, will return the same matcher each time.
if (this.previousMatchers.length === matchers.length && this.previousMatchers.every((cachedMatcher, index)=>cachedMatcher === matchers[index])) {
return;
}
this.previousMatchers = matchers;
// For matchers that are for static routes, filter them now.
this.matchers.static = matchers.filter((matcher)=>!matcher.isDynamic);
// For matchers that are for dynamic routes, filter them and sort them now.
const dynamic = matchers.filter((matcher)=>matcher.isDynamic);
// As `getSortedRoutes` only takes an array of strings, we need to create
// a map of the pathnames (used for sorting) and the matchers. When we
// have locales, there may be multiple matches for the same pathname. To
// handle this, we keep a map of all the indexes (in `reference`) and
// merge them in later.
const reference = new Map();
const pathnames = new Array();
for(let index = 0; index < dynamic.length; index++){
// Grab the pathname from the definition.
const pathname = dynamic[index].definition.pathname;
// Grab the index in the dynamic array, push it into the reference.
const indexes = reference.get(pathname) ?? [];
indexes.push(index);
// If this is the first one set it. If it isn't, we don't need to
// because pushing above on the array will mutate the array already
// stored there because array's are always a reference!
if (indexes.length === 1) reference.set(pathname, indexes);
else continue;
pathnames.push(pathname);
}
// Sort the array of pathnames.
const sorted = (0, _utils.getSortedRoutes)(pathnames);
// For each of the sorted pathnames, iterate over them, grabbing the list
// of indexes and merging them back into the new `sortedDynamicMatchers`
// array. The order of the same matching pathname doesn't matter because
// they will have other matching characteristics (like the locale) that
// is considered.
const sortedDynamicMatchers = [];
for (const pathname of sorted){
const indexes = reference.get(pathname);
if (!Array.isArray(indexes)) {
throw new Error("Invariant: expected to find identity in indexes map");
}
const dynamicMatches = indexes.map((index)=>dynamic[index]);
sortedDynamicMatchers.push(...dynamicMatches);
}
this.matchers.dynamic = sortedDynamicMatchers;
// This means that there was a new matcher pushed while we were waiting
if (this.compilationID !== compilationID) {
throw new Error("Invariant: expected compilation to finish before new matchers were added, possible missing await");
}
} catch (err) {
callbacks.reject(err);
} finally{
// The compilation ID matched, so mark the complication as finished.
this.lastCompilationID = compilationID;
callbacks.resolve();
}
}
push(provider) {
this.providers.push(provider);
}
async test(pathname, options) {
// See if there's a match for the pathname...
const match = await this.match(pathname, options);
// This default implementation only needs to check to see if there _was_ a
// match. The development matcher actually changes it's behavior by not
// recompiling the routes.
return match !== null;
}
async match(pathname, options) {
// "Iterate" over the match options. Once we found a single match, exit with
// it, otherwise return null below. If no match is found, the inner block
// won't be called.
for await (const match of this.matchAll(pathname, options)){
return match;
}
return null;
}
/**
* This is a point for other managers to override to inject other checking
* behavior like duplicate route checking on a per-request basis.
*
* @param pathname the pathname to validate against
* @param matcher the matcher to validate/test with
* @returns the match if found
*/ validate(pathname, matcher, options) {
var _options_i18n;
if (matcher instanceof _localeroutematcher.LocaleRouteMatcher) {
return matcher.match(pathname, options);
}
// If the locale was inferred from the default locale, then it will have
// already added a locale to the pathname. We need to remove it before
// matching because this matcher is not locale aware.
if ((_options_i18n = options.i18n) == null ? void 0 : _options_i18n.inferredFromDefault) {
return matcher.match(options.i18n.pathname);
}
return matcher.match(pathname);
}
async *matchAll(pathname, options) {
// Guard against the matcher manager from being run before it needs to be
// recompiled. This was preferred to re-running the compilation here because
// it should be re-ran only when it changes. If a match is attempted before
// this is done, it indicates that there is a case where a provider is added
// before it was recompiled (an error). We also don't want to affect request
// times.
if (this.lastCompilationID !== this.compilationID) {
throw new Error("Invariant: expected routes to have been loaded before match");
}
// Ensure that path matching is done with a leading slash.
pathname = (0, _ensureleadingslash.ensureLeadingSlash)(pathname);
// If this pathname doesn't look like a dynamic route, and this pathname is
// listed in the normalized list of routes, then return it. This ensures
// that when a route like `/user/[id]` is encountered, it doesn't just match
// with the list of normalized routes.
if (!(0, _utils.isDynamicRoute)(pathname)) {
for (const matcher of this.matchers.static){
const match = this.validate(pathname, matcher, options);
if (!match) continue;
yield match;
}
}
// If we should skip handling dynamic routes, exit now.
if (options == null ? void 0 : options.skipDynamic) return null;
// Loop over the dynamic matchers, yielding each match.
for (const matcher of this.matchers.dynamic){
const match = this.validate(pathname, matcher, options);
if (!match) continue;
yield match;
}
// We tried direct matching against the pathname and against all the dynamic
// paths, so there was no match.
return null;
}
constructor(){
this.providers = [];
this.matchers = {
static: [],
dynamic: [],
duplicates: {}
};
this.lastCompilationID = this.compilationID;
this.previousMatchers = [];
}
}
//# sourceMappingURL=default-route-matcher-manager.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,19 @@
import { RouteKind } from '../route-kind';
import { RouteMatch } from '../route-matches/route-match';
import { RouteDefinition } from '../route-definitions/route-definition';
import { DefaultRouteMatcherManager } from './default-route-matcher-manager';
import { MatchOptions, RouteMatcherManager } from './route-matcher-manager';
import { RouteMatcher } from '../route-matchers/route-matcher';
export interface RouteEnsurer {
ensure(match: RouteMatch): Promise<void>;
}
export declare class DevRouteMatcherManager extends DefaultRouteMatcherManager {
private readonly production;
private readonly ensurer;
private readonly dir;
constructor(production: RouteMatcherManager, ensurer: RouteEnsurer, dir: string);
test(pathname: string, options: MatchOptions): Promise<boolean>;
protected validate(pathname: string, matcher: RouteMatcher, options: MatchOptions): RouteMatch | null;
matchAll(pathname: string, options: MatchOptions): AsyncGenerator<RouteMatch<RouteDefinition<RouteKind>>, null, undefined>;
reload(): Promise<void>;
}

View File

@@ -0,0 +1,124 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "DevRouteMatcherManager", {
enumerable: true,
get: function() {
return DevRouteMatcherManager;
}
});
const _routekind = require("../route-kind");
const _defaultroutematchermanager = require("./default-route-matcher-manager");
const _path = /*#__PURE__*/ _interop_require_default(require("../../../shared/lib/isomorphic/path"));
const _log = /*#__PURE__*/ _interop_require_wildcard(require("../../../build/output/log"));
const _chalk = /*#__PURE__*/ _interop_require_default(require("next/dist/compiled/chalk"));
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
class DevRouteMatcherManager extends _defaultroutematchermanager.DefaultRouteMatcherManager {
constructor(production, ensurer, dir){
super();
this.production = production;
this.ensurer = ensurer;
this.dir = dir;
}
async test(pathname, options) {
// Try to find a match within the developer routes.
const match = await super.match(pathname, options);
// Return if the match wasn't null. Unlike the implementation of `match`
// which uses `matchAll` here, this does not call `ensure` on the match
// found via the development matches.
return match !== null;
}
validate(pathname, matcher, options) {
const match = super.validate(pathname, matcher, options);
// If a match was found, check to see if there were any conflicting app or
// pages files.
// TODO: maybe expand this to _any_ duplicated routes instead?
if (match && matcher.duplicated && matcher.duplicated.some((duplicate)=>duplicate.definition.kind === _routekind.RouteKind.APP_PAGE || duplicate.definition.kind === _routekind.RouteKind.APP_ROUTE) && matcher.duplicated.some((duplicate)=>duplicate.definition.kind === _routekind.RouteKind.PAGES || duplicate.definition.kind === _routekind.RouteKind.PAGES_API)) {
return null;
}
return match;
}
async *matchAll(pathname, options) {
// Compile the development routes.
// TODO: we may want to only run this during testing, users won't be fast enough to require this many dir scans
await super.reload();
// Iterate over the development matches to see if one of them match the
// request path.
for await (const development of super.matchAll(pathname, options)){
// We're here, which means that we haven't seen this match yet, so we
// should try to ensure it and recompile the production matcher.
await this.ensurer.ensure(development);
await this.production.reload();
// Iterate over the production matches again, this time we should be able
// to match it against the production matcher unless there's an error.
for await (const production of this.production.matchAll(pathname, options)){
yield production;
}
}
// We tried direct matching against the pathname and against all the dynamic
// paths, so there was no match.
return null;
}
async reload() {
// Compile the production routes again.
await this.production.reload();
// Compile the development routes.
await super.reload();
// Check for and warn of any duplicates.
for (const [pathname, matchers] of Object.entries(this.matchers.duplicates)){
// We only want to warn about matchers resolving to the same path if their
// identities are different.
const identity = matchers[0].identity;
if (matchers.slice(1).some((matcher)=>matcher.identity !== identity)) {
continue;
}
_log.warn(`Duplicate page detected. ${matchers.map((matcher)=>_chalk.default.cyan(_path.default.relative(this.dir, matcher.definition.filename))).join(" and ")} resolve to ${_chalk.default.cyan(pathname)}`);
}
}
}
//# sourceMappingURL=dev-route-matcher-manager.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/future/route-matcher-managers/dev-route-matcher-manager.ts"],"names":["DevRouteMatcherManager","DefaultRouteMatcherManager","constructor","production","ensurer","dir","test","pathname","options","match","validate","matcher","duplicated","some","duplicate","definition","kind","RouteKind","APP_PAGE","APP_ROUTE","PAGES","PAGES_API","matchAll","reload","development","ensure","matchers","Object","entries","duplicates","identity","slice","Log","warn","map","chalk","cyan","path","relative","filename","join"],"mappings":";;;;+BAcaA;;;eAAAA;;;2BAda;4CAGiB;6DAE1B;6DACI;8DACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOX,MAAMA,+BAA+BC,sDAA0B;IACpEC,YACmBC,YACAC,SACAC,IACjB;QACA,KAAK;0BAJYF;uBACAC;mBACAC;IAGnB;IAEA,MAAaC,KAAKC,QAAgB,EAAEC,OAAqB,EAAoB;QAC3E,mDAAmD;QACnD,MAAMC,QAAQ,MAAM,KAAK,CAACA,MAAMF,UAAUC;QAE1C,wEAAwE;QACxE,uEAAuE;QACvE,qCAAqC;QACrC,OAAOC,UAAU;IACnB;IAEUC,SACRH,QAAgB,EAChBI,OAAqB,EACrBH,OAAqB,EACF;QACnB,MAAMC,QAAQ,KAAK,CAACC,SAASH,UAAUI,SAASH;QAEhD,0EAA0E;QAC1E,eAAe;QACf,8DAA8D;QAC9D,IACEC,SACAE,QAAQC,UAAU,IAClBD,QAAQC,UAAU,CAACC,IAAI,CACrB,CAACC,YACCA,UAAUC,UAAU,CAACC,IAAI,KAAKC,oBAAS,CAACC,QAAQ,IAChDJ,UAAUC,UAAU,CAACC,IAAI,KAAKC,oBAAS,CAACE,SAAS,KAErDR,QAAQC,UAAU,CAACC,IAAI,CACrB,CAACC,YACCA,UAAUC,UAAU,CAACC,IAAI,KAAKC,oBAAS,CAACG,KAAK,IAC7CN,UAAUC,UAAU,CAACC,IAAI,KAAKC,oBAAS,CAACI,SAAS,GAErD;YACA,OAAO;QACT;QAEA,OAAOZ;IACT;IAEA,OAAca,SACZf,QAAgB,EAChBC,OAAqB,EACoD;QACzE,kCAAkC;QAClC,+GAA+G;QAC/G,MAAM,KAAK,CAACe;QAEZ,uEAAuE;QACvE,gBAAgB;QAChB,WAAW,MAAMC,eAAe,KAAK,CAACF,SAASf,UAAUC,SAAU;YACjE,qEAAqE;YACrE,gEAAgE;YAChE,MAAM,IAAI,CAACJ,OAAO,CAACqB,MAAM,CAACD;YAC1B,MAAM,IAAI,CAACrB,UAAU,CAACoB,MAAM;YAE5B,yEAAyE;YACzE,sEAAsE;YACtE,WAAW,MAAMpB,cAAc,IAAI,CAACA,UAAU,CAACmB,QAAQ,CACrDf,UACAC,SACC;gBACD,MAAML;YACR;QACF;QAEA,4EAA4E;QAC5E,gCAAgC;QAChC,OAAO;IACT;IAEA,MAAaoB,SAAwB;QACnC,uCAAuC;QACvC,MAAM,IAAI,CAACpB,UAAU,CAACoB,MAAM;QAE5B,kCAAkC;QAClC,MAAM,KAAK,CAACA;QAEZ,wCAAwC;QACxC,KAAK,MAAM,CAAChB,UAAUmB,SAAS,IAAIC,OAAOC,OAAO,CAC/C,IAAI,CAACF,QAAQ,CAACG,UAAU,EACvB;YACD,0EAA0E;YAC1E,4BAA4B;YAC5B,MAAMC,WAAWJ,QAAQ,CAAC,EAAE,CAACI,QAAQ;YACrC,IAAIJ,SAASK,KAAK,CAAC,GAAGlB,IAAI,CAAC,CAACF,UAAYA,QAAQmB,QAAQ,KAAKA,WAAW;gBACtE;YACF;YAEAE,KAAIC,IAAI,CACN,CAAC,yBAAyB,EAAEP,SACzBQ,GAAG,CAAC,CAACvB,UACJwB,cAAK,CAACC,IAAI,CAACC,aAAI,CAACC,QAAQ,CAAC,IAAI,CAACjC,GAAG,EAAEM,QAAQI,UAAU,CAACwB,QAAQ,IAE/DC,IAAI,CAAC,SAAS,YAAY,EAAEL,cAAK,CAACC,IAAI,CAAC7B,UAAU,CAAC;QAEzD;IACF;AACF"}

View File

@@ -0,0 +1,55 @@
import { RouteMatch } from '../route-matches/route-match';
import { RouteMatcherProvider } from '../route-matcher-providers/route-matcher-provider';
import type { LocaleAnalysisResult } from '../helpers/i18n-provider';
export type MatchOptions = {
skipDynamic?: boolean;
/**
* If defined, this indicates to the matcher that the request should be
* treated as locale-aware. If this is undefined, it means that this
* application was not configured for additional locales.
*/
i18n?: LocaleAnalysisResult | undefined;
};
export interface RouteMatcherManager {
/**
* Returns a promise that resolves when the matcher manager has finished
* reloading.
*/
waitTillReady(): Promise<void>;
/**
* Pushes in a new matcher for this manager to manage. After all the
* providers have been pushed, the manager must be reloaded.
*
* @param provider the provider for this manager to also manage
*/
push(provider: RouteMatcherProvider): void;
/**
* Reloads the matchers from the providers. This should be done after all the
* providers have been added or the underlying providers should be refreshed.
*/
reload(): Promise<void>;
/**
* Tests the underlying matchers to find a match. It does not return the
* match.
*
* @param pathname the pathname to test for matches
* @param options the options for the testing
*/
test(pathname: string, options: MatchOptions): Promise<boolean>;
/**
* Returns the first match for a given request.
*
* @param pathname the pathname to match against
* @param options the options for the matching
*/
match(pathname: string, options: MatchOptions): Promise<RouteMatch | null>;
/**
* Returns a generator for each match for a given request. This should be
* consumed in a `for await (...)` loop, when finished, breaking or returning
* from the loop will terminate the matching operation.
*
* @param pathname the pathname to match against
* @param options the options for the matching
*/
matchAll(pathname: string, options: MatchOptions): AsyncGenerator<RouteMatch, null, undefined>;
}

View File

@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=route-matcher-manager.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":[],"names":[],"mappings":""}

Some files were not shown because too many files have changed in this diff Show More