update wings
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "AppPageRouteMatcherProvider", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return AppPageRouteMatcherProvider;
|
||||
}
|
||||
});
|
||||
const _isapppageroute = require("../../lib/is-app-page-route");
|
||||
const _constants = require("../../shared/lib/constants");
|
||||
const _app = require("../normalizers/built/app");
|
||||
const _routekind = require("../route-kind");
|
||||
const _apppageroutematcher = require("../route-matchers/app-page-route-matcher");
|
||||
const _manifestroutematcherprovider = require("./manifest-route-matcher-provider");
|
||||
class AppPageRouteMatcherProvider extends _manifestroutematcherprovider.ManifestRouteMatcherProvider {
|
||||
constructor(distDir, manifestLoader){
|
||||
super(_constants.APP_PATHS_MANIFEST, manifestLoader);
|
||||
this.normalizers = new _app.AppNormalizers(distDir);
|
||||
}
|
||||
async transform(manifest) {
|
||||
// This matcher only matches app pages.
|
||||
const pages = Object.keys(manifest).filter((page)=>(0, _isapppageroute.isAppPageRoute)(page));
|
||||
// Collect all the app paths for each page. This could include any parallel
|
||||
// routes.
|
||||
const allAppPaths = {};
|
||||
for (const page of pages){
|
||||
const pathname = this.normalizers.pathname.normalize(page);
|
||||
if (pathname in allAppPaths) allAppPaths[pathname].push(page);
|
||||
else allAppPaths[pathname] = [
|
||||
page
|
||||
];
|
||||
}
|
||||
// Format the routes.
|
||||
const matchers = [];
|
||||
for (const [pathname, appPaths] of Object.entries(allAppPaths)){
|
||||
// TODO-APP: (wyattjoh) this is a hack right now, should be more deterministic
|
||||
const page = appPaths[0];
|
||||
const filename = this.normalizers.filename.normalize(manifest[page]);
|
||||
const bundlePath = this.normalizers.bundlePath.normalize(page);
|
||||
matchers.push(new _apppageroutematcher.AppPageRouteMatcher({
|
||||
kind: _routekind.RouteKind.APP_PAGE,
|
||||
pathname,
|
||||
page,
|
||||
bundlePath,
|
||||
filename,
|
||||
appPaths
|
||||
}));
|
||||
}
|
||||
return matchers;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=app-page-route-matcher-provider.js.map
|
||||
@@ -1,43 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "AppRouteRouteMatcherProvider", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return AppRouteRouteMatcherProvider;
|
||||
}
|
||||
});
|
||||
const _isapprouteroute = require("../../lib/is-app-route-route");
|
||||
const _constants = require("../../shared/lib/constants");
|
||||
const _routekind = require("../route-kind");
|
||||
const _approuteroutematcher = require("../route-matchers/app-route-route-matcher");
|
||||
const _manifestroutematcherprovider = require("./manifest-route-matcher-provider");
|
||||
const _app = require("../normalizers/built/app");
|
||||
class AppRouteRouteMatcherProvider extends _manifestroutematcherprovider.ManifestRouteMatcherProvider {
|
||||
constructor(distDir, manifestLoader){
|
||||
super(_constants.APP_PATHS_MANIFEST, manifestLoader);
|
||||
this.normalizers = new _app.AppNormalizers(distDir);
|
||||
}
|
||||
async transform(manifest) {
|
||||
// This matcher only matches app routes.
|
||||
const pages = Object.keys(manifest).filter((page)=>(0, _isapprouteroute.isAppRouteRoute)(page));
|
||||
// Format the routes.
|
||||
const matchers = [];
|
||||
for (const page of pages){
|
||||
const filename = this.normalizers.filename.normalize(manifest[page]);
|
||||
const pathname = this.normalizers.pathname.normalize(page);
|
||||
const bundlePath = this.normalizers.bundlePath.normalize(page);
|
||||
matchers.push(new _approuteroutematcher.AppRouteRouteMatcher({
|
||||
kind: _routekind.RouteKind.APP_ROUTE,
|
||||
pathname,
|
||||
page,
|
||||
bundlePath,
|
||||
filename
|
||||
}));
|
||||
}
|
||||
return matchers;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=app-route-route-matcher-provider.js.map
|
||||
@@ -1,91 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "DevAppPageRouteMatcherProvider", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return DevAppPageRouteMatcherProvider;
|
||||
}
|
||||
});
|
||||
const _apppageroutematcher = require("../../route-matchers/app-page-route-matcher");
|
||||
const _routekind = require("../../route-kind");
|
||||
const _filecacheroutematcherprovider = require("./file-cache-route-matcher-provider");
|
||||
const _app = require("../../normalizers/built/app");
|
||||
const _normalizecatchallroutes = require("../../../build/normalize-catchall-routes");
|
||||
const _apppaths = require("../../../shared/lib/router/utils/app-paths");
|
||||
class DevAppPageRouteMatcherProvider extends _filecacheroutematcherprovider.FileCacheRouteMatcherProvider {
|
||||
constructor(appDir, extensions, reader, isTurbopack){
|
||||
super(appDir, reader);
|
||||
this.normalizers = new _app.DevAppNormalizers(appDir, extensions, isTurbopack);
|
||||
// Match any page file that ends with `/page.${extension}` or `/default.${extension}` under the app
|
||||
// directory.
|
||||
this.expression = new RegExp(`[/\\\\](page|default)\\.(?:${extensions.join('|')})$`);
|
||||
this.isTurbopack = isTurbopack;
|
||||
}
|
||||
async transform(files) {
|
||||
// Collect all the app paths for each page. This could include any parallel
|
||||
// routes.
|
||||
const cache = new Map();
|
||||
const routeFilenames = new Array();
|
||||
let appPaths = {};
|
||||
for (const filename of files){
|
||||
// If the file isn't a match for this matcher, then skip it.
|
||||
if (!this.expression.test(filename)) continue;
|
||||
let page = this.normalizers.page.normalize(filename);
|
||||
// Validate that this is not an ignored page.
|
||||
if (page.includes('/_')) continue;
|
||||
// Turbopack uses the correct page name with the underscore normalized.
|
||||
// TODO: Move implementation to packages/next/src/server/normalizers/built/app/app-page-normalizer.ts.
|
||||
// The `includes('/_')` check above needs to be moved for that to work as otherwise `%5Fsegmentname`
|
||||
// will result in `_segmentname` which hits that includes check and be skipped.
|
||||
if (this.isTurbopack) {
|
||||
page = page.replace(/%5F/g, '_');
|
||||
}
|
||||
// This is a valid file that we want to create a matcher for.
|
||||
routeFilenames.push(filename);
|
||||
const pathname = this.normalizers.pathname.normalize(filename);
|
||||
const bundlePath = this.normalizers.bundlePath.normalize(filename);
|
||||
// Save the normalization results.
|
||||
cache.set(filename, {
|
||||
page,
|
||||
pathname,
|
||||
bundlePath
|
||||
});
|
||||
if (pathname in appPaths) appPaths[pathname].push(page);
|
||||
else appPaths[pathname] = [
|
||||
page
|
||||
];
|
||||
}
|
||||
(0, _normalizecatchallroutes.normalizeCatchAllRoutes)(appPaths);
|
||||
// Make sure to sort parallel routes to make the result deterministic.
|
||||
appPaths = Object.fromEntries(Object.entries(appPaths).map(([k, v])=>[
|
||||
k,
|
||||
v.sort(_apppaths.compareAppPaths)
|
||||
]));
|
||||
const matchers = [];
|
||||
for (const filename of routeFilenames){
|
||||
// Grab the cached values (and the appPaths).
|
||||
const cached = cache.get(filename);
|
||||
if (!cached) {
|
||||
throw Object.defineProperty(new Error('Invariant: expected filename to exist in cache'), "__NEXT_ERROR_CODE", {
|
||||
value: "E190",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
const { pathname, page, bundlePath } = cached;
|
||||
matchers.push(new _apppageroutematcher.AppPageRouteMatcher({
|
||||
kind: _routekind.RouteKind.APP_PAGE,
|
||||
pathname,
|
||||
page,
|
||||
bundlePath,
|
||||
filename,
|
||||
appPaths: appPaths[pathname]
|
||||
}));
|
||||
}
|
||||
return matchers;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=dev-app-page-route-matcher-provider.js.map
|
||||
@@ -1,112 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "DevAppRouteRouteMatcherProvider", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return DevAppRouteRouteMatcherProvider;
|
||||
}
|
||||
});
|
||||
const _approuteroutematcher = require("../../route-matchers/app-route-route-matcher");
|
||||
const _routekind = require("../../route-kind");
|
||||
const _filecacheroutematcherprovider = require("./file-cache-route-matcher-provider");
|
||||
const _isapprouteroute = require("../../../lib/is-app-route-route");
|
||||
const _app = require("../../normalizers/built/app");
|
||||
const _ismetadataroute = require("../../../lib/metadata/is-metadata-route");
|
||||
const _getmetadataroute = require("../../../lib/metadata/get-metadata-route");
|
||||
const _path = /*#__PURE__*/ _interop_require_default(require("../../../shared/lib/isomorphic/path"));
|
||||
function _interop_require_default(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
class DevAppRouteRouteMatcherProvider extends _filecacheroutematcherprovider.FileCacheRouteMatcherProvider {
|
||||
constructor(appDir, extensions, reader, isTurbopack){
|
||||
super(appDir, reader);
|
||||
this.appDir = appDir;
|
||||
this.isTurbopack = isTurbopack;
|
||||
this.normalizers = new _app.DevAppNormalizers(appDir, extensions, isTurbopack);
|
||||
}
|
||||
async transform(files) {
|
||||
const matchers = [];
|
||||
for (const filename of files){
|
||||
// Skip static metadata files as they are served from filesystem.
|
||||
if ((0, _ismetadataroute.isStaticMetadataFile)(filename.replace(this.appDir, ''))) {
|
||||
continue;
|
||||
}
|
||||
let page = this.normalizers.page.normalize(filename);
|
||||
// If the file isn't a match for this matcher, then skip it.
|
||||
if (!(0, _isapprouteroute.isAppRouteRoute)(page)) continue;
|
||||
// Validate that this is not an ignored page.
|
||||
if (page.includes('/_')) continue;
|
||||
// Turbopack uses the correct page name with the underscore normalized.
|
||||
// TODO: Move implementation to packages/next/src/server/normalizers/built/app/app-page-normalizer.ts.
|
||||
// The `includes('/_')` check above needs to be moved for that to work as otherwise `%5Fsegmentname`
|
||||
// will result in `_segmentname` which hits that includes check and be skipped.
|
||||
if (this.isTurbopack) {
|
||||
page = page.replace(/%5F/g, '_');
|
||||
}
|
||||
const pathname = this.normalizers.pathname.normalize(filename);
|
||||
const bundlePath = this.normalizers.bundlePath.normalize(filename);
|
||||
const ext = _path.default.extname(filename).slice(1);
|
||||
const isEntryMetadataRouteFile = (0, _ismetadataroute.isMetadataRouteFile)(filename.replace(this.appDir, ''), [
|
||||
ext
|
||||
], true);
|
||||
if (isEntryMetadataRouteFile && !(0, _ismetadataroute.isStaticMetadataRoute)(page)) {
|
||||
// Matching dynamic metadata routes.
|
||||
// Add 2 possibilities for both single and multiple routes:
|
||||
{
|
||||
// single:
|
||||
// /sitemap.ts -> /sitemap.xml/route
|
||||
// /icon.ts -> /icon/route
|
||||
// We'll map the filename before normalization:
|
||||
// sitemap.ts -> sitemap.xml/route.ts
|
||||
// icon.ts -> icon/route.ts
|
||||
const metadataPage = (0, _getmetadataroute.normalizeMetadataPageToRoute)(page, false);
|
||||
const metadataPathname = (0, _getmetadataroute.normalizeMetadataPageToRoute)(pathname, false);
|
||||
const metadataBundlePath = (0, _getmetadataroute.normalizeMetadataPageToRoute)(bundlePath, false);
|
||||
const matcher = new _approuteroutematcher.AppRouteRouteMatcher({
|
||||
kind: _routekind.RouteKind.APP_ROUTE,
|
||||
page: metadataPage,
|
||||
pathname: metadataPathname,
|
||||
bundlePath: metadataBundlePath,
|
||||
filename
|
||||
});
|
||||
matchers.push(matcher);
|
||||
}
|
||||
{
|
||||
// multiple:
|
||||
// /sitemap.ts -> /sitemap/[__metadata_id__]/route
|
||||
// /icon.ts -> /icon/[__metadata_id__]/route
|
||||
// We'll map the filename before normalization:
|
||||
// sitemap.ts -> sitemap.xml/[__metadata_id__].ts
|
||||
// icon.ts -> icon/[__metadata_id__].ts
|
||||
const metadataPage = (0, _getmetadataroute.normalizeMetadataPageToRoute)(page, true);
|
||||
const metadataPathname = (0, _getmetadataroute.normalizeMetadataPageToRoute)(pathname, true);
|
||||
const metadataBundlePath = (0, _getmetadataroute.normalizeMetadataPageToRoute)(bundlePath, true);
|
||||
const matcher = new _approuteroutematcher.AppRouteRouteMatcher({
|
||||
kind: _routekind.RouteKind.APP_ROUTE,
|
||||
page: metadataPage,
|
||||
pathname: metadataPathname,
|
||||
bundlePath: metadataBundlePath,
|
||||
filename
|
||||
});
|
||||
matchers.push(matcher);
|
||||
}
|
||||
} else {
|
||||
// Normal app routes.
|
||||
matchers.push(new _approuteroutematcher.AppRouteRouteMatcher({
|
||||
kind: _routekind.RouteKind.APP_ROUTE,
|
||||
page,
|
||||
pathname,
|
||||
bundlePath,
|
||||
filename
|
||||
}));
|
||||
}
|
||||
}
|
||||
return matchers;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=dev-app-route-route-matcher-provider.js.map
|
||||
@@ -1,77 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "DevPagesAPIRouteMatcherProvider", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return DevPagesAPIRouteMatcherProvider;
|
||||
}
|
||||
});
|
||||
const _pagesapiroutematcher = require("../../route-matchers/pages-api-route-matcher");
|
||||
const _routekind = require("../../route-kind");
|
||||
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
||||
const _filecacheroutematcherprovider = require("./file-cache-route-matcher-provider");
|
||||
const _pages = require("../../normalizers/built/pages");
|
||||
function _interop_require_default(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
class DevPagesAPIRouteMatcherProvider extends _filecacheroutematcherprovider.FileCacheRouteMatcherProvider {
|
||||
constructor(pagesDir, extensions, reader, localeNormalizer){
|
||||
super(pagesDir, reader), this.pagesDir = pagesDir, this.extensions = extensions, this.localeNormalizer = localeNormalizer;
|
||||
// Match any route file that ends with `/${filename}.${extension}` under the
|
||||
// pages directory.
|
||||
this.expression = new RegExp(`\\.(?:${extensions.join('|')})$`);
|
||||
this.normalizers = new _pages.DevPagesNormalizers(pagesDir, extensions);
|
||||
}
|
||||
test(filename) {
|
||||
// If the file does not end in the correct extension it's not a match.
|
||||
if (!this.expression.test(filename)) return false;
|
||||
// Pages API routes must exist in the pages directory with the `/api/`
|
||||
// prefix. The pathnames being tested here though are the full filenames,
|
||||
// so we need to include the pages directory.
|
||||
// TODO: could path separator normalization be needed here?
|
||||
if (filename.startsWith(_path.default.join(this.pagesDir, '/api/'))) return true;
|
||||
for (const extension of this.extensions){
|
||||
// We can also match if we have `pages/api.${extension}`, so check to
|
||||
// see if it's a match.
|
||||
if (filename === _path.default.join(this.pagesDir, `api.${extension}`)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
async transform(files) {
|
||||
const matchers = [];
|
||||
for (const filename of files){
|
||||
// If the file isn't a match for this matcher, then skip it.
|
||||
if (!this.test(filename)) continue;
|
||||
const pathname = this.normalizers.pathname.normalize(filename);
|
||||
const page = this.normalizers.page.normalize(filename);
|
||||
const bundlePath = this.normalizers.bundlePath.normalize(filename);
|
||||
if (this.localeNormalizer) {
|
||||
matchers.push(new _pagesapiroutematcher.PagesAPILocaleRouteMatcher({
|
||||
kind: _routekind.RouteKind.PAGES_API,
|
||||
pathname,
|
||||
page,
|
||||
bundlePath,
|
||||
filename,
|
||||
i18n: {}
|
||||
}));
|
||||
} else {
|
||||
matchers.push(new _pagesapiroutematcher.PagesAPIRouteMatcher({
|
||||
kind: _routekind.RouteKind.PAGES_API,
|
||||
pathname,
|
||||
page,
|
||||
bundlePath,
|
||||
filename
|
||||
}));
|
||||
}
|
||||
}
|
||||
return matchers;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=dev-pages-api-route-matcher-provider.js.map
|
||||
@@ -1,77 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "DevPagesRouteMatcherProvider", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return DevPagesRouteMatcherProvider;
|
||||
}
|
||||
});
|
||||
const _pagesroutematcher = require("../../route-matchers/pages-route-matcher");
|
||||
const _routekind = require("../../route-kind");
|
||||
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
||||
const _filecacheroutematcherprovider = require("./file-cache-route-matcher-provider");
|
||||
const _pages = require("../../normalizers/built/pages");
|
||||
function _interop_require_default(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
class DevPagesRouteMatcherProvider extends _filecacheroutematcherprovider.FileCacheRouteMatcherProvider {
|
||||
constructor(pagesDir, extensions, reader, localeNormalizer){
|
||||
super(pagesDir, reader), this.pagesDir = pagesDir, this.extensions = extensions, this.localeNormalizer = localeNormalizer;
|
||||
// Match any route file that ends with `/${filename}.${extension}` under the
|
||||
// pages directory.
|
||||
this.expression = new RegExp(`\\.(?:${extensions.join('|')})$`);
|
||||
this.normalizers = new _pages.DevPagesNormalizers(pagesDir, extensions);
|
||||
}
|
||||
test(filename) {
|
||||
// If the file does not end in the correct extension it's not a match.
|
||||
if (!this.expression.test(filename)) return false;
|
||||
// Pages routes must exist in the pages directory without the `/api/`
|
||||
// prefix. The pathnames being tested here though are the full filenames,
|
||||
// so we need to include the pages directory.
|
||||
// TODO: could path separator normalization be needed here?
|
||||
if (filename.startsWith(_path.default.join(this.pagesDir, '/api/'))) return false;
|
||||
for (const extension of this.extensions){
|
||||
// We can also match if we have `pages/api.${extension}`, so check to
|
||||
// see if it's a match.
|
||||
if (filename === _path.default.join(this.pagesDir, `api.${extension}`)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
async transform(files) {
|
||||
const matchers = [];
|
||||
for (const filename of files){
|
||||
// If the file isn't a match for this matcher, then skip it.
|
||||
if (!this.test(filename)) continue;
|
||||
const pathname = this.normalizers.pathname.normalize(filename);
|
||||
const page = this.normalizers.page.normalize(filename);
|
||||
const bundlePath = this.normalizers.bundlePath.normalize(filename);
|
||||
if (this.localeNormalizer) {
|
||||
matchers.push(new _pagesroutematcher.PagesLocaleRouteMatcher({
|
||||
kind: _routekind.RouteKind.PAGES,
|
||||
pathname,
|
||||
page,
|
||||
bundlePath,
|
||||
filename,
|
||||
i18n: {}
|
||||
}));
|
||||
} else {
|
||||
matchers.push(new _pagesroutematcher.PagesRouteMatcher({
|
||||
kind: _routekind.RouteKind.PAGES,
|
||||
pathname,
|
||||
page,
|
||||
bundlePath,
|
||||
filename
|
||||
}));
|
||||
}
|
||||
}
|
||||
return matchers;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=dev-pages-route-matcher-provider.js.map
|
||||
@@ -1,28 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "FileCacheRouteMatcherProvider", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return FileCacheRouteMatcherProvider;
|
||||
}
|
||||
});
|
||||
const _cachedroutematcherprovider = require("../helpers/cached-route-matcher-provider");
|
||||
class FileCacheRouteMatcherProvider extends _cachedroutematcherprovider.CachedRouteMatcherProvider {
|
||||
constructor(dir, reader){
|
||||
super({
|
||||
load: async ()=>reader.read(dir),
|
||||
compare: (left, right)=>{
|
||||
if (left.length !== right.length) return false;
|
||||
// Assuming the file traversal order is deterministic...
|
||||
for(let i = 0; i < left.length; i++){
|
||||
if (left[i] !== right[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=file-cache-route-matcher-provider.js.map
|
||||
@@ -1,106 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "BatchedFileReader", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return BatchedFileReader;
|
||||
}
|
||||
});
|
||||
class BatchedFileReader {
|
||||
constructor(reader){
|
||||
this.reader = reader;
|
||||
}
|
||||
schedule(callback) {
|
||||
if (!this.schedulePromise) {
|
||||
this.schedulePromise = Promise.resolve();
|
||||
}
|
||||
this.schedulePromise.then(()=>{
|
||||
process.nextTick(callback);
|
||||
});
|
||||
}
|
||||
getOrCreateBatch() {
|
||||
// If there is an existing batch and it's not completed, then reuse it.
|
||||
if (this.batch && !this.batch.completed) {
|
||||
return this.batch;
|
||||
}
|
||||
const batch = {
|
||||
completed: false,
|
||||
directories: [],
|
||||
callbacks: []
|
||||
};
|
||||
this.batch = batch;
|
||||
this.schedule(async ()=>{
|
||||
batch.completed = true;
|
||||
if (batch.directories.length === 0) return;
|
||||
// Collect all the results for each of the directories. If any error
|
||||
// occurs, send the results back to the loaders.
|
||||
let values;
|
||||
try {
|
||||
values = await this.load(batch.directories);
|
||||
} catch (err) {
|
||||
// Reject all the callbacks.
|
||||
for (const { reject } of batch.callbacks){
|
||||
reject(err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Loop over all the callbacks and send them their results.
|
||||
for(let i = 0; i < batch.callbacks.length; i++){
|
||||
const value = values[i];
|
||||
if (value instanceof Error) {
|
||||
batch.callbacks[i].reject(value);
|
||||
} else {
|
||||
batch.callbacks[i].resolve(value);
|
||||
}
|
||||
}
|
||||
});
|
||||
return batch;
|
||||
}
|
||||
async load(directories) {
|
||||
// Make a unique array of directories. This is what lets us de-duplicate
|
||||
// loads for the same directory.
|
||||
const unique = [
|
||||
...new Set(directories)
|
||||
];
|
||||
const results = await Promise.all(unique.map(async (directory)=>{
|
||||
let files;
|
||||
let error;
|
||||
try {
|
||||
files = await this.reader.read(directory);
|
||||
} catch (err) {
|
||||
if (err instanceof Error) error = err;
|
||||
}
|
||||
return {
|
||||
directory,
|
||||
files,
|
||||
error
|
||||
};
|
||||
}));
|
||||
return directories.map((directory)=>{
|
||||
const found = results.find((result)=>result.directory === directory);
|
||||
if (!found) return [];
|
||||
if (found.files) return found.files;
|
||||
if (found.error) return found.error;
|
||||
return [];
|
||||
});
|
||||
}
|
||||
async read(dir) {
|
||||
// Get or create a new file reading batch.
|
||||
const batch = this.getOrCreateBatch();
|
||||
// Push this directory into the batch to resolve.
|
||||
batch.directories.push(dir);
|
||||
// Push the promise handles into the batch (under the same index) so it can
|
||||
// be resolved later when it's scheduled.
|
||||
const promise = new Promise((resolve, reject)=>{
|
||||
batch.callbacks.push({
|
||||
resolve,
|
||||
reject
|
||||
});
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=batched-file-reader.js.map
|
||||
@@ -1,42 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "DefaultFileReader", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return DefaultFileReader;
|
||||
}
|
||||
});
|
||||
const _recursivereaddir = require("../../../../../lib/recursive-readdir");
|
||||
class DefaultFileReader {
|
||||
/**
|
||||
* Creates a new file reader.
|
||||
*
|
||||
* @param pathnameFilter filter to ignore files with absolute pathnames, false to ignore
|
||||
* @param ignoreFilter filter to ignore files and directories with absolute pathnames, false to ignore
|
||||
* @param ignorePartFilter filter to ignore files and directories with the pathname part, false to ignore
|
||||
*/ constructor(options){
|
||||
this.options = options;
|
||||
}
|
||||
/**
|
||||
* Reads all the files in the directory and its subdirectories following any
|
||||
* symbolic links.
|
||||
*
|
||||
* @param dir the directory to read
|
||||
* @returns a promise that resolves to the list of files
|
||||
*/ async read(dir) {
|
||||
return (0, _recursivereaddir.recursiveReadDir)(dir, {
|
||||
pathnameFilter: this.options.pathnameFilter,
|
||||
ignorePartFilter: this.options.ignorePartFilter,
|
||||
// We don't need to sort the results because we're not depending on the
|
||||
// order of the results.
|
||||
sortPathnames: false,
|
||||
// We want absolute pathnames because we're going to be comparing them
|
||||
// with other absolute pathnames.
|
||||
relativePathnames: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=default-file-reader.js.map
|
||||
@@ -1,6 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
//# sourceMappingURL=file-reader.js.map
|
||||
@@ -1,30 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "CachedRouteMatcherProvider", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return CachedRouteMatcherProvider;
|
||||
}
|
||||
});
|
||||
class CachedRouteMatcherProvider {
|
||||
constructor(loader){
|
||||
this.loader = loader;
|
||||
this.cached = [];
|
||||
}
|
||||
async matchers() {
|
||||
const data = await this.loader.load();
|
||||
if (!data) return [];
|
||||
// Return the cached matchers if the data has not changed.
|
||||
if (this.data && this.loader.compare(this.data, data)) return this.cached;
|
||||
this.data = data;
|
||||
// Transform the manifest into matchers.
|
||||
const matchers = await this.transform(data);
|
||||
// Cache the matchers.
|
||||
this.cached = matchers;
|
||||
return matchers;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=cached-route-matcher-provider.js.map
|
||||
@@ -1,6 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
//# sourceMappingURL=manifest-loader.js.map
|
||||
@@ -1,34 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "NodeManifestLoader", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return NodeManifestLoader;
|
||||
}
|
||||
});
|
||||
const _constants = require("../../../../shared/lib/constants");
|
||||
const _path = /*#__PURE__*/ _interop_require_default(require("../../../../shared/lib/isomorphic/path"));
|
||||
function _interop_require_default(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
class NodeManifestLoader {
|
||||
constructor(distDir){
|
||||
this.distDir = distDir;
|
||||
}
|
||||
static require(id) {
|
||||
try {
|
||||
return require(id);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
load(name) {
|
||||
return NodeManifestLoader.require(_path.default.join(this.distDir, _constants.SERVER_DIRECTORY, name));
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=node-manifest-loader.js.map
|
||||
@@ -1,20 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "ServerManifestLoader", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return ServerManifestLoader;
|
||||
}
|
||||
});
|
||||
class ServerManifestLoader {
|
||||
constructor(getter){
|
||||
this.getter = getter;
|
||||
}
|
||||
load(name) {
|
||||
return this.getter(name);
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=server-manifest-loader.js.map
|
||||
@@ -1,21 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "ManifestRouteMatcherProvider", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return ManifestRouteMatcherProvider;
|
||||
}
|
||||
});
|
||||
const _cachedroutematcherprovider = require("./helpers/cached-route-matcher-provider");
|
||||
class ManifestRouteMatcherProvider extends _cachedroutematcherprovider.CachedRouteMatcherProvider {
|
||||
constructor(manifestName, manifestLoader){
|
||||
super({
|
||||
load: async ()=>manifestLoader.load(manifestName),
|
||||
compare: (left, right)=>left === right
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=manifest-route-matcher-provider.js.map
|
||||
@@ -1,55 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "PagesAPIRouteMatcherProvider", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return PagesAPIRouteMatcherProvider;
|
||||
}
|
||||
});
|
||||
const _isapiroute = require("../../lib/is-api-route");
|
||||
const _constants = require("../../shared/lib/constants");
|
||||
const _routekind = require("../route-kind");
|
||||
const _pagesapiroutematcher = require("../route-matchers/pages-api-route-matcher");
|
||||
const _manifestroutematcherprovider = require("./manifest-route-matcher-provider");
|
||||
const _pages = require("../normalizers/built/pages");
|
||||
class PagesAPIRouteMatcherProvider extends _manifestroutematcherprovider.ManifestRouteMatcherProvider {
|
||||
constructor(distDir, manifestLoader, i18nProvider){
|
||||
super(_constants.PAGES_MANIFEST, manifestLoader), this.i18nProvider = i18nProvider;
|
||||
this.normalizers = new _pages.PagesNormalizers(distDir);
|
||||
}
|
||||
async transform(manifest) {
|
||||
// This matcher is only for Pages API routes.
|
||||
const pathnames = Object.keys(manifest).filter((pathname)=>(0, _isapiroute.isAPIRoute)(pathname));
|
||||
const matchers = [];
|
||||
for (const page of pathnames){
|
||||
if (this.i18nProvider) {
|
||||
// Match the locale on the page name, or default to the default locale.
|
||||
const { detectedLocale, pathname } = this.i18nProvider.analyze(page);
|
||||
matchers.push(new _pagesapiroutematcher.PagesAPILocaleRouteMatcher({
|
||||
kind: _routekind.RouteKind.PAGES_API,
|
||||
pathname,
|
||||
page,
|
||||
bundlePath: this.normalizers.bundlePath.normalize(page),
|
||||
filename: this.normalizers.filename.normalize(manifest[page]),
|
||||
i18n: {
|
||||
locale: detectedLocale
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
matchers.push(new _pagesapiroutematcher.PagesAPIRouteMatcher({
|
||||
kind: _routekind.RouteKind.PAGES_API,
|
||||
// In `pages/`, the page is the same as the pathname.
|
||||
pathname: page,
|
||||
page,
|
||||
bundlePath: this.normalizers.bundlePath.normalize(page),
|
||||
filename: this.normalizers.filename.normalize(manifest[page])
|
||||
}));
|
||||
}
|
||||
}
|
||||
return matchers;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=pages-api-route-matcher-provider.js.map
|
||||
@@ -1,64 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "PagesRouteMatcherProvider", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return PagesRouteMatcherProvider;
|
||||
}
|
||||
});
|
||||
const _isapiroute = require("../../lib/is-api-route");
|
||||
const _constants = require("../../shared/lib/constants");
|
||||
const _routekind = require("../route-kind");
|
||||
const _pagesroutematcher = require("../route-matchers/pages-route-matcher");
|
||||
const _manifestroutematcherprovider = require("./manifest-route-matcher-provider");
|
||||
const _pages = require("../normalizers/built/pages");
|
||||
class PagesRouteMatcherProvider extends _manifestroutematcherprovider.ManifestRouteMatcherProvider {
|
||||
constructor(distDir, manifestLoader, i18nProvider){
|
||||
super(_constants.PAGES_MANIFEST, manifestLoader), this.i18nProvider = i18nProvider;
|
||||
this.normalizers = new _pages.PagesNormalizers(distDir);
|
||||
}
|
||||
async transform(manifest) {
|
||||
// This matcher is only for Pages routes, not Pages API routes which are
|
||||
// included in this manifest.
|
||||
const pathnames = Object.keys(manifest).filter((pathname)=>!(0, _isapiroute.isAPIRoute)(pathname))// Remove any blocked pages (page that can't be routed to, like error or
|
||||
// internal pages).
|
||||
.filter((pathname)=>{
|
||||
var _this_i18nProvider;
|
||||
const normalized = ((_this_i18nProvider = this.i18nProvider) == null ? void 0 : _this_i18nProvider.analyze(pathname).pathname) ?? pathname;
|
||||
// Skip any blocked pages.
|
||||
if (_constants.BLOCKED_PAGES.includes(normalized)) return false;
|
||||
return true;
|
||||
});
|
||||
const matchers = [];
|
||||
for (const page of pathnames){
|
||||
if (this.i18nProvider) {
|
||||
// Match the locale on the page name, or default to the default locale.
|
||||
const { detectedLocale, pathname } = this.i18nProvider.analyze(page);
|
||||
matchers.push(new _pagesroutematcher.PagesLocaleRouteMatcher({
|
||||
kind: _routekind.RouteKind.PAGES,
|
||||
pathname,
|
||||
page,
|
||||
bundlePath: this.normalizers.bundlePath.normalize(page),
|
||||
filename: this.normalizers.filename.normalize(manifest[page]),
|
||||
i18n: {
|
||||
locale: detectedLocale
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
matchers.push(new _pagesroutematcher.PagesRouteMatcher({
|
||||
kind: _routekind.RouteKind.PAGES,
|
||||
// In `pages/`, the page is the same as the pathname.
|
||||
pathname: page,
|
||||
page,
|
||||
bundlePath: this.normalizers.bundlePath.normalize(page),
|
||||
filename: this.normalizers.filename.normalize(manifest[page])
|
||||
}));
|
||||
}
|
||||
}
|
||||
return matchers;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=pages-route-matcher-provider.js.map
|
||||
@@ -1,6 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
//# sourceMappingURL=route-matcher-provider.js.map
|
||||
Reference in New Issue
Block a user