including-modules
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
||||
import type { Project } from '../../../build/swc/types';
|
||||
/**
|
||||
* Subscribes to compilation events for `project` and prints them using the
|
||||
* `Log` library.
|
||||
*
|
||||
* The `signal` argument is partially implemented. The abort may not happen until the next
|
||||
* compilation event arrives.
|
||||
*/
|
||||
export declare function backgroundLogCompilationEvents(project: Project, { eventTypes, signal }?: {
|
||||
eventTypes?: string[];
|
||||
signal?: AbortSignal;
|
||||
}): void;
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "backgroundLogCompilationEvents", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return backgroundLogCompilationEvents;
|
||||
}
|
||||
});
|
||||
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
||||
const _log = /*#__PURE__*/ _interop_require_wildcard._(require("../../../build/output/log"));
|
||||
function backgroundLogCompilationEvents(project, { eventTypes, signal } = {}) {
|
||||
;
|
||||
(async function() {
|
||||
for await (const event of project.compilationEventsSubscribe(eventTypes)){
|
||||
if (signal?.aborted) {
|
||||
return;
|
||||
}
|
||||
switch(event.severity){
|
||||
case 'EVENT':
|
||||
_log.event(event.message);
|
||||
break;
|
||||
case 'TRACE':
|
||||
_log.trace(event.message);
|
||||
break;
|
||||
case 'INFO':
|
||||
_log.info(event.message);
|
||||
break;
|
||||
case 'WARNING':
|
||||
_log.warn(event.message);
|
||||
break;
|
||||
case 'ERROR':
|
||||
_log.error(event.message);
|
||||
break;
|
||||
case 'FATAL':
|
||||
_log.error(event.message);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
//# sourceMappingURL=compilation-events.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/shared/lib/turbopack/compilation-events.ts"],"sourcesContent":["import type { Project } from '../../../build/swc/types'\nimport * as Log from '../../../build/output/log'\n\n/**\n * Subscribes to compilation events for `project` and prints them using the\n * `Log` library.\n *\n * The `signal` argument is partially implemented. The abort may not happen until the next\n * compilation event arrives.\n */\nexport function backgroundLogCompilationEvents(\n project: Project,\n { eventTypes, signal }: { eventTypes?: string[]; signal?: AbortSignal } = {}\n) {\n ;(async function () {\n for await (const event of project.compilationEventsSubscribe(eventTypes)) {\n if (signal?.aborted) {\n return\n }\n switch (event.severity) {\n case 'EVENT':\n Log.event(event.message)\n break\n case 'TRACE':\n Log.trace(event.message)\n break\n case 'INFO':\n Log.info(event.message)\n break\n case 'WARNING':\n Log.warn(event.message)\n break\n case 'ERROR':\n Log.error(event.message)\n break\n case 'FATAL':\n Log.error(event.message)\n break\n default:\n break\n }\n }\n })()\n}\n"],"names":["backgroundLogCompilationEvents","project","eventTypes","signal","event","compilationEventsSubscribe","aborted","severity","Log","message","trace","info","warn","error"],"mappings":";;;;+BAUgBA;;;eAAAA;;;;+DATK;AASd,SAASA,+BACdC,OAAgB,EAChB,EAAEC,UAAU,EAAEC,MAAM,EAAmD,GAAG,CAAC,CAAC;;IAE1E,CAAA;QACA,WAAW,MAAMC,SAASH,QAAQI,0BAA0B,CAACH,YAAa;YACxE,IAAIC,QAAQG,SAAS;gBACnB;YACF;YACA,OAAQF,MAAMG,QAAQ;gBACpB,KAAK;oBACHC,KAAIJ,KAAK,CAACA,MAAMK,OAAO;oBACvB;gBACF,KAAK;oBACHD,KAAIE,KAAK,CAACN,MAAMK,OAAO;oBACvB;gBACF,KAAK;oBACHD,KAAIG,IAAI,CAACP,MAAMK,OAAO;oBACtB;gBACF,KAAK;oBACHD,KAAII,IAAI,CAACR,MAAMK,OAAO;oBACtB;gBACF,KAAK;oBACHD,KAAIK,KAAK,CAACT,MAAMK,OAAO;oBACvB;gBACF,KAAK;oBACHD,KAAIK,KAAK,CAACT,MAAMK,OAAO;oBACvB;gBACF;oBACE;YACJ;QACF;IACF,CAAA;AACF","ignoreList":[0]}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* `app` -> app dir
|
||||
* `pages` -> pages dir
|
||||
* `root` -> middleware / instrumentation
|
||||
* `assets` -> assets
|
||||
*/
|
||||
export type EntryKeyType = 'app' | 'pages' | 'root' | 'assets';
|
||||
export type EntryKeySide = 'client' | 'server';
|
||||
export type EntryKey = `{"type":"${EntryKeyType}","side":"${EntryKeyType}","page":"${string}"}`;
|
||||
/**
|
||||
* Get a key that's unique across all entrypoints.
|
||||
*/
|
||||
export declare function getEntryKey(type: EntryKeyType, side: EntryKeySide, page: string): EntryKey;
|
||||
/**
|
||||
* Split an `EntryKey` up into its components.
|
||||
*/
|
||||
export declare function splitEntryKey(key: EntryKey): {
|
||||
type: EntryKeyType;
|
||||
side: EntryKeySide;
|
||||
page: string;
|
||||
};
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* `app` -> app dir
|
||||
* `pages` -> pages dir
|
||||
* `root` -> middleware / instrumentation
|
||||
* `assets` -> assets
|
||||
*/ "use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
0 && (module.exports = {
|
||||
getEntryKey: null,
|
||||
splitEntryKey: null
|
||||
});
|
||||
function _export(target, all) {
|
||||
for(var name in all)Object.defineProperty(target, name, {
|
||||
enumerable: true,
|
||||
get: all[name]
|
||||
});
|
||||
}
|
||||
_export(exports, {
|
||||
getEntryKey: function() {
|
||||
return getEntryKey;
|
||||
},
|
||||
splitEntryKey: function() {
|
||||
return splitEntryKey;
|
||||
}
|
||||
});
|
||||
function getEntryKey(type, side, page) {
|
||||
return JSON.stringify({
|
||||
type,
|
||||
side,
|
||||
page
|
||||
});
|
||||
}
|
||||
function splitEntryKey(key) {
|
||||
return JSON.parse(key);
|
||||
}
|
||||
|
||||
//# sourceMappingURL=entry-key.js.map
|
||||
+1
@@ -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","splitEntryKey","type","side","page","JSON","stringify","key","parse"],"mappings":"AAAA;;;;;CAKC;;;;;;;;;;;;;;;IAWeA,WAAW;eAAXA;;IAWAC,aAAa;eAAbA;;;AAXT,SAASD,YACdE,IAAkB,EAClBC,IAAkB,EAClBC,IAAY;IAEZ,OAAOC,KAAKC,SAAS,CAAC;QAAEJ;QAAMC;QAAMC;IAAK;AAC3C;AAKO,SAASH,cAAcM,GAAa;IAKzC,OAAOF,KAAKG,KAAK,CAACD;AACpB","ignoreList":[0]}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
import type { TurbopackInternalErrorOpts } from '../../../build/swc/generated-native';
|
||||
/**
|
||||
* An error caused by a bug in Turbopack, and not the user's code (e.g. a Rust panic). These should
|
||||
* be written to a log file and details should not be shown to the user.
|
||||
*
|
||||
* These are constructed in Turbopack by calling `throwTurbopackInternalError`.
|
||||
*/
|
||||
export declare class TurbopackInternalError extends Error {
|
||||
name: string;
|
||||
location: string | undefined;
|
||||
__NEXT_ERROR_CODE: string;
|
||||
constructor({ message, anonymizedLocation }: TurbopackInternalErrorOpts);
|
||||
}
|
||||
/**
|
||||
* A helper used by the napi Rust entrypoints to construct and throw a `TurbopackInternalError`.
|
||||
*
|
||||
* When called, this will emit a telemetry event.
|
||||
*/
|
||||
export declare function throwTurbopackInternalError(conversionError: Error | null, opts: TurbopackInternalErrorOpts): never;
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
0 && (module.exports = {
|
||||
TurbopackInternalError: null,
|
||||
throwTurbopackInternalError: null
|
||||
});
|
||||
function _export(target, all) {
|
||||
for(var name in all)Object.defineProperty(target, name, {
|
||||
enumerable: true,
|
||||
get: all[name]
|
||||
});
|
||||
}
|
||||
_export(exports, {
|
||||
TurbopackInternalError: function() {
|
||||
return TurbopackInternalError;
|
||||
},
|
||||
throwTurbopackInternalError: function() {
|
||||
return throwTurbopackInternalError;
|
||||
}
|
||||
});
|
||||
const _events = require("../../../telemetry/events");
|
||||
const _shared = require("../../../trace/shared");
|
||||
class TurbopackInternalError extends Error {
|
||||
constructor({ message, anonymizedLocation }){
|
||||
super(message), this.name = 'TurbopackInternalError', // Manually set this as this isn't statically determinable
|
||||
this.__NEXT_ERROR_CODE = 'TurbopackInternalError';
|
||||
this.location = anonymizedLocation;
|
||||
}
|
||||
}
|
||||
function throwTurbopackInternalError(conversionError, opts) {
|
||||
if (conversionError != null) {
|
||||
// Somehow napi failed to convert `opts` to a JS object??? Just give up and throw that instead.
|
||||
throw Object.defineProperty(new Error('NAPI type conversion error in throwTurbopackInternalError', {
|
||||
cause: conversionError
|
||||
}), "__NEXT_ERROR_CODE", {
|
||||
value: "E723",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
const err = new TurbopackInternalError(opts);
|
||||
const telemetry = _shared.traceGlobals.get('telemetry');
|
||||
if (telemetry) {
|
||||
telemetry.record((0, _events.eventErrorThrown)(err, opts.anonymizedLocation));
|
||||
} else {
|
||||
console.error('Expected `telemetry` to be set in globals');
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=internal-error.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/shared/lib/turbopack/internal-error.ts"],"sourcesContent":["import type { TurbopackInternalErrorOpts } from '../../../build/swc/generated-native'\nimport { eventErrorThrown } from '../../../telemetry/events'\nimport { traceGlobals } from '../../../trace/shared'\n\n/**\n * An error caused by a bug in Turbopack, and not the user's code (e.g. a Rust panic). These should\n * be written to a log file and details should not be shown to the user.\n *\n * These are constructed in Turbopack by calling `throwTurbopackInternalError`.\n */\nexport class TurbopackInternalError extends Error {\n name = 'TurbopackInternalError'\n location: string | undefined\n\n // Manually set this as this isn't statically determinable\n __NEXT_ERROR_CODE = 'TurbopackInternalError'\n\n constructor({ message, anonymizedLocation }: TurbopackInternalErrorOpts) {\n super(message)\n this.location = anonymizedLocation\n }\n}\n\n/**\n * A helper used by the napi Rust entrypoints to construct and throw a `TurbopackInternalError`.\n *\n * When called, this will emit a telemetry event.\n */\nexport function throwTurbopackInternalError(\n conversionError: Error | null,\n opts: TurbopackInternalErrorOpts\n): never {\n if (conversionError != null) {\n // Somehow napi failed to convert `opts` to a JS object??? Just give up and throw that instead.\n throw new Error(\n 'NAPI type conversion error in throwTurbopackInternalError',\n {\n cause: conversionError,\n }\n )\n }\n const err = new TurbopackInternalError(opts)\n const telemetry = traceGlobals.get('telemetry')\n if (telemetry) {\n telemetry.record(eventErrorThrown(err, opts.anonymizedLocation))\n } else {\n console.error('Expected `telemetry` to be set in globals')\n }\n throw err\n}\n"],"names":["TurbopackInternalError","throwTurbopackInternalError","Error","constructor","message","anonymizedLocation","name","__NEXT_ERROR_CODE","location","conversionError","opts","cause","err","telemetry","traceGlobals","get","record","eventErrorThrown","console","error"],"mappings":";;;;;;;;;;;;;;;IAUaA,sBAAsB;eAAtBA;;IAkBGC,2BAA2B;eAA3BA;;;wBA3BiB;wBACJ;AAQtB,MAAMD,+BAA+BE;IAO1CC,YAAY,EAAEC,OAAO,EAAEC,kBAAkB,EAA8B,CAAE;QACvE,KAAK,CAACD,eAPRE,OAAO,0BAGP,0DAA0D;aAC1DC,oBAAoB;QAIlB,IAAI,CAACC,QAAQ,GAAGH;IAClB;AACF;AAOO,SAASJ,4BACdQ,eAA6B,EAC7BC,IAAgC;IAEhC,IAAID,mBAAmB,MAAM;QAC3B,+FAA+F;QAC/F,MAAM,qBAKL,CALK,IAAIP,MACR,6DACA;YACES,OAAOF;QACT,IAJI,qBAAA;mBAAA;wBAAA;0BAAA;QAKN;IACF;IACA,MAAMG,MAAM,IAAIZ,uBAAuBU;IACvC,MAAMG,YAAYC,oBAAY,CAACC,GAAG,CAAC;IACnC,IAAIF,WAAW;QACbA,UAAUG,MAAM,CAACC,IAAAA,wBAAgB,EAACL,KAAKF,KAAKL,kBAAkB;IAChE,OAAO;QACLa,QAAQC,KAAK,CAAC;IAChB;IACA,MAAMP;AACR","ignoreList":[0]}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
import type { MiddlewareManifest } from '../../../build/webpack/plugins/middleware-plugin';
|
||||
import type { SetupOpts } from '../../../server/lib/router-utils/setup-dev-bundler';
|
||||
import { type EntryKey } from './entry-key';
|
||||
import type { CustomRoutes } from '../../../lib/load-custom-routes';
|
||||
import type { Entrypoints } from '../../../build/swc/types';
|
||||
interface InstrumentationDefinition {
|
||||
files: string[];
|
||||
name: 'instrumentation';
|
||||
}
|
||||
type TurbopackMiddlewareManifest = MiddlewareManifest & {
|
||||
instrumentation?: InstrumentationDefinition;
|
||||
};
|
||||
export declare class TurbopackManifestLoader {
|
||||
private actionManifests;
|
||||
private appPathsManifests;
|
||||
private buildManifests;
|
||||
private clientBuildManifests;
|
||||
private fontManifests;
|
||||
private middlewareManifests;
|
||||
private pagesManifests;
|
||||
private webpackStats;
|
||||
private encryptionKey;
|
||||
private cachedInterceptionRewrites;
|
||||
private readonly distDir;
|
||||
private readonly buildId;
|
||||
constructor({ distDir, buildId, encryptionKey, }: {
|
||||
buildId: string;
|
||||
distDir: string;
|
||||
encryptionKey: string;
|
||||
});
|
||||
delete(key: EntryKey): void;
|
||||
loadActionManifest(pageName: string): void;
|
||||
private mergeActionManifests;
|
||||
private writeActionManifest;
|
||||
loadAppPathsManifest(pageName: string): void;
|
||||
private writeAppPathsManifest;
|
||||
private writeWebpackStats;
|
||||
loadBuildManifest(pageName: string, type?: 'app' | 'pages'): void;
|
||||
loadClientBuildManifest(pageName: string, type?: 'app' | 'pages'): void;
|
||||
loadWebpackStats(pageName: string, type?: 'app' | 'pages'): void;
|
||||
private mergeWebpackStats;
|
||||
private mergeBuildManifests;
|
||||
private mergeClientBuildManifests;
|
||||
private writeInterceptionRouteRewriteManifest;
|
||||
private writeBuildManifest;
|
||||
private writeClientBuildManifest;
|
||||
loadFontManifest(pageName: string, type?: 'app' | 'pages'): void;
|
||||
private mergeFontManifests;
|
||||
private writeNextFontManifest;
|
||||
/**
|
||||
* @returns If the manifest was written or not
|
||||
*/
|
||||
loadMiddlewareManifest(pageName: string, type: 'pages' | 'app' | 'middleware' | 'instrumentation'): boolean;
|
||||
getMiddlewareManifest(key: EntryKey): TurbopackMiddlewareManifest | undefined;
|
||||
deleteMiddlewareManifest(key: EntryKey): void;
|
||||
private mergeMiddlewareManifests;
|
||||
private writeMiddlewareManifest;
|
||||
loadPagesManifest(pageName: string): void;
|
||||
private mergePagesManifests;
|
||||
private writePagesManifest;
|
||||
writeManifests({ devRewrites, productionRewrites, entrypoints, }: {
|
||||
devRewrites: SetupOpts['fsChecker']['rewrites'] | undefined;
|
||||
productionRewrites: CustomRoutes['rewrites'] | undefined;
|
||||
entrypoints: Entrypoints;
|
||||
}): void;
|
||||
}
|
||||
export {};
|
||||
+524
@@ -0,0 +1,524 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "TurbopackManifestLoader", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return TurbopackManifestLoader;
|
||||
}
|
||||
});
|
||||
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
||||
const _constants = require("../constants");
|
||||
const _path = require("path");
|
||||
const _fs = require("fs");
|
||||
const _requirecache = require("../../../server/dev/require-cache");
|
||||
const _writeatomic = require("../../../lib/fs/write-atomic");
|
||||
const _generateinterceptionroutesrewrites = require("../../../lib/generate-interception-routes-rewrites");
|
||||
const _getassetpathfromroute = /*#__PURE__*/ _interop_require_default._(require("../router/utils/get-asset-path-from-route"));
|
||||
const _entrykey = require("./entry-key");
|
||||
const _utils = require("../router/utils");
|
||||
const _turbopackutils = require("../../../server/dev/turbopack-utils");
|
||||
const _trytoparsepath = require("../../../lib/try-to-parse-path");
|
||||
const _routematchutils = require("../router/utils/route-match-utils");
|
||||
const _buildmanifestpluginutils = require("../../../build/webpack/plugins/build-manifest-plugin-utils");
|
||||
const getManifestPath = (page, distDir, name, type, firstCall)=>{
|
||||
let manifestPath = _path.posix.join(distDir, `server`, type, type === 'middleware' || type === 'instrumentation' ? '' : type === 'app' ? page : (0, _getassetpathfromroute.default)(page), name);
|
||||
if (firstCall) {
|
||||
const isSitemapRoute = /[\\/]sitemap(.xml)?\/route$/.test(page);
|
||||
// Check the ambiguity of /sitemap and /sitemap.xml
|
||||
if (isSitemapRoute && !(0, _fs.existsSync)(manifestPath)) {
|
||||
manifestPath = getManifestPath(page.replace(/\/sitemap\/route$/, '/sitemap.xml/route'), distDir, name, type, false);
|
||||
}
|
||||
// existsSync is faster than using the async version
|
||||
if (!(0, _fs.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 = (0, _turbopackutils.addRouteSuffix)((0, _turbopackutils.addMetadataIdToRoute)((0, _turbopackutils.removeRouteSuffix)(page)));
|
||||
manifestPath = getManifestPath(metadataPage, distDir, name, type, false);
|
||||
}
|
||||
}
|
||||
return manifestPath;
|
||||
};
|
||||
function readPartialManifestContent(distDir, name, pageName, type = 'pages') {
|
||||
const page = pageName;
|
||||
const manifestPath = getManifestPath(page, distDir, name, type, true);
|
||||
return (0, _fs.readFileSync)(_path.posix.join(manifestPath), 'utf-8');
|
||||
}
|
||||
/// Helper class that stores a map of manifests and tracks if they have changed
|
||||
/// since the last time they were written to disk. This is used to avoid
|
||||
/// unnecessary writes to disk.
|
||||
class ManifestsMap {
|
||||
set(key, value) {
|
||||
if (this.rawMap.get(key) === value) return;
|
||||
this.changed = true;
|
||||
this.rawMap.set(key, value);
|
||||
this.map.set(key, JSON.parse(value));
|
||||
}
|
||||
delete(key) {
|
||||
if (this.map.has(key)) {
|
||||
this.changed = true;
|
||||
this.rawMap.delete(key);
|
||||
this.map.delete(key);
|
||||
}
|
||||
}
|
||||
get(key) {
|
||||
return this.map.get(key);
|
||||
}
|
||||
takeChanged(extraInvalidationKey) {
|
||||
let changed = this.changed;
|
||||
if (extraInvalidationKey !== undefined) {
|
||||
const stringified = JSON.stringify(extraInvalidationKey);
|
||||
if (this.extraInvalidationKey !== stringified) {
|
||||
this.extraInvalidationKey = stringified;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
this.changed = false;
|
||||
return changed;
|
||||
}
|
||||
values() {
|
||||
return this.map.values();
|
||||
}
|
||||
constructor(){
|
||||
this.rawMap = new Map();
|
||||
this.map = new Map();
|
||||
this.extraInvalidationKey = undefined;
|
||||
this.changed = true;
|
||||
}
|
||||
}
|
||||
class TurbopackManifestLoader {
|
||||
constructor({ distDir, buildId, encryptionKey }){
|
||||
this.actionManifests = new ManifestsMap();
|
||||
this.appPathsManifests = new ManifestsMap();
|
||||
this.buildManifests = new ManifestsMap();
|
||||
this.clientBuildManifests = new ManifestsMap();
|
||||
this.fontManifests = new ManifestsMap();
|
||||
this.middlewareManifests = new ManifestsMap();
|
||||
this.pagesManifests = new ManifestsMap();
|
||||
this.webpackStats = new ManifestsMap();
|
||||
/// interceptionRewrites that have been written to disk
|
||||
/// This is used to avoid unnecessary writes if the rewrites haven't changed
|
||||
this.cachedInterceptionRewrites = undefined;
|
||||
this.distDir = distDir;
|
||||
this.buildId = buildId;
|
||||
this.encryptionKey = encryptionKey;
|
||||
}
|
||||
delete(key) {
|
||||
this.actionManifests.delete(key);
|
||||
this.appPathsManifests.delete(key);
|
||||
this.buildManifests.delete(key);
|
||||
this.clientBuildManifests.delete(key);
|
||||
this.fontManifests.delete(key);
|
||||
this.middlewareManifests.delete(key);
|
||||
this.pagesManifests.delete(key);
|
||||
this.webpackStats.delete(key);
|
||||
}
|
||||
loadActionManifest(pageName) {
|
||||
this.actionManifests.set((0, _entrykey.getEntryKey)('app', 'server', pageName), readPartialManifestContent(this.distDir, `${_constants.SERVER_REFERENCE_MANIFEST}.json`, pageName, 'app'));
|
||||
}
|
||||
mergeActionManifests(manifests) {
|
||||
const manifest = {
|
||||
node: {},
|
||||
edge: {},
|
||||
encryptionKey: this.encryptionKey
|
||||
};
|
||||
function mergeActionIds(actionEntries, other) {
|
||||
for(const key in other){
|
||||
const action = actionEntries[key] ??= {
|
||||
workers: {},
|
||||
layer: {}
|
||||
};
|
||||
action.filename = other[key].filename;
|
||||
action.exportedName = other[key].exportedName;
|
||||
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;
|
||||
}
|
||||
writeActionManifest() {
|
||||
if (!this.actionManifests.takeChanged()) {
|
||||
return;
|
||||
}
|
||||
const actionManifest = this.mergeActionManifests(this.actionManifests.values());
|
||||
const actionManifestJsonPath = (0, _path.join)(this.distDir, 'server', `${_constants.SERVER_REFERENCE_MANIFEST}.json`);
|
||||
const actionManifestJsPath = (0, _path.join)(this.distDir, 'server', `${_constants.SERVER_REFERENCE_MANIFEST}.js`);
|
||||
const json = JSON.stringify(actionManifest, null, 2);
|
||||
(0, _requirecache.deleteCache)(actionManifestJsonPath);
|
||||
(0, _requirecache.deleteCache)(actionManifestJsPath);
|
||||
(0, _writeatomic.writeFileAtomic)(actionManifestJsonPath, json);
|
||||
(0, _writeatomic.writeFileAtomic)(actionManifestJsPath, `self.__RSC_SERVER_MANIFEST=${JSON.stringify(json)}`);
|
||||
}
|
||||
loadAppPathsManifest(pageName) {
|
||||
this.appPathsManifests.set((0, _entrykey.getEntryKey)('app', 'server', pageName), readPartialManifestContent(this.distDir, _constants.APP_PATHS_MANIFEST, pageName, 'app'));
|
||||
}
|
||||
writeAppPathsManifest() {
|
||||
if (!this.appPathsManifests.takeChanged()) {
|
||||
return;
|
||||
}
|
||||
const appPathsManifest = this.mergePagesManifests(this.appPathsManifests.values());
|
||||
const appPathsManifestPath = (0, _path.join)(this.distDir, 'server', _constants.APP_PATHS_MANIFEST);
|
||||
(0, _requirecache.deleteCache)(appPathsManifestPath);
|
||||
(0, _writeatomic.writeFileAtomic)(appPathsManifestPath, JSON.stringify(appPathsManifest, null, 2));
|
||||
}
|
||||
writeWebpackStats() {
|
||||
if (!this.webpackStats.takeChanged()) {
|
||||
return;
|
||||
}
|
||||
const webpackStats = this.mergeWebpackStats(this.webpackStats.values());
|
||||
const path = (0, _path.join)(this.distDir, 'server', _constants.WEBPACK_STATS);
|
||||
(0, _requirecache.deleteCache)(path);
|
||||
(0, _writeatomic.writeFileAtomic)(path, JSON.stringify(webpackStats, null, 2));
|
||||
}
|
||||
loadBuildManifest(pageName, type = 'pages') {
|
||||
this.buildManifests.set((0, _entrykey.getEntryKey)(type, 'server', pageName), readPartialManifestContent(this.distDir, _constants.BUILD_MANIFEST, pageName, type));
|
||||
}
|
||||
loadClientBuildManifest(pageName, type = 'pages') {
|
||||
this.clientBuildManifests.set((0, _entrykey.getEntryKey)(type, 'server', pageName), readPartialManifestContent(this.distDir, _constants.TURBOPACK_CLIENT_BUILD_MANIFEST, pageName, type));
|
||||
}
|
||||
loadWebpackStats(pageName, type = 'pages') {
|
||||
this.webpackStats.set((0, _entrykey.getEntryKey)(type, 'client', pageName), readPartialManifestContent(this.distDir, _constants.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.id)) {
|
||||
chunks.set(chunk.id, 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 {
|
||||
version: 'Turbopack',
|
||||
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: [],
|
||||
polyfillFiles: [],
|
||||
lowPriorityFiles: [
|
||||
`static/${this.buildId}/_ssgManifest.js`,
|
||||
`static/${this.buildId}/_buildManifest.js`
|
||||
],
|
||||
rootMainFiles: []
|
||||
};
|
||||
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;
|
||||
}
|
||||
mergeClientBuildManifests(manifests, rewrites, sortedPageKeys) {
|
||||
const manifest = {
|
||||
__rewrites: rewrites,
|
||||
sortedPages: sortedPageKeys
|
||||
};
|
||||
for (const m of manifests){
|
||||
Object.assign(manifest, m);
|
||||
}
|
||||
return sortObjectByKey(manifest);
|
||||
}
|
||||
writeInterceptionRouteRewriteManifest(devRewrites, productionRewrites) {
|
||||
const rewrites = productionRewrites ?? {
|
||||
...devRewrites,
|
||||
beforeFiles: (devRewrites?.beforeFiles ?? []).map(_buildmanifestpluginutils.processRoute),
|
||||
afterFiles: (devRewrites?.afterFiles ?? []).map(_buildmanifestpluginutils.processRoute),
|
||||
fallback: (devRewrites?.fallback ?? []).map(_buildmanifestpluginutils.processRoute)
|
||||
};
|
||||
const interceptionRewrites = JSON.stringify(rewrites.beforeFiles.filter(_generateinterceptionroutesrewrites.isInterceptionRouteRewrite));
|
||||
if (this.cachedInterceptionRewrites === interceptionRewrites) {
|
||||
return;
|
||||
}
|
||||
this.cachedInterceptionRewrites = interceptionRewrites;
|
||||
const interceptionRewriteManifestPath = (0, _path.join)(this.distDir, 'server', `${_constants.INTERCEPTION_ROUTE_REWRITE_MANIFEST}.js`);
|
||||
(0, _requirecache.deleteCache)(interceptionRewriteManifestPath);
|
||||
(0, _writeatomic.writeFileAtomic)(interceptionRewriteManifestPath, `self.__INTERCEPTION_ROUTE_REWRITE_MANIFEST=${JSON.stringify(interceptionRewrites)};`);
|
||||
}
|
||||
writeBuildManifest() {
|
||||
if (!this.buildManifests.takeChanged()) {
|
||||
return;
|
||||
}
|
||||
const buildManifest = this.mergeBuildManifests(this.buildManifests.values());
|
||||
const buildManifestPath = (0, _path.join)(this.distDir, _constants.BUILD_MANIFEST);
|
||||
const middlewareBuildManifestPath = (0, _path.join)(this.distDir, 'server', `${_constants.MIDDLEWARE_BUILD_MANIFEST}.js`);
|
||||
(0, _requirecache.deleteCache)(buildManifestPath);
|
||||
(0, _requirecache.deleteCache)(middlewareBuildManifestPath);
|
||||
(0, _writeatomic.writeFileAtomic)(buildManifestPath, JSON.stringify(buildManifest, null, 2));
|
||||
(0, _writeatomic.writeFileAtomic)(middlewareBuildManifestPath, // we use globalThis here because middleware can be node
|
||||
// which doesn't have "self"
|
||||
(0, _buildmanifestpluginutils.createEdgeRuntimeManifest)(buildManifest));
|
||||
// Write fallback build manifest
|
||||
const fallbackBuildManifest = this.mergeBuildManifests([
|
||||
this.buildManifests.get((0, _entrykey.getEntryKey)('pages', 'server', '_app')),
|
||||
this.buildManifests.get((0, _entrykey.getEntryKey)('pages', 'server', '_error'))
|
||||
].filter(Boolean));
|
||||
const fallbackBuildManifestPath = (0, _path.join)(this.distDir, `fallback-${_constants.BUILD_MANIFEST}`);
|
||||
(0, _requirecache.deleteCache)(fallbackBuildManifestPath);
|
||||
(0, _writeatomic.writeFileAtomic)(fallbackBuildManifestPath, JSON.stringify(fallbackBuildManifest, null, 2));
|
||||
}
|
||||
writeClientBuildManifest(entrypoints, devRewrites, productionRewrites) {
|
||||
const rewrites = (0, _buildmanifestpluginutils.normalizeRewritesForBuildManifest)(productionRewrites ?? {
|
||||
...devRewrites,
|
||||
beforeFiles: (devRewrites?.beforeFiles ?? []).map(_buildmanifestpluginutils.processRoute),
|
||||
afterFiles: (devRewrites?.afterFiles ?? []).map(_buildmanifestpluginutils.processRoute),
|
||||
fallback: (devRewrites?.fallback ?? []).map(_buildmanifestpluginutils.processRoute)
|
||||
});
|
||||
const pagesKeys = [
|
||||
...entrypoints.page.keys()
|
||||
];
|
||||
if (entrypoints.global.app) {
|
||||
pagesKeys.push('/_app');
|
||||
}
|
||||
if (entrypoints.global.error) {
|
||||
pagesKeys.push('/_error');
|
||||
}
|
||||
const sortedPageKeys = (0, _utils.getSortedRoutes)(pagesKeys);
|
||||
if (!this.clientBuildManifests.takeChanged({
|
||||
rewrites,
|
||||
sortedPageKeys
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
const clientBuildManifest = this.mergeClientBuildManifests(this.clientBuildManifests.values(), rewrites, sortedPageKeys);
|
||||
const clientBuildManifestJs = `self.__BUILD_MANIFEST = ${JSON.stringify(clientBuildManifest, null, 2)};self.__BUILD_MANIFEST_CB && self.__BUILD_MANIFEST_CB()`;
|
||||
(0, _writeatomic.writeFileAtomic)((0, _path.join)(this.distDir, 'static', this.buildId, '_buildManifest.js'), clientBuildManifestJs);
|
||||
(0, _writeatomic.writeFileAtomic)((0, _path.join)(this.distDir, 'static', this.buildId, '_ssgManifest.js'), _buildmanifestpluginutils.srcEmptySsgManifest);
|
||||
}
|
||||
loadFontManifest(pageName, type = 'pages') {
|
||||
this.fontManifests.set((0, _entrykey.getEntryKey)(type, 'server', pageName), readPartialManifestContent(this.distDir, `${_constants.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() {
|
||||
if (!this.fontManifests.takeChanged()) {
|
||||
return;
|
||||
}
|
||||
const fontManifest = this.mergeFontManifests(this.fontManifests.values());
|
||||
const json = JSON.stringify(fontManifest, null, 2);
|
||||
const fontManifestJsonPath = (0, _path.join)(this.distDir, 'server', `${_constants.NEXT_FONT_MANIFEST}.json`);
|
||||
const fontManifestJsPath = (0, _path.join)(this.distDir, 'server', `${_constants.NEXT_FONT_MANIFEST}.js`);
|
||||
(0, _requirecache.deleteCache)(fontManifestJsonPath);
|
||||
(0, _requirecache.deleteCache)(fontManifestJsPath);
|
||||
(0, _writeatomic.writeFileAtomic)(fontManifestJsonPath, json);
|
||||
(0, _writeatomic.writeFileAtomic)(fontManifestJsPath, `self.__NEXT_FONT_MANIFEST=${JSON.stringify(json)}`);
|
||||
}
|
||||
/**
|
||||
* @returns If the manifest was written or not
|
||||
*/ loadMiddlewareManifest(pageName, type) {
|
||||
const middlewareManifestPath = getManifestPath(pageName, this.distDir, _constants.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 (!(0, _fs.existsSync)(middlewareManifestPath)) {
|
||||
return false;
|
||||
}
|
||||
this.middlewareManifests.set((0, _entrykey.getEntryKey)(type === 'middleware' || type === 'instrumentation' ? 'root' : type, 'server', pageName), readPartialManifestContent(this.distDir, _constants.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)=>{
|
||||
return {
|
||||
...fun,
|
||||
files: [
|
||||
...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 = (0, _routematchutils.safePathToRegexp)(matcher.originalSource, [], {
|
||||
delimiter: '/',
|
||||
sensitive: false,
|
||||
strict: true
|
||||
}).source.replaceAll('\\/', '/');
|
||||
}
|
||||
}
|
||||
}
|
||||
manifest.sortedMiddleware = Object.keys(manifest.middleware);
|
||||
return manifest;
|
||||
}
|
||||
writeMiddlewareManifest() {
|
||||
if (!this.middlewareManifests.takeChanged()) {
|
||||
return;
|
||||
}
|
||||
const middlewareManifest = this.mergeMiddlewareManifests(this.middlewareManifests.values());
|
||||
// Server middleware manifest
|
||||
// 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 = (0, _trytoparsepath.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 = (0, _path.join)(this.distDir, 'server', _constants.MIDDLEWARE_MANIFEST);
|
||||
(0, _requirecache.deleteCache)(middlewareManifestPath);
|
||||
(0, _writeatomic.writeFileAtomic)(middlewareManifestPath, JSON.stringify(middlewareManifest, null, 2));
|
||||
// Client middleware manifest
|
||||
const matchers = middlewareManifest?.middleware['/']?.matchers || [];
|
||||
const clientMiddlewareManifestPath = (0, _path.join)(this.distDir, 'static', this.buildId, `${_constants.TURBOPACK_CLIENT_MIDDLEWARE_MANIFEST}`);
|
||||
(0, _requirecache.deleteCache)(clientMiddlewareManifestPath);
|
||||
(0, _writeatomic.writeFileAtomic)(clientMiddlewareManifestPath, JSON.stringify(matchers, null, 2));
|
||||
}
|
||||
loadPagesManifest(pageName) {
|
||||
this.pagesManifests.set((0, _entrykey.getEntryKey)('pages', 'server', pageName), readPartialManifestContent(this.distDir, _constants.PAGES_MANIFEST, pageName));
|
||||
}
|
||||
mergePagesManifests(manifests) {
|
||||
const manifest = {};
|
||||
for (const m of manifests){
|
||||
Object.assign(manifest, m);
|
||||
}
|
||||
return sortObjectByKey(manifest);
|
||||
}
|
||||
writePagesManifest() {
|
||||
if (!this.pagesManifests.takeChanged()) {
|
||||
return;
|
||||
}
|
||||
const pagesManifest = this.mergePagesManifests(this.pagesManifests.values());
|
||||
const pagesManifestPath = (0, _path.join)(this.distDir, 'server', _constants.PAGES_MANIFEST);
|
||||
(0, _requirecache.deleteCache)(pagesManifestPath);
|
||||
(0, _writeatomic.writeFileAtomic)(pagesManifestPath, JSON.stringify(pagesManifest, null, 2));
|
||||
}
|
||||
writeManifests({ devRewrites, productionRewrites, entrypoints }) {
|
||||
this.writeActionManifest();
|
||||
this.writeAppPathsManifest();
|
||||
this.writeBuildManifest();
|
||||
this.writeInterceptionRouteRewriteManifest(devRewrites, productionRewrites);
|
||||
this.writeClientBuildManifest(entrypoints, devRewrites, productionRewrites);
|
||||
this.writeMiddlewareManifest();
|
||||
this.writeNextFontManifest();
|
||||
this.writePagesManifest();
|
||||
if (process.env.TURBOPACK_STATS != null) {
|
||||
this.writeWebpackStats();
|
||||
}
|
||||
}
|
||||
}
|
||||
function sortObjectByKey(obj) {
|
||||
return Object.keys(obj).sort().reduce((acc, key)=>{
|
||||
acc[key] = obj[key];
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
//# sourceMappingURL=manifest-loader.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+27
@@ -0,0 +1,27 @@
|
||||
import type { Issue, StyledString, TurbopackResult } from '../../../build/swc/types';
|
||||
import type { EntryKey } from './entry-key';
|
||||
import type { NextConfigComplete } from '../../../server/config-shared';
|
||||
type IssueKey = `${Issue['severity']}-${Issue['filePath']}-${string}-${string}`;
|
||||
export type IssuesMap = Map<IssueKey, Issue>;
|
||||
export type EntryIssuesMap = Map<EntryKey, IssuesMap>;
|
||||
export type TopLevelIssuesMap = IssuesMap;
|
||||
/**
|
||||
* An error generated from emitted Turbopack issues. This can include build
|
||||
* errors caused by issues with user code.
|
||||
*/
|
||||
export declare class ModuleBuildError extends Error {
|
||||
name: string;
|
||||
}
|
||||
/**
|
||||
* Thin stopgap workaround layer to mimic existing wellknown-errors-plugin in webpack's build
|
||||
* to emit certain type of errors into cli.
|
||||
*/
|
||||
export declare function isWellKnownError(issue: Issue): boolean;
|
||||
export declare function getIssueKey(issue: Issue): IssueKey;
|
||||
export declare function processIssues(currentEntryIssues: EntryIssuesMap, key: EntryKey, result: TurbopackResult, throwIssue: boolean, logErrors: boolean): void;
|
||||
export declare function formatIssue(issue: Issue): string;
|
||||
export declare function isRelevantWarning(issue: Issue): boolean;
|
||||
export declare function renderStyledStringToErrorAnsi(string: StyledString): string;
|
||||
export declare function isFileSystemCacheEnabledForDev(config: NextConfigComplete): boolean;
|
||||
export declare function isFileSystemCacheEnabledForBuild(config: NextConfigComplete): boolean;
|
||||
export {};
|
||||
+279
@@ -0,0 +1,279 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
0 && (module.exports = {
|
||||
ModuleBuildError: null,
|
||||
formatIssue: null,
|
||||
getIssueKey: null,
|
||||
isFileSystemCacheEnabledForBuild: null,
|
||||
isFileSystemCacheEnabledForDev: null,
|
||||
isRelevantWarning: null,
|
||||
isWellKnownError: null,
|
||||
processIssues: null,
|
||||
renderStyledStringToErrorAnsi: null
|
||||
});
|
||||
function _export(target, all) {
|
||||
for(var name in all)Object.defineProperty(target, name, {
|
||||
enumerable: true,
|
||||
get: all[name]
|
||||
});
|
||||
}
|
||||
_export(exports, {
|
||||
ModuleBuildError: function() {
|
||||
return ModuleBuildError;
|
||||
},
|
||||
formatIssue: function() {
|
||||
return formatIssue;
|
||||
},
|
||||
getIssueKey: function() {
|
||||
return getIssueKey;
|
||||
},
|
||||
isFileSystemCacheEnabledForBuild: function() {
|
||||
return isFileSystemCacheEnabledForBuild;
|
||||
},
|
||||
isFileSystemCacheEnabledForDev: function() {
|
||||
return isFileSystemCacheEnabledForDev;
|
||||
},
|
||||
isRelevantWarning: function() {
|
||||
return isRelevantWarning;
|
||||
},
|
||||
isWellKnownError: function() {
|
||||
return isWellKnownError;
|
||||
},
|
||||
processIssues: function() {
|
||||
return processIssues;
|
||||
},
|
||||
renderStyledStringToErrorAnsi: function() {
|
||||
return renderStyledStringToErrorAnsi;
|
||||
}
|
||||
});
|
||||
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
||||
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
||||
const _picocolors = require("../../../lib/picocolors");
|
||||
const _isinternal = /*#__PURE__*/ _interop_require_default._(require("../is-internal"));
|
||||
const _magicidentifier = require("../magic-identifier");
|
||||
const _log = /*#__PURE__*/ _interop_require_wildcard._(require("../../../build/output/log"));
|
||||
const VERBOSE_ISSUES = !!process.env.NEXT_TURBOPACK_VERBOSE_ISSUES;
|
||||
class ModuleBuildError extends Error {
|
||||
constructor(...args){
|
||||
super(...args), this.name = 'ModuleBuildError';
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
function getIssueKey(issue) {
|
||||
return `${issue.severity}-${issue.filePath}-${JSON.stringify(issue.title)}-${JSON.stringify(issue.description)}`;
|
||||
}
|
||||
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
|
||||
});
|
||||
}
|
||||
}
|
||||
function formatIssue(issue) {
|
||||
const { filePath, title, description, detail, source, importTraces } = issue;
|
||||
let { documentationLink } = issue;
|
||||
const 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';
|
||||
}
|
||||
const formattedFilePath = filePath.replace('[project]/', './').replaceAll('/./', '/').replace('\\\\?\\', '');
|
||||
let message = '';
|
||||
if (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?.range && source.source.content && // ignore Next.js/React internals, as these can often be huge bundled files.
|
||||
!(0, _isinternal.default)(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) {
|
||||
if (description.type === 'text' && description.value.includes(`Cannot find module 'sass'`)) {
|
||||
message += "To use Next.js' built-in Sass support, you first need to install `sass`.\n";
|
||||
message += 'Run `npm i sass` or `yarn add sass` inside your workspace.\n';
|
||||
message += '\nLearn more: https://nextjs.org/docs/messages/install-sass\n';
|
||||
} else {
|
||||
message += renderStyledStringToErrorAnsi(description) + '\n\n';
|
||||
}
|
||||
}
|
||||
// TODO: make it easier to enable this for debugging
|
||||
if (VERBOSE_ISSUES && detail) {
|
||||
message += renderStyledStringToErrorAnsi(detail) + '\n\n';
|
||||
}
|
||||
if (importTraces?.length) {
|
||||
// This is the same logic as in turbopack/crates/turbopack-cli-utils/src/issue.rs
|
||||
// We end up with multiple traces when the file with the error is reachable from multiple
|
||||
// different entry points (e.g. ssr, client)
|
||||
message += `Import trace${importTraces.length > 1 ? 's' : ''}:\n`;
|
||||
const everyTraceHasADistinctRootLayer = new Set(importTraces.map(leafLayerName).filter((l)=>l != null)).size === importTraces.length;
|
||||
for(let i = 0; i < importTraces.length; i++){
|
||||
const trace = importTraces[i];
|
||||
const layer = leafLayerName(trace);
|
||||
let traceIndent = ' ';
|
||||
// If this is true, layer must be present
|
||||
if (everyTraceHasADistinctRootLayer) {
|
||||
message += ` ${layer}:\n`;
|
||||
} else {
|
||||
if (importTraces.length > 1) {
|
||||
// Otherwise use simple 1 based indices to disambiguate
|
||||
message += ` #${i + 1}`;
|
||||
if (layer) {
|
||||
message += ` [${layer}]`;
|
||||
}
|
||||
message += ':\n';
|
||||
} else if (layer) {
|
||||
message += ` [${layer}]:\n`;
|
||||
} else {
|
||||
// If there is a single trace and no layer name just don't indent it.
|
||||
traceIndent = ' ';
|
||||
}
|
||||
}
|
||||
message += formatIssueTrace(trace, traceIndent, !identicalLayers(trace));
|
||||
}
|
||||
}
|
||||
if (documentationLink) {
|
||||
message += documentationLink + '\n\n';
|
||||
}
|
||||
return message;
|
||||
}
|
||||
/** Returns the first present layer name in the trace */ function leafLayerName(items) {
|
||||
for (const item of items){
|
||||
const layer = item.layer;
|
||||
if (layer != null) return layer;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/**
|
||||
* Returns whether or not all items share the same layer.
|
||||
* If a layer is absent we ignore it in this analysis
|
||||
*/ function identicalLayers(items) {
|
||||
const firstPresentLayer = items.findIndex((t)=>t.layer != null);
|
||||
if (firstPresentLayer === -1) return true // all layers are absent
|
||||
;
|
||||
const layer = items[firstPresentLayer].layer;
|
||||
for(let i = firstPresentLayer + 1; i < items.length; i++){
|
||||
const itemLayer = items[i].layer;
|
||||
if (itemLayer == null || itemLayer !== layer) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function formatIssueTrace(items, indent, printLayers) {
|
||||
return `${items.map((item)=>{
|
||||
let r = indent;
|
||||
if (item.fsName !== 'project') {
|
||||
r += `[${item.fsName}]/`;
|
||||
} else {
|
||||
// This is consistent with webpack's output
|
||||
r += './';
|
||||
}
|
||||
r += item.path;
|
||||
if (printLayers && item.layer) {
|
||||
r += ` [${item.layer}]`;
|
||||
}
|
||||
return r;
|
||||
}).join('\n')}\n\n`;
|
||||
}
|
||||
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/'));
|
||||
}
|
||||
function renderStyledStringToErrorAnsi(string) {
|
||||
function applyDeobfuscation(str) {
|
||||
// Use shared deobfuscate function and apply magenta color to identifiers
|
||||
const deobfuscated = (0, _magicidentifier.deobfuscateText)(str);
|
||||
// Color any {...} wrapped identifiers with magenta
|
||||
return deobfuscated.replace(/\{([^}]+)\}/g, (match)=>(0, _picocolors.magenta)(match));
|
||||
}
|
||||
switch(string.type){
|
||||
case 'text':
|
||||
return applyDeobfuscation(string.value);
|
||||
case 'strong':
|
||||
return (0, _picocolors.bold)((0, _picocolors.red)(applyDeobfuscation(string.value)));
|
||||
case 'code':
|
||||
return (0, _picocolors.green)(applyDeobfuscation(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
|
||||
});
|
||||
}
|
||||
}
|
||||
function isFileSystemCacheEnabledForDev(config) {
|
||||
return config.experimental?.turbopackFileSystemCacheForDev || false;
|
||||
}
|
||||
function isFileSystemCacheEnabledForBuild(config) {
|
||||
return config.experimental?.turbopackFileSystemCacheForBuild || false;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=utils.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user