Initial boiler plate project

This commit is contained in:
2024-09-24 03:52:46 +00:00
parent 6120b2d6c3
commit 154b93e267
10034 changed files with 2079352 additions and 2 deletions

View File

@ -0,0 +1,2 @@
import type { Update as TurbopackUpdate } from '../../build/swc';
export declare function extractModulesFromTurbopackMessage(data: TurbopackUpdate | TurbopackUpdate[]): string[];

View File

@ -0,0 +1,37 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "extractModulesFromTurbopackMessage", {
enumerable: true,
get: function() {
return extractModulesFromTurbopackMessage;
}
});
function extractModulesFromTurbopackMessage(data) {
const updatedModules = new Set();
const updates = Array.isArray(data) ? data : [
data
];
for (const update of updates){
// TODO this won't capture changes to CSS since they don't result in a "merged" update
if (update.type !== "partial" || update.instruction.type !== "ChunkListUpdate" || update.instruction.merged === undefined) {
continue;
}
for (const mergedUpdate of update.instruction.merged){
for (const name of Object.keys(mergedUpdate.entries)){
const res = /(.*)\s+\[.*/.exec(name);
if (res === null) {
console.error("[Turbopack HMR] Expected module to match pattern: " + name);
continue;
}
updatedModules.add(res[1]);
}
}
}
return [
...updatedModules
];
}
//# sourceMappingURL=extract-modules-from-turbopack-message.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/dev/extract-modules-from-turbopack-message.ts"],"names":["extractModulesFromTurbopackMessage","data","updatedModules","Set","updates","Array","isArray","update","type","instruction","merged","undefined","mergedUpdate","name","Object","keys","entries","res","exec","console","error","add"],"mappings":";;;;+BAEgBA;;;eAAAA;;;AAAT,SAASA,mCACdC,IAAyC;IAEzC,MAAMC,iBAA8B,IAAIC;IAExC,MAAMC,UAAUC,MAAMC,OAAO,CAACL,QAAQA,OAAO;QAACA;KAAK;IACnD,KAAK,MAAMM,UAAUH,QAAS;QAC5B,sFAAsF;QACtF,IACEG,OAAOC,IAAI,KAAK,aAChBD,OAAOE,WAAW,CAACD,IAAI,KAAK,qBAC5BD,OAAOE,WAAW,CAACC,MAAM,KAAKC,WAC9B;YACA;QACF;QAEA,KAAK,MAAMC,gBAAgBL,OAAOE,WAAW,CAACC,MAAM,CAAE;YACpD,KAAK,MAAMG,QAAQC,OAAOC,IAAI,CAACH,aAAaI,OAAO,EAAG;gBACpD,MAAMC,MAAM,cAAcC,IAAI,CAACL;gBAC/B,IAAII,QAAQ,MAAM;oBAChBE,QAAQC,KAAK,CACX,uDAAuDP;oBAEzD;gBACF;gBAEAX,eAAemB,GAAG,CAACJ,GAAG,CAAC,EAAE;YAC3B;QACF;IACF;IAEA,OAAO;WAAIf;KAAe;AAC5B"}

48
node_modules/next/dist/server/dev/hot-middleware.d.ts generated vendored Normal file
View File

@ -0,0 +1,48 @@
/// <reference types="ws" />
import type { webpack } from 'next/dist/compiled/webpack/webpack';
import type ws from 'next/dist/compiled/ws';
import type { VersionInfo } from './parse-version-info';
import type { HMR_ACTION_TYPES } from './hot-reloader-types';
declare class EventStream {
clients: Set<ws>;
constructor();
everyClient(fn: (client: ws) => void): void;
close(): void;
handler(client: ws): void;
publish(payload: any): void;
}
export declare class WebpackHotMiddleware {
eventStream: EventStream;
clientLatestStats: {
ts: number;
stats: webpack.Stats;
} | null;
middlewareLatestStats: {
ts: number;
stats: webpack.Stats;
} | null;
serverLatestStats: {
ts: number;
stats: webpack.Stats;
} | null;
closed: boolean;
versionInfo: VersionInfo;
constructor(compilers: webpack.Compiler[], versionInfo: VersionInfo);
onClientInvalid: () => void;
onClientDone: (statsResult: webpack.Stats) => void;
onServerInvalid: () => void;
onServerDone: (statsResult: webpack.Stats) => void;
onEdgeServerInvalid: () => void;
onEdgeServerDone: (statsResult: webpack.Stats) => void;
/**
* To sync we use the most recent stats but also we append middleware
* errors. This is because it is possible that middleware fails to compile
* and we still want to show the client overlay with the error while
* the error page should be rendered just fine.
*/
onHMR: (client: ws) => void;
publishStats: (statsResult: webpack.Stats) => void;
publish: (payload: HMR_ACTION_TYPES) => void;
close: () => void;
}
export {};

215
node_modules/next/dist/server/dev/hot-middleware.js generated vendored Normal file
View File

@ -0,0 +1,215 @@
// Based on https://github.com/webpack-contrib/webpack-hot-middleware/blob/9708d781ae0e46179cf8ea1a94719de4679aaf53/middleware.js
// Included License below
// Copyright JS Foundation and other contributors
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// 'Software'), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "WebpackHotMiddleware", {
enumerable: true,
get: function() {
return WebpackHotMiddleware;
}
});
const _utils = require("../../build/utils");
const _hotreloadertypes = require("./hot-reloader-types");
function isMiddlewareStats(stats) {
for (const key of stats.compilation.entrypoints.keys()){
if ((0, _utils.isMiddlewareFilename)(key)) {
return true;
}
}
return false;
}
function statsToJson(stats) {
if (!stats) return {};
return stats.toJson({
all: false,
errors: true,
hash: true,
warnings: true
});
}
function getStatsForSyncEvent(clientStats, serverStats) {
if (!clientStats) return serverStats == null ? void 0 : serverStats.stats;
if (!serverStats) return clientStats == null ? void 0 : clientStats.stats;
// Prefer the server compiler stats if it has errors.
// Otherwise we may end up in a state where the client compilation is the latest but without errors.
// This causes the error overlay to not display the build error.
if (serverStats.stats.hasErrors()) {
return serverStats.stats;
}
// Return the latest stats
return serverStats.ts > clientStats.ts ? serverStats.stats : clientStats.stats;
}
class EventStream {
constructor(){
this.clients = new Set();
}
everyClient(fn) {
for (const client of this.clients){
fn(client);
}
}
close() {
this.everyClient((client)=>{
client.close();
});
this.clients.clear();
}
handler(client) {
this.clients.add(client);
client.addEventListener("close", ()=>{
this.clients.delete(client);
});
}
publish(payload) {
this.everyClient((client)=>{
client.send(JSON.stringify(payload));
});
}
}
class WebpackHotMiddleware {
constructor(compilers, versionInfo){
this.onClientInvalid = ()=>{
var _this_serverLatestStats;
if (this.closed || ((_this_serverLatestStats = this.serverLatestStats) == null ? void 0 : _this_serverLatestStats.stats.hasErrors())) return;
this.publish({
action: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.BUILDING
});
};
this.onClientDone = (statsResult)=>{
var _this_serverLatestStats;
this.clientLatestStats = {
ts: Date.now(),
stats: statsResult
};
if (this.closed || ((_this_serverLatestStats = this.serverLatestStats) == null ? void 0 : _this_serverLatestStats.stats.hasErrors())) return;
this.publishStats(statsResult);
};
this.onServerInvalid = ()=>{
var _this_serverLatestStats, _this_clientLatestStats;
if (!((_this_serverLatestStats = this.serverLatestStats) == null ? void 0 : _this_serverLatestStats.stats.hasErrors())) return;
this.serverLatestStats = null;
if ((_this_clientLatestStats = this.clientLatestStats) == null ? void 0 : _this_clientLatestStats.stats) {
this.publishStats(this.clientLatestStats.stats);
}
};
this.onServerDone = (statsResult)=>{
if (this.closed) return;
if (statsResult.hasErrors()) {
this.serverLatestStats = {
ts: Date.now(),
stats: statsResult
};
this.publishStats(statsResult);
}
};
this.onEdgeServerInvalid = ()=>{
var _this_middlewareLatestStats, _this_clientLatestStats;
if (!((_this_middlewareLatestStats = this.middlewareLatestStats) == null ? void 0 : _this_middlewareLatestStats.stats.hasErrors())) return;
this.middlewareLatestStats = null;
if ((_this_clientLatestStats = this.clientLatestStats) == null ? void 0 : _this_clientLatestStats.stats) {
this.publishStats(this.clientLatestStats.stats);
}
};
this.onEdgeServerDone = (statsResult)=>{
if (!isMiddlewareStats(statsResult)) {
this.onServerInvalid();
this.onServerDone(statsResult);
return;
}
if (statsResult.hasErrors()) {
this.middlewareLatestStats = {
ts: Date.now(),
stats: statsResult
};
this.publishStats(statsResult);
}
};
/**
* To sync we use the most recent stats but also we append middleware
* errors. This is because it is possible that middleware fails to compile
* and we still want to show the client overlay with the error while
* the error page should be rendered just fine.
*/ this.onHMR = (client)=>{
if (this.closed) return;
this.eventStream.handler(client);
const syncStats = getStatsForSyncEvent(this.clientLatestStats, this.serverLatestStats);
if (syncStats) {
var _this_middlewareLatestStats;
const stats = statsToJson(syncStats);
const middlewareStats = statsToJson((_this_middlewareLatestStats = this.middlewareLatestStats) == null ? void 0 : _this_middlewareLatestStats.stats);
this.publish({
action: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.SYNC,
hash: stats.hash,
errors: [
...stats.errors || [],
...middlewareStats.errors || []
],
warnings: [
...stats.warnings || [],
...middlewareStats.warnings || []
],
versionInfo: this.versionInfo
});
}
};
this.publishStats = (statsResult)=>{
const stats = statsResult.toJson({
all: false,
hash: true,
warnings: true,
errors: true,
moduleTrace: true
});
this.publish({
action: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.BUILT,
hash: stats.hash,
warnings: stats.warnings || [],
errors: stats.errors || []
});
};
this.publish = (payload)=>{
if (this.closed) return;
this.eventStream.publish(payload);
};
this.close = ()=>{
if (this.closed) return;
// Can't remove compiler plugins, so we just set a flag and noop if closed
// https://github.com/webpack/tapable/issues/32#issuecomment-350644466
this.closed = true;
this.eventStream.close();
};
this.eventStream = new EventStream();
this.clientLatestStats = null;
this.middlewareLatestStats = null;
this.serverLatestStats = null;
this.closed = false;
this.versionInfo = versionInfo;
compilers[0].hooks.invalid.tap("webpack-hot-middleware", this.onClientInvalid);
compilers[0].hooks.done.tap("webpack-hot-middleware", this.onClientDone);
compilers[1].hooks.invalid.tap("webpack-hot-middleware", this.onServerInvalid);
compilers[1].hooks.done.tap("webpack-hot-middleware", this.onServerDone);
compilers[2].hooks.done.tap("webpack-hot-middleware", this.onEdgeServerDone);
compilers[2].hooks.invalid.tap("webpack-hot-middleware", this.onEdgeServerInvalid);
}
}
//# sourceMappingURL=hot-middleware.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,3 @@
import type { NextJsHotReloaderInterface } from './hot-reloader-types';
import { type ServerFields, type SetupOpts } from '../lib/router-utils/setup-dev-bundler';
export declare function createHotReloaderTurbopack(opts: SetupOpts, serverFields: ServerFields, distDir: string): Promise<NextJsHotReloaderInterface>;

View File

@ -0,0 +1,748 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "createHotReloaderTurbopack", {
enumerable: true,
get: function() {
return createHotReloaderTurbopack;
}
});
const _promises = require("fs/promises");
const _path = require("path");
const _ws = /*#__PURE__*/ _interop_require_default(require("next/dist/compiled/ws"));
const _store = require("../../build/output/store");
const _hotreloadertypes = require("./hot-reloader-types");
const _swc = require("../../build/swc");
const _log = /*#__PURE__*/ _interop_require_wildcard(require("../../build/output/log"));
const _hotreloaderwebpack = require("./hot-reloader-webpack");
const _constants = require("../../shared/lib/constants");
const _middlewareturbopack = require("../../client/components/react-dev-overlay/server/middleware-turbopack");
const _utils = require("../../shared/lib/utils");
const _utils1 = require("../utils");
const _nextjsrequirecachehotreloader = require("../../build/webpack/plugins/nextjs-require-cache-hot-reloader");
const _renderserver = require("../lib/render-server");
const _denormalizepagepath = require("../../shared/lib/page-path/denormalize-page-path");
const _trace = require("../../trace");
const _turbopackutils = require("./turbopack-utils");
const _setupdevbundler = require("../lib/router-utils/setup-dev-bundler");
const _manifestloader = require("./turbopack/manifest-loader");
const _ondemandentryhandler = require("./on-demand-entry-handler");
const _entrykey = require("./turbopack/entry-key");
const _messages = require("./messages");
const _encryptionutils = require("../app-render/encryption-utils");
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {
__proto__: null
};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
const wsServer = new _ws.default.Server({
noServer: true
});
const isTestMode = !!(process.env.NEXT_TEST_MODE || process.env.__NEXT_TEST_MODE || process.env.DEBUG);
async function createHotReloaderTurbopack(opts, serverFields, distDir) {
const buildId = "development";
const { nextConfig, dir } = opts;
const { loadBindings } = require("../../build/swc");
let bindings = await loadBindings();
// For the debugging purpose, check if createNext or equivalent next instance setup in test cases
// works correctly. Normally `run-test` hides output so only will be visible when `--debug` flag is used.
if (process.env.TURBOPACK && isTestMode) {
require("console").log("Creating turbopack project", {
dir,
testMode: isTestMode
});
}
const hasRewrites = opts.fsChecker.rewrites.afterFiles.length > 0 || opts.fsChecker.rewrites.beforeFiles.length > 0 || opts.fsChecker.rewrites.fallback.length > 0;
const hotReloaderSpan = (0, _trace.trace)("hot-reloader", undefined, {
version: "14.2.13"
});
// Ensure the hotReloaderSpan is flushed immediately as it's the parentSpan for all processing
// of the current `next dev` invocation.
hotReloaderSpan.stop();
const encryptionKey = await (0, _encryptionutils.generateEncryptionKeyBase64)(true);
const project = await bindings.turbo.createProject({
projectPath: dir,
rootPath: opts.nextConfig.experimental.outputFileTracingRoot || dir,
nextConfig: opts.nextConfig,
jsConfig: await (0, _turbopackutils.getTurbopackJsConfig)(dir, nextConfig),
watch: true,
dev: true,
env: process.env,
defineEnv: (0, _swc.createDefineEnv)({
isTurbopack: true,
// TODO: Implement
clientRouterFilters: undefined,
config: nextConfig,
dev: true,
distDir,
fetchCacheKeyPrefix: opts.nextConfig.experimental.fetchCacheKeyPrefix,
hasRewrites,
// TODO: Implement
middlewareMatchers: undefined
}),
buildId,
encryptionKey,
previewProps: opts.fsChecker.prerenderManifest.preview
});
const entrypointsSubscription = project.entrypointsSubscribe();
const currentEntrypoints = {
global: {
app: undefined,
document: undefined,
error: undefined,
middleware: undefined,
instrumentation: undefined
},
page: new Map(),
app: new Map()
};
const currentTopLevelIssues = new Map();
const currentEntryIssues = new Map();
const manifestLoader = new _manifestloader.TurbopackManifestLoader({
buildId,
distDir,
encryptionKey
});
// Dev specific
const changeSubscriptions = new Map();
const serverPathState = new Map();
const readyIds = new Set();
let currentEntriesHandlingResolve;
let currentEntriesHandling = new Promise((resolve)=>currentEntriesHandlingResolve = resolve);
const assetMapper = new _turbopackutils.AssetMapper();
function clearRequireCache(key, writtenEndpoint) {
// Figure out if the server files have changed
let hasChange = false;
for (const { path, contentHash } of writtenEndpoint.serverPaths){
// We ignore source maps
if (path.endsWith(".map")) continue;
const localKey = `${key}:${path}`;
const localHash = serverPathState.get(localKey);
const globalHash = serverPathState.get(path);
if (localHash && localHash !== contentHash || globalHash && globalHash !== contentHash) {
hasChange = true;
serverPathState.set(key, contentHash);
serverPathState.set(path, contentHash);
} else {
if (!localHash) {
serverPathState.set(key, contentHash);
}
if (!globalHash) {
serverPathState.set(path, contentHash);
}
}
}
if (!hasChange) {
return;
}
const hasAppPaths = writtenEndpoint.serverPaths.some(({ path: p })=>p.startsWith("server/app"));
if (hasAppPaths) {
(0, _nextjsrequirecachehotreloader.deleteAppClientCache)();
}
const serverPaths = writtenEndpoint.serverPaths.map(({ path: p })=>(0, _path.join)(distDir, p));
for (const file of serverPaths){
(0, _renderserver.clearModuleContext)(file);
(0, _nextjsrequirecachehotreloader.deleteCache)(file);
}
return;
}
const buildingIds = new Set();
const startBuilding = (id, requestUrl, forceRebuild)=>{
if (!forceRebuild && readyIds.has(id)) {
return ()=>{};
}
if (buildingIds.size === 0) {
_store.store.setState({
loading: true,
trigger: id,
url: requestUrl
}, true);
}
buildingIds.add(id);
return function finishBuilding() {
if (buildingIds.size === 0) {
return;
}
readyIds.add(id);
buildingIds.delete(id);
if (buildingIds.size === 0) {
hmrEventHappened = false;
_store.store.setState({
loading: false
}, true);
}
};
};
let hmrEventHappened = false;
let hmrHash = 0;
const clients = new Set();
const clientStates = new WeakMap();
function sendToClient(client, payload) {
client.send(JSON.stringify(payload));
}
function sendEnqueuedMessages() {
for (const [, issueMap] of currentEntryIssues){
if ([
...issueMap.values()
].filter((i)=>i.severity !== "warning").length > 0) {
// During compilation errors we want to delay the HMR events until errors are fixed
return;
}
}
for (const client of clients){
const state = clientStates.get(client);
if (!state) {
continue;
}
for (const [, issueMap] of state.clientIssues){
if ([
...issueMap.values()
].filter((i)=>i.severity !== "warning").length > 0) {
// During compilation errors we want to delay the HMR events until errors are fixed
return;
}
}
for (const payload of state.hmrPayloads.values()){
sendToClient(client, payload);
}
state.hmrPayloads.clear();
if (state.turbopackUpdates.length > 0) {
sendToClient(client, {
action: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE,
data: state.turbopackUpdates
});
state.turbopackUpdates.length = 0;
}
}
}
const sendEnqueuedMessagesDebounce = (0, _utils1.debounce)(sendEnqueuedMessages, 2);
const sendHmr = (id, payload)=>{
for (const client of clients){
var _clientStates_get;
(_clientStates_get = clientStates.get(client)) == null ? void 0 : _clientStates_get.hmrPayloads.set(id, payload);
}
hmrEventHappened = true;
sendEnqueuedMessagesDebounce();
};
function sendTurbopackMessage(payload) {
// TODO(PACK-2049): For some reason we end up emitting hundreds of issues messages on bigger apps,
// a lot of which are duplicates.
// They are currently not handled on the client at all, so might as well not send them for now.
payload.diagnostics = [];
payload.issues = [];
for (const client of clients){
var _clientStates_get;
(_clientStates_get = clientStates.get(client)) == null ? void 0 : _clientStates_get.turbopackUpdates.push(payload);
}
hmrEventHappened = true;
sendEnqueuedMessagesDebounce();
}
async function subscribeToChanges(key, includeIssues, endpoint, makePayload) {
if (changeSubscriptions.has(key)) {
return;
}
const { side } = (0, _entrykey.splitEntryKey)(key);
const changedPromise = endpoint[`${side}Changed`](includeIssues);
changeSubscriptions.set(key, changedPromise);
const changed = await changedPromise;
for await (const change of changed){
(0, _turbopackutils.processIssues)(currentEntryIssues, key, change, false, true);
const payload = await makePayload(change);
if (payload) {
sendHmr(key, payload);
}
}
}
async function unsubscribeFromChanges(key) {
const subscription = await changeSubscriptions.get(key);
if (subscription) {
await (subscription.return == null ? void 0 : subscription.return.call(subscription));
changeSubscriptions.delete(key);
}
currentEntryIssues.delete(key);
}
async function subscribeToHmrEvents(client, id) {
const key = (0, _entrykey.getEntryKey)("assets", "client", id);
if (!(0, _turbopackutils.hasEntrypointForKey)(currentEntrypoints, key, assetMapper)) {
// maybe throw an error / force the client to reload?
return;
}
const state = clientStates.get(client);
if (!state || state.subscriptions.has(id)) {
return;
}
const subscription = project.hmrEvents(id);
state.subscriptions.set(id, subscription);
// The subscription will always emit once, which is the initial
// computation. This is not a change, so swallow it.
try {
await subscription.next();
for await (const data of subscription){
(0, _turbopackutils.processIssues)(state.clientIssues, key, data, false, true);
if (data.type !== "issues") {
sendTurbopackMessage(data);
}
}
} catch (e) {
// The client might be using an HMR session from a previous server, tell them
// to fully reload the page to resolve the issue. We can't use
// `hotReloader.send` since that would force every connected client to
// reload, only this client is out of date.
const reloadAction = {
action: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.RELOAD_PAGE
};
sendToClient(client, reloadAction);
client.close();
return;
}
}
function unsubscribeFromHmrEvents(client, id) {
const state = clientStates.get(client);
if (!state) {
return;
}
const subscription = state.subscriptions.get(id);
subscription == null ? void 0 : subscription.return();
const key = (0, _entrykey.getEntryKey)("assets", "client", id);
state.clientIssues.delete(key);
}
async function handleEntrypointsSubscription() {
for await (const entrypoints of entrypointsSubscription){
if (!currentEntriesHandlingResolve) {
currentEntriesHandling = new Promise(// eslint-disable-next-line no-loop-func
(resolve)=>currentEntriesHandlingResolve = resolve);
}
(0, _turbopackutils.processTopLevelIssues)(currentTopLevelIssues, entrypoints);
await (0, _turbopackutils.handleEntrypoints)({
entrypoints,
currentEntrypoints,
currentEntryIssues,
manifestLoader,
nextConfig: opts.nextConfig,
rewrites: opts.fsChecker.rewrites,
logErrors: true,
dev: {
assetMapper,
changeSubscriptions,
clients,
clientStates,
serverFields,
hooks: {
handleWrittenEndpoint: (id, result)=>{
clearRequireCache(id, result);
},
propagateServerField: _setupdevbundler.propagateServerField.bind(null, opts),
sendHmr,
startBuilding,
subscribeToChanges,
unsubscribeFromChanges,
unsubscribeFromHmrEvents
}
}
});
currentEntriesHandlingResolve();
currentEntriesHandlingResolve = undefined;
}
}
await (0, _promises.mkdir)((0, _path.join)(distDir, "server"), {
recursive: true
});
await (0, _promises.mkdir)((0, _path.join)(distDir, "static", buildId), {
recursive: true
});
await (0, _promises.writeFile)((0, _path.join)(distDir, "package.json"), JSON.stringify({
type: "commonjs"
}, null, 2));
const overlayMiddleware = (0, _middlewareturbopack.getOverlayMiddleware)(project);
const versionInfoPromise = (0, _hotreloaderwebpack.getVersionInfo)(isTestMode || opts.telemetry.isEnabled);
const hotReloader = {
turbopackProject: project,
activeWebpackConfigs: undefined,
serverStats: null,
edgeServerStats: null,
async run (req, res, _parsedUrl) {
var _req_url;
// intercept page chunks request and ensure them with turbopack
if ((_req_url = req.url) == null ? void 0 : _req_url.startsWith("/_next/static/chunks/pages/")) {
const params = (0, _hotreloaderwebpack.matchNextPageBundleRequest)(req.url);
if (params) {
const decodedPagePath = `/${params.path.map((param)=>decodeURIComponent(param)).join("/")}`;
const denormalizedPagePath = (0, _denormalizepagepath.denormalizePagePath)(decodedPagePath);
await hotReloader.ensurePage({
page: denormalizedPagePath,
clientOnly: false,
definition: undefined,
url: req.url
}).catch(console.error);
}
}
await overlayMiddleware(req, res);
// Request was not finished.
return {
finished: undefined
};
},
// TODO: Figure out if socket type can match the NextJsHotReloaderInterface
onHMR (req, socket, head) {
wsServer.handleUpgrade(req, socket, head, (client)=>{
const clientIssues = new Map();
const subscriptions = new Map();
clients.add(client);
clientStates.set(client, {
clientIssues,
hmrPayloads: new Map(),
turbopackUpdates: [],
subscriptions
});
client.on("close", ()=>{
// Remove active subscriptions
for (const subscription of subscriptions.values()){
subscription.return == null ? void 0 : subscription.return.call(subscription);
}
clientStates.delete(client);
clients.delete(client);
});
client.addEventListener("message", ({ data })=>{
const parsedData = JSON.parse(typeof data !== "string" ? data.toString() : data);
// Next.js messages
switch(parsedData.event){
case "ping":
break;
case "span-end":
{
hotReloaderSpan.manualTraceChild(parsedData.spanName, (0, _turbopackutils.msToNs)(parsedData.startTime), (0, _turbopackutils.msToNs)(parsedData.endTime), parsedData.attributes);
break;
}
case "client-hmr-latency":
hotReloaderSpan.manualTraceChild(parsedData.event, (0, _turbopackutils.msToNs)(parsedData.startTime), (0, _turbopackutils.msToNs)(parsedData.endTime), {
updatedModules: parsedData.updatedModules,
page: parsedData.page,
isPageHidden: parsedData.isPageHidden
});
break;
case "client-error":
case "client-warning":
case "client-success":
case "server-component-reload-page":
case "client-reload-page":
case "client-removed-page":
case "client-full-reload":
const { hadRuntimeError, dependencyChain } = parsedData;
if (hadRuntimeError) {
_log.warn(_messages.FAST_REFRESH_RUNTIME_RELOAD);
}
if (Array.isArray(dependencyChain) && typeof dependencyChain[0] === "string") {
const cleanedModulePath = dependencyChain[0].replace(/^\[project\]/, ".").replace(/ \[.*\] \(.*\)$/, "");
_log.warn(`Fast Refresh had to perform a full reload when ${cleanedModulePath} changed. Read more: https://nextjs.org/docs/messages/fast-refresh-reload`);
}
break;
case "client-added-page":
break;
default:
// Might be a Turbopack message...
if (!parsedData.type) {
throw new Error(`unrecognized HMR message "${data}"`);
}
}
// Turbopack messages
switch(parsedData.type){
case "turbopack-subscribe":
subscribeToHmrEvents(client, parsedData.path);
break;
case "turbopack-unsubscribe":
unsubscribeFromHmrEvents(client, parsedData.path);
break;
default:
if (!parsedData.event) {
throw new Error(`unrecognized Turbopack HMR message "${data}"`);
}
}
});
const turbopackConnected = {
action: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED
};
sendToClient(client, turbopackConnected);
const errors = [];
for (const entryIssues of currentEntryIssues.values()){
for (const issue of entryIssues.values()){
if (issue.severity !== "warning") {
errors.push({
message: (0, _turbopackutils.formatIssue)(issue)
});
} else {
(0, _turbopackutils.printNonFatalIssue)(issue);
}
}
}
(async function() {
const versionInfo = await versionInfoPromise;
const sync = {
action: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.SYNC,
errors,
warnings: [],
hash: "",
versionInfo
};
sendToClient(client, sync);
})();
});
},
send (action) {
const payload = JSON.stringify(action);
for (const client of clients){
client.send(payload);
}
},
setHmrServerError (_error) {
// Not implemented yet.
},
clearHmrServerError () {
// Not implemented yet.
},
async start () {},
async stop () {
// Not implemented yet.
},
async getCompilationErrors (page) {
const appEntryKey = (0, _entrykey.getEntryKey)("app", "server", page);
const pagesEntryKey = (0, _entrykey.getEntryKey)("pages", "server", page);
const topLevelIssues = currentTopLevelIssues.values();
const thisEntryIssues = currentEntryIssues.get(appEntryKey) ?? currentEntryIssues.get(pagesEntryKey);
if (thisEntryIssues !== undefined && thisEntryIssues.size > 0) {
// If there is an error related to the requesting page we display it instead of the first error
return [
...topLevelIssues,
...thisEntryIssues.values()
].map((issue)=>{
const formattedIssue = (0, _turbopackutils.formatIssue)(issue);
if (issue.severity === "warning") {
(0, _turbopackutils.printNonFatalIssue)(issue);
return null;
} else if ((0, _turbopackutils.isWellKnownError)(issue)) {
_log.error(formattedIssue);
}
return new Error(formattedIssue);
}).filter((error)=>error !== null);
}
// Otherwise, return all errors across pages
const errors = [];
for (const issue of topLevelIssues){
if (issue.severity !== "warning") {
errors.push(new Error((0, _turbopackutils.formatIssue)(issue)));
}
}
for (const entryIssues of currentEntryIssues.values()){
for (const issue of entryIssues.values()){
if (issue.severity !== "warning") {
const message = (0, _turbopackutils.formatIssue)(issue);
errors.push(new Error(message));
} else {
(0, _turbopackutils.printNonFatalIssue)(issue);
}
}
}
return errors;
},
async invalidate ({ // .env files or tsconfig/jsconfig change
reloadAfterInvalidation }) {
if (reloadAfterInvalidation) {
await (0, _renderserver.clearAllModuleContexts)();
this.send({
action: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.SERVER_COMPONENT_CHANGES
});
}
},
async buildFallbackError () {
// Not implemented yet.
},
async ensurePage ({ page: inputPage, // Unused parameters
// clientOnly,
// appPaths,
definition, isApp, url: requestUrl }) {
if (_constants.BLOCKED_PAGES.includes(inputPage) && inputPage !== "/_error") {
return;
}
let routeDef = definition ?? await (0, _ondemandentryhandler.findPagePathData)(dir, inputPage, nextConfig.pageExtensions, opts.pagesDir, opts.appDir);
const page = routeDef.page;
const pathname = (definition == null ? void 0 : definition.pathname) ?? inputPage;
if (page === "/_error") {
let finishBuilding = startBuilding(pathname, requestUrl, false);
try {
await (0, _turbopackutils.handlePagesErrorRoute)({
currentEntryIssues,
entrypoints: currentEntrypoints,
manifestLoader,
rewrites: opts.fsChecker.rewrites,
logErrors: true,
hooks: {
subscribeToChanges,
handleWrittenEndpoint: (id, result)=>{
clearRequireCache(id, result);
assetMapper.setPathsForKey(id, result.clientPaths);
}
}
});
} finally{
finishBuilding();
}
return;
}
await currentEntriesHandling;
const isInsideAppDir = routeDef.bundlePath.startsWith("app/");
const route = isInsideAppDir ? currentEntrypoints.app.get(page) : currentEntrypoints.page.get(page);
if (!route) {
// TODO: why is this entry missing in turbopack?
if (page === "/middleware") return;
if (page === "/src/middleware") return;
if (page === "/instrumentation") return;
if (page === "/src/instrumentation") return;
throw new _utils.PageNotFoundError(`route not found ${page}`);
}
// We don't throw on ensureOpts.isApp === true for page-api
// since this can happen when app pages make
// api requests to page API routes.
if (isApp && route.type === "page") {
throw new Error(`mis-matched route type: isApp && page for ${page}`);
}
const finishBuilding = startBuilding(pathname, requestUrl, false);
try {
await (0, _turbopackutils.handleRouteType)({
dev: true,
page,
pathname,
route,
currentEntryIssues,
entrypoints: currentEntrypoints,
manifestLoader,
readyIds,
rewrites: opts.fsChecker.rewrites,
logErrors: true,
hooks: {
subscribeToChanges,
handleWrittenEndpoint: (id, result)=>{
clearRequireCache(id, result);
assetMapper.setPathsForKey(id, result.clientPaths);
}
}
});
} finally{
finishBuilding();
}
}
};
handleEntrypointsSubscription().catch((err)=>{
console.error(err);
process.exit(1);
});
// Write empty manifests
await currentEntriesHandling;
await manifestLoader.writeManifests({
rewrites: opts.fsChecker.rewrites,
pageEntrypoints: currentEntrypoints.page
});
async function handleProjectUpdates() {
for await (const updateMessage of project.updateInfoSubscribe(30)){
switch(updateMessage.updateType){
case "start":
{
hotReloader.send({
action: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.BUILDING
});
break;
}
case "end":
{
sendEnqueuedMessages();
function addErrors(errorsMap, issues) {
for (const issueMap of issues.values()){
for (const [key, issue] of issueMap){
if (issue.severity === "warning") continue;
if (errorsMap.has(key)) continue;
const message = (0, _turbopackutils.formatIssue)(issue);
errorsMap.set(key, {
message,
details: issue.detail ? (0, _turbopackutils.renderStyledStringToErrorAnsi)(issue.detail) : undefined
});
}
}
}
const errors = new Map();
addErrors(errors, currentEntryIssues);
for (const client of clients){
const state = clientStates.get(client);
if (!state) {
continue;
}
const clientErrors = new Map(errors);
addErrors(clientErrors, state.clientIssues);
sendToClient(client, {
action: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.BUILT,
hash: String(++hmrHash),
errors: [
...clientErrors.values()
],
warnings: []
});
}
if (hmrEventHappened) {
const time = updateMessage.value.duration;
const timeMessage = time > 2000 ? `${Math.round(time / 100) / 10}s` : `${time}ms`;
_log.event(`Compiled in ${timeMessage}`);
hmrEventHappened = false;
}
break;
}
default:
}
}
}
handleProjectUpdates().catch((err)=>{
console.error(err);
process.exit(1);
});
return hotReloader;
}
//# sourceMappingURL=hot-reloader-turbopack.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,134 @@
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import type { IncomingMessage, ServerResponse } from 'http';
import type { UrlObject } from 'url';
import type { Duplex } from 'stream';
import type { webpack } from 'next/dist/compiled/webpack/webpack';
import type getBaseWebpackConfig from '../../build/webpack-config';
import type { RouteDefinition } from '../future/route-definitions/route-definition';
import type { Project, Update as TurbopackUpdate } from '../../build/swc';
import type { VersionInfo } from './parse-version-info';
export declare const enum HMR_ACTIONS_SENT_TO_BROWSER {
ADDED_PAGE = "addedPage",
REMOVED_PAGE = "removedPage",
RELOAD_PAGE = "reloadPage",
SERVER_COMPONENT_CHANGES = "serverComponentChanges",
MIDDLEWARE_CHANGES = "middlewareChanges",
CLIENT_CHANGES = "clientChanges",
SERVER_ONLY_CHANGES = "serverOnlyChanges",
SYNC = "sync",
BUILT = "built",
BUILDING = "building",
DEV_PAGES_MANIFEST_UPDATE = "devPagesManifestUpdate",
TURBOPACK_MESSAGE = "turbopack-message",
SERVER_ERROR = "serverError",
TURBOPACK_CONNECTED = "turbopack-connected"
}
interface ServerErrorAction {
action: HMR_ACTIONS_SENT_TO_BROWSER.SERVER_ERROR;
errorJSON: string;
}
export interface TurbopackMessageAction {
action: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE;
data: TurbopackUpdate | TurbopackUpdate[];
}
interface BuildingAction {
action: HMR_ACTIONS_SENT_TO_BROWSER.BUILDING;
}
export interface CompilationError {
moduleName?: string;
message: string;
details?: string;
moduleTrace?: Array<{
moduleName?: string;
}>;
stack?: string;
}
export interface SyncAction {
action: HMR_ACTIONS_SENT_TO_BROWSER.SYNC;
hash: string;
errors: ReadonlyArray<CompilationError>;
warnings: ReadonlyArray<CompilationError>;
versionInfo: VersionInfo;
updatedModules?: ReadonlyArray<string>;
}
interface BuiltAction {
action: HMR_ACTIONS_SENT_TO_BROWSER.BUILT;
hash: string;
errors: ReadonlyArray<CompilationError>;
warnings: ReadonlyArray<CompilationError>;
updatedModules?: ReadonlyArray<string>;
}
interface AddedPageAction {
action: HMR_ACTIONS_SENT_TO_BROWSER.ADDED_PAGE;
data: [page: string | null];
}
interface RemovedPageAction {
action: HMR_ACTIONS_SENT_TO_BROWSER.REMOVED_PAGE;
data: [page: string | null];
}
export interface ReloadPageAction {
action: HMR_ACTIONS_SENT_TO_BROWSER.RELOAD_PAGE;
}
interface ServerComponentChangesAction {
action: HMR_ACTIONS_SENT_TO_BROWSER.SERVER_COMPONENT_CHANGES;
}
interface MiddlewareChangesAction {
event: HMR_ACTIONS_SENT_TO_BROWSER.MIDDLEWARE_CHANGES;
}
interface ClientChangesAction {
event: HMR_ACTIONS_SENT_TO_BROWSER.CLIENT_CHANGES;
}
interface ServerOnlyChangesAction {
event: HMR_ACTIONS_SENT_TO_BROWSER.SERVER_ONLY_CHANGES;
pages: ReadonlyArray<string>;
}
interface DevPagesManifestUpdateAction {
action: HMR_ACTIONS_SENT_TO_BROWSER.DEV_PAGES_MANIFEST_UPDATE;
data: [
{
devPagesManifest: true;
}
];
}
export interface TurbopackConnectedAction {
action: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED;
}
export type HMR_ACTION_TYPES = TurbopackMessageAction | TurbopackConnectedAction | BuildingAction | SyncAction | BuiltAction | AddedPageAction | RemovedPageAction | ReloadPageAction | ServerComponentChangesAction | ClientChangesAction | MiddlewareChangesAction | ServerOnlyChangesAction | DevPagesManifestUpdateAction | ServerErrorAction;
export type TurbopackMsgToBrowser = {
type: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE;
data: any;
} | {
type: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED;
};
export interface NextJsHotReloaderInterface {
turbopackProject?: Project;
activeWebpackConfigs?: Array<Awaited<ReturnType<typeof getBaseWebpackConfig>>>;
serverStats: webpack.Stats | null;
edgeServerStats: webpack.Stats | null;
run(req: IncomingMessage, res: ServerResponse, parsedUrl: UrlObject): Promise<{
finished?: true;
}>;
setHmrServerError(error: Error | null): void;
clearHmrServerError(): void;
start(): Promise<void>;
stop(): Promise<void>;
send(action: HMR_ACTION_TYPES): void;
getCompilationErrors(page: string): Promise<any[]>;
onHMR(req: IncomingMessage, _socket: Duplex, head: Buffer): void;
invalidate({ reloadAfterInvalidation, }: {
reloadAfterInvalidation: boolean;
}): Promise<void> | void;
buildFallbackError(): Promise<void>;
ensurePage({ page, clientOnly, appPaths, definition, isApp, url, }: {
page: string;
clientOnly: boolean;
appPaths?: ReadonlyArray<string> | null;
isApp?: boolean;
definition: RouteDefinition | undefined;
url?: string;
}): Promise<void>;
}
export {};

View File

@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "HMR_ACTIONS_SENT_TO_BROWSER", {
enumerable: true,
get: function() {
return HMR_ACTIONS_SENT_TO_BROWSER;
}
});
var HMR_ACTIONS_SENT_TO_BROWSER;
(function(HMR_ACTIONS_SENT_TO_BROWSER) {
HMR_ACTIONS_SENT_TO_BROWSER["ADDED_PAGE"] = "addedPage";
HMR_ACTIONS_SENT_TO_BROWSER["REMOVED_PAGE"] = "removedPage";
HMR_ACTIONS_SENT_TO_BROWSER["RELOAD_PAGE"] = "reloadPage";
HMR_ACTIONS_SENT_TO_BROWSER["SERVER_COMPONENT_CHANGES"] = "serverComponentChanges";
HMR_ACTIONS_SENT_TO_BROWSER["MIDDLEWARE_CHANGES"] = "middlewareChanges";
HMR_ACTIONS_SENT_TO_BROWSER["CLIENT_CHANGES"] = "clientChanges";
HMR_ACTIONS_SENT_TO_BROWSER["SERVER_ONLY_CHANGES"] = "serverOnlyChanges";
HMR_ACTIONS_SENT_TO_BROWSER["SYNC"] = "sync";
HMR_ACTIONS_SENT_TO_BROWSER["BUILT"] = "built";
HMR_ACTIONS_SENT_TO_BROWSER["BUILDING"] = "building";
HMR_ACTIONS_SENT_TO_BROWSER["DEV_PAGES_MANIFEST_UPDATE"] = "devPagesManifestUpdate";
HMR_ACTIONS_SENT_TO_BROWSER["TURBOPACK_MESSAGE"] = "turbopack-message";
HMR_ACTIONS_SENT_TO_BROWSER["SERVER_ERROR"] = "serverError";
HMR_ACTIONS_SENT_TO_BROWSER["TURBOPACK_CONNECTED"] = "turbopack-connected";
})(HMR_ACTIONS_SENT_TO_BROWSER || (HMR_ACTIONS_SENT_TO_BROWSER = {}));
//# sourceMappingURL=hot-reloader-types.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/dev/hot-reloader-types.ts"],"names":["HMR_ACTIONS_SENT_TO_BROWSER"],"mappings":";;;;;;;;;;;UASkBA;;;;;;;;;;;;;;;GAAAA,gCAAAA"}

View File

@ -0,0 +1,97 @@
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import type { NextConfigComplete } from '../config-shared';
import type { CustomRoutes } from '../../lib/load-custom-routes';
import type { Duplex } from 'stream';
import type { Telemetry } from '../../telemetry/storage';
import type { IncomingMessage, ServerResponse } from 'http';
import type { UrlObject } from 'url';
import type { RouteDefinition } from '../future/route-definitions/route-definition';
import { webpack } from 'next/dist/compiled/webpack/webpack';
import getBaseWebpackConfig from '../../build/webpack-config';
import type { __ApiPreviewProps } from '../api-utils';
import type { UnwrapPromise } from '../../lib/coalesced-function';
import type { VersionInfo } from './parse-version-info';
import { type NextJsHotReloaderInterface } from './hot-reloader-types';
import type { HMR_ACTION_TYPES } from './hot-reloader-types';
export declare function renderScriptError(res: ServerResponse, error: Error, { verbose }?: {
verbose?: boolean | undefined;
}): Promise<{
finished: true | undefined;
}>;
export declare const matchNextPageBundleRequest: import("../../shared/lib/router/utils/path-match").PatchMatcher;
export declare function getVersionInfo(enabled: boolean): Promise<VersionInfo>;
export default class HotReloaderWebpack implements NextJsHotReloaderInterface {
private hasAmpEntrypoints;
private hasAppRouterEntrypoints;
private hasPagesRouterEntrypoints;
private dir;
private buildId;
private encryptionKey;
private interceptors;
private pagesDir?;
private distDir;
private webpackHotMiddleware?;
private config;
private clientStats;
private clientError;
private serverError;
private hmrServerError;
private serverPrevDocumentHash;
private serverChunkNames?;
private prevChunkNames?;
private onDemandEntries?;
private previewProps;
private watcher;
private rewrites;
private fallbackWatcher;
private hotReloaderSpan;
private pagesMapping;
private appDir?;
private telemetry;
private versionInfo;
private reloadAfterInvalidation;
serverStats: webpack.Stats | null;
edgeServerStats: webpack.Stats | null;
multiCompiler?: webpack.MultiCompiler;
activeWebpackConfigs?: Array<UnwrapPromise<ReturnType<typeof getBaseWebpackConfig>>>;
constructor(dir: string, { config, pagesDir, distDir, buildId, encryptionKey, previewProps, rewrites, appDir, telemetry, }: {
config: NextConfigComplete;
pagesDir?: string;
distDir: string;
buildId: string;
encryptionKey: string;
previewProps: __ApiPreviewProps;
rewrites: CustomRoutes['rewrites'];
appDir?: string;
telemetry: Telemetry;
});
run(req: IncomingMessage, res: ServerResponse, parsedUrl: UrlObject): Promise<{
finished?: true;
}>;
setHmrServerError(error: Error | null): void;
clearHmrServerError(): void;
protected refreshServerComponents(): Promise<void>;
onHMR(req: IncomingMessage, _socket: Duplex, head: Buffer): void;
private clean;
private getWebpackConfig;
buildFallbackError(): Promise<void>;
private tracedGetVersionInfo;
start(): Promise<void>;
invalidate({ reloadAfterInvalidation }?: {
reloadAfterInvalidation: boolean;
}): void;
stop(): Promise<void>;
getCompilationErrors(page: string): Promise<Error[]>;
send(action: HMR_ACTION_TYPES): void;
ensurePage({ page, clientOnly, appPaths, definition, isApp, url, }: {
page: string;
clientOnly: boolean;
appPaths?: ReadonlyArray<string> | null;
isApp?: boolean;
definition?: RouteDefinition;
url?: string;
}): Promise<void>;
}

1192
node_modules/next/dist/server/dev/hot-reloader-webpack.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
export declare function logAppDirError(err: unknown): void;

80
node_modules/next/dist/server/dev/log-app-dir-error.js generated vendored Normal file
View File

@ -0,0 +1,80 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "logAppDirError", {
enumerable: true,
get: function() {
return logAppDirError;
}
});
const _iserror = /*#__PURE__*/ _interop_require_default(require("../../lib/is-error"));
const _log = /*#__PURE__*/ _interop_require_wildcard(require("../../build/output/log"));
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {
__proto__: null
};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
function logAppDirError(err) {
if ((0, _iserror.default)(err) && (err == null ? void 0 : err.stack)) {
const cleanedStack = err.stack.split("\n").map((line)=>// Remove 'webpack-internal:' noise from the path
line.replace(/(webpack-internal:\/\/\/|file:\/\/)(\(.*\)\/)?/, ""));
const filteredStack = cleanedStack// Only display stack frames from the user's code
.filter((line)=>!/next[\\/]dist[\\/]compiled/.test(line) && !/node_modules[\\/]/.test(line) && !/node:internal[\\/]/.test(line));
if (filteredStack.length === 1) {
// This is an error that happened outside of user code, keep full stack
_log.error(`Internal error: ${cleanedStack.join("\n")}`);
} else {
_log.error(filteredStack.join("\n"));
}
if (typeof err.digest !== "undefined") {
console.error(`digest: ${JSON.stringify(err.digest)}`);
}
if (err.cause) console.error("Cause:", err.cause);
} else {
_log.error(err);
}
}
//# sourceMappingURL=log-app-dir-error.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/dev/log-app-dir-error.ts"],"names":["logAppDirError","err","isError","stack","cleanedStack","split","map","line","replace","filteredStack","filter","test","length","Log","error","join","digest","console","JSON","stringify","cause"],"mappings":";;;;+BAGgBA;;;eAAAA;;;gEAHI;6DACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEd,SAASA,eAAeC,GAAY;IACzC,IAAIC,IAAAA,gBAAO,EAACD,SAAQA,uBAAAA,IAAKE,KAAK,GAAE;QAC9B,MAAMC,eAAeH,IAAIE,KAAK,CAACE,KAAK,CAAC,MAAMC,GAAG,CAAC,CAACC,OAC9C,iDAAiD;YACjDA,KAAKC,OAAO,CAAC,kDAAkD;QAEjE,MAAMC,gBAAgBL,YACpB,iDAAiD;SAChDM,MAAM,CACL,CAACH,OACC,CAAC,6BAA6BI,IAAI,CAACJ,SACnC,CAAC,oBAAoBI,IAAI,CAACJ,SAC1B,CAAC,qBAAqBI,IAAI,CAACJ;QAEjC,IAAIE,cAAcG,MAAM,KAAK,GAAG;YAC9B,uEAAuE;YACvEC,KAAIC,KAAK,CAAC,CAAC,gBAAgB,EAAEV,aAAaW,IAAI,CAAC,MAAM,CAAC;QACxD,OAAO;YACLF,KAAIC,KAAK,CAACL,cAAcM,IAAI,CAAC;QAC/B;QACA,IAAI,OAAO,AAACd,IAAYe,MAAM,KAAK,aAAa;YAC9CC,QAAQH,KAAK,CAAC,CAAC,QAAQ,EAAEI,KAAKC,SAAS,CAAC,AAAClB,IAAYe,MAAM,EAAE,CAAC;QAChE;QAEA,IAAIf,IAAImB,KAAK,EAAEH,QAAQH,KAAK,CAAC,UAAUb,IAAImB,KAAK;IAClD,OAAO;QACLP,KAAIC,KAAK,CAACb;IACZ;AACF"}

1
node_modules/next/dist/server/dev/messages.d.ts generated vendored Normal file
View File

@ -0,0 +1 @@
export declare const FAST_REFRESH_RUNTIME_RELOAD = "Fast Refresh had to perform a full reload due to a runtime error.";

13
node_modules/next/dist/server/dev/messages.js generated vendored Normal file
View File

@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "FAST_REFRESH_RUNTIME_RELOAD", {
enumerable: true,
get: function() {
return FAST_REFRESH_RUNTIME_RELOAD;
}
});
const FAST_REFRESH_RUNTIME_RELOAD = "Fast Refresh had to perform a full reload due to a runtime error.";
//# sourceMappingURL=messages.js.map

1
node_modules/next/dist/server/dev/messages.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/dev/messages.ts"],"names":["FAST_REFRESH_RUNTIME_RELOAD"],"mappings":";;;;+BAAaA;;;eAAAA;;;AAAN,MAAMA,8BACX"}

133
node_modules/next/dist/server/dev/next-dev-server.d.ts generated vendored Normal file
View File

@ -0,0 +1,133 @@
/// <reference types="node" />
/// <reference types="node" />
import type { FindComponentsResult } from '../next-server';
import type { LoadComponentsReturnType } from '../load-components';
import type { Options as ServerOptions } from '../next-server';
import type { Params } from '../../shared/lib/router/utils/route-matcher';
import type { ParsedUrl } from '../../shared/lib/router/utils/parse-url';
import type { ParsedUrlQuery } from 'querystring';
import type { UrlWithParsedQuery } from 'url';
import type { BaseNextRequest, BaseNextResponse } from '../base-http';
import type { MiddlewareRoutingItem } from '../base-server';
import type { RouteDefinition } from '../future/route-definitions/route-definition';
import type { RouteMatcherManager } from '../future/route-matcher-managers/route-matcher-manager';
import type { NextParsedUrlQuery, NextUrlWithParsedQuery } from '../request-meta';
import type { DevBundlerService } from '../lib/dev-bundler-service';
import type { IncrementalCache } from '../lib/incremental-cache';
import type { NodeNextResponse, NodeNextRequest } from '../base-http/node';
import type { PagesManifest } from '../../build/webpack/plugins/pages-manifest-plugin';
import Server from '../next-server';
import { type Span } from '../../trace';
export interface Options extends ServerOptions {
/**
* Tells of Next.js is running from the `next dev` command
*/
isNextDevCommand?: boolean;
/**
* Interface to the development bundler.
*/
bundlerService: DevBundlerService;
/**
* Trace span for server startup.
*/
startServerSpan: Span;
}
export default class DevServer extends Server {
/**
* The promise that resolves when the server is ready. When this is unset
* the server is ready.
*/
private ready?;
protected sortedRoutes?: string[];
private pagesDir?;
private appDir?;
private actualMiddlewareFile?;
private actualInstrumentationHookFile?;
private middleware?;
private originalFetch?;
private readonly bundlerService;
private staticPathsCache;
private startServerSpan;
protected staticPathsWorker?: {
[key: string]: any;
} & {
loadStaticPaths: typeof import('./static-paths-worker').loadStaticPaths;
};
private getStaticPathsWorker;
constructor(options: Options);
protected getRouteMatchers(): RouteMatcherManager;
protected getBuildId(): string;
protected prepareImpl(): Promise<void>;
protected close(): Promise<void>;
protected hasPage(pathname: string): Promise<boolean>;
runMiddleware(params: {
request: BaseNextRequest;
response: BaseNextResponse;
parsedUrl: ParsedUrl;
parsed: UrlWithParsedQuery;
middlewareList: MiddlewareRoutingItem[];
}): Promise<import("../web/types").FetchEventResult | {
finished: boolean;
}>;
runEdgeFunction(params: {
req: BaseNextRequest;
res: BaseNextResponse;
query: ParsedUrlQuery;
params: Params | undefined;
page: string;
appPaths: string[] | null;
isAppPath: boolean;
}): Promise<import("../web/types").FetchEventResult | null>;
handleRequest(req: BaseNextRequest, res: BaseNextResponse, parsedUrl?: NextUrlWithParsedQuery): Promise<void>;
run(req: NodeNextRequest, res: NodeNextResponse, parsedUrl: UrlWithParsedQuery): Promise<void>;
protected logErrorWithOriginalStack(err?: unknown, type?: 'unhandledRejection' | 'uncaughtException' | 'warning' | 'app-dir'): Promise<void>;
protected getPagesManifest(): PagesManifest | undefined;
protected getAppPathsManifest(): PagesManifest | undefined;
protected getinterceptionRoutePatterns(): RegExp[];
protected getMiddleware(): MiddlewareRoutingItem | undefined;
protected getNextFontManifest(): undefined;
protected hasMiddleware(): Promise<boolean>;
protected ensureMiddleware(url: string): Promise<void>;
private runInstrumentationHookIfAvailable;
protected ensureEdgeFunction({ page, appPaths, url, }: {
page: string;
appPaths: string[] | null;
url: string;
}): Promise<void>;
generateRoutes(_dev?: boolean): void;
_filterAmpDevelopmentScript(html: string, event: {
line: number;
col: number;
code: string;
}): boolean;
protected getStaticPaths({ pathname, requestHeaders, page, isAppPath, }: {
pathname: string;
requestHeaders: IncrementalCache['requestHeaders'];
page: string;
isAppPath: boolean;
}): Promise<{
staticPaths?: string[];
fallbackMode?: false | 'static' | 'blocking';
}>;
private storeGlobals;
private restorePatchedGlobals;
protected ensurePage(opts: {
page: string;
clientOnly: boolean;
appPaths?: ReadonlyArray<string> | null;
definition: RouteDefinition | undefined;
url?: string;
}): Promise<void>;
protected findPageComponents({ page, query, params, isAppPath, appPaths, shouldEnsure, url, }: {
page: string;
query: NextParsedUrlQuery;
params: Params;
isAppPath: boolean;
sriEnabled?: boolean;
appPaths?: ReadonlyArray<string> | null;
shouldEnsure: boolean;
url?: string;
}): Promise<FindComponentsResult | null>;
protected getFallbackErrorComponents(url?: string): Promise<LoadComponentsReturnType | null>;
getCompilationError(page: string): Promise<any>;
}

601
node_modules/next/dist/server/dev/next-dev-server.js generated vendored Normal file
View File

@ -0,0 +1,601 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return DevServer;
}
});
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
const _jestworker = require("next/dist/compiled/jest-worker");
const _path = require("path");
const _output = require("../../build/output");
const _constants = require("../../lib/constants");
const _findpagesdir = require("../../lib/find-pages-dir");
const _constants1 = require("../../shared/lib/constants");
const _nextserver = /*#__PURE__*/ _interop_require_wildcard(require("../next-server"));
const _normalizepagepath = require("../../shared/lib/page-path/normalize-page-path");
const _pathhasprefix = require("../../shared/lib/router/utils/path-has-prefix");
const _removepathprefix = require("../../shared/lib/router/utils/remove-path-prefix");
const _storage = require("../../telemetry/storage");
const _trace = require("../../trace");
const _findpagefile = require("../lib/find-page-file");
const _utils = require("../lib/utils");
const _coalescedfunction = require("../../lib/coalesced-function");
const _loaddefaulterrorcomponents = require("../load-default-error-components");
const _utils1 = require("../../shared/lib/utils");
const _log = /*#__PURE__*/ _interop_require_wildcard(require("../../build/output/log"));
const _iserror = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/is-error"));
const _utils2 = require("../../build/utils");
const _formatservererror = require("../../lib/format-server-error");
const _devroutematchermanager = require("../future/route-matcher-managers/dev-route-matcher-manager");
const _devpagesroutematcherprovider = require("../future/route-matcher-providers/dev/dev-pages-route-matcher-provider");
const _devpagesapiroutematcherprovider = require("../future/route-matcher-providers/dev/dev-pages-api-route-matcher-provider");
const _devapppageroutematcherprovider = require("../future/route-matcher-providers/dev/dev-app-page-route-matcher-provider");
const _devapprouteroutematcherprovider = require("../future/route-matcher-providers/dev/dev-app-route-route-matcher-provider");
const _nodemanifestloader = require("../future/route-matcher-providers/helpers/manifest-loaders/node-manifest-loader");
const _batchedfilereader = require("../future/route-matcher-providers/dev/helpers/file-reader/batched-file-reader");
const _defaultfilereader = require("../future/route-matcher-providers/dev/helpers/file-reader/default-file-reader");
const _lrucache = /*#__PURE__*/ _interop_require_default(require("next/dist/compiled/lru-cache"));
const _middlewareroutematcher = require("../../shared/lib/router/utils/middleware-route-matcher");
const _detachedpromise = require("../../lib/detached-promise");
const _ispostpone = require("../lib/router-utils/is-postpone");
const _generateinterceptionroutesrewrites = require("../../lib/generate-interception-routes-rewrites");
const _buildcustomroute = require("../../lib/build-custom-route");
const _errorsource = require("../../shared/lib/error-source");
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {
__proto__: null
};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
// Load ReactDevOverlay only when needed
let ReactDevOverlayImpl;
const ReactDevOverlay = (props)=>{
if (ReactDevOverlayImpl === undefined) {
ReactDevOverlayImpl = require("../../client/components/react-dev-overlay/pages/client").ReactDevOverlay;
}
return ReactDevOverlayImpl(props);
};
class DevServer extends _nextserver.default {
getStaticPathsWorker() {
const worker = new _jestworker.Worker(require.resolve("./static-paths-worker"), {
maxRetries: 1,
// For dev server, it's not necessary to spin up too many workers as long as you are not doing a load test.
// This helps reusing the memory a lot.
numWorkers: 1,
enableWorkerThreads: this.nextConfig.experimental.workerThreads,
forkOptions: {
env: {
...process.env,
// discard --inspect/--inspect-brk flags from process.env.NODE_OPTIONS. Otherwise multiple Node.js debuggers
// would be started if user launch Next.js in debugging mode. The number of debuggers is linked to
// the number of workers Next.js tries to launch. The only worker users are interested in debugging
// is the main Next.js one
NODE_OPTIONS: (0, _utils.getNodeOptionsWithoutInspect)()
}
}
});
worker.getStdout().pipe(process.stdout);
worker.getStderr().pipe(process.stderr);
return worker;
}
constructor(options){
var _this_nextConfig_experimental_amp, _this_nextConfig_experimental;
try {
// Increase the number of stack frames on the server
Error.stackTraceLimit = 50;
} catch {}
super({
...options,
dev: true
});
/**
* The promise that resolves when the server is ready. When this is unset
* the server is ready.
*/ this.ready = new _detachedpromise.DetachedPromise();
this.bundlerService = options.bundlerService;
this.startServerSpan = options.startServerSpan ?? (0, _trace.trace)("start-next-dev-server");
this.storeGlobals();
this.renderOpts.dev = true;
this.renderOpts.appDirDevErrorLogger = (err)=>this.logErrorWithOriginalStack(err, "app-dir");
this.renderOpts.ErrorDebug = ReactDevOverlay;
this.staticPathsCache = new _lrucache.default({
// 5MB
max: 5 * 1024 * 1024,
length (value) {
return JSON.stringify(value.staticPaths).length;
}
});
this.renderOpts.ampSkipValidation = ((_this_nextConfig_experimental = this.nextConfig.experimental) == null ? void 0 : (_this_nextConfig_experimental_amp = _this_nextConfig_experimental.amp) == null ? void 0 : _this_nextConfig_experimental_amp.skipValidation) ?? false;
this.renderOpts.ampValidator = (html, pathname)=>{
const validatorPath = this.nextConfig.experimental && this.nextConfig.experimental.amp && this.nextConfig.experimental.amp.validator;
const AmpHtmlValidator = require("next/dist/compiled/amphtml-validator");
return AmpHtmlValidator.getInstance(validatorPath).then((validator)=>{
const result = validator.validateString(html);
(0, _output.ampValidation)(pathname, result.errors.filter((e)=>e.severity === "ERROR").filter((e)=>this._filterAmpDevelopmentScript(html, e)), result.errors.filter((e)=>e.severity !== "ERROR"));
});
};
const { pagesDir, appDir } = (0, _findpagesdir.findPagesDir)(this.dir);
this.pagesDir = pagesDir;
this.appDir = appDir;
}
getRouteMatchers() {
const { pagesDir, appDir } = (0, _findpagesdir.findPagesDir)(this.dir);
const ensurer = {
ensure: async (match, pathname)=>{
await this.ensurePage({
definition: match.definition,
page: match.definition.page,
clientOnly: false,
url: pathname
});
}
};
const matchers = new _devroutematchermanager.DevRouteMatcherManager(super.getRouteMatchers(), ensurer, this.dir);
const extensions = this.nextConfig.pageExtensions;
const extensionsExpression = new RegExp(`\\.(?:${extensions.join("|")})$`);
// If the pages directory is available, then configure those matchers.
if (pagesDir) {
const fileReader = new _batchedfilereader.BatchedFileReader(new _defaultfilereader.DefaultFileReader({
// Only allow files that have the correct extensions.
pathnameFilter: (pathname)=>extensionsExpression.test(pathname)
}));
matchers.push(new _devpagesroutematcherprovider.DevPagesRouteMatcherProvider(pagesDir, extensions, fileReader, this.localeNormalizer));
matchers.push(new _devpagesapiroutematcherprovider.DevPagesAPIRouteMatcherProvider(pagesDir, extensions, fileReader, this.localeNormalizer));
}
if (appDir) {
// We create a new file reader for the app directory because we don't want
// to include any folders or files starting with an underscore. This will
// prevent the reader from wasting time reading files that we know we
// don't care about.
const fileReader = new _batchedfilereader.BatchedFileReader(new _defaultfilereader.DefaultFileReader({
// Ignore any directory prefixed with an underscore.
ignorePartFilter: (part)=>part.startsWith("_")
}));
matchers.push(new _devapppageroutematcherprovider.DevAppPageRouteMatcherProvider(appDir, extensions, fileReader));
matchers.push(new _devapprouteroutematcherprovider.DevAppRouteRouteMatcherProvider(appDir, extensions, fileReader));
}
return matchers;
}
getBuildId() {
return "development";
}
async prepareImpl() {
var _this_ready;
(0, _trace.setGlobal)("distDir", this.distDir);
(0, _trace.setGlobal)("phase", _constants1.PHASE_DEVELOPMENT_SERVER);
const telemetry = new _storage.Telemetry({
distDir: this.distDir
});
await super.prepareImpl();
await this.startServerSpan.traceChild("run-instrumentation-hook").traceAsyncFn(()=>this.runInstrumentationHookIfAvailable());
await this.matchers.reload();
// Store globals again to preserve changes made by the instrumentation hook.
this.storeGlobals();
(_this_ready = this.ready) == null ? void 0 : _this_ready.resolve();
this.ready = undefined;
// In dev, this needs to be called after prepare because the build entries won't be known in the constructor
this.interceptionRoutePatterns = this.getinterceptionRoutePatterns();
// This is required by the tracing subsystem.
(0, _trace.setGlobal)("appDir", this.appDir);
(0, _trace.setGlobal)("pagesDir", this.pagesDir);
(0, _trace.setGlobal)("telemetry", telemetry);
process.on("unhandledRejection", (reason)=>{
if ((0, _ispostpone.isPostpone)(reason)) {
// React postpones that are unhandled might end up logged here but they're
// not really errors. They're just part of rendering.
return;
}
this.logErrorWithOriginalStack(reason, "unhandledRejection").catch(()=>{});
});
process.on("uncaughtException", (err)=>{
this.logErrorWithOriginalStack(err, "uncaughtException").catch(()=>{});
});
}
async close() {}
async hasPage(pathname) {
let normalizedPath;
try {
normalizedPath = (0, _normalizepagepath.normalizePagePath)(pathname);
} catch (err) {
console.error(err);
// if normalizing the page fails it means it isn't valid
// so it doesn't exist so don't throw and return false
// to ensure we return 404 instead of 500
return false;
}
if ((0, _utils2.isMiddlewareFile)(normalizedPath)) {
return (0, _findpagefile.findPageFile)(this.dir, normalizedPath, this.nextConfig.pageExtensions, false).then(Boolean);
}
let appFile = null;
let pagesFile = null;
if (this.appDir) {
appFile = await (0, _findpagefile.findPageFile)(this.appDir, normalizedPath + "/page", this.nextConfig.pageExtensions, true);
}
if (this.pagesDir) {
pagesFile = await (0, _findpagefile.findPageFile)(this.pagesDir, normalizedPath, this.nextConfig.pageExtensions, false);
}
if (appFile && pagesFile) {
return false;
}
return Boolean(appFile || pagesFile);
}
async runMiddleware(params) {
try {
const result = await super.runMiddleware({
...params,
onWarning: (warn)=>{
this.logErrorWithOriginalStack(warn, "warning");
}
});
if ("finished" in result) {
return result;
}
result.waitUntil.catch((error)=>{
this.logErrorWithOriginalStack(error, "unhandledRejection");
});
return result;
} catch (error) {
if (error instanceof _utils1.DecodeError) {
throw error;
}
/**
* We only log the error when it is not a MiddlewareNotFound error as
* in that case we should be already displaying a compilation error
* which is what makes the module not found.
*/ if (!(error instanceof _utils1.MiddlewareNotFoundError)) {
this.logErrorWithOriginalStack(error);
}
const err = (0, _iserror.getProperError)(error);
(0, _errorsource.decorateServerError)(err, _constants1.COMPILER_NAMES.edgeServer);
const { request, response, parsedUrl } = params;
/**
* When there is a failure for an internal Next.js request from
* middleware we bypass the error without finishing the request
* so we can serve the required chunks to render the error.
*/ if (request.url.includes("/_next/static") || request.url.includes("/__nextjs_original-stack-frame")) {
return {
finished: false
};
}
response.statusCode = 500;
await this.renderError(err, request, response, parsedUrl.pathname);
return {
finished: true
};
}
}
async runEdgeFunction(params) {
try {
return super.runEdgeFunction({
...params,
onError: (err)=>this.logErrorWithOriginalStack(err, "app-dir"),
onWarning: (warn)=>{
this.logErrorWithOriginalStack(warn, "warning");
}
});
} catch (error) {
if (error instanceof _utils1.DecodeError) {
throw error;
}
this.logErrorWithOriginalStack(error, "warning");
const err = (0, _iserror.getProperError)(error);
const { req, res, page } = params;
res.statusCode = 500;
await this.renderError(err, req, res, page);
return null;
}
}
async handleRequest(req, res, parsedUrl) {
const span = (0, _trace.trace)("handle-request", undefined, {
url: req.url
});
const result = await span.traceAsyncFn(async ()=>{
var _this_ready;
await ((_this_ready = this.ready) == null ? void 0 : _this_ready.promise);
return await super.handleRequest(req, res, parsedUrl);
});
const memoryUsage = process.memoryUsage();
span.traceChild("memory-usage", {
url: req.url,
"memory.rss": String(memoryUsage.rss),
"memory.heapUsed": String(memoryUsage.heapUsed),
"memory.heapTotal": String(memoryUsage.heapTotal)
}).stop();
return result;
}
async run(req, res, parsedUrl) {
var _this_ready;
await ((_this_ready = this.ready) == null ? void 0 : _this_ready.promise);
const { basePath } = this.nextConfig;
let originalPathname = null;
// TODO: see if we can remove this in the future
if (basePath && (0, _pathhasprefix.pathHasPrefix)(parsedUrl.pathname || "/", basePath)) {
// strip basePath before handling dev bundles
// If replace ends up replacing the full url it'll be `undefined`, meaning we have to default it to `/`
originalPathname = parsedUrl.pathname;
parsedUrl.pathname = (0, _removepathprefix.removePathPrefix)(parsedUrl.pathname || "/", basePath);
}
const { pathname } = parsedUrl;
if (pathname.startsWith("/_next")) {
if (_fs.default.existsSync((0, _path.join)(this.publicDir, "_next"))) {
throw new Error(_constants.PUBLIC_DIR_MIDDLEWARE_CONFLICT);
}
}
if (originalPathname) {
// restore the path before continuing so that custom-routes can accurately determine
// if they should match against the basePath or not
parsedUrl.pathname = originalPathname;
}
try {
return await super.run(req, res, parsedUrl);
} catch (error) {
const err = (0, _iserror.getProperError)(error);
(0, _formatservererror.formatServerError)(err);
this.logErrorWithOriginalStack(err).catch(()=>{});
if (!res.sent) {
res.statusCode = 500;
try {
return await this.renderError(err, req, res, pathname, {
__NEXT_PAGE: (0, _iserror.default)(err) && err.page || pathname || ""
});
} catch (internalErr) {
console.error(internalErr);
res.body("Internal Server Error").send();
}
}
}
}
async logErrorWithOriginalStack(err, type) {
await this.bundlerService.logErrorWithOriginalStack(err, type);
}
getPagesManifest() {
return _nodemanifestloader.NodeManifestLoader.require((0, _path.join)(this.serverDistDir, _constants1.PAGES_MANIFEST)) ?? undefined;
}
getAppPathsManifest() {
if (!this.enabledDirectories.app) return undefined;
return _nodemanifestloader.NodeManifestLoader.require((0, _path.join)(this.serverDistDir, _constants1.APP_PATHS_MANIFEST)) ?? undefined;
}
getinterceptionRoutePatterns() {
const rewrites = (0, _generateinterceptionroutesrewrites.generateInterceptionRoutesRewrites)(Object.keys(this.appPathRoutes ?? {}), this.nextConfig.basePath).map((route)=>new RegExp((0, _buildcustomroute.buildCustomRoute)("rewrite", route).regex));
return rewrites ?? [];
}
getMiddleware() {
var _this_middleware;
// We need to populate the match
// field as it isn't serializable
if (((_this_middleware = this.middleware) == null ? void 0 : _this_middleware.match) === null) {
this.middleware.match = (0, _middlewareroutematcher.getMiddlewareRouteMatcher)(this.middleware.matchers || []);
}
return this.middleware;
}
getNextFontManifest() {
return undefined;
}
async hasMiddleware() {
return this.hasPage(this.actualMiddlewareFile);
}
async ensureMiddleware(url) {
return this.ensurePage({
page: this.actualMiddlewareFile,
clientOnly: false,
definition: undefined,
url
});
}
async runInstrumentationHookIfAvailable() {
if (this.actualInstrumentationHookFile && await this.ensurePage({
page: this.actualInstrumentationHookFile,
clientOnly: false,
definition: undefined
}).then(()=>true).catch(()=>false)) {
try {
const instrumentationHook = await require((0, _path.join)(this.distDir, "server", _constants.INSTRUMENTATION_HOOK_FILENAME));
await instrumentationHook.register();
} catch (err) {
err.message = `An error occurred while loading instrumentation hook: ${err.message}`;
throw err;
}
}
}
async ensureEdgeFunction({ page, appPaths, url }) {
return this.ensurePage({
page,
appPaths,
clientOnly: false,
definition: undefined,
url
});
}
generateRoutes(_dev) {
// In development we expose all compiled files for react-error-overlay's line show feature
// We use unshift so that we're sure the routes is defined before Next's default routes
// routes.unshift({
// match: getPathMatch('/_next/development/:path*'),
// type: 'route',
// name: '_next/development catchall',
// fn: async (req, res, params) => {
// const p = pathJoin(this.distDir, ...(params.path || []))
// await this.serveStatic(req, res, p)
// return {
// finished: true,
// }
// },
// })
}
_filterAmpDevelopmentScript(html, event) {
if (event.code !== "DISALLOWED_SCRIPT_TAG") {
return true;
}
const snippetChunks = html.split("\n");
let snippet;
if (!(snippet = html.split("\n")[event.line - 1]) || !(snippet = snippet.substring(event.col))) {
return true;
}
snippet = snippet + snippetChunks.slice(event.line).join("\n");
snippet = snippet.substring(0, snippet.indexOf("</script>"));
return !snippet.includes("data-amp-development-mode-only");
}
async getStaticPaths({ pathname, requestHeaders, page, isAppPath }) {
// we lazy load the staticPaths to prevent the user
// from waiting on them for the page to load in dev mode
const __getStaticPaths = async ()=>{
const { configFileName, publicRuntimeConfig, serverRuntimeConfig, httpAgentOptions } = this.nextConfig;
const { locales, defaultLocale } = this.nextConfig.i18n || {};
const staticPathsWorker = this.getStaticPathsWorker();
try {
const pathsResult = await staticPathsWorker.loadStaticPaths({
dir: this.dir,
distDir: this.distDir,
pathname,
config: {
configFileName,
publicRuntimeConfig,
serverRuntimeConfig
},
httpAgentOptions,
locales,
defaultLocale,
page,
isAppPath,
requestHeaders,
cacheHandler: this.nextConfig.cacheHandler,
fetchCacheKeyPrefix: this.nextConfig.experimental.fetchCacheKeyPrefix,
isrFlushToDisk: this.nextConfig.experimental.isrFlushToDisk,
maxMemoryCacheSize: this.nextConfig.cacheMaxMemorySize,
ppr: this.nextConfig.experimental.ppr === true
});
return pathsResult;
} finally{
// we don't re-use workers so destroy the used one
staticPathsWorker.end();
}
};
const result = this.staticPathsCache.get(pathname);
const nextInvoke = (0, _coalescedfunction.withCoalescedInvoke)(__getStaticPaths)(`staticPaths-${pathname}`, []).then((res)=>{
const { paths: staticPaths = [], fallback } = res.value;
if (!isAppPath && this.nextConfig.output === "export") {
if (fallback === "blocking") {
throw new Error('getStaticPaths with "fallback: blocking" cannot be used with "output: export". See more info here: https://nextjs.org/docs/advanced-features/static-html-export');
} else if (fallback === true) {
throw new Error('getStaticPaths with "fallback: true" cannot be used with "output: export". See more info here: https://nextjs.org/docs/advanced-features/static-html-export');
}
}
const value = {
staticPaths,
fallbackMode: fallback === "blocking" ? "blocking" : fallback === true ? "static" : fallback
};
this.staticPathsCache.set(pathname, value);
return value;
}).catch((err)=>{
this.staticPathsCache.del(pathname);
if (!result) throw err;
_log.error(`Failed to generate static paths for ${pathname}:`);
console.error(err);
});
if (result) {
return result;
}
return nextInvoke;
}
storeGlobals() {
this.originalFetch = global.fetch;
}
restorePatchedGlobals() {
global.fetch = this.originalFetch ?? global.fetch;
}
async ensurePage(opts) {
await this.bundlerService.ensurePage(opts);
}
async findPageComponents({ page, query, params, isAppPath, appPaths = null, shouldEnsure, url }) {
var _this_ready;
await ((_this_ready = this.ready) == null ? void 0 : _this_ready.promise);
const compilationErr = await this.getCompilationError(page);
if (compilationErr) {
// Wrap build errors so that they don't get logged again
throw new _nextserver.WrappedBuildError(compilationErr);
}
try {
if (shouldEnsure || this.renderOpts.customServer) {
await this.ensurePage({
page,
appPaths,
clientOnly: false,
definition: undefined,
url
});
}
this.nextFontManifest = super.getNextFontManifest();
// before we re-evaluate a route module, we want to restore globals that might
// have been patched previously to their original state so that we don't
// patch on top of the previous patch, which would keep the context of the previous
// patched global in memory, creating a memory leak.
this.restorePatchedGlobals();
return await super.findPageComponents({
page,
query,
params,
isAppPath,
shouldEnsure,
url
});
} catch (err) {
if (err.code !== "ENOENT") {
throw err;
}
return null;
}
}
async getFallbackErrorComponents(url) {
await this.bundlerService.getFallbackErrorComponents(url);
return await (0, _loaddefaulterrorcomponents.loadDefaultErrorComponents)(this.distDir);
}
async getCompilationError(page) {
return await this.bundlerService.getCompilationError(page);
}
}
//# sourceMappingURL=next-dev-server.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,129 @@
import type ws from 'next/dist/compiled/ws';
import type { webpack } from 'next/dist/compiled/webpack/webpack';
import type { NextConfigComplete } from '../config-shared';
import type { CompilerNameValues } from '../../shared/lib/constants';
import type { RouteDefinition } from '../future/route-definitions/route-definition';
import type HotReloaderWebpack from './hot-reloader-webpack';
import { COMPILER_INDEXES } from '../../shared/lib/constants';
import { PAGE_TYPES } from '../../lib/page-types';
declare const COMPILER_KEYS: CompilerNameValues[];
/**
* format: {compiler type}@{page type}@{page path}
* e.g. client@pages@/index
* e.g. server@app@app/page
*
* This guarantees the uniqueness for each page, to avoid conflicts between app/ and pages/
*/
export declare function getEntryKey(compilerType: CompilerNameValues, pageBundleType: PAGE_TYPES, page: string): string;
export declare const ADDED: unique symbol;
export declare const BUILDING: unique symbol;
export declare const BUILT: unique symbol;
interface EntryType {
/**
* Tells if a page is scheduled to be disposed.
*/
dispose?: boolean;
/**
* Timestamp with the last time the page was active.
*/
lastActiveTime?: number;
/**
* Page build status.
*/
status?: typeof ADDED | typeof BUILDING | typeof BUILT;
/**
* Path to the page file relative to the dist folder with no extension.
* For example: `pages/about/index`
*/
bundlePath: string;
/**
* Webpack request to create a dependency for.
*/
request: string;
}
export declare const enum EntryTypes {
ENTRY = 0,
CHILD_ENTRY = 1
}
interface Entry extends EntryType {
type: EntryTypes.ENTRY;
/**
* The absolute page to the page file. Used for detecting if the file was removed. For example:
* `/Users/Rick/project/pages/about/index.js`
*/
absolutePagePath: string;
/**
* All parallel pages that match the same entry, for example:
* ['/parallel/@bar/nested/@a/page', '/parallel/@bar/nested/@b/page', '/parallel/@foo/nested/@a/page', '/parallel/@foo/nested/@b/page']
*/
appPaths: ReadonlyArray<string> | null;
}
interface ChildEntry extends EntryType {
type: EntryTypes.CHILD_ENTRY;
/**
* Which parent entries use this childEntry.
*/
parentEntries: Set<string>;
/**
* The absolute page to the entry file. Used for detecting if the file was removed. For example:
* `/Users/Rick/project/app/about/layout.js`
*/
absoluteEntryFilePath?: string;
}
declare const entriesMap: Map<string, {
/**
* The key composed of the compiler name and the page. For example:
* `edge-server/about`
*/
[entryName: string]: Entry | ChildEntry;
}>;
export declare const getEntries: (dir: string) => NonNullable<ReturnType<(typeof entriesMap)['get']>>;
export declare const getInvalidator: (dir: string) => Invalidator | undefined;
declare class Invalidator {
private multiCompiler;
private building;
private rebuildAgain;
constructor(multiCompiler: webpack.MultiCompiler);
shouldRebuildAll(): boolean;
invalidate(compilerKeys?: typeof COMPILER_KEYS): void;
startBuilding(compilerKey: keyof typeof COMPILER_INDEXES): void;
doneBuilding(compilerKeys?: typeof COMPILER_KEYS): void;
willRebuild(compilerKey: keyof typeof COMPILER_INDEXES): boolean;
}
interface PagePathData {
filename: string;
bundlePath: string;
page: string;
}
/**
* Attempts to find a page file path from the given pages absolute directory,
* a page and allowed extensions. If the page can't be found it will throw an
* error. It defaults the `/_error` page to Next.js internal error page.
*
* @param rootDir Absolute path to the project root.
* @param page The page normalized (it will be denormalized).
* @param extensions Array of page extensions.
* @param pagesDir Absolute path to the pages folder with trailing `/pages`.
* @param appDir Absolute path to the app folder with trailing `/app`.
*/
export declare function findPagePathData(rootDir: string, page: string, extensions: string[], pagesDir?: string, appDir?: string): Promise<PagePathData>;
export declare function onDemandEntryHandler({ hotReloader, maxInactiveAge, multiCompiler, nextConfig, pagesBufferLength, pagesDir, rootDir, appDir, }: {
hotReloader: HotReloaderWebpack;
maxInactiveAge: number;
multiCompiler: webpack.MultiCompiler;
nextConfig: NextConfigComplete;
pagesBufferLength: number;
pagesDir?: string;
rootDir: string;
appDir?: string;
}): {
ensurePage({ page, appPaths, definition, isApp, url, }: {
page: string;
appPaths?: readonly string[] | null | undefined;
definition?: RouteDefinition<import("../future/route-kind").RouteKind> | undefined;
isApp?: boolean | undefined;
url?: string | undefined;
}): Promise<void>;
onHMR(client: ws, getHmrServerError: () => Error | null): void;
};
export {};

View File

@ -0,0 +1,663 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
ADDED: null,
BUILDING: null,
BUILT: null,
EntryTypes: null,
findPagePathData: null,
getEntries: null,
getEntryKey: null,
getInvalidator: null,
onDemandEntryHandler: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
ADDED: function() {
return ADDED;
},
BUILDING: function() {
return BUILDING;
},
BUILT: function() {
return BUILT;
},
EntryTypes: function() {
return EntryTypes;
},
findPagePathData: function() {
return findPagePathData;
},
getEntries: function() {
return getEntries;
},
getEntryKey: function() {
return getEntryKey;
},
getInvalidator: function() {
return getInvalidator;
},
onDemandEntryHandler: function() {
return onDemandEntryHandler;
}
});
const _debug = /*#__PURE__*/ _interop_require_default(require("next/dist/compiled/debug"));
const _events = require("events");
const _findpagefile = require("../lib/find-page-file");
const _entries = require("../../build/entries");
const _path = require("path");
const _normalizepathsep = require("../../shared/lib/page-path/normalize-path-sep");
const _normalizepagepath = require("../../shared/lib/page-path/normalize-page-path");
const _ensureleadingslash = require("../../shared/lib/page-path/ensure-leading-slash");
const _removepagepathtail = require("../../shared/lib/page-path/remove-page-path-tail");
const _output = require("../../build/output");
const _getroutefromentrypoint = /*#__PURE__*/ _interop_require_default(require("../get-route-from-entrypoint"));
const _utils = require("../../build/utils");
const _utils1 = require("../../shared/lib/utils");
const _constants = require("../../shared/lib/constants");
const _segment = require("../../shared/lib/segment");
const _hotreloadertypes = require("./hot-reloader-types");
const _apppageroutedefinition = require("../future/route-definitions/app-page-route-definition");
const _scheduler = require("../../lib/scheduler");
const _batcher = require("../../lib/batcher");
const _apppaths = require("../../shared/lib/router/utils/app-paths");
const _pagetypes = require("../../lib/page-types");
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
const debug = (0, _debug.default)("next:on-demand-entry-handler");
/**
* Returns object keys with type inferred from the object key
*/ const keys = Object.keys;
const COMPILER_KEYS = keys(_constants.COMPILER_INDEXES);
function treePathToEntrypoint(segmentPath, parentPath) {
const [parallelRouteKey, segment] = segmentPath;
// TODO-APP: modify this path to cover parallelRouteKey convention
const path = (parentPath ? parentPath + "/" : "") + (parallelRouteKey !== "children" && !segment.startsWith("@") ? `@${parallelRouteKey}/` : "") + (segment === "" ? "page" : segment);
// Last segment
if (segmentPath.length === 2) {
return path;
}
const childSegmentPath = segmentPath.slice(2);
return treePathToEntrypoint(childSegmentPath, path);
}
function convertDynamicParamTypeToSyntax(dynamicParamTypeShort, param) {
switch(dynamicParamTypeShort){
case "c":
case "ci":
return `[...${param}]`;
case "oc":
return `[[...${param}]]`;
case "d":
case "di":
return `[${param}]`;
default:
throw new Error("Unknown dynamic param type");
}
}
function getEntryKey(compilerType, pageBundleType, page) {
// TODO: handle the /children slot better
// this is a quick hack to handle when children is provided as children/page instead of /page
const pageKey = page.replace(/(@[^/]+)\/children/g, "$1");
return `${compilerType}@${pageBundleType}@${pageKey}`;
}
function getPageBundleType(pageBundlePath) {
// Handle special case for /_error
if (pageBundlePath === "/_error") return _pagetypes.PAGE_TYPES.PAGES;
if ((0, _utils.isMiddlewareFilename)(pageBundlePath)) return _pagetypes.PAGE_TYPES.ROOT;
return pageBundlePath.startsWith("pages/") ? _pagetypes.PAGE_TYPES.PAGES : pageBundlePath.startsWith("app/") ? _pagetypes.PAGE_TYPES.APP : _pagetypes.PAGE_TYPES.ROOT;
}
function getEntrypointsFromTree(tree, isFirst, parentPath = []) {
const [segment, parallelRoutes] = tree;
const currentSegment = Array.isArray(segment) ? convertDynamicParamTypeToSyntax(segment[2], segment[0]) : segment;
const isPageSegment = currentSegment.startsWith(_segment.PAGE_SEGMENT_KEY);
const currentPath = [
...parentPath,
isPageSegment ? "" : currentSegment
];
if (!isFirst && isPageSegment) {
// TODO get rid of '' at the start of tree
return [
treePathToEntrypoint(currentPath.slice(1))
];
}
return Object.keys(parallelRoutes).reduce((paths, key)=>{
const childTree = parallelRoutes[key];
const childPages = getEntrypointsFromTree(childTree, false, [
...currentPath,
key
]);
return [
...paths,
...childPages
];
}, []);
}
const ADDED = Symbol("added");
const BUILDING = Symbol("building");
const BUILT = Symbol("built");
var EntryTypes;
(function(EntryTypes) {
EntryTypes[EntryTypes["ENTRY"] = 0] = "ENTRY";
EntryTypes[EntryTypes["CHILD_ENTRY"] = 1] = "CHILD_ENTRY";
})(EntryTypes || (EntryTypes = {}));
const entriesMap = new Map();
// remove /server from end of output for server compiler
const normalizeOutputPath = (dir)=>dir.replace(/[/\\]server$/, "");
const getEntries = (dir)=>{
dir = normalizeOutputPath(dir);
const entries = entriesMap.get(dir) || {};
entriesMap.set(dir, entries);
return entries;
};
const invalidators = new Map();
const getInvalidator = (dir)=>{
dir = normalizeOutputPath(dir);
return invalidators.get(dir);
};
const doneCallbacks = new _events.EventEmitter();
const lastClientAccessPages = [
""
];
const lastServerAccessPagesForAppDir = [
""
];
// Make sure only one invalidation happens at a time
// Otherwise, webpack hash gets changed and it'll force the client to reload.
class Invalidator {
constructor(multiCompiler){
this.building = new Set();
this.rebuildAgain = new Set();
this.multiCompiler = multiCompiler;
}
shouldRebuildAll() {
return this.rebuildAgain.size > 0;
}
invalidate(compilerKeys = COMPILER_KEYS) {
for (const key of compilerKeys){
var _this_multiCompiler_compilers_COMPILER_INDEXES_key_watching;
// If there's a current build is processing, we won't abort it by invalidating.
// (If aborted, it'll cause a client side hard reload)
// But let it to invalidate just after the completion.
// So, it can re-build the queued pages at once.
if (this.building.has(key)) {
this.rebuildAgain.add(key);
continue;
}
this.building.add(key);
(_this_multiCompiler_compilers_COMPILER_INDEXES_key_watching = this.multiCompiler.compilers[_constants.COMPILER_INDEXES[key]].watching) == null ? void 0 : _this_multiCompiler_compilers_COMPILER_INDEXES_key_watching.invalidate();
}
}
startBuilding(compilerKey) {
this.building.add(compilerKey);
}
doneBuilding(compilerKeys = []) {
const rebuild = [];
for (const key of compilerKeys){
this.building.delete(key);
if (this.rebuildAgain.has(key)) {
rebuild.push(key);
this.rebuildAgain.delete(key);
}
}
this.invalidate(rebuild);
}
willRebuild(compilerKey) {
return this.rebuildAgain.has(compilerKey);
}
}
function disposeInactiveEntries(entries, maxInactiveAge) {
Object.keys(entries).forEach((entryKey)=>{
const entryData = entries[entryKey];
const { lastActiveTime, status, dispose, bundlePath } = entryData;
// TODO-APP: implement disposing of CHILD_ENTRY
if (entryData.type === 1) {
return;
}
// For the root middleware and the instrumentation hook files,
// we don't dispose them periodically as it's needed for every request.
if ((0, _utils.isMiddlewareFilename)(bundlePath) || (0, _utils.isInstrumentationHookFilename)(bundlePath)) {
return;
}
if (dispose) // Skip pages already scheduled for disposing
return;
// This means this entry is currently building or just added
// We don't need to dispose those entries.
if (status !== BUILT) return;
// We should not build the last accessed page even we didn't get any pings
// Sometimes, it's possible our XHR ping to wait before completing other requests.
// In that case, we should not dispose the current viewing page
if (lastClientAccessPages.includes(entryKey) || lastServerAccessPagesForAppDir.includes(entryKey)) return;
if (lastActiveTime && Date.now() - lastActiveTime > maxInactiveAge) {
entries[entryKey].dispose = true;
}
});
}
// Normalize both app paths and page paths
function tryToNormalizePagePath(page) {
try {
return (0, _normalizepagepath.normalizePagePath)(page);
} catch (err) {
console.error(err);
throw new _utils1.PageNotFoundError(page);
}
}
async function findPagePathData(rootDir, page, extensions, pagesDir, appDir) {
const normalizedPagePath = tryToNormalizePagePath(page);
let pagePath = null;
const isInstrumentation = (0, _utils.isInstrumentationHookFile)(normalizedPagePath);
if ((0, _utils.isMiddlewareFile)(normalizedPagePath) || isInstrumentation) {
pagePath = await (0, _findpagefile.findPageFile)(rootDir, normalizedPagePath, extensions, false);
if (!pagePath) {
throw new _utils1.PageNotFoundError(normalizedPagePath);
}
const pageUrl = (0, _ensureleadingslash.ensureLeadingSlash)((0, _removepagepathtail.removePagePathTail)((0, _normalizepathsep.normalizePathSep)(pagePath), {
extensions
}));
let bundlePath = normalizedPagePath;
let pageKey = _path.posix.normalize(pageUrl);
if (isInstrumentation) {
bundlePath = bundlePath.replace("/src", "");
pageKey = page.replace("/src", "");
}
return {
filename: (0, _path.join)(rootDir, pagePath),
bundlePath: bundlePath.slice(1),
page: pageKey
};
}
// Check appDir first falling back to pagesDir
if (appDir) {
if (page === _constants.UNDERSCORE_NOT_FOUND_ROUTE_ENTRY) {
const notFoundPath = await (0, _findpagefile.findPageFile)(appDir, "not-found", extensions, true);
if (notFoundPath) {
return {
filename: (0, _path.join)(appDir, notFoundPath),
bundlePath: `app${_constants.UNDERSCORE_NOT_FOUND_ROUTE_ENTRY}`,
page: _constants.UNDERSCORE_NOT_FOUND_ROUTE_ENTRY
};
}
return {
filename: require.resolve("next/dist/client/components/not-found-error"),
bundlePath: `app${_constants.UNDERSCORE_NOT_FOUND_ROUTE_ENTRY}`,
page: _constants.UNDERSCORE_NOT_FOUND_ROUTE_ENTRY
};
}
pagePath = await (0, _findpagefile.findPageFile)(appDir, normalizedPagePath, extensions, true);
if (pagePath) {
const pageUrl = (0, _ensureleadingslash.ensureLeadingSlash)((0, _removepagepathtail.removePagePathTail)((0, _normalizepathsep.normalizePathSep)(pagePath), {
keepIndex: true,
extensions
}));
return {
filename: (0, _path.join)(appDir, pagePath),
bundlePath: _path.posix.join("app", pageUrl),
page: _path.posix.normalize(pageUrl)
};
}
}
if (!pagePath && pagesDir) {
pagePath = await (0, _findpagefile.findPageFile)(pagesDir, normalizedPagePath, extensions, false);
}
if (pagePath !== null && pagesDir) {
const pageUrl = (0, _ensureleadingslash.ensureLeadingSlash)((0, _removepagepathtail.removePagePathTail)((0, _normalizepathsep.normalizePathSep)(pagePath), {
extensions
}));
return {
filename: (0, _path.join)(pagesDir, pagePath),
bundlePath: _path.posix.join("pages", (0, _normalizepagepath.normalizePagePath)(pageUrl)),
page: _path.posix.normalize(pageUrl)
};
}
if (page === "/_error") {
return {
filename: require.resolve("next/dist/pages/_error"),
bundlePath: page,
page: (0, _normalizepathsep.normalizePathSep)(page)
};
} else {
throw new _utils1.PageNotFoundError(normalizedPagePath);
}
}
function onDemandEntryHandler({ hotReloader, maxInactiveAge, multiCompiler, nextConfig, pagesBufferLength, pagesDir, rootDir, appDir }) {
const hasAppDir = !!appDir;
let curInvalidator = getInvalidator(multiCompiler.outputPath);
const curEntries = getEntries(multiCompiler.outputPath);
if (!curInvalidator) {
curInvalidator = new Invalidator(multiCompiler);
invalidators.set(multiCompiler.outputPath, curInvalidator);
}
const startBuilding = (compilation)=>{
const compilationName = compilation.name;
curInvalidator.startBuilding(compilationName);
};
for (const compiler of multiCompiler.compilers){
compiler.hooks.make.tap("NextJsOnDemandEntries", startBuilding);
}
function getPagePathsFromEntrypoints(type, entrypoints) {
const pagePaths = [];
for (const entrypoint of entrypoints.values()){
const page = (0, _getroutefromentrypoint.default)(entrypoint.name, hasAppDir);
if (page) {
var _entrypoint_name;
const pageBundleType = ((_entrypoint_name = entrypoint.name) == null ? void 0 : _entrypoint_name.startsWith("app/")) ? _pagetypes.PAGE_TYPES.APP : _pagetypes.PAGE_TYPES.PAGES;
pagePaths.push(getEntryKey(type, pageBundleType, page));
} else if ((0, _utils.isMiddlewareFilename)(entrypoint.name) || (0, _utils.isInstrumentationHookFilename)(entrypoint.name)) {
pagePaths.push(getEntryKey(type, _pagetypes.PAGE_TYPES.ROOT, `/${entrypoint.name}`));
}
}
return pagePaths;
}
for (const compiler of multiCompiler.compilers){
compiler.hooks.done.tap("NextJsOnDemandEntries", ()=>{
var _getInvalidator;
return (_getInvalidator = getInvalidator(compiler.outputPath)) == null ? void 0 : _getInvalidator.doneBuilding([
compiler.name
]);
});
}
multiCompiler.hooks.done.tap("NextJsOnDemandEntries", (multiStats)=>{
var _getInvalidator;
const [clientStats, serverStats, edgeServerStats] = multiStats.stats;
const entryNames = [
...getPagePathsFromEntrypoints(_constants.COMPILER_NAMES.client, clientStats.compilation.entrypoints),
...getPagePathsFromEntrypoints(_constants.COMPILER_NAMES.server, serverStats.compilation.entrypoints),
...edgeServerStats ? getPagePathsFromEntrypoints(_constants.COMPILER_NAMES.edgeServer, edgeServerStats.compilation.entrypoints) : []
];
for (const name of entryNames){
const entry = curEntries[name];
if (!entry) {
continue;
}
if (entry.status !== BUILDING) {
continue;
}
entry.status = BUILT;
doneCallbacks.emit(name);
}
(_getInvalidator = getInvalidator(multiCompiler.outputPath)) == null ? void 0 : _getInvalidator.doneBuilding([
...COMPILER_KEYS
]);
});
const pingIntervalTime = Math.max(1000, Math.min(5000, maxInactiveAge));
setInterval(function() {
disposeInactiveEntries(curEntries, maxInactiveAge);
}, pingIntervalTime + 1000).unref();
function handleAppDirPing(tree) {
const pages = getEntrypointsFromTree(tree, true);
for (const page of pages){
for (const compilerType of [
_constants.COMPILER_NAMES.client,
_constants.COMPILER_NAMES.server,
_constants.COMPILER_NAMES.edgeServer
]){
const entryKey = getEntryKey(compilerType, _pagetypes.PAGE_TYPES.APP, `/${page}`);
const entryInfo = curEntries[entryKey];
// If there's no entry, it may have been invalidated and needs to be re-built.
if (!entryInfo) {
continue;
}
// We don't need to maintain active state of anything other than BUILT entries
if (entryInfo.status !== BUILT) continue;
// If there's an entryInfo
if (!lastServerAccessPagesForAppDir.includes(entryKey)) {
lastServerAccessPagesForAppDir.unshift(entryKey);
// Maintain the buffer max length
// TODO: verify that the current pageKey is not at the end of the array as multiple entrypoints can exist
if (lastServerAccessPagesForAppDir.length > pagesBufferLength) {
lastServerAccessPagesForAppDir.pop();
}
}
entryInfo.lastActiveTime = Date.now();
entryInfo.dispose = false;
}
}
}
function handlePing(pg) {
const page = (0, _normalizepathsep.normalizePathSep)(pg);
for (const compilerType of [
_constants.COMPILER_NAMES.client,
_constants.COMPILER_NAMES.server,
_constants.COMPILER_NAMES.edgeServer
]){
const entryKey = getEntryKey(compilerType, _pagetypes.PAGE_TYPES.PAGES, page);
const entryInfo = curEntries[entryKey];
// If there's no entry, it may have been invalidated and needs to be re-built.
if (!entryInfo) {
// if (page !== lastEntry) client pings, but there's no entry for page
if (compilerType === _constants.COMPILER_NAMES.client) {
return;
}
continue;
}
// We don't need to maintain active state of anything other than BUILT entries
if (entryInfo.status !== BUILT) continue;
// If there's an entryInfo
if (!lastClientAccessPages.includes(entryKey)) {
lastClientAccessPages.unshift(entryKey);
// Maintain the buffer max length
if (lastClientAccessPages.length > pagesBufferLength) {
lastClientAccessPages.pop();
}
}
entryInfo.lastActiveTime = Date.now();
entryInfo.dispose = false;
}
return;
}
async function ensurePageImpl({ page, appPaths, definition, isApp, url }) {
const stalledTime = 60;
const stalledEnsureTimeout = setTimeout(()=>{
debug(`Ensuring ${page} has taken longer than ${stalledTime}s, if this continues to stall this may be a bug`);
}, stalledTime * 1000);
try {
let route;
if (definition) {
route = definition;
} else {
route = await findPagePathData(rootDir, page, nextConfig.pageExtensions, pagesDir, appDir);
}
const isInsideAppDir = !!appDir && route.filename.startsWith(appDir);
if (typeof isApp === "boolean" && isApp !== isInsideAppDir) {
Error.stackTraceLimit = 15;
throw new Error(`Ensure bailed, found path "${route.page}" does not match ensure type (${isApp ? "app" : "pages"})`);
}
const pageBundleType = getPageBundleType(route.bundlePath);
const addEntry = (compilerType)=>{
const entryKey = getEntryKey(compilerType, pageBundleType, route.page);
if (curEntries[entryKey] && // there can be an overlap in the entryKey for the instrumentation hook file and a page named the same
// this is a quick fix to support this scenario by overwriting the instrumentation hook entry, since we only use it one time
// any changes to the instrumentation hook file will require a restart of the dev server anyway
!(0, _utils.isInstrumentationHookFilename)(curEntries[entryKey].bundlePath)) {
curEntries[entryKey].dispose = false;
curEntries[entryKey].lastActiveTime = Date.now();
if (curEntries[entryKey].status === BUILT) {
return {
entryKey,
newEntry: false,
shouldInvalidate: false
};
}
return {
entryKey,
newEntry: false,
shouldInvalidate: true
};
}
curEntries[entryKey] = {
type: 0,
appPaths,
absolutePagePath: route.filename,
request: route.filename,
bundlePath: route.bundlePath,
dispose: false,
lastActiveTime: Date.now(),
status: ADDED
};
return {
entryKey: entryKey,
newEntry: true,
shouldInvalidate: true
};
};
const staticInfo = await (0, _entries.getStaticInfoIncludingLayouts)({
page,
pageFilePath: route.filename,
isInsideAppDir,
pageExtensions: nextConfig.pageExtensions,
isDev: true,
config: nextConfig,
appDir
});
const added = new Map();
const isServerComponent = isInsideAppDir && staticInfo.rsc !== _constants.RSC_MODULE_TYPES.client;
(0, _entries.runDependingOnPageType)({
page: route.page,
pageRuntime: staticInfo.runtime,
pageType: pageBundleType,
onClient: ()=>{
// Skip adding the client entry for app / Server Components.
if (isServerComponent || isInsideAppDir) {
return;
}
added.set(_constants.COMPILER_NAMES.client, addEntry(_constants.COMPILER_NAMES.client));
},
onServer: ()=>{
added.set(_constants.COMPILER_NAMES.server, addEntry(_constants.COMPILER_NAMES.server));
const edgeServerEntry = getEntryKey(_constants.COMPILER_NAMES.edgeServer, pageBundleType, route.page);
if (curEntries[edgeServerEntry] && !(0, _utils.isInstrumentationHookFile)(route.page)) {
// Runtime switched from edge to server
delete curEntries[edgeServerEntry];
}
},
onEdgeServer: ()=>{
added.set(_constants.COMPILER_NAMES.edgeServer, addEntry(_constants.COMPILER_NAMES.edgeServer));
const serverEntry = getEntryKey(_constants.COMPILER_NAMES.server, pageBundleType, route.page);
if (curEntries[serverEntry] && !(0, _utils.isInstrumentationHookFile)(route.page)) {
// Runtime switched from server to edge
delete curEntries[serverEntry];
}
}
});
const addedValues = [
...added.values()
];
const entriesThatShouldBeInvalidated = [
...added.entries()
].filter(([, entry])=>entry.shouldInvalidate);
const hasNewEntry = addedValues.some((entry)=>entry.newEntry);
if (hasNewEntry) {
const routePage = isApp ? route.page : (0, _apppaths.normalizeAppPath)(route.page);
(0, _output.reportTrigger)(routePage, url);
}
if (entriesThatShouldBeInvalidated.length > 0) {
const invalidatePromise = Promise.all(entriesThatShouldBeInvalidated.map(([compilerKey, { entryKey }])=>{
return new Promise((resolve, reject)=>{
doneCallbacks.once(entryKey, (err)=>{
if (err) {
return reject(err);
}
// If the invalidation also triggers a rebuild, we need to
// wait for that additional build to prevent race conditions.
const needsRebuild = curInvalidator.willRebuild(compilerKey);
if (needsRebuild) {
doneCallbacks.once(entryKey, (rebuildErr)=>{
if (rebuildErr) {
return reject(rebuildErr);
}
resolve();
});
} else {
resolve();
}
});
});
}));
curInvalidator.invalidate([
...added.keys()
]);
await invalidatePromise;
}
} finally{
clearTimeout(stalledEnsureTimeout);
}
}
// Make sure that we won't have multiple invalidations ongoing concurrently.
const batcher = _batcher.Batcher.create({
// The cache key here is composed of the elements that affect the
// compilation, namely, the page, whether it's client only, and whether
// it's an app page. This ensures that we don't have multiple compilations
// for the same page happening concurrently.
//
// We don't include the whole match because it contains match specific
// parameters (like route params) that would just bust this cache. Any
// details that would possibly bust the cache should be listed here.
cacheKeyFn: (options)=>JSON.stringify(options),
// Schedule the invocation of the ensurePageImpl function on the next tick.
schedulerFn: _scheduler.scheduleOnNextTick
});
return {
async ensurePage ({ page, appPaths = null, definition, isApp, url }) {
// If the route is actually an app page route, then we should have access
// to the app route definition, and therefore, the appPaths from it.
if (!appPaths && definition && (0, _apppageroutedefinition.isAppPageRouteDefinition)(definition)) {
appPaths = definition.appPaths;
}
// Wrap the invocation of the ensurePageImpl function in the pending
// wrapper, which will ensure that we don't have multiple compilations
// for the same page happening concurrently.
return batcher.batch({
page,
appPaths,
definition,
isApp
}, async ()=>{
await ensurePageImpl({
page,
appPaths,
definition,
isApp,
url
});
});
},
onHMR (client, getHmrServerError) {
let bufferedHmrServerError = null;
client.addEventListener("close", ()=>{
bufferedHmrServerError = null;
});
client.addEventListener("message", ({ data })=>{
try {
const error = getHmrServerError();
// New error occurred: buffered error is flushed and new error occurred
if (!bufferedHmrServerError && error) {
hotReloader.send({
action: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.SERVER_ERROR,
errorJSON: (0, _utils1.stringifyError)(error)
});
bufferedHmrServerError = null;
}
const parsedData = JSON.parse(typeof data !== "string" ? data.toString() : data);
if (parsedData.event === "ping") {
if (parsedData.appDirRoute) {
handleAppDirPing(parsedData.tree);
} else {
handlePing(parsedData.page);
}
}
} catch {}
});
}
};
}
//# sourceMappingURL=on-demand-entry-handler.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,10 @@
export interface VersionInfo {
installed: string;
staleness: 'fresh' | 'stale-patch' | 'stale-minor' | 'stale-major' | 'stale-prerelease' | 'newer-than-npm' | 'unknown';
expected?: string;
}
export declare function parseVersionInfo(o: {
installed: string;
latest: string;
canary: string;
}): VersionInfo;

108
node_modules/next/dist/server/dev/parse-version-info.js generated vendored Normal file
View File

@ -0,0 +1,108 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "parseVersionInfo", {
enumerable: true,
get: function() {
return parseVersionInfo;
}
});
const _semver = /*#__PURE__*/ _interop_require_wildcard(require("next/dist/compiled/semver"));
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {
__proto__: null
};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
function parseVersionInfo(o) {
const latest = _semver.parse(o.latest);
const canary = _semver.parse(o.canary);
const installedParsed = _semver.parse(o.installed);
const installed = o.installed;
if (installedParsed && latest && canary) {
if (installedParsed.major < latest.major) {
// Old major version
return {
staleness: "stale-major",
expected: latest.raw,
installed
};
} else if (installedParsed.prerelease[0] === "canary" && _semver.lt(installedParsed, canary)) {
// Matching major, but old canary
return {
staleness: "stale-prerelease",
expected: canary.raw,
installed
};
} else if (!installedParsed.prerelease.length && _semver.lt(installedParsed, latest)) {
// Stable, but not the latest
if (installedParsed.minor === latest.minor) {
// Same major and minor, but not the latest patch
return {
staleness: "stale-patch",
expected: latest.raw,
installed
};
}
return {
staleness: "stale-minor",
expected: latest.raw,
installed
};
} else if (_semver.gt(installedParsed, latest) && installedParsed.version !== canary.version) {
// Newer major version
return {
staleness: "newer-than-npm",
installed
};
} else {
// Latest and greatest
return {
staleness: "fresh",
installed
};
}
}
return {
installed: (installedParsed == null ? void 0 : installedParsed.raw) ?? "0.0.0",
staleness: "unknown"
};
}
//# sourceMappingURL=parse-version-info.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/dev/parse-version-info.ts"],"names":["parseVersionInfo","o","latest","semver","parse","canary","installedParsed","installed","major","staleness","expected","raw","prerelease","lt","length","minor","gt","version"],"mappings":";;;;+BAegBA;;;eAAAA;;;gEAfQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAejB,SAASA,iBAAiBC,CAIhC;IACC,MAAMC,SAASC,QAAOC,KAAK,CAACH,EAAEC,MAAM;IACpC,MAAMG,SAASF,QAAOC,KAAK,CAACH,EAAEI,MAAM;IACpC,MAAMC,kBAAkBH,QAAOC,KAAK,CAACH,EAAEM,SAAS;IAChD,MAAMA,YAAYN,EAAEM,SAAS;IAC7B,IAAID,mBAAmBJ,UAAUG,QAAQ;QACvC,IAAIC,gBAAgBE,KAAK,GAAGN,OAAOM,KAAK,EAAE;YACxC,oBAAoB;YACpB,OAAO;gBAAEC,WAAW;gBAAeC,UAAUR,OAAOS,GAAG;gBAAEJ;YAAU;QACrE,OAAO,IACLD,gBAAgBM,UAAU,CAAC,EAAE,KAAK,YAClCT,QAAOU,EAAE,CAACP,iBAAiBD,SAC3B;YACA,iCAAiC;YACjC,OAAO;gBACLI,WAAW;gBACXC,UAAUL,OAAOM,GAAG;gBACpBJ;YACF;QACF,OAAO,IACL,CAACD,gBAAgBM,UAAU,CAACE,MAAM,IAClCX,QAAOU,EAAE,CAACP,iBAAiBJ,SAC3B;YACA,6BAA6B;YAC7B,IAAII,gBAAgBS,KAAK,KAAKb,OAAOa,KAAK,EAAE;gBAC1C,iDAAiD;gBACjD,OAAO;oBACLN,WAAW;oBACXC,UAAUR,OAAOS,GAAG;oBACpBJ;gBACF;YACF;YACA,OAAO;gBAAEE,WAAW;gBAAeC,UAAUR,OAAOS,GAAG;gBAAEJ;YAAU;QACrE,OAAO,IACLJ,QAAOa,EAAE,CAACV,iBAAiBJ,WAC3BI,gBAAgBW,OAAO,KAAKZ,OAAOY,OAAO,EAC1C;YACA,sBAAsB;YACtB,OAAO;gBAAER,WAAW;gBAAkBF;YAAU;QAClD,OAAO;YACL,sBAAsB;YACtB,OAAO;gBAAEE,WAAW;gBAASF;YAAU;QACzC;IACF;IAEA,OAAO;QACLA,WAAWD,CAAAA,mCAAAA,gBAAiBK,GAAG,KAAI;QACnCF,WAAW;IACb;AACF"}

View File

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

View File

@ -0,0 +1,35 @@
import type { NextConfigComplete } from '../config-shared';
import '../require-hook';
import '../node-environment';
import type { IncrementalCache } from '../lib/incremental-cache';
type RuntimeConfig = {
configFileName: string;
publicRuntimeConfig: {
[key: string]: any;
};
serverRuntimeConfig: {
[key: string]: any;
};
};
export declare function loadStaticPaths({ dir, distDir, pathname, config, httpAgentOptions, locales, defaultLocale, isAppPath, page, isrFlushToDisk, fetchCacheKeyPrefix, maxMemoryCacheSize, requestHeaders, cacheHandler, ppr, }: {
dir: string;
distDir: string;
pathname: string;
config: RuntimeConfig;
httpAgentOptions: NextConfigComplete['httpAgentOptions'];
locales?: string[];
defaultLocale?: string;
isAppPath: boolean;
page: string;
isrFlushToDisk?: boolean;
fetchCacheKeyPrefix?: string;
maxMemoryCacheSize?: number;
requestHeaders: IncrementalCache['requestHeaders'];
cacheHandler?: string;
ppr: boolean;
}): Promise<{
paths?: string[];
encodedPaths?: string[];
fallback?: boolean | 'blocking';
}>;
export {};

View File

@ -0,0 +1,71 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "loadStaticPaths", {
enumerable: true,
get: function() {
return loadStaticPaths;
}
});
require("../require-hook");
require("../node-environment");
const _utils = require("../../build/utils");
const _loadcomponents = require("../load-components");
const _setuphttpagentenv = require("../setup-http-agent-env");
const _checks = require("../future/route-modules/checks");
async function loadStaticPaths({ dir, distDir, pathname, config, httpAgentOptions, locales, defaultLocale, isAppPath, page, isrFlushToDisk, fetchCacheKeyPrefix, maxMemoryCacheSize, requestHeaders, cacheHandler, ppr }) {
// update work memory runtime-config
require("../../shared/lib/runtime-config.external").setConfig(config);
(0, _setuphttpagentenv.setHttpClientAndAgentOptions)({
httpAgentOptions
});
const components = await (0, _loadcomponents.loadComponents)({
distDir,
// In `pages/`, the page is the same as the pathname.
page: page || pathname,
isAppPath
});
if (!components.getStaticPaths && !isAppPath) {
// we shouldn't get to this point since the worker should
// only be called for SSG pages with getStaticPaths
throw new Error(`Invariant: failed to load page with getStaticPaths for ${pathname}`);
}
if (isAppPath) {
const { routeModule } = components;
const generateParams = routeModule && (0, _checks.isAppRouteRouteModule)(routeModule) ? [
{
config: {
revalidate: routeModule.userland.revalidate,
dynamic: routeModule.userland.dynamic,
dynamicParams: routeModule.userland.dynamicParams
},
generateStaticParams: routeModule.userland.generateStaticParams,
segmentPath: pathname
}
] : await (0, _utils.collectGenerateParams)(components.ComponentMod.tree);
return await (0, _utils.buildAppStaticPaths)({
dir,
page: pathname,
generateParams,
configFileName: config.configFileName,
distDir,
requestHeaders,
cacheHandler,
isrFlushToDisk,
fetchCacheKeyPrefix,
maxMemoryCacheSize,
ppr,
ComponentMod: components.ComponentMod
});
}
return await (0, _utils.buildStaticPaths)({
page: pathname,
getStaticPaths: components.getStaticPaths,
configFileName: config.configFileName,
locales,
defaultLocale
});
}
//# sourceMappingURL=static-paths-worker.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/dev/static-paths-worker.ts"],"names":["loadStaticPaths","dir","distDir","pathname","config","httpAgentOptions","locales","defaultLocale","isAppPath","page","isrFlushToDisk","fetchCacheKeyPrefix","maxMemoryCacheSize","requestHeaders","cacheHandler","ppr","require","setConfig","setHttpClientAndAgentOptions","components","loadComponents","getStaticPaths","Error","routeModule","generateParams","isAppRouteRouteModule","revalidate","userland","dynamic","dynamicParams","generateStaticParams","segmentPath","collectGenerateParams","ComponentMod","tree","buildAppStaticPaths","configFileName","buildStaticPaths"],"mappings":";;;;+BAyBsBA;;;eAAAA;;;QAvBf;QACA;uBAMA;gCAEwB;mCACc;wBAEP;AAW/B,eAAeA,gBAAgB,EACpCC,GAAG,EACHC,OAAO,EACPC,QAAQ,EACRC,MAAM,EACNC,gBAAgB,EAChBC,OAAO,EACPC,aAAa,EACbC,SAAS,EACTC,IAAI,EACJC,cAAc,EACdC,mBAAmB,EACnBC,kBAAkB,EAClBC,cAAc,EACdC,YAAY,EACZC,GAAG,EAiBJ;IAKC,oCAAoC;IACpCC,QAAQ,4CAA4CC,SAAS,CAACb;IAC9Dc,IAAAA,+CAA4B,EAAC;QAC3Bb;IACF;IAEA,MAAMc,aAAa,MAAMC,IAAAA,8BAAc,EAAC;QACtClB;QACA,qDAAqD;QACrDO,MAAMA,QAAQN;QACdK;IACF;IAEA,IAAI,CAACW,WAAWE,cAAc,IAAI,CAACb,WAAW;QAC5C,yDAAyD;QACzD,mDAAmD;QACnD,MAAM,IAAIc,MACR,CAAC,uDAAuD,EAAEnB,SAAS,CAAC;IAExE;IAEA,IAAIK,WAAW;QACb,MAAM,EAAEe,WAAW,EAAE,GAAGJ;QACxB,MAAMK,iBACJD,eAAeE,IAAAA,6BAAqB,EAACF,eACjC;YACE;gBACEnB,QAAQ;oBACNsB,YAAYH,YAAYI,QAAQ,CAACD,UAAU;oBAC3CE,SAASL,YAAYI,QAAQ,CAACC,OAAO;oBACrCC,eAAeN,YAAYI,QAAQ,CAACE,aAAa;gBACnD;gBACAC,sBAAsBP,YAAYI,QAAQ,CAACG,oBAAoB;gBAC/DC,aAAa5B;YACf;SACD,GACD,MAAM6B,IAAAA,4BAAqB,EAACb,WAAWc,YAAY,CAACC,IAAI;QAE9D,OAAO,MAAMC,IAAAA,0BAAmB,EAAC;YAC/BlC;YACAQ,MAAMN;YACNqB;YACAY,gBAAgBhC,OAAOgC,cAAc;YACrClC;YACAW;YACAC;YACAJ;YACAC;YACAC;YACAG;YACAkB,cAAcd,WAAWc,YAAY;QACvC;IACF;IAEA,OAAO,MAAMI,IAAAA,uBAAgB,EAAC;QAC5B5B,MAAMN;QACNkB,gBAAgBF,WAAWE,cAAc;QACzCe,gBAAgBhC,OAAOgC,cAAc;QACrC9B;QACAC;IACF;AACF"}

120
node_modules/next/dist/server/dev/turbopack-utils.d.ts generated vendored Normal file
View File

@ -0,0 +1,120 @@
/// <reference types="ws" />
import type { NextConfigComplete } from '../config-shared';
import type { ServerFields, SetupOpts } from '../lib/router-utils/setup-dev-bundler';
import type { Endpoint, Entrypoints as RawEntrypoints, Issue, StyledString, TurbopackResult, Update as TurbopackUpdate, WrittenEndpoint } from '../../build/swc';
import { type HMR_ACTION_TYPES } from './hot-reloader-types';
import type { PropagateToWorkersField } from '../lib/router-utils/types';
import type { TurbopackManifestLoader } from './turbopack/manifest-loader';
import type { AppRoute, Entrypoints, PageRoute } from './turbopack/types';
import { type EntryKey } from './turbopack/entry-key';
import type ws from 'next/dist/compiled/ws';
export declare function getTurbopackJsConfig(dir: string, nextConfig: NextConfigComplete): Promise<{
compilerOptions: Record<string, any>;
}>;
/**
* 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 printNonFatalIssue(issue: Issue): void;
export declare function isRelevantWarning(issue: Issue): boolean;
export declare function formatIssue(issue: Issue): string;
type IssueKey = `${Issue['severity']}-${Issue['filePath']}-${string}-${string}`;
export type IssuesMap = Map<IssueKey, Issue>;
export type EntryIssuesMap = Map<EntryKey, IssuesMap>;
export type TopLevelIssuesMap = IssuesMap;
export declare function processTopLevelIssues(currentTopLevelIssues: TopLevelIssuesMap, result: TurbopackResult): void;
export declare function processIssues(currentEntryIssues: EntryIssuesMap, key: EntryKey, result: TurbopackResult, throwIssue: boolean, logErrors: boolean): void;
export declare function renderStyledStringToErrorAnsi(string: StyledString): string;
export declare function msToNs(ms: number): bigint;
export type ChangeSubscriptions = Map<EntryKey, Promise<AsyncIterableIterator<TurbopackResult>>>;
export type HandleWrittenEndpoint = (key: EntryKey, result: TurbopackResult<WrittenEndpoint>) => void;
export type StartChangeSubscription = (key: EntryKey, includeIssues: boolean, endpoint: Endpoint, makePayload: (change: TurbopackResult) => Promise<HMR_ACTION_TYPES> | HMR_ACTION_TYPES | void) => Promise<void>;
export type StopChangeSubscription = (key: EntryKey) => Promise<void>;
export type SendHmr = (id: string, payload: HMR_ACTION_TYPES) => void;
export type StartBuilding = (id: string, requestUrl: string | undefined, forceRebuild: boolean) => () => void;
export type ReadyIds = Set<string>;
export type ClientState = {
clientIssues: EntryIssuesMap;
hmrPayloads: Map<string, HMR_ACTION_TYPES>;
turbopackUpdates: TurbopackUpdate[];
subscriptions: Map<string, AsyncIterator<any>>;
};
export type ClientStateMap = WeakMap<ws, ClientState>;
type HandleRouteTypeHooks = {
handleWrittenEndpoint: HandleWrittenEndpoint;
subscribeToChanges: StartChangeSubscription;
};
export declare function handleRouteType({ dev, page, pathname, route, currentEntryIssues, entrypoints, manifestLoader, readyIds, rewrites, hooks, logErrors, }: {
dev: boolean;
page: string;
pathname: string;
route: PageRoute | AppRoute;
currentEntryIssues: EntryIssuesMap;
entrypoints: Entrypoints;
manifestLoader: TurbopackManifestLoader;
rewrites: SetupOpts['fsChecker']['rewrites'];
logErrors: boolean;
readyIds?: ReadyIds;
hooks?: HandleRouteTypeHooks;
}): Promise<void>;
/**
* Maintains a mapping between entrypoins and the corresponding client asset paths.
*/
export declare class AssetMapper {
private entryMap;
private assetMap;
/**
* Overrides asset paths for a key and updates the mapping from path to key.
*
* @param key
* @param assetPaths asset paths relative to the .next directory
*/
setPathsForKey(key: EntryKey, assetPaths: string[]): void;
/**
* Deletes the key and any asset only referenced by this key.
*
* @param key
*/
delete(key: EntryKey): void;
getAssetPathsByKey(key: EntryKey): string[];
getKeysByAsset(path: string): EntryKey[];
keys(): IterableIterator<EntryKey>;
}
export declare function hasEntrypointForKey(entrypoints: Entrypoints, key: EntryKey, assetMapper: AssetMapper | undefined): boolean;
type HandleEntrypointsHooks = {
handleWrittenEndpoint: HandleWrittenEndpoint;
propagateServerField: (field: PropagateToWorkersField, args: any) => Promise<void>;
sendHmr: SendHmr;
startBuilding: StartBuilding;
subscribeToChanges: StartChangeSubscription;
unsubscribeFromChanges: StopChangeSubscription;
unsubscribeFromHmrEvents: (client: ws, id: string) => void;
};
type HandleEntrypointsDevOpts = {
assetMapper: AssetMapper;
changeSubscriptions: ChangeSubscriptions;
clients: Set<ws>;
clientStates: ClientStateMap;
serverFields: ServerFields;
hooks: HandleEntrypointsHooks;
};
export declare function handleEntrypoints({ entrypoints, currentEntrypoints, currentEntryIssues, manifestLoader, nextConfig, rewrites, logErrors, dev, }: {
entrypoints: TurbopackResult<RawEntrypoints>;
currentEntrypoints: Entrypoints;
currentEntryIssues: EntryIssuesMap;
manifestLoader: TurbopackManifestLoader;
nextConfig: NextConfigComplete;
rewrites: SetupOpts['fsChecker']['rewrites'];
logErrors: boolean;
dev?: HandleEntrypointsDevOpts;
}): Promise<void>;
export declare function handlePagesErrorRoute({ currentEntryIssues, entrypoints, manifestLoader, rewrites, logErrors, hooks, }: {
currentEntryIssues: EntryIssuesMap;
entrypoints: Entrypoints;
manifestLoader: TurbopackManifestLoader;
rewrites: SetupOpts['fsChecker']['rewrites'];
logErrors: boolean;
hooks?: HandleRouteTypeHooks;
}): Promise<void>;
export {};

713
node_modules/next/dist/server/dev/turbopack-utils.js generated vendored Normal file
View File

@ -0,0 +1,713 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
AssetMapper: null,
formatIssue: null,
getTurbopackJsConfig: null,
handleEntrypoints: null,
handlePagesErrorRoute: null,
handleRouteType: null,
hasEntrypointForKey: null,
isRelevantWarning: null,
isWellKnownError: null,
msToNs: null,
printNonFatalIssue: null,
processIssues: null,
processTopLevelIssues: null,
renderStyledStringToErrorAnsi: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
AssetMapper: function() {
return AssetMapper;
},
formatIssue: function() {
return formatIssue;
},
getTurbopackJsConfig: function() {
return getTurbopackJsConfig;
},
handleEntrypoints: function() {
return handleEntrypoints;
},
handlePagesErrorRoute: function() {
return handlePagesErrorRoute;
},
handleRouteType: function() {
return handleRouteType;
},
hasEntrypointForKey: function() {
return hasEntrypointForKey;
},
isRelevantWarning: function() {
return isRelevantWarning;
},
isWellKnownError: function() {
return isWellKnownError;
},
msToNs: function() {
return msToNs;
},
printNonFatalIssue: function() {
return printNonFatalIssue;
},
processIssues: function() {
return processIssues;
},
processTopLevelIssues: function() {
return processTopLevelIssues;
},
renderStyledStringToErrorAnsi: function() {
return renderStyledStringToErrorAnsi;
}
});
const _loadjsconfig = /*#__PURE__*/ _interop_require_default(require("../../build/load-jsconfig"));
const _magicidentifier = require("../../shared/lib/magic-identifier");
const _picocolors = require("../../lib/picocolors");
const _hotreloadertypes = require("./hot-reloader-types");
const _log = /*#__PURE__*/ _interop_require_wildcard(require("../../build/output/log"));
const _entrykey = require("./turbopack/entry-key");
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {
__proto__: null
};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
async function getTurbopackJsConfig(dir, nextConfig) {
const { jsConfig } = await (0, _loadjsconfig.default)(dir, nextConfig);
return jsConfig ?? {
compilerOptions: {}
};
}
class ModuleBuildError extends Error {
}
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 printNonFatalIssue(issue) {
if (isRelevantWarning(issue)) {
_log.warn(formatIssue(issue));
}
}
function isNodeModulesIssue(issue) {
return issue.severity === "warning" && issue.filePath.match(/^(?:.*[\\/])?node_modules(?:[\\/].*)?$/) !== null;
}
function isRelevantWarning(issue) {
return issue.severity === "warning" && !isNodeModulesIssue(issue);
}
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) {
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;
}
function getIssueKey(issue) {
return `${issue.severity}-${issue.filePath}-${JSON.stringify(issue.title)}-${JSON.stringify(issue.description)}`;
}
function processTopLevelIssues(currentTopLevelIssues, result) {
currentTopLevelIssues.clear();
for (const issue of result.issues){
const issueKey = getIssueKey(issue);
currentTopLevelIssues.set(issueKey, issue);
}
}
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);
const formatted = formatIssue(issue);
newIssues.set(issueKey, issue);
if (issue.severity !== "warning") {
relevantIssues.add(formatted);
if (logErrors && isWellKnownError(issue)) {
_log.error(formatted);
}
}
}
if (relevantIssues.size && throwIssue) {
throw new ModuleBuildError([
...relevantIssues
].join("\n\n"));
}
}
function renderStyledStringToErrorAnsi(string) {
function decodeMagicIdentifiers(str) {
return str.replaceAll(_magicidentifier.MAGIC_IDENTIFIER_REGEX, (ident)=>{
try {
return (0, _picocolors.magenta)(`{${(0, _magicidentifier.decodeMagicIdentifier)(ident)}}`);
} catch (e) {
return (0, _picocolors.magenta)(`{${ident} (decoding failed: ${e})}`);
}
});
}
switch(string.type){
case "text":
return decodeMagicIdentifiers(string.value);
case "strong":
return (0, _picocolors.bold)((0, _picocolors.red)(decodeMagicIdentifiers(string.value)));
case "code":
return (0, _picocolors.green)(decodeMagicIdentifiers(string.value));
case "line":
return string.value.map(renderStyledStringToErrorAnsi).join("");
case "stack":
return string.value.map(renderStyledStringToErrorAnsi).join("\n");
default:
throw new Error("Unknown StyledString type", string);
}
}
const MILLISECONDS_IN_NANOSECOND = BigInt(1000000);
function msToNs(ms) {
return BigInt(Math.floor(ms)) * MILLISECONDS_IN_NANOSECOND;
}
async function handleRouteType({ dev, page, pathname, route, currentEntryIssues, entrypoints, manifestLoader, readyIds, rewrites, hooks, logErrors }) {
switch(route.type){
case "page":
{
const clientKey = (0, _entrykey.getEntryKey)("pages", "client", page);
const serverKey = (0, _entrykey.getEntryKey)("pages", "server", page);
try {
if (entrypoints.global.app) {
const key = (0, _entrykey.getEntryKey)("pages", "server", "_app");
const writtenEndpoint = await entrypoints.global.app.writeToDisk();
hooks == null ? void 0 : hooks.handleWrittenEndpoint(key, writtenEndpoint);
processIssues(currentEntryIssues, key, writtenEndpoint, false, logErrors);
}
await manifestLoader.loadBuildManifest("_app");
await manifestLoader.loadPagesManifest("_app");
if (entrypoints.global.document) {
const key = (0, _entrykey.getEntryKey)("pages", "server", "_document");
const writtenEndpoint = await entrypoints.global.document.writeToDisk();
hooks == null ? void 0 : hooks.handleWrittenEndpoint(key, writtenEndpoint);
processIssues(currentEntryIssues, key, writtenEndpoint, false, logErrors);
}
await manifestLoader.loadPagesManifest("_document");
const writtenEndpoint = await route.htmlEndpoint.writeToDisk();
hooks == null ? void 0 : hooks.handleWrittenEndpoint(serverKey, writtenEndpoint);
const type = writtenEndpoint == null ? void 0 : writtenEndpoint.type;
await manifestLoader.loadBuildManifest(page);
await manifestLoader.loadPagesManifest(page);
if (type === "edge") {
await manifestLoader.loadMiddlewareManifest(page, "pages");
} else {
manifestLoader.deleteMiddlewareManifest(serverKey);
}
await manifestLoader.loadFontManifest("/_app", "pages");
await manifestLoader.loadFontManifest(page, "pages");
await manifestLoader.loadLoadableManifest(page, "pages");
await manifestLoader.writeManifests({
rewrites,
pageEntrypoints: entrypoints.page
});
processIssues(currentEntryIssues, serverKey, writtenEndpoint, false, logErrors);
} finally{
// TODO subscriptions should only be caused by the WebSocket connections
// otherwise we don't known when to unsubscribe and this leaking
hooks == null ? void 0 : hooks.subscribeToChanges(serverKey, false, route.dataEndpoint, ()=>{
// Report the next compilation again
readyIds == null ? void 0 : readyIds.delete(pathname);
return {
event: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.SERVER_ONLY_CHANGES,
pages: [
page
]
};
});
hooks == null ? void 0 : hooks.subscribeToChanges(clientKey, false, route.htmlEndpoint, ()=>{
return {
event: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.CLIENT_CHANGES
};
});
if (entrypoints.global.document) {
hooks == null ? void 0 : hooks.subscribeToChanges((0, _entrykey.getEntryKey)("pages", "server", "_document"), false, entrypoints.global.document, ()=>{
return {
action: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.RELOAD_PAGE
};
});
}
}
break;
}
case "page-api":
{
const key = (0, _entrykey.getEntryKey)("pages", "server", page);
const writtenEndpoint = await route.endpoint.writeToDisk();
hooks == null ? void 0 : hooks.handleWrittenEndpoint(key, writtenEndpoint);
const type = writtenEndpoint == null ? void 0 : writtenEndpoint.type;
await manifestLoader.loadPagesManifest(page);
if (type === "edge") {
await manifestLoader.loadMiddlewareManifest(page, "pages");
} else {
manifestLoader.deleteMiddlewareManifest(key);
}
await manifestLoader.loadLoadableManifest(page, "pages");
await manifestLoader.writeManifests({
rewrites,
pageEntrypoints: entrypoints.page
});
processIssues(currentEntryIssues, key, writtenEndpoint, true, logErrors);
break;
}
case "app-page":
{
const key = (0, _entrykey.getEntryKey)("app", "server", page);
const writtenEndpoint = await route.htmlEndpoint.writeToDisk();
hooks == null ? void 0 : hooks.handleWrittenEndpoint(key, writtenEndpoint);
// TODO subscriptions should only be caused by the WebSocket connections
// otherwise we don't known when to unsubscribe and this leaking
hooks == null ? void 0 : hooks.subscribeToChanges(key, true, route.rscEndpoint, (change)=>{
if (change.issues.some((issue)=>issue.severity === "error")) {
// Ignore any updates that has errors
// There will be another update without errors eventually
return;
}
// Report the next compilation again
readyIds == null ? void 0 : readyIds.delete(pathname);
return {
action: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.SERVER_COMPONENT_CHANGES
};
});
const type = writtenEndpoint == null ? void 0 : writtenEndpoint.type;
if (type === "edge") {
await manifestLoader.loadMiddlewareManifest(page, "app");
} else {
manifestLoader.deleteMiddlewareManifest(key);
}
await manifestLoader.loadAppBuildManifest(page);
await manifestLoader.loadBuildManifest(page, "app");
await manifestLoader.loadAppPathsManifest(page);
await manifestLoader.loadActionManifest(page);
await manifestLoader.loadLoadableManifest(page, "app");
await manifestLoader.loadFontManifest(page, "app");
await manifestLoader.writeManifests({
rewrites,
pageEntrypoints: entrypoints.page
});
processIssues(currentEntryIssues, key, writtenEndpoint, dev, logErrors);
break;
}
case "app-route":
{
const key = (0, _entrykey.getEntryKey)("app", "server", page);
const writtenEndpoint = await route.endpoint.writeToDisk();
hooks == null ? void 0 : hooks.handleWrittenEndpoint(key, writtenEndpoint);
const type = writtenEndpoint == null ? void 0 : writtenEndpoint.type;
await manifestLoader.loadAppPathsManifest(page);
if (type === "edge") {
await manifestLoader.loadMiddlewareManifest(page, "app");
} else {
manifestLoader.deleteMiddlewareManifest(key);
}
await manifestLoader.writeManifests({
rewrites,
pageEntrypoints: entrypoints.page
});
processIssues(currentEntryIssues, key, writtenEndpoint, true, logErrors);
break;
}
default:
{
throw new Error(`unknown route type ${route.type} for ${page}`);
}
}
}
class AssetMapper {
/**
* Overrides asset paths for a key and updates the mapping from path to key.
*
* @param key
* @param assetPaths asset paths relative to the .next directory
*/ setPathsForKey(key, assetPaths) {
this.delete(key);
const newAssetPaths = new Set(assetPaths);
this.entryMap.set(key, newAssetPaths);
for (const assetPath of newAssetPaths){
let assetPathKeys = this.assetMap.get(assetPath);
if (!assetPathKeys) {
assetPathKeys = new Set();
this.assetMap.set(assetPath, assetPathKeys);
}
assetPathKeys.add(key);
}
}
/**
* Deletes the key and any asset only referenced by this key.
*
* @param key
*/ delete(key) {
for (const assetPath of this.getAssetPathsByKey(key)){
const assetPathKeys = this.assetMap.get(assetPath);
assetPathKeys == null ? void 0 : assetPathKeys.delete(key);
if (!(assetPathKeys == null ? void 0 : assetPathKeys.size)) {
this.assetMap.delete(assetPath);
}
}
this.entryMap.delete(key);
}
getAssetPathsByKey(key) {
return Array.from(this.entryMap.get(key) ?? []);
}
getKeysByAsset(path) {
return Array.from(this.assetMap.get(path) ?? []);
}
keys() {
return this.entryMap.keys();
}
constructor(){
this.entryMap = new Map();
this.assetMap = new Map();
}
}
function hasEntrypointForKey(entrypoints, key, assetMapper) {
const { type, page } = (0, _entrykey.splitEntryKey)(key);
switch(type){
case "app":
return entrypoints.app.has(page);
case "pages":
switch(page){
case "_app":
return entrypoints.global.app != null;
case "_document":
return entrypoints.global.document != null;
case "_error":
return entrypoints.global.error != null;
default:
return entrypoints.page.has(page);
}
case "root":
switch(page){
case "middleware":
return entrypoints.global.middleware != null;
case "instrumentation":
return entrypoints.global.instrumentation != null;
default:
return false;
}
case "assets":
if (!assetMapper) {
return false;
}
return assetMapper.getKeysByAsset(page).some((pageKey)=>hasEntrypointForKey(entrypoints, pageKey, assetMapper));
default:
{
// validation that we covered all cases, this should never run.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _ = type;
return false;
}
}
}
async function handleEntrypoints({ entrypoints, currentEntrypoints, currentEntryIssues, manifestLoader, nextConfig, rewrites, logErrors, dev }) {
currentEntrypoints.global.app = entrypoints.pagesAppEndpoint;
currentEntrypoints.global.document = entrypoints.pagesDocumentEndpoint;
currentEntrypoints.global.error = entrypoints.pagesErrorEndpoint;
currentEntrypoints.global.instrumentation = entrypoints.instrumentation;
currentEntrypoints.page.clear();
currentEntrypoints.app.clear();
for (const [pathname, route] of entrypoints.routes){
switch(route.type){
case "page":
case "page-api":
currentEntrypoints.page.set(pathname, route);
break;
case "app-page":
{
route.pages.forEach((page)=>{
currentEntrypoints.app.set(page.originalName, {
type: "app-page",
...page
});
});
break;
}
case "app-route":
{
currentEntrypoints.app.set(route.originalName, route);
break;
}
default:
_log.info(`skipping ${pathname} (${route.type})`);
break;
}
}
if (dev) {
await handleEntrypointsDevCleanup({
currentEntryIssues,
currentEntrypoints,
...dev
});
}
const { middleware, instrumentation } = entrypoints;
// We check for explicit true/false, since it's initialized to
// undefined during the first loop (middlewareChanges event is
// unnecessary during the first serve)
if (currentEntrypoints.global.middleware && !middleware) {
const key = (0, _entrykey.getEntryKey)("root", "server", "middleware");
// Went from middleware to no middleware
await (dev == null ? void 0 : dev.hooks.unsubscribeFromChanges(key));
currentEntryIssues.delete(key);
dev == null ? void 0 : dev.hooks.sendHmr("middleware", {
event: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.MIDDLEWARE_CHANGES
});
} else if (!currentEntrypoints.global.middleware && middleware) {
// Went from no middleware to middleware
dev == null ? void 0 : dev.hooks.sendHmr("middleware", {
event: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.MIDDLEWARE_CHANGES
});
}
currentEntrypoints.global.middleware = middleware;
if (nextConfig.experimental.instrumentationHook && instrumentation) {
const processInstrumentation = async (name, prop)=>{
const key = (0, _entrykey.getEntryKey)("root", "server", name);
const writtenEndpoint = await instrumentation[prop].writeToDisk();
dev == null ? void 0 : dev.hooks.handleWrittenEndpoint(key, writtenEndpoint);
processIssues(currentEntryIssues, key, writtenEndpoint, false, logErrors);
};
await processInstrumentation("instrumentation.nodeJs", "nodeJs");
await processInstrumentation("instrumentation.edge", "edge");
await manifestLoader.loadMiddlewareManifest("instrumentation", "instrumentation");
await manifestLoader.writeManifests({
rewrites: rewrites,
pageEntrypoints: currentEntrypoints.page
});
if (dev) {
dev.serverFields.actualInstrumentationHookFile = "/instrumentation";
await dev.hooks.propagateServerField("actualInstrumentationHookFile", dev.serverFields.actualInstrumentationHookFile);
}
} else {
if (dev) {
dev.serverFields.actualInstrumentationHookFile = undefined;
await dev.hooks.propagateServerField("actualInstrumentationHookFile", dev.serverFields.actualInstrumentationHookFile);
}
}
if (middleware) {
const key = (0, _entrykey.getEntryKey)("root", "server", "middleware");
const endpoint = middleware.endpoint;
async function processMiddleware() {
const writtenEndpoint = await endpoint.writeToDisk();
dev == null ? void 0 : dev.hooks.handleWrittenEndpoint(key, writtenEndpoint);
processIssues(currentEntryIssues, key, writtenEndpoint, false, logErrors);
await manifestLoader.loadMiddlewareManifest("middleware", "middleware");
if (dev) {
var _manifestLoader_getMiddlewareManifest;
dev.serverFields.middleware = {
match: null,
page: "/",
matchers: (_manifestLoader_getMiddlewareManifest = manifestLoader.getMiddlewareManifest(key)) == null ? void 0 : _manifestLoader_getMiddlewareManifest.middleware["/"].matchers
};
}
}
await processMiddleware();
dev == null ? void 0 : dev.hooks.subscribeToChanges(key, false, endpoint, async ()=>{
const finishBuilding = dev.hooks.startBuilding("middleware", undefined, true);
await processMiddleware();
await dev.hooks.propagateServerField("actualMiddlewareFile", dev.serverFields.actualMiddlewareFile);
await dev.hooks.propagateServerField("middleware", dev.serverFields.middleware);
await manifestLoader.writeManifests({
rewrites: rewrites,
pageEntrypoints: currentEntrypoints.page
});
finishBuilding == null ? void 0 : finishBuilding();
return {
event: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.MIDDLEWARE_CHANGES
};
});
} else {
manifestLoader.deleteMiddlewareManifest((0, _entrykey.getEntryKey)("root", "server", "middleware"));
if (dev) {
dev.serverFields.actualMiddlewareFile = undefined;
dev.serverFields.middleware = undefined;
}
}
if (dev) {
await dev.hooks.propagateServerField("actualMiddlewareFile", dev.serverFields.actualMiddlewareFile);
await dev.hooks.propagateServerField("middleware", dev.serverFields.middleware);
}
}
async function handleEntrypointsDevCleanup({ currentEntryIssues, currentEntrypoints, assetMapper, changeSubscriptions, clients, clientStates, hooks }) {
// this needs to be first as `hasEntrypointForKey` uses the `assetMapper`
for (const key of assetMapper.keys()){
if (!hasEntrypointForKey(currentEntrypoints, key, assetMapper)) {
assetMapper.delete(key);
}
}
for (const key of changeSubscriptions.keys()){
// middleware is handled separately
if (!hasEntrypointForKey(currentEntrypoints, key, assetMapper)) {
await hooks.unsubscribeFromChanges(key);
}
}
for (const [key] of currentEntryIssues){
if (!hasEntrypointForKey(currentEntrypoints, key, assetMapper)) {
currentEntryIssues.delete(key);
}
}
for (const client of clients){
const state = clientStates.get(client);
if (!state) {
continue;
}
for (const key of state.clientIssues.keys()){
if (!hasEntrypointForKey(currentEntrypoints, key, assetMapper)) {
state.clientIssues.delete(key);
}
}
for (const id of state.subscriptions.keys()){
if (!hasEntrypointForKey(currentEntrypoints, (0, _entrykey.getEntryKey)("assets", "client", id), assetMapper)) {
hooks.unsubscribeFromHmrEvents(client, id);
}
}
}
}
async function handlePagesErrorRoute({ currentEntryIssues, entrypoints, manifestLoader, rewrites, logErrors, hooks }) {
if (entrypoints.global.app) {
const key = (0, _entrykey.getEntryKey)("pages", "server", "_app");
const writtenEndpoint = await entrypoints.global.app.writeToDisk();
hooks == null ? void 0 : hooks.handleWrittenEndpoint(key, writtenEndpoint);
hooks == null ? void 0 : hooks.subscribeToChanges(key, false, entrypoints.global.app, ()=>{
// There's a special case for this in `../client/page-bootstrap.ts`.
// https://github.com/vercel/next.js/blob/08d7a7e5189a835f5dcb82af026174e587575c0e/packages/next/src/client/page-bootstrap.ts#L69-L71
return {
event: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.CLIENT_CHANGES
};
});
processIssues(currentEntryIssues, key, writtenEndpoint, false, logErrors);
}
await manifestLoader.loadBuildManifest("_app");
await manifestLoader.loadPagesManifest("_app");
await manifestLoader.loadFontManifest("_app");
if (entrypoints.global.document) {
const key = (0, _entrykey.getEntryKey)("pages", "server", "_document");
const writtenEndpoint = await entrypoints.global.document.writeToDisk();
hooks == null ? void 0 : hooks.handleWrittenEndpoint(key, writtenEndpoint);
hooks == null ? void 0 : hooks.subscribeToChanges(key, false, entrypoints.global.document, ()=>{
return {
action: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.RELOAD_PAGE
};
});
processIssues(currentEntryIssues, key, writtenEndpoint, false, logErrors);
}
await manifestLoader.loadPagesManifest("_document");
if (entrypoints.global.error) {
const key = (0, _entrykey.getEntryKey)("pages", "server", "_error");
const writtenEndpoint = await entrypoints.global.error.writeToDisk();
hooks == null ? void 0 : hooks.handleWrittenEndpoint(key, writtenEndpoint);
hooks == null ? void 0 : hooks.subscribeToChanges(key, false, entrypoints.global.error, ()=>{
// There's a special case for this in `../client/page-bootstrap.ts`.
// https://github.com/vercel/next.js/blob/08d7a7e5189a835f5dcb82af026174e587575c0e/packages/next/src/client/page-bootstrap.ts#L69-L71
return {
event: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.CLIENT_CHANGES
};
});
processIssues(currentEntryIssues, key, writtenEndpoint, false, logErrors);
}
await manifestLoader.loadBuildManifest("_error");
await manifestLoader.loadPagesManifest("_error");
await manifestLoader.loadFontManifest("_error");
await manifestLoader.writeManifests({
rewrites,
pageEntrypoints: entrypoints.page
});
}
//# sourceMappingURL=turbopack-utils.js.map

File diff suppressed because one or more lines are too long

View File

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

View File

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

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/dev/turbopack/entry-key.ts"],"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"}

View File

@ -0,0 +1,65 @@
import type { MiddlewareManifest } from '../../../build/webpack/plugins/middleware-plugin';
import type { SetupOpts } from '../../lib/router-utils/setup-dev-bundler';
import type { PageEntrypoints } from './types';
import { type EntryKey } from './entry-key';
interface InstrumentationDefinition {
files: string[];
name: 'instrumentation';
}
type TurbopackMiddlewareManifest = MiddlewareManifest & {
instrumentation?: InstrumentationDefinition;
};
export declare class TurbopackManifestLoader {
private actionManifests;
private appBuildManifests;
private appPathsManifests;
private buildManifests;
private fontManifests;
private loadableManifests;
private middlewareManifests;
private pagesManifests;
private encryptionKey;
private readonly distDir;
private readonly buildId;
constructor({ distDir, buildId, encryptionKey, }: {
buildId: string;
distDir: string;
encryptionKey: string;
});
delete(key: EntryKey): void;
loadActionManifest(pageName: string): Promise<void>;
private mergeActionManifests;
private writeActionManifest;
loadAppBuildManifest(pageName: string): Promise<void>;
private mergeAppBuildManifests;
private writeAppBuildManifest;
loadAppPathsManifest(pageName: string): Promise<void>;
private writeAppPathsManifest;
/**
* Turbopack doesn't support this functionality, so it writes an empty manifest.
*/
private writeAutomaticFontOptimizationManifest;
loadBuildManifest(pageName: string, type?: 'app' | 'pages'): Promise<void>;
private mergeBuildManifests;
private writeBuildManifest;
private writeFallbackBuildManifest;
loadFontManifest(pageName: string, type?: 'app' | 'pages'): Promise<void>;
private mergeFontManifests;
private writeNextFontManifest;
loadLoadableManifest(pageName: string, type?: 'app' | 'pages'): Promise<void>;
private mergeLoadableManifests;
private writeLoadableManifest;
loadMiddlewareManifest(pageName: string, type: 'pages' | 'app' | 'middleware' | 'instrumentation'): Promise<void>;
getMiddlewareManifest(key: EntryKey): TurbopackMiddlewareManifest | undefined;
deleteMiddlewareManifest(key: EntryKey): boolean;
private mergeMiddlewareManifests;
private writeMiddlewareManifest;
loadPagesManifest(pageName: string): Promise<void>;
private mergePagesManifests;
private writePagesManifest;
writeManifests({ rewrites, pageEntrypoints, }: {
rewrites: SetupOpts['fsChecker']['rewrites'];
pageEntrypoints: PageEntrypoints;
}): Promise<void>;
}
export {};

View File

@ -0,0 +1,327 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "TurbopackManifestLoader", {
enumerable: true,
get: function() {
return TurbopackManifestLoader;
}
});
const _pathtoregexp = require("next/dist/compiled/path-to-regexp");
const _constants = require("../../../shared/lib/constants");
const _path = require("path");
const _promises = require("fs/promises");
const _nextjsrequirecachehotreloader = require("../../../build/webpack/plugins/nextjs-require-cache-hot-reloader");
const _writeatomic = require("../../../lib/fs/write-atomic");
const _generateinterceptionroutesrewrites = require("../../../lib/generate-interception-routes-rewrites");
const _buildmanifestplugin = require("../../../build/webpack/plugins/build-manifest-plugin");
const _getassetpathfromroute = /*#__PURE__*/ _interop_require_default(require("../../../shared/lib/router/utils/get-asset-path-from-route"));
const _entrykey = require("./entry-key");
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
async function readPartialManifest(distDir, name, pageName, type = "pages") {
const manifestPath = _path.posix.join(distDir, `server`, type, type === "middleware" || type === "instrumentation" ? "" : type === "app" ? pageName : (0, _getassetpathfromroute.default)(pageName), name);
return JSON.parse(await (0, _promises.readFile)(_path.posix.join(manifestPath), "utf-8"));
}
class TurbopackManifestLoader {
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.loadableManifests = new Map();
this.middlewareManifests = new Map();
this.pagesManifests = new Map();
this.distDir = distDir;
this.buildId = buildId;
this.encryptionKey = encryptionKey;
}
delete(key) {
this.actionManifests.delete(key);
this.appBuildManifests.delete(key);
this.appPathsManifests.delete(key);
this.buildManifests.delete(key);
this.fontManifests.delete(key);
this.loadableManifests.delete(key);
this.middlewareManifests.delete(key);
this.pagesManifests.delete(key);
}
async loadActionManifest(pageName) {
this.actionManifests.set((0, _entrykey.getEntryKey)("app", "server", pageName), await readPartialManifest(this.distDir, `${_constants.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){
const action = 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);
}
return manifest;
}
async writeActionManifest() {
const actionManifest = await 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, _nextjsrequirecachehotreloader.deleteCache)(actionManifestJsonPath);
(0, _nextjsrequirecachehotreloader.deleteCache)(actionManifestJsPath);
await (0, _promises.writeFile)(actionManifestJsonPath, json, "utf-8");
await (0, _promises.writeFile)(actionManifestJsPath, `self.__RSC_SERVER_MANIFEST=${JSON.stringify(json)}`, "utf-8");
}
async loadAppBuildManifest(pageName) {
this.appBuildManifests.set((0, _entrykey.getEntryKey)("app", "server", pageName), await readPartialManifest(this.distDir, _constants.APP_BUILD_MANIFEST, pageName, "app"));
}
mergeAppBuildManifests(manifests) {
const manifest = {
pages: {}
};
for (const m of manifests){
Object.assign(manifest.pages, m.pages);
}
return manifest;
}
async writeAppBuildManifest() {
const appBuildManifest = this.mergeAppBuildManifests(this.appBuildManifests.values());
const appBuildManifestPath = (0, _path.join)(this.distDir, _constants.APP_BUILD_MANIFEST);
(0, _nextjsrequirecachehotreloader.deleteCache)(appBuildManifestPath);
await (0, _writeatomic.writeFileAtomic)(appBuildManifestPath, JSON.stringify(appBuildManifest, null, 2));
}
async loadAppPathsManifest(pageName) {
this.appPathsManifests.set((0, _entrykey.getEntryKey)("app", "server", pageName), await readPartialManifest(this.distDir, _constants.APP_PATHS_MANIFEST, pageName, "app"));
}
async writeAppPathsManifest() {
const appPathsManifest = this.mergePagesManifests(this.appPathsManifests.values());
const appPathsManifestPath = (0, _path.join)(this.distDir, "server", _constants.APP_PATHS_MANIFEST);
(0, _nextjsrequirecachehotreloader.deleteCache)(appPathsManifestPath);
await (0, _writeatomic.writeFileAtomic)(appPathsManifestPath, JSON.stringify(appPathsManifest, null, 2));
}
/**
* Turbopack doesn't support this functionality, so it writes an empty manifest.
*/ async writeAutomaticFontOptimizationManifest() {
const manifestPath = (0, _path.join)(this.distDir, "server", _constants.AUTOMATIC_FONT_OPTIMIZATION_MANIFEST);
await (0, _writeatomic.writeFileAtomic)(manifestPath, JSON.stringify([]));
}
async loadBuildManifest(pageName, type = "pages") {
this.buildManifests.set((0, _entrykey.getEntryKey)(type, "server", pageName), await readPartialManifest(this.distDir, _constants.BUILD_MANIFEST, pageName, type));
}
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/development/_ssgManifest.js",
"static/development/_buildManifest.js"
],
rootMainFiles: [],
ampFirstPages: []
};
for (const m of manifests){
Object.assign(manifest.pages, m.pages);
if (m.rootMainFiles.length) manifest.rootMainFiles = m.rootMainFiles;
}
return manifest;
}
async writeBuildManifest(pageEntrypoints, rewrites) {
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`);
const interceptionRewriteManifestPath = (0, _path.join)(this.distDir, "server", `${_constants.INTERCEPTION_ROUTE_REWRITE_MANIFEST}.js`);
(0, _nextjsrequirecachehotreloader.deleteCache)(buildManifestPath);
(0, _nextjsrequirecachehotreloader.deleteCache)(middlewareBuildManifestPath);
(0, _nextjsrequirecachehotreloader.deleteCache)(interceptionRewriteManifestPath);
await (0, _writeatomic.writeFileAtomic)(buildManifestPath, JSON.stringify(buildManifest, null, 2));
await (0, _writeatomic.writeFileAtomic)(middlewareBuildManifestPath, `self.__BUILD_MANIFEST=${JSON.stringify(buildManifest)};`);
const interceptionRewrites = JSON.stringify(rewrites.beforeFiles.filter(_generateinterceptionroutesrewrites.isInterceptionRouteRewrite));
await (0, _writeatomic.writeFileAtomic)(interceptionRewriteManifestPath, `self.__INTERCEPTION_ROUTE_REWRITE_MANIFEST=${JSON.stringify(interceptionRewrites)};`);
const content = {
__rewrites: rewrites ? (0, _buildmanifestplugin.normalizeRewritesForBuildManifest)(rewrites) : {
afterFiles: [],
beforeFiles: [],
fallback: []
},
...Object.fromEntries([
...pageEntrypoints.keys()
].map((pathname)=>[
pathname,
`static/chunks/pages${pathname === "/" ? "/index" : pathname}.js`
])),
sortedPages: [
...pageEntrypoints.keys()
]
};
const buildManifestJs = `self.__BUILD_MANIFEST = ${JSON.stringify(content)};self.__BUILD_MANIFEST_CB && self.__BUILD_MANIFEST_CB()`;
await (0, _writeatomic.writeFileAtomic)((0, _path.join)(this.distDir, "static", this.buildId, "_buildManifest.js"), buildManifestJs);
await (0, _writeatomic.writeFileAtomic)((0, _path.join)(this.distDir, "static", this.buildId, "_ssgManifest.js"), _buildmanifestplugin.srcEmptySsgManifest);
}
async writeFallbackBuildManifest() {
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, _nextjsrequirecachehotreloader.deleteCache)(fallbackBuildManifestPath);
await (0, _writeatomic.writeFileAtomic)(fallbackBuildManifestPath, JSON.stringify(fallbackBuildManifest, null, 2));
}
async loadFontManifest(pageName, type = "pages") {
this.fontManifests.set((0, _entrykey.getEntryKey)(type, "server", pageName), await readPartialManifest(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;
}
return manifest;
}
async writeNextFontManifest() {
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, _nextjsrequirecachehotreloader.deleteCache)(fontManifestJsonPath);
(0, _nextjsrequirecachehotreloader.deleteCache)(fontManifestJsPath);
await (0, _writeatomic.writeFileAtomic)(fontManifestJsonPath, json);
await (0, _writeatomic.writeFileAtomic)(fontManifestJsPath, `self.__NEXT_FONT_MANIFEST=${JSON.stringify(json)}`);
}
async loadLoadableManifest(pageName, type = "pages") {
this.loadableManifests.set((0, _entrykey.getEntryKey)(type, "server", pageName), await readPartialManifest(this.distDir, _constants.REACT_LOADABLE_MANIFEST, pageName, type));
}
mergeLoadableManifests(manifests) {
const manifest = {};
for (const m of manifests){
Object.assign(manifest, m);
}
return manifest;
}
async writeLoadableManifest() {
const loadableManifest = this.mergeLoadableManifests(this.loadableManifests.values());
const loadableManifestPath = (0, _path.join)(this.distDir, _constants.REACT_LOADABLE_MANIFEST);
const middlewareloadableManifestPath = (0, _path.join)(this.distDir, "server", `${_constants.MIDDLEWARE_REACT_LOADABLE_MANIFEST}.js`);
const json = JSON.stringify(loadableManifest, null, 2);
(0, _nextjsrequirecachehotreloader.deleteCache)(loadableManifestPath);
(0, _nextjsrequirecachehotreloader.deleteCache)(middlewareloadableManifestPath);
await (0, _writeatomic.writeFileAtomic)(loadableManifestPath, json);
await (0, _writeatomic.writeFileAtomic)(middlewareloadableManifestPath, `self.__REACT_LOADABLE_MANIFEST=${JSON.stringify(json)}`);
}
async loadMiddlewareManifest(pageName, type) {
this.middlewareManifests.set((0, _entrykey.getEntryKey)(type === "middleware" || type === "instrumentation" ? "root" : type, "server", pageName), await readPartialManifest(this.distDir, _constants.MIDDLEWARE_MANIFEST, pageName, type));
}
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;
}
}
const updateFunctionDefinition = (fun)=>{
return {
...fun,
files: [
...(instrumentation == null ? void 0 : 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, _pathtoregexp.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());
const middlewareManifestPath = (0, _path.join)(this.distDir, "server", _constants.MIDDLEWARE_MANIFEST);
(0, _nextjsrequirecachehotreloader.deleteCache)(middlewareManifestPath);
await (0, _writeatomic.writeFileAtomic)(middlewareManifestPath, JSON.stringify(middlewareManifest, null, 2));
}
async loadPagesManifest(pageName) {
this.pagesManifests.set((0, _entrykey.getEntryKey)("pages", "server", pageName), await readPartialManifest(this.distDir, _constants.PAGES_MANIFEST, pageName));
}
mergePagesManifests(manifests) {
const manifest = {};
for (const m of manifests){
Object.assign(manifest, m);
}
return manifest;
}
async writePagesManifest() {
const pagesManifest = this.mergePagesManifests(this.pagesManifests.values());
const pagesManifestPath = (0, _path.join)(this.distDir, "server", _constants.PAGES_MANIFEST);
(0, _nextjsrequirecachehotreloader.deleteCache)(pagesManifestPath);
await (0, _writeatomic.writeFileAtomic)(pagesManifestPath, JSON.stringify(pagesManifest, null, 2));
}
async writeManifests({ rewrites, pageEntrypoints }) {
await this.writeActionManifest();
await this.writeAppBuildManifest();
await this.writeAppPathsManifest();
await this.writeAutomaticFontOptimizationManifest();
await this.writeBuildManifest(pageEntrypoints, rewrites);
await this.writeFallbackBuildManifest();
await this.writeLoadableManifest();
await this.writeMiddlewareManifest();
await this.writeNextFontManifest();
await this.writePagesManifest();
}
}
//# sourceMappingURL=manifest-loader.js.map

File diff suppressed because one or more lines are too long

31
node_modules/next/dist/server/dev/turbopack/types.d.ts generated vendored Normal file
View File

@ -0,0 +1,31 @@
import type { Endpoint, Instrumentation, Middleware } from '../../../build/swc';
export interface GlobalEntrypoints {
app: Endpoint | undefined;
document: Endpoint | undefined;
error: Endpoint | undefined;
middleware: Middleware | undefined;
instrumentation: Instrumentation | undefined;
}
export type PageRoute = {
type: 'page';
htmlEndpoint: Endpoint;
dataEndpoint: Endpoint;
} | {
type: 'page-api';
endpoint: Endpoint;
};
export type AppRoute = {
type: 'app-page';
htmlEndpoint: Endpoint;
rscEndpoint: Endpoint;
} | {
type: 'app-route';
endpoint: Endpoint;
};
export type PageEntrypoints = Map<string, PageRoute>;
export type AppEntrypoints = Map<string, AppRoute>;
export type Entrypoints = {
global: GlobalEntrypoints;
page: PageEntrypoints;
app: AppEntrypoints;
};

6
node_modules/next/dist/server/dev/turbopack/types.js generated vendored Normal file
View File

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

View File

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