Initial commit
This commit is contained in:
commit
78f8d225ee
21173 changed files with 2907774 additions and 0 deletions
21
node_modules/next/dist/esm/shared/lib/turbopack/entry-key.js
generated
vendored
Normal file
21
node_modules/next/dist/esm/shared/lib/turbopack/entry-key.js
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* `app` -> app dir
|
||||
* `pages` -> pages dir
|
||||
* `root` -> middleware / instrumentation
|
||||
* `assets` -> assets
|
||||
*/ /**
|
||||
* Get a key that's unique across all entrypoints.
|
||||
*/ export function getEntryKey(type, side, page) {
|
||||
return JSON.stringify({
|
||||
type,
|
||||
side,
|
||||
page
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Split an `EntryKey` up into its components.
|
||||
*/ export function splitEntryKey(key) {
|
||||
return JSON.parse(key);
|
||||
}
|
||||
|
||||
//# sourceMappingURL=entry-key.js.map
|
||||
1
node_modules/next/dist/esm/shared/lib/turbopack/entry-key.js.map
generated
vendored
Normal file
1
node_modules/next/dist/esm/shared/lib/turbopack/entry-key.js.map
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"sources":["../../../../src/shared/lib/turbopack/entry-key.ts"],"sourcesContent":["/**\n * `app` -> app dir\n * `pages` -> pages dir\n * `root` -> middleware / instrumentation\n * `assets` -> assets\n */\nexport type EntryKeyType = 'app' | 'pages' | 'root' | 'assets'\nexport type EntryKeySide = 'client' | 'server'\n\n// custom type to make sure you can't accidentally use a \"generic\" string\nexport type EntryKey =\n `{\"type\":\"${EntryKeyType}\",\"side\":\"${EntryKeyType}\",\"page\":\"${string}\"}`\n\n/**\n * Get a key that's unique across all entrypoints.\n */\nexport function getEntryKey(\n type: EntryKeyType,\n side: EntryKeySide,\n page: string\n): EntryKey {\n return JSON.stringify({ type, side, page }) as EntryKey\n}\n\n/**\n * Split an `EntryKey` up into its components.\n */\nexport function splitEntryKey(key: EntryKey): {\n type: EntryKeyType\n side: EntryKeySide\n page: string\n} {\n return JSON.parse(key)\n}\n"],"names":["getEntryKey","type","side","page","JSON","stringify","splitEntryKey","key","parse"],"mappings":"AAAA;;;;;CAKC,GAQD;;CAEC,GACD,OAAO,SAASA,YACdC,IAAkB,EAClBC,IAAkB,EAClBC,IAAY;IAEZ,OAAOC,KAAKC,SAAS,CAAC;QAAEJ;QAAMC;QAAMC;IAAK;AAC3C;AAEA;;CAEC,GACD,OAAO,SAASG,cAAcC,GAAa;IAKzC,OAAOH,KAAKI,KAAK,CAACD;AACpB"}
|
||||
455
node_modules/next/dist/esm/shared/lib/turbopack/manifest-loader.js
generated
vendored
Normal file
455
node_modules/next/dist/esm/shared/lib/turbopack/manifest-loader.js
generated
vendored
Normal file
|
|
@ -0,0 +1,455 @@
|
|||
import { pathToRegexp } from 'next/dist/compiled/path-to-regexp';
|
||||
import { APP_BUILD_MANIFEST, APP_PATHS_MANIFEST, BUILD_MANIFEST, INTERCEPTION_ROUTE_REWRITE_MANIFEST, MIDDLEWARE_BUILD_MANIFEST, MIDDLEWARE_MANIFEST, NEXT_FONT_MANIFEST, PAGES_MANIFEST, SERVER_REFERENCE_MANIFEST, TURBOPACK_CLIENT_MIDDLEWARE_MANIFEST, WEBPACK_STATS } from '../constants';
|
||||
import { join, posix } from 'path';
|
||||
import { readFile } from 'fs/promises';
|
||||
import { deleteCache } from '../../../server/dev/require-cache';
|
||||
import { writeFileAtomic } from '../../../lib/fs/write-atomic';
|
||||
import { isInterceptionRouteRewrite } from '../../../lib/generate-interception-routes-rewrites';
|
||||
import { normalizeRewritesForBuildManifest, srcEmptySsgManifest, processRoute, createEdgeRuntimeManifest } from '../../../build/webpack/plugins/build-manifest-plugin';
|
||||
import getAssetPathFromRoute from '../router/utils/get-asset-path-from-route';
|
||||
import { getEntryKey } from './entry-key';
|
||||
import { getSortedRoutes } from '../router/utils';
|
||||
import { existsSync } from 'fs';
|
||||
import { addMetadataIdToRoute, addRouteSuffix, removeRouteSuffix } from '../../../server/dev/turbopack-utils';
|
||||
import { tryToParsePath } from '../../../lib/try-to-parse-path';
|
||||
const getManifestPath = (page, distDir, name, type, firstCall)=>{
|
||||
let manifestPath = posix.join(distDir, "server", type, type === 'middleware' || type === 'instrumentation' ? '' : type === 'app' ? page : getAssetPathFromRoute(page), name);
|
||||
if (firstCall) {
|
||||
const isSitemapRoute = /[\\/]sitemap(.xml)?\/route$/.test(page);
|
||||
// Check the ambiguity of /sitemap and /sitemap.xml
|
||||
if (isSitemapRoute && !existsSync(manifestPath)) {
|
||||
manifestPath = getManifestPath(page.replace(/\/sitemap\/route$/, '/sitemap.xml/route'), distDir, name, type, false);
|
||||
}
|
||||
// existsSync is faster than using the async version
|
||||
if (!existsSync(manifestPath) && page.endsWith('/route')) {
|
||||
// TODO: Improve implementation of metadata routes, currently it requires this extra check for the variants of the files that can be written.
|
||||
let metadataPage = addRouteSuffix(addMetadataIdToRoute(removeRouteSuffix(page)));
|
||||
manifestPath = getManifestPath(metadataPage, distDir, name, type, false);
|
||||
}
|
||||
}
|
||||
return manifestPath;
|
||||
};
|
||||
async function readPartialManifest(distDir, name, pageName, type) {
|
||||
if (type === void 0) type = 'pages';
|
||||
const page = pageName;
|
||||
const manifestPath = getManifestPath(page, distDir, name, type, true);
|
||||
return JSON.parse(await readFile(posix.join(manifestPath), 'utf-8'));
|
||||
}
|
||||
export class TurbopackManifestLoader {
|
||||
delete(key) {
|
||||
this.actionManifests.delete(key);
|
||||
this.appBuildManifests.delete(key);
|
||||
this.appPathsManifests.delete(key);
|
||||
this.buildManifests.delete(key);
|
||||
this.fontManifests.delete(key);
|
||||
this.middlewareManifests.delete(key);
|
||||
this.pagesManifests.delete(key);
|
||||
this.webpackStats.delete(key);
|
||||
}
|
||||
async loadActionManifest(pageName) {
|
||||
this.actionManifests.set(getEntryKey('app', 'server', pageName), await readPartialManifest(this.distDir, "" + SERVER_REFERENCE_MANIFEST + ".json", pageName, 'app'));
|
||||
}
|
||||
async mergeActionManifests(manifests) {
|
||||
const manifest = {
|
||||
node: {},
|
||||
edge: {},
|
||||
encryptionKey: this.encryptionKey
|
||||
};
|
||||
function mergeActionIds(actionEntries, other) {
|
||||
for(const key in other){
|
||||
var _actionEntries, _key;
|
||||
var _;
|
||||
const action = (_ = (_actionEntries = actionEntries)[_key = key]) != null ? _ : _actionEntries[_key] = {
|
||||
workers: {},
|
||||
layer: {}
|
||||
};
|
||||
Object.assign(action.workers, other[key].workers);
|
||||
Object.assign(action.layer, other[key].layer);
|
||||
}
|
||||
}
|
||||
for (const m of manifests){
|
||||
mergeActionIds(manifest.node, m.node);
|
||||
mergeActionIds(manifest.edge, m.edge);
|
||||
}
|
||||
for(const key in manifest.node){
|
||||
const entry = manifest.node[key];
|
||||
entry.workers = sortObjectByKey(entry.workers);
|
||||
entry.layer = sortObjectByKey(entry.layer);
|
||||
}
|
||||
for(const key in manifest.edge){
|
||||
const entry = manifest.edge[key];
|
||||
entry.workers = sortObjectByKey(entry.workers);
|
||||
entry.layer = sortObjectByKey(entry.layer);
|
||||
}
|
||||
return manifest;
|
||||
}
|
||||
async writeActionManifest() {
|
||||
const actionManifest = await this.mergeActionManifests(this.actionManifests.values());
|
||||
const actionManifestJsonPath = join(this.distDir, 'server', "" + SERVER_REFERENCE_MANIFEST + ".json");
|
||||
const actionManifestJsPath = join(this.distDir, 'server', "" + SERVER_REFERENCE_MANIFEST + ".js");
|
||||
const json = JSON.stringify(actionManifest, null, 2);
|
||||
deleteCache(actionManifestJsonPath);
|
||||
deleteCache(actionManifestJsPath);
|
||||
await writeFileAtomic(actionManifestJsonPath, json);
|
||||
await writeFileAtomic(actionManifestJsPath, "self.__RSC_SERVER_MANIFEST=" + JSON.stringify(json));
|
||||
}
|
||||
async loadAppBuildManifest(pageName) {
|
||||
this.appBuildManifests.set(getEntryKey('app', 'server', pageName), await readPartialManifest(this.distDir, APP_BUILD_MANIFEST, pageName, 'app'));
|
||||
}
|
||||
mergeAppBuildManifests(manifests) {
|
||||
const manifest = {
|
||||
pages: {}
|
||||
};
|
||||
for (const m of manifests){
|
||||
Object.assign(manifest.pages, m.pages);
|
||||
}
|
||||
manifest.pages = sortObjectByKey(manifest.pages);
|
||||
return manifest;
|
||||
}
|
||||
async writeAppBuildManifest() {
|
||||
const appBuildManifest = this.mergeAppBuildManifests(this.appBuildManifests.values());
|
||||
const appBuildManifestPath = join(this.distDir, APP_BUILD_MANIFEST);
|
||||
deleteCache(appBuildManifestPath);
|
||||
await writeFileAtomic(appBuildManifestPath, JSON.stringify(appBuildManifest, null, 2));
|
||||
}
|
||||
async loadAppPathsManifest(pageName) {
|
||||
this.appPathsManifests.set(getEntryKey('app', 'server', pageName), await readPartialManifest(this.distDir, APP_PATHS_MANIFEST, pageName, 'app'));
|
||||
}
|
||||
async writeAppPathsManifest() {
|
||||
const appPathsManifest = this.mergePagesManifests(this.appPathsManifests.values());
|
||||
const appPathsManifestPath = join(this.distDir, 'server', APP_PATHS_MANIFEST);
|
||||
deleteCache(appPathsManifestPath);
|
||||
await writeFileAtomic(appPathsManifestPath, JSON.stringify(appPathsManifest, null, 2));
|
||||
}
|
||||
async writeWebpackStats() {
|
||||
const webpackStats = this.mergeWebpackStats(this.webpackStats.values());
|
||||
const path = join(this.distDir, 'server', WEBPACK_STATS);
|
||||
deleteCache(path);
|
||||
await writeFileAtomic(path, JSON.stringify(webpackStats, null, 2));
|
||||
}
|
||||
async loadBuildManifest(pageName, type) {
|
||||
if (type === void 0) type = 'pages';
|
||||
this.buildManifests.set(getEntryKey(type, 'server', pageName), await readPartialManifest(this.distDir, BUILD_MANIFEST, pageName, type));
|
||||
}
|
||||
async loadWebpackStats(pageName, type) {
|
||||
if (type === void 0) type = 'pages';
|
||||
this.webpackStats.set(getEntryKey(type, 'client', pageName), await readPartialManifest(this.distDir, WEBPACK_STATS, pageName, type));
|
||||
}
|
||||
mergeWebpackStats(statsFiles) {
|
||||
const entrypoints = {};
|
||||
const assets = new Map();
|
||||
const chunks = new Map();
|
||||
const modules = new Map();
|
||||
for (const statsFile of statsFiles){
|
||||
if (statsFile.entrypoints) {
|
||||
for (const [k, v] of Object.entries(statsFile.entrypoints)){
|
||||
if (!entrypoints[k]) {
|
||||
entrypoints[k] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (statsFile.assets) {
|
||||
for (const asset of statsFile.assets){
|
||||
if (!assets.has(asset.name)) {
|
||||
assets.set(asset.name, asset);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (statsFile.chunks) {
|
||||
for (const chunk of statsFile.chunks){
|
||||
if (!chunks.has(chunk.name)) {
|
||||
chunks.set(chunk.name, chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (statsFile.modules) {
|
||||
for (const module of statsFile.modules){
|
||||
const id = module.id;
|
||||
if (id != null) {
|
||||
// Merge the chunk list for the module. This can vary across endpoints.
|
||||
const existing = modules.get(id);
|
||||
if (existing == null) {
|
||||
modules.set(id, module);
|
||||
} else if (module.chunks != null && existing.chunks != null) {
|
||||
for (const chunk of module.chunks){
|
||||
if (!existing.chunks.includes(chunk)) {
|
||||
existing.chunks.push(chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
entrypoints,
|
||||
assets: [
|
||||
...assets.values()
|
||||
],
|
||||
chunks: [
|
||||
...chunks.values()
|
||||
],
|
||||
modules: [
|
||||
...modules.values()
|
||||
]
|
||||
};
|
||||
}
|
||||
mergeBuildManifests(manifests) {
|
||||
const manifest = {
|
||||
pages: {
|
||||
'/_app': []
|
||||
},
|
||||
// Something in next.js depends on these to exist even for app dir rendering
|
||||
devFiles: [],
|
||||
ampDevFiles: [],
|
||||
polyfillFiles: [],
|
||||
lowPriorityFiles: [
|
||||
"static/" + this.buildId + "/_ssgManifest.js",
|
||||
"static/" + this.buildId + "/_buildManifest.js"
|
||||
],
|
||||
rootMainFiles: [],
|
||||
ampFirstPages: []
|
||||
};
|
||||
for (const m of manifests){
|
||||
Object.assign(manifest.pages, m.pages);
|
||||
if (m.rootMainFiles.length) manifest.rootMainFiles = m.rootMainFiles;
|
||||
// polyfillFiles should always be the same, so we can overwrite instead of actually merging
|
||||
if (m.polyfillFiles.length) manifest.polyfillFiles = m.polyfillFiles;
|
||||
}
|
||||
manifest.pages = sortObjectByKey(manifest.pages);
|
||||
return manifest;
|
||||
}
|
||||
async writeBuildManifest(entrypoints, devRewrites, productionRewrites) {
|
||||
var _devRewrites_beforeFiles, _devRewrites_afterFiles, _devRewrites_fallback;
|
||||
const rewrites = productionRewrites != null ? productionRewrites : {
|
||||
...devRewrites,
|
||||
beforeFiles: ((_devRewrites_beforeFiles = devRewrites == null ? void 0 : devRewrites.beforeFiles) != null ? _devRewrites_beforeFiles : []).map(processRoute),
|
||||
afterFiles: ((_devRewrites_afterFiles = devRewrites == null ? void 0 : devRewrites.afterFiles) != null ? _devRewrites_afterFiles : []).map(processRoute),
|
||||
fallback: ((_devRewrites_fallback = devRewrites == null ? void 0 : devRewrites.fallback) != null ? _devRewrites_fallback : []).map(processRoute)
|
||||
};
|
||||
const buildManifest = this.mergeBuildManifests(this.buildManifests.values());
|
||||
const buildManifestPath = join(this.distDir, BUILD_MANIFEST);
|
||||
const middlewareBuildManifestPath = join(this.distDir, 'server', "" + MIDDLEWARE_BUILD_MANIFEST + ".js");
|
||||
const interceptionRewriteManifestPath = join(this.distDir, 'server', "" + INTERCEPTION_ROUTE_REWRITE_MANIFEST + ".js");
|
||||
deleteCache(buildManifestPath);
|
||||
deleteCache(middlewareBuildManifestPath);
|
||||
deleteCache(interceptionRewriteManifestPath);
|
||||
await writeFileAtomic(buildManifestPath, JSON.stringify(buildManifest, null, 2));
|
||||
await writeFileAtomic(middlewareBuildManifestPath, // we use globalThis here because middleware can be node
|
||||
// which doesn't have "self"
|
||||
createEdgeRuntimeManifest(buildManifest));
|
||||
const interceptionRewrites = JSON.stringify(rewrites.beforeFiles.filter(isInterceptionRouteRewrite));
|
||||
await writeFileAtomic(interceptionRewriteManifestPath, "self.__INTERCEPTION_ROUTE_REWRITE_MANIFEST=" + JSON.stringify(interceptionRewrites) + ";");
|
||||
const pagesKeys = [
|
||||
...entrypoints.page.keys()
|
||||
];
|
||||
if (entrypoints.global.app) {
|
||||
pagesKeys.push('/_app');
|
||||
}
|
||||
if (entrypoints.global.error) {
|
||||
pagesKeys.push('/_error');
|
||||
}
|
||||
const sortedPageKeys = getSortedRoutes(pagesKeys);
|
||||
const content = {
|
||||
__rewrites: normalizeRewritesForBuildManifest(rewrites),
|
||||
...Object.fromEntries(sortedPageKeys.map((pathname)=>[
|
||||
pathname,
|
||||
[
|
||||
"static/chunks/pages" + (pathname === '/' ? '/index' : pathname) + ".js"
|
||||
]
|
||||
])),
|
||||
sortedPages: sortedPageKeys
|
||||
};
|
||||
const buildManifestJs = "self.__BUILD_MANIFEST = " + JSON.stringify(content) + ";self.__BUILD_MANIFEST_CB && self.__BUILD_MANIFEST_CB()";
|
||||
await writeFileAtomic(join(this.distDir, 'static', this.buildId, '_buildManifest.js'), buildManifestJs);
|
||||
await writeFileAtomic(join(this.distDir, 'static', this.buildId, '_ssgManifest.js'), srcEmptySsgManifest);
|
||||
}
|
||||
async writeClientMiddlewareManifest() {
|
||||
var _middlewareManifest_middleware_;
|
||||
const middlewareManifest = this.mergeMiddlewareManifests(this.middlewareManifests.values());
|
||||
const matchers = (middlewareManifest == null ? void 0 : (_middlewareManifest_middleware_ = middlewareManifest.middleware['/']) == null ? void 0 : _middlewareManifest_middleware_.matchers) || [];
|
||||
const clientMiddlewareManifestPath = join(this.distDir, 'static', this.buildId, "" + TURBOPACK_CLIENT_MIDDLEWARE_MANIFEST);
|
||||
deleteCache(clientMiddlewareManifestPath);
|
||||
await writeFileAtomic(clientMiddlewareManifestPath, JSON.stringify(matchers, null, 2));
|
||||
}
|
||||
async writeFallbackBuildManifest() {
|
||||
const fallbackBuildManifest = this.mergeBuildManifests([
|
||||
this.buildManifests.get(getEntryKey('pages', 'server', '_app')),
|
||||
this.buildManifests.get(getEntryKey('pages', 'server', '_error'))
|
||||
].filter(Boolean));
|
||||
const fallbackBuildManifestPath = join(this.distDir, "fallback-" + BUILD_MANIFEST);
|
||||
deleteCache(fallbackBuildManifestPath);
|
||||
await writeFileAtomic(fallbackBuildManifestPath, JSON.stringify(fallbackBuildManifest, null, 2));
|
||||
}
|
||||
async loadFontManifest(pageName, type) {
|
||||
if (type === void 0) type = 'pages';
|
||||
this.fontManifests.set(getEntryKey(type, 'server', pageName), await readPartialManifest(this.distDir, "" + NEXT_FONT_MANIFEST + ".json", pageName, type));
|
||||
}
|
||||
mergeFontManifests(manifests) {
|
||||
const manifest = {
|
||||
app: {},
|
||||
appUsingSizeAdjust: false,
|
||||
pages: {},
|
||||
pagesUsingSizeAdjust: false
|
||||
};
|
||||
for (const m of manifests){
|
||||
Object.assign(manifest.app, m.app);
|
||||
Object.assign(manifest.pages, m.pages);
|
||||
manifest.appUsingSizeAdjust = manifest.appUsingSizeAdjust || m.appUsingSizeAdjust;
|
||||
manifest.pagesUsingSizeAdjust = manifest.pagesUsingSizeAdjust || m.pagesUsingSizeAdjust;
|
||||
}
|
||||
manifest.app = sortObjectByKey(manifest.app);
|
||||
manifest.pages = sortObjectByKey(manifest.pages);
|
||||
return manifest;
|
||||
}
|
||||
async writeNextFontManifest() {
|
||||
const fontManifest = this.mergeFontManifests(this.fontManifests.values());
|
||||
const json = JSON.stringify(fontManifest, null, 2);
|
||||
const fontManifestJsonPath = join(this.distDir, 'server', "" + NEXT_FONT_MANIFEST + ".json");
|
||||
const fontManifestJsPath = join(this.distDir, 'server', "" + NEXT_FONT_MANIFEST + ".js");
|
||||
deleteCache(fontManifestJsonPath);
|
||||
deleteCache(fontManifestJsPath);
|
||||
await writeFileAtomic(fontManifestJsonPath, json);
|
||||
await writeFileAtomic(fontManifestJsPath, "self.__NEXT_FONT_MANIFEST=" + JSON.stringify(json));
|
||||
}
|
||||
/**
|
||||
* @returns If the manifest was written or not
|
||||
*/ async loadMiddlewareManifest(pageName, type) {
|
||||
const middlewareManifestPath = getManifestPath(pageName, this.distDir, MIDDLEWARE_MANIFEST, type, true);
|
||||
// middlewareManifest is actually "edge manifest" and not all routes are edge runtime. If it is not written we skip it.
|
||||
if (!existsSync(middlewareManifestPath)) {
|
||||
return false;
|
||||
}
|
||||
this.middlewareManifests.set(getEntryKey(type === 'middleware' || type === 'instrumentation' ? 'root' : type, 'server', pageName), await readPartialManifest(this.distDir, MIDDLEWARE_MANIFEST, pageName, type));
|
||||
return true;
|
||||
}
|
||||
getMiddlewareManifest(key) {
|
||||
return this.middlewareManifests.get(key);
|
||||
}
|
||||
deleteMiddlewareManifest(key) {
|
||||
return this.middlewareManifests.delete(key);
|
||||
}
|
||||
mergeMiddlewareManifests(manifests) {
|
||||
const manifest = {
|
||||
version: 3,
|
||||
middleware: {},
|
||||
sortedMiddleware: [],
|
||||
functions: {}
|
||||
};
|
||||
let instrumentation = undefined;
|
||||
for (const m of manifests){
|
||||
Object.assign(manifest.functions, m.functions);
|
||||
Object.assign(manifest.middleware, m.middleware);
|
||||
if (m.instrumentation) {
|
||||
instrumentation = m.instrumentation;
|
||||
}
|
||||
}
|
||||
manifest.functions = sortObjectByKey(manifest.functions);
|
||||
manifest.middleware = sortObjectByKey(manifest.middleware);
|
||||
const updateFunctionDefinition = (fun)=>{
|
||||
var _instrumentation_files;
|
||||
return {
|
||||
...fun,
|
||||
files: [
|
||||
...(_instrumentation_files = instrumentation == null ? void 0 : instrumentation.files) != null ? _instrumentation_files : [],
|
||||
...fun.files
|
||||
]
|
||||
};
|
||||
};
|
||||
for (const key of Object.keys(manifest.middleware)){
|
||||
const value = manifest.middleware[key];
|
||||
manifest.middleware[key] = updateFunctionDefinition(value);
|
||||
}
|
||||
for (const key of Object.keys(manifest.functions)){
|
||||
const value = manifest.functions[key];
|
||||
manifest.functions[key] = updateFunctionDefinition(value);
|
||||
}
|
||||
for (const fun of Object.values(manifest.functions).concat(Object.values(manifest.middleware))){
|
||||
for (const matcher of fun.matchers){
|
||||
if (!matcher.regexp) {
|
||||
matcher.regexp = pathToRegexp(matcher.originalSource, [], {
|
||||
delimiter: '/',
|
||||
sensitive: false,
|
||||
strict: true
|
||||
}).source.replaceAll('\\/', '/');
|
||||
}
|
||||
}
|
||||
}
|
||||
manifest.sortedMiddleware = Object.keys(manifest.middleware);
|
||||
return manifest;
|
||||
}
|
||||
async writeMiddlewareManifest() {
|
||||
const middlewareManifest = this.mergeMiddlewareManifests(this.middlewareManifests.values());
|
||||
// Normalize regexes as it uses path-to-regexp
|
||||
for(const key in middlewareManifest.middleware){
|
||||
middlewareManifest.middleware[key].matchers.forEach((matcher)=>{
|
||||
if (!matcher.regexp.startsWith('^')) {
|
||||
const parsedPage = tryToParsePath(matcher.regexp);
|
||||
if (parsedPage.error || !parsedPage.regexStr) {
|
||||
throw Object.defineProperty(new Error("Invalid source: " + matcher.regexp), "__NEXT_ERROR_CODE", {
|
||||
value: "E442",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
matcher.regexp = parsedPage.regexStr;
|
||||
}
|
||||
});
|
||||
}
|
||||
const middlewareManifestPath = join(this.distDir, 'server', MIDDLEWARE_MANIFEST);
|
||||
deleteCache(middlewareManifestPath);
|
||||
await writeFileAtomic(middlewareManifestPath, JSON.stringify(middlewareManifest, null, 2));
|
||||
}
|
||||
async loadPagesManifest(pageName) {
|
||||
this.pagesManifests.set(getEntryKey('pages', 'server', pageName), await readPartialManifest(this.distDir, PAGES_MANIFEST, pageName));
|
||||
}
|
||||
mergePagesManifests(manifests) {
|
||||
const manifest = {};
|
||||
for (const m of manifests){
|
||||
Object.assign(manifest, m);
|
||||
}
|
||||
return sortObjectByKey(manifest);
|
||||
}
|
||||
async writePagesManifest() {
|
||||
const pagesManifest = this.mergePagesManifests(this.pagesManifests.values());
|
||||
const pagesManifestPath = join(this.distDir, 'server', PAGES_MANIFEST);
|
||||
deleteCache(pagesManifestPath);
|
||||
await writeFileAtomic(pagesManifestPath, JSON.stringify(pagesManifest, null, 2));
|
||||
}
|
||||
async writeManifests(param) {
|
||||
let { devRewrites, productionRewrites, entrypoints } = param;
|
||||
await this.writeActionManifest();
|
||||
await this.writeAppBuildManifest();
|
||||
await this.writeAppPathsManifest();
|
||||
await this.writeBuildManifest(entrypoints, devRewrites, productionRewrites);
|
||||
await this.writeFallbackBuildManifest();
|
||||
await this.writeMiddlewareManifest();
|
||||
await this.writeClientMiddlewareManifest();
|
||||
await this.writeNextFontManifest();
|
||||
await this.writePagesManifest();
|
||||
if (process.env.TURBOPACK_STATS != null) {
|
||||
await this.writeWebpackStats();
|
||||
}
|
||||
}
|
||||
constructor({ distDir, buildId, encryptionKey }){
|
||||
this.actionManifests = new Map();
|
||||
this.appBuildManifests = new Map();
|
||||
this.appPathsManifests = new Map();
|
||||
this.buildManifests = new Map();
|
||||
this.fontManifests = new Map();
|
||||
this.middlewareManifests = new Map();
|
||||
this.pagesManifests = new Map();
|
||||
this.webpackStats = new Map();
|
||||
this.distDir = distDir;
|
||||
this.buildId = buildId;
|
||||
this.encryptionKey = encryptionKey;
|
||||
}
|
||||
}
|
||||
function sortObjectByKey(obj) {
|
||||
return Object.keys(obj).sort().reduce((acc, key)=>{
|
||||
acc[key] = obj[key];
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
//# sourceMappingURL=manifest-loader.js.map
|
||||
1
node_modules/next/dist/esm/shared/lib/turbopack/manifest-loader.js.map
generated
vendored
Normal file
1
node_modules/next/dist/esm/shared/lib/turbopack/manifest-loader.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
185
node_modules/next/dist/esm/shared/lib/turbopack/utils.js
generated
vendored
Normal file
185
node_modules/next/dist/esm/shared/lib/turbopack/utils.js
generated
vendored
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
import { bold, green, magenta, red } from '../../../lib/picocolors';
|
||||
import isInternal from '../is-internal';
|
||||
import { decodeMagicIdentifier, MAGIC_IDENTIFIER_REGEX } from '../magic-identifier';
|
||||
import * as Log from '../../../build/output/log';
|
||||
import loadJsConfig from '../../../build/load-jsconfig';
|
||||
import { eventErrorThrown } from '../../../telemetry/events';
|
||||
import { traceGlobals } from '../../../trace/shared';
|
||||
// An error generated from emitted Turbopack issues. This can include build
|
||||
// errors caused by issues with user code.
|
||||
export class ModuleBuildError extends Error {
|
||||
constructor(...args){
|
||||
super(...args), this.name = 'ModuleBuildError';
|
||||
}
|
||||
}
|
||||
// An error caused by an internal issue in Turbopack. These should be written
|
||||
// to a log file and details should not be shown to the user.
|
||||
export class TurbopackInternalError extends Error {
|
||||
static createAndRecordTelemetry(cause) {
|
||||
const error = new TurbopackInternalError(cause);
|
||||
const telemetry = traceGlobals.get('telemetry');
|
||||
if (telemetry) {
|
||||
telemetry.record(eventErrorThrown(error));
|
||||
} else {
|
||||
console.error('Expected `telemetry` to be set in globals');
|
||||
}
|
||||
return error;
|
||||
}
|
||||
constructor(cause){
|
||||
super(cause.message), this.name = 'TurbopackInternalError', // Manually set this as this isn't statically determinable
|
||||
this.__NEXT_ERROR_CODE = 'TurbopackInternalError';
|
||||
this.stack = cause.stack;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Thin stopgap workaround layer to mimic existing wellknown-errors-plugin in webpack's build
|
||||
* to emit certain type of errors into cli.
|
||||
*/ export function isWellKnownError(issue) {
|
||||
const { title } = issue;
|
||||
const formattedTitle = renderStyledStringToErrorAnsi(title);
|
||||
// TODO: add more well known errors
|
||||
if (formattedTitle.includes('Module not found') || formattedTitle.includes('Unknown module type')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function getIssueKey(issue) {
|
||||
return issue.severity + "-" + issue.filePath + "-" + JSON.stringify(issue.title) + "-" + JSON.stringify(issue.description);
|
||||
}
|
||||
export async function getTurbopackJsConfig(dir, nextConfig) {
|
||||
const { jsConfig } = await loadJsConfig(dir, nextConfig);
|
||||
return jsConfig != null ? jsConfig : {
|
||||
compilerOptions: {}
|
||||
};
|
||||
}
|
||||
export function processIssues(currentEntryIssues, key, result, throwIssue, logErrors) {
|
||||
const newIssues = new Map();
|
||||
currentEntryIssues.set(key, newIssues);
|
||||
const relevantIssues = new Set();
|
||||
for (const issue of result.issues){
|
||||
if (issue.severity !== 'error' && issue.severity !== 'fatal' && issue.severity !== 'warning') continue;
|
||||
const issueKey = getIssueKey(issue);
|
||||
newIssues.set(issueKey, issue);
|
||||
if (issue.severity !== 'warning') {
|
||||
if (throwIssue) {
|
||||
const formatted = formatIssue(issue);
|
||||
relevantIssues.add(formatted);
|
||||
} else if (logErrors && isWellKnownError(issue)) {
|
||||
const formatted = formatIssue(issue);
|
||||
Log.error(formatted);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (relevantIssues.size && throwIssue) {
|
||||
throw Object.defineProperty(new ModuleBuildError([
|
||||
...relevantIssues
|
||||
].join('\n\n')), "__NEXT_ERROR_CODE", {
|
||||
value: "E394",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
}
|
||||
export function formatIssue(issue) {
|
||||
const { filePath, title, description, source } = issue;
|
||||
let { documentationLink } = issue;
|
||||
let formattedTitle = renderStyledStringToErrorAnsi(title).replace(/\n/g, '\n ');
|
||||
// TODO: Use error codes to identify these
|
||||
// TODO: Generalize adapting Turbopack errors to Next.js errors
|
||||
if (formattedTitle.includes('Module not found')) {
|
||||
// For compatiblity with webpack
|
||||
// TODO: include columns in webpack errors.
|
||||
documentationLink = 'https://nextjs.org/docs/messages/module-not-found';
|
||||
}
|
||||
let formattedFilePath = filePath.replace('[project]/', './').replaceAll('/./', '/').replace('\\\\?\\', '');
|
||||
let message = '';
|
||||
if (source && source.range) {
|
||||
const { start } = source.range;
|
||||
message = formattedFilePath + ":" + (start.line + 1) + ":" + (start.column + 1) + "\n" + formattedTitle;
|
||||
} else if (formattedFilePath) {
|
||||
message = formattedFilePath + "\n" + formattedTitle;
|
||||
} else {
|
||||
message = formattedTitle;
|
||||
}
|
||||
message += '\n';
|
||||
if ((source == null ? void 0 : source.range) && source.source.content && // ignore Next.js/React internals, as these can often be huge bundled files.
|
||||
!isInternal(filePath)) {
|
||||
const { start, end } = source.range;
|
||||
const { codeFrameColumns } = require('next/dist/compiled/babel/code-frame');
|
||||
message += codeFrameColumns(source.source.content, {
|
||||
start: {
|
||||
line: start.line + 1,
|
||||
column: start.column + 1
|
||||
},
|
||||
end: {
|
||||
line: end.line + 1,
|
||||
column: end.column + 1
|
||||
}
|
||||
}, {
|
||||
forceColor: true
|
||||
}).trim() + '\n\n';
|
||||
}
|
||||
if (description) {
|
||||
message += renderStyledStringToErrorAnsi(description) + '\n\n';
|
||||
}
|
||||
// TODO: make it possible to enable this for debugging, but not in tests.
|
||||
// if (detail) {
|
||||
// message += renderStyledStringToErrorAnsi(detail) + '\n\n'
|
||||
// }
|
||||
// TODO: Include a trace from the issue.
|
||||
if (documentationLink) {
|
||||
message += documentationLink + '\n\n';
|
||||
}
|
||||
return message;
|
||||
}
|
||||
export function isRelevantWarning(issue) {
|
||||
return issue.severity === 'warning' && !isNodeModulesIssue(issue);
|
||||
}
|
||||
function isNodeModulesIssue(issue) {
|
||||
if (issue.severity === 'warning' && issue.stage === 'config') {
|
||||
// Override for the externalize issue
|
||||
// `Package foo (serverExternalPackages or default list) can't be external`
|
||||
if (renderStyledStringToErrorAnsi(issue.title).includes("can't be external")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return issue.severity === 'warning' && (issue.filePath.match(/^(?:.*[\\/])?node_modules(?:[\\/].*)?$/) !== null || // Ignore Next.js itself when running next directly in the monorepo where it is not inside
|
||||
// node_modules anyway.
|
||||
// TODO(mischnic) prevent matches when this is published to npm
|
||||
issue.filePath.startsWith('[project]/packages/next/'));
|
||||
}
|
||||
export function renderStyledStringToErrorAnsi(string) {
|
||||
function decodeMagicIdentifiers(str) {
|
||||
return str.replaceAll(MAGIC_IDENTIFIER_REGEX, (ident)=>{
|
||||
try {
|
||||
return magenta("{" + decodeMagicIdentifier(ident) + "}");
|
||||
} catch (e) {
|
||||
return magenta("{" + ident + " (decoding failed: " + e + ")}");
|
||||
}
|
||||
});
|
||||
}
|
||||
switch(string.type){
|
||||
case 'text':
|
||||
return decodeMagicIdentifiers(string.value);
|
||||
case 'strong':
|
||||
return bold(red(decodeMagicIdentifiers(string.value)));
|
||||
case 'code':
|
||||
return green(decodeMagicIdentifiers(string.value));
|
||||
case 'line':
|
||||
return string.value.map(renderStyledStringToErrorAnsi).join('');
|
||||
case 'stack':
|
||||
return string.value.map(renderStyledStringToErrorAnsi).join('\n');
|
||||
default:
|
||||
throw Object.defineProperty(new Error('Unknown StyledString type', string), "__NEXT_ERROR_CODE", {
|
||||
value: "E138",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
}
|
||||
export function isPersistentCachingEnabled(config) {
|
||||
var _config_experimental;
|
||||
return ((_config_experimental = config.experimental) == null ? void 0 : _config_experimental.turbopackPersistentCaching) || false;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=utils.js.map
|
||||
1
node_modules/next/dist/esm/shared/lib/turbopack/utils.js.map
generated
vendored
Normal file
1
node_modules/next/dist/esm/shared/lib/turbopack/utils.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue