feat(blog): add file-based blog with dynamic slugs, MDX content and layout shell

- Introduced blog routing using Next.js App Router
- Implemented dynamic [slug] pages for blog posts
- Added MDX-based content loading via lib/posts
- Integrated shared TopBar layout with navigation
- Established clear content, lib and component separation
This commit is contained in:
PascalSchattenburg
2026-01-22 14:14:15 +01:00
parent b717952234
commit d147843c76
10412 changed files with 2475583 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
import type { ServerResponse, IncomingMessage } from 'http';
export declare function getAttachNodejsDebuggerMiddleware(): (req: IncomingMessage, res: ServerResponse, next: () => void) => Promise<void>;

View File

@@ -0,0 +1,55 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "getAttachNodejsDebuggerMiddleware", {
enumerable: true,
get: function() {
return getAttachNodejsDebuggerMiddleware;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _middlewareresponse = require("./middleware-response");
const _inspector = /*#__PURE__*/ _interop_require_wildcard._(require("inspector"));
function getAttachNodejsDebuggerMiddleware() {
return async function(req, res, next) {
const { pathname } = new URL(`http://n${req.url}`);
if (pathname !== '/__nextjs_attach-nodejs-inspector') {
return next();
}
try {
const isInspecting = _inspector.url() !== undefined;
const debugPort = process.debugPort;
if (!isInspecting) {
// Node.js will already log that the inspector is listening.
_inspector.open(debugPort);
}
const inspectorURLRaw = _inspector.url();
if (inspectorURLRaw === undefined) {
// could not open, possibly because already in use.
return _middlewareresponse.middlewareResponse.badRequest(res, `Failed to open port "${debugPort}". Address may be already in use.`);
}
const inspectorURL = new URL(inspectorURLRaw);
const debugInfoListResponse = await fetch(`http://${inspectorURL.host}/json/list`);
const debugInfoList = await debugInfoListResponse.json();
if (!Array.isArray(debugInfoList) || debugInfoList.length === 0) {
throw Object.defineProperty(new Error('No debug targets found'), "__NEXT_ERROR_CODE", {
value: "E927",
enumerable: false,
configurable: true
});
}
return _middlewareresponse.middlewareResponse.json(res, debugInfoList[0].devtoolsFrontendUrl);
} catch (error) {
return _middlewareresponse.middlewareResponse.internalServerError(res);
}
};
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=attach-nodejs-debugger-middleware.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/next-devtools/server/attach-nodejs-debugger-middleware.ts"],"sourcesContent":["import { middlewareResponse } from './middleware-response'\nimport type { ServerResponse, IncomingMessage } from 'http'\nimport * as inspector from 'inspector'\n\nexport function getAttachNodejsDebuggerMiddleware() {\n return async function (\n req: IncomingMessage,\n res: ServerResponse,\n next: () => void\n ): Promise<void> {\n const { pathname } = new URL(`http://n${req.url}`)\n\n if (pathname !== '/__nextjs_attach-nodejs-inspector') {\n return next()\n }\n\n try {\n const isInspecting = inspector.url() !== undefined\n const debugPort = process.debugPort\n if (!isInspecting) {\n // Node.js will already log that the inspector is listening.\n inspector.open(debugPort)\n }\n\n const inspectorURLRaw = inspector.url()\n if (inspectorURLRaw === undefined) {\n // could not open, possibly because already in use.\n return middlewareResponse.badRequest(\n res,\n `Failed to open port \"${debugPort}\". Address may be already in use.`\n )\n }\n const inspectorURL = new URL(inspectorURLRaw)\n\n const debugInfoListResponse = await fetch(\n `http://${inspectorURL.host}/json/list`\n )\n const debugInfoList = await debugInfoListResponse.json()\n if (!Array.isArray(debugInfoList) || debugInfoList.length === 0) {\n throw new Error('No debug targets found')\n }\n\n return middlewareResponse.json(res, debugInfoList[0].devtoolsFrontendUrl)\n } catch (error) {\n return middlewareResponse.internalServerError(res)\n }\n }\n}\n"],"names":["getAttachNodejsDebuggerMiddleware","req","res","next","pathname","URL","url","isInspecting","inspector","undefined","debugPort","process","open","inspectorURLRaw","middlewareResponse","badRequest","inspectorURL","debugInfoListResponse","fetch","host","debugInfoList","json","Array","isArray","length","Error","devtoolsFrontendUrl","error","internalServerError"],"mappings":";;;;+BAIgBA;;;eAAAA;;;;oCAJmB;qEAER;AAEpB,SAASA;IACd,OAAO,eACLC,GAAoB,EACpBC,GAAmB,EACnBC,IAAgB;QAEhB,MAAM,EAAEC,QAAQ,EAAE,GAAG,IAAIC,IAAI,CAAC,QAAQ,EAAEJ,IAAIK,GAAG,EAAE;QAEjD,IAAIF,aAAa,qCAAqC;YACpD,OAAOD;QACT;QAEA,IAAI;YACF,MAAMI,eAAeC,WAAUF,GAAG,OAAOG;YACzC,MAAMC,YAAYC,QAAQD,SAAS;YACnC,IAAI,CAACH,cAAc;gBACjB,4DAA4D;gBAC5DC,WAAUI,IAAI,CAACF;YACjB;YAEA,MAAMG,kBAAkBL,WAAUF,GAAG;YACrC,IAAIO,oBAAoBJ,WAAW;gBACjC,mDAAmD;gBACnD,OAAOK,sCAAkB,CAACC,UAAU,CAClCb,KACA,CAAC,qBAAqB,EAAEQ,UAAU,iCAAiC,CAAC;YAExE;YACA,MAAMM,eAAe,IAAIX,IAAIQ;YAE7B,MAAMI,wBAAwB,MAAMC,MAClC,CAAC,OAAO,EAAEF,aAAaG,IAAI,CAAC,UAAU,CAAC;YAEzC,MAAMC,gBAAgB,MAAMH,sBAAsBI,IAAI;YACtD,IAAI,CAACC,MAAMC,OAAO,CAACH,kBAAkBA,cAAcI,MAAM,KAAK,GAAG;gBAC/D,MAAM,qBAAmC,CAAnC,IAAIC,MAAM,2BAAV,qBAAA;2BAAA;gCAAA;kCAAA;gBAAkC;YAC1C;YAEA,OAAOX,sCAAkB,CAACO,IAAI,CAACnB,KAAKkB,aAAa,CAAC,EAAE,CAACM,mBAAmB;QAC1E,EAAE,OAAOC,OAAO;YACd,OAAOb,sCAAkB,CAACc,mBAAmB,CAAC1B;QAChD;IACF;AACF","ignoreList":[0]}

View File

@@ -0,0 +1,2 @@
import type { ServerResponse, IncomingMessage } from 'http';
export declare function getDisableDevIndicatorMiddleware(): (req: IncomingMessage, res: ServerResponse, next: () => void) => Promise<void>;

View File

@@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "getDisableDevIndicatorMiddleware", {
enumerable: true,
get: function() {
return getDisableDevIndicatorMiddleware;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _middlewareresponse = require("./middleware-response");
const _log = /*#__PURE__*/ _interop_require_wildcard._(require("../../build/output/log"));
const _devindicatorserverstate = require("../../server/dev/dev-indicator-server-state");
const DISABLE_DEV_INDICATOR_PREFIX = '/__nextjs_disable_dev_indicator';
const COOLDOWN_TIME_MS = process.env.__NEXT_DEV_INDICATOR_COOLDOWN_MS ? parseInt(process.env.__NEXT_DEV_INDICATOR_COOLDOWN_MS) : 1000 * 60 * 60 * 24;
function getDisableDevIndicatorMiddleware() {
return async function disableDevIndicatorMiddleware(req, res, next) {
try {
const { pathname } = new URL(`http://n${req.url}`);
if (!pathname.startsWith(DISABLE_DEV_INDICATOR_PREFIX)) {
return next();
}
if (req.method !== 'POST') {
return _middlewareresponse.middlewareResponse.methodNotAllowed(res);
}
_devindicatorserverstate.devIndicatorServerState.disabledUntil = Date.now() + COOLDOWN_TIME_MS;
return _middlewareresponse.middlewareResponse.noContent(res);
} catch (err) {
_log.error('Failed to disable the dev indicator:', err instanceof Error ? err.message : err);
return _middlewareresponse.middlewareResponse.internalServerError(res);
}
};
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=dev-indicator-middleware.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/next-devtools/server/dev-indicator-middleware.ts"],"sourcesContent":["import type { ServerResponse, IncomingMessage } from 'http'\nimport { middlewareResponse } from './middleware-response'\nimport * as Log from '../../build/output/log'\nimport { devIndicatorServerState } from '../../server/dev/dev-indicator-server-state'\n\nconst DISABLE_DEV_INDICATOR_PREFIX = '/__nextjs_disable_dev_indicator'\n\nconst COOLDOWN_TIME_MS = process.env.__NEXT_DEV_INDICATOR_COOLDOWN_MS\n ? parseInt(process.env.__NEXT_DEV_INDICATOR_COOLDOWN_MS)\n : // 1 day from now\n 1000 * 60 * 60 * 24\n\nexport function getDisableDevIndicatorMiddleware() {\n return async function disableDevIndicatorMiddleware(\n req: IncomingMessage,\n res: ServerResponse,\n next: () => void\n ): Promise<void> {\n try {\n const { pathname } = new URL(`http://n${req.url}`)\n\n if (!pathname.startsWith(DISABLE_DEV_INDICATOR_PREFIX)) {\n return next()\n }\n\n if (req.method !== 'POST') {\n return middlewareResponse.methodNotAllowed(res)\n }\n\n devIndicatorServerState.disabledUntil = Date.now() + COOLDOWN_TIME_MS\n\n return middlewareResponse.noContent(res)\n } catch (err) {\n Log.error(\n 'Failed to disable the dev indicator:',\n err instanceof Error ? err.message : err\n )\n return middlewareResponse.internalServerError(res)\n }\n }\n}\n"],"names":["getDisableDevIndicatorMiddleware","DISABLE_DEV_INDICATOR_PREFIX","COOLDOWN_TIME_MS","process","env","__NEXT_DEV_INDICATOR_COOLDOWN_MS","parseInt","disableDevIndicatorMiddleware","req","res","next","pathname","URL","url","startsWith","method","middlewareResponse","methodNotAllowed","devIndicatorServerState","disabledUntil","Date","now","noContent","err","Log","error","Error","message","internalServerError"],"mappings":";;;;+BAYgBA;;;eAAAA;;;;oCAXmB;+DACd;yCACmB;AAExC,MAAMC,+BAA+B;AAErC,MAAMC,mBAAmBC,QAAQC,GAAG,CAACC,gCAAgC,GACjEC,SAASH,QAAQC,GAAG,CAACC,gCAAgC,IAErD,OAAO,KAAK,KAAK;AAEd,SAASL;IACd,OAAO,eAAeO,8BACpBC,GAAoB,EACpBC,GAAmB,EACnBC,IAAgB;QAEhB,IAAI;YACF,MAAM,EAAEC,QAAQ,EAAE,GAAG,IAAIC,IAAI,CAAC,QAAQ,EAAEJ,IAAIK,GAAG,EAAE;YAEjD,IAAI,CAACF,SAASG,UAAU,CAACb,+BAA+B;gBACtD,OAAOS;YACT;YAEA,IAAIF,IAAIO,MAAM,KAAK,QAAQ;gBACzB,OAAOC,sCAAkB,CAACC,gBAAgB,CAACR;YAC7C;YAEAS,gDAAuB,CAACC,aAAa,GAAGC,KAAKC,GAAG,KAAKnB;YAErD,OAAOc,sCAAkB,CAACM,SAAS,CAACb;QACtC,EAAE,OAAOc,KAAK;YACZC,KAAIC,KAAK,CACP,wCACAF,eAAeG,QAAQH,IAAII,OAAO,GAAGJ;YAEvC,OAAOP,sCAAkB,CAACY,mBAAmB,CAACnB;QAChD;IACF;AACF","ignoreList":[0]}

View File

@@ -0,0 +1,7 @@
import type { IncomingMessage, ServerResponse } from 'http';
import type { DevToolsConfig } from '../dev-overlay/shared';
export declare function devToolsConfigMiddleware({ distDir, sendUpdateSignal, }: {
distDir: string;
sendUpdateSignal: (data: DevToolsConfig) => void;
}): (req: IncomingMessage, res: ServerResponse, next: () => void) => Promise<void>;
export declare function getDevToolsConfig(distDir: string): Promise<DevToolsConfig>;

View File

@@ -0,0 +1,82 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
devToolsConfigMiddleware: null,
getDevToolsConfig: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
devToolsConfigMiddleware: function() {
return devToolsConfigMiddleware;
},
getDevToolsConfig: function() {
return getDevToolsConfig;
}
});
const _fs = require("fs");
const _promises = require("fs/promises");
const _path = require("path");
const _middlewareresponse = require("./middleware-response");
const _devtoolsconfigschema = require("../shared/devtools-config-schema");
const _deepmerge = require("../shared/deepmerge");
const DEVTOOLS_CONFIG_FILENAME = 'next-devtools-config.json';
const DEVTOOLS_CONFIG_MIDDLEWARE_ENDPOINT = '/__nextjs_devtools_config';
function devToolsConfigMiddleware({ distDir, sendUpdateSignal }) {
const configPath = (0, _path.join)(distDir, 'cache', DEVTOOLS_CONFIG_FILENAME);
return async function devToolsConfigMiddlewareHandler(req, res, next) {
const { pathname } = new URL(`http://n${req.url}`);
if (pathname !== DEVTOOLS_CONFIG_MIDDLEWARE_ENDPOINT) {
return next();
}
if (req.method !== 'POST') {
return _middlewareresponse.middlewareResponse.methodNotAllowed(res);
}
const currentConfig = await getDevToolsConfig(distDir);
const chunks = [];
for await (const chunk of req){
chunks.push(Buffer.from(chunk));
}
let body = Buffer.concat(chunks).toString('utf8');
try {
body = JSON.parse(body);
} catch (error) {
console.error('[Next.js DevTools] Invalid config body passed:', error);
return _middlewareresponse.middlewareResponse.badRequest(res);
}
const validation = _devtoolsconfigschema.devToolsConfigSchema.safeParse(body);
if (!validation.success) {
console.error('[Next.js DevTools] Invalid config passed:', validation.error.message);
return _middlewareresponse.middlewareResponse.badRequest(res);
}
const newConfig = (0, _deepmerge.deepMerge)(currentConfig, validation.data);
await (0, _promises.writeFile)(configPath, JSON.stringify(newConfig, null, 2));
sendUpdateSignal(newConfig);
return _middlewareresponse.middlewareResponse.noContent(res);
};
}
async function getDevToolsConfig(distDir) {
const configPath = (0, _path.join)(distDir, 'cache', DEVTOOLS_CONFIG_FILENAME);
if (!(0, _fs.existsSync)(configPath)) {
await (0, _promises.mkdir)((0, _path.dirname)(configPath), {
recursive: true
});
await (0, _promises.writeFile)(configPath, JSON.stringify({}));
return {};
}
return JSON.parse(await (0, _promises.readFile)(configPath, 'utf8'));
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=devtools-config-middleware.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/next-devtools/server/devtools-config-middleware.ts"],"sourcesContent":["import type { IncomingMessage, ServerResponse } from 'http'\nimport type { DevToolsConfig } from '../dev-overlay/shared'\n\nimport { existsSync } from 'fs'\nimport { readFile, writeFile, mkdir } from 'fs/promises'\nimport { dirname, join } from 'path'\n\nimport { middlewareResponse } from './middleware-response'\nimport { devToolsConfigSchema } from '../shared/devtools-config-schema'\nimport { deepMerge } from '../shared/deepmerge'\n\nconst DEVTOOLS_CONFIG_FILENAME = 'next-devtools-config.json'\nconst DEVTOOLS_CONFIG_MIDDLEWARE_ENDPOINT = '/__nextjs_devtools_config'\n\nexport function devToolsConfigMiddleware({\n distDir,\n sendUpdateSignal,\n}: {\n distDir: string\n sendUpdateSignal: (data: DevToolsConfig) => void\n}) {\n const configPath = join(distDir, 'cache', DEVTOOLS_CONFIG_FILENAME)\n\n return async function devToolsConfigMiddlewareHandler(\n req: IncomingMessage,\n res: ServerResponse,\n next: () => void\n ): Promise<void> {\n const { pathname } = new URL(`http://n${req.url}`)\n\n if (pathname !== DEVTOOLS_CONFIG_MIDDLEWARE_ENDPOINT) {\n return next()\n }\n\n if (req.method !== 'POST') {\n return middlewareResponse.methodNotAllowed(res)\n }\n\n const currentConfig = await getDevToolsConfig(distDir)\n\n const chunks: Buffer[] = []\n for await (const chunk of req) {\n chunks.push(Buffer.from(chunk))\n }\n\n let body = Buffer.concat(chunks).toString('utf8')\n try {\n body = JSON.parse(body)\n } catch (error) {\n console.error('[Next.js DevTools] Invalid config body passed:', error)\n return middlewareResponse.badRequest(res)\n }\n\n const validation = devToolsConfigSchema.safeParse(body)\n if (!validation.success) {\n console.error(\n '[Next.js DevTools] Invalid config passed:',\n validation.error.message\n )\n return middlewareResponse.badRequest(res)\n }\n\n const newConfig = deepMerge(currentConfig, validation.data)\n await writeFile(configPath, JSON.stringify(newConfig, null, 2))\n\n sendUpdateSignal(newConfig)\n\n return middlewareResponse.noContent(res)\n }\n}\n\nexport async function getDevToolsConfig(\n distDir: string\n): Promise<DevToolsConfig> {\n const configPath = join(distDir, 'cache', DEVTOOLS_CONFIG_FILENAME)\n\n if (!existsSync(configPath)) {\n await mkdir(dirname(configPath), { recursive: true })\n await writeFile(configPath, JSON.stringify({}))\n return {}\n }\n\n return JSON.parse(await readFile(configPath, 'utf8'))\n}\n"],"names":["devToolsConfigMiddleware","getDevToolsConfig","DEVTOOLS_CONFIG_FILENAME","DEVTOOLS_CONFIG_MIDDLEWARE_ENDPOINT","distDir","sendUpdateSignal","configPath","join","devToolsConfigMiddlewareHandler","req","res","next","pathname","URL","url","method","middlewareResponse","methodNotAllowed","currentConfig","chunks","chunk","push","Buffer","from","body","concat","toString","JSON","parse","error","console","badRequest","validation","devToolsConfigSchema","safeParse","success","message","newConfig","deepMerge","data","writeFile","stringify","noContent","existsSync","mkdir","dirname","recursive","readFile"],"mappings":";;;;;;;;;;;;;;;IAcgBA,wBAAwB;eAAxBA;;IAyDMC,iBAAiB;eAAjBA;;;oBApEK;0BACgB;sBACb;oCAEK;sCACE;2BACX;AAE1B,MAAMC,2BAA2B;AACjC,MAAMC,sCAAsC;AAErC,SAASH,yBAAyB,EACvCI,OAAO,EACPC,gBAAgB,EAIjB;IACC,MAAMC,aAAaC,IAAAA,UAAI,EAACH,SAAS,SAASF;IAE1C,OAAO,eAAeM,gCACpBC,GAAoB,EACpBC,GAAmB,EACnBC,IAAgB;QAEhB,MAAM,EAAEC,QAAQ,EAAE,GAAG,IAAIC,IAAI,CAAC,QAAQ,EAAEJ,IAAIK,GAAG,EAAE;QAEjD,IAAIF,aAAaT,qCAAqC;YACpD,OAAOQ;QACT;QAEA,IAAIF,IAAIM,MAAM,KAAK,QAAQ;YACzB,OAAOC,sCAAkB,CAACC,gBAAgB,CAACP;QAC7C;QAEA,MAAMQ,gBAAgB,MAAMjB,kBAAkBG;QAE9C,MAAMe,SAAmB,EAAE;QAC3B,WAAW,MAAMC,SAASX,IAAK;YAC7BU,OAAOE,IAAI,CAACC,OAAOC,IAAI,CAACH;QAC1B;QAEA,IAAII,OAAOF,OAAOG,MAAM,CAACN,QAAQO,QAAQ,CAAC;QAC1C,IAAI;YACFF,OAAOG,KAAKC,KAAK,CAACJ;QACpB,EAAE,OAAOK,OAAO;YACdC,QAAQD,KAAK,CAAC,kDAAkDA;YAChE,OAAOb,sCAAkB,CAACe,UAAU,CAACrB;QACvC;QAEA,MAAMsB,aAAaC,0CAAoB,CAACC,SAAS,CAACV;QAClD,IAAI,CAACQ,WAAWG,OAAO,EAAE;YACvBL,QAAQD,KAAK,CACX,6CACAG,WAAWH,KAAK,CAACO,OAAO;YAE1B,OAAOpB,sCAAkB,CAACe,UAAU,CAACrB;QACvC;QAEA,MAAM2B,YAAYC,IAAAA,oBAAS,EAACpB,eAAec,WAAWO,IAAI;QAC1D,MAAMC,IAAAA,mBAAS,EAAClC,YAAYqB,KAAKc,SAAS,CAACJ,WAAW,MAAM;QAE5DhC,iBAAiBgC;QAEjB,OAAOrB,sCAAkB,CAAC0B,SAAS,CAAChC;IACtC;AACF;AAEO,eAAeT,kBACpBG,OAAe;IAEf,MAAME,aAAaC,IAAAA,UAAI,EAACH,SAAS,SAASF;IAE1C,IAAI,CAACyC,IAAAA,cAAU,EAACrC,aAAa;QAC3B,MAAMsC,IAAAA,eAAK,EAACC,IAAAA,aAAO,EAACvC,aAAa;YAAEwC,WAAW;QAAK;QACnD,MAAMN,IAAAA,mBAAS,EAAClC,YAAYqB,KAAKc,SAAS,CAAC,CAAC;QAC5C,OAAO,CAAC;IACV;IAEA,OAAOd,KAAKC,KAAK,CAAC,MAAMmB,IAAAA,kBAAQ,EAACzC,YAAY;AAC/C","ignoreList":[0]}

Binary file not shown.

View File

@@ -0,0 +1,2 @@
import type { ServerResponse, IncomingMessage } from 'http';
export declare function getDevOverlayFontMiddleware(): (req: IncomingMessage, res: ServerResponse, next: () => void) => Promise<void>;

View File

@@ -0,0 +1,71 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "getDevOverlayFontMiddleware", {
enumerable: true,
get: function() {
return getDevOverlayFontMiddleware;
}
});
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _path = /*#__PURE__*/ _interop_require_default._(require("path"));
const _promises = /*#__PURE__*/ _interop_require_wildcard._(require("fs/promises"));
const _fs = require("fs");
const _log = /*#__PURE__*/ _interop_require_wildcard._(require("../../../build/output/log"));
const _middlewareresponse = require("../middleware-response");
const FONT_PREFIX = '/__nextjs_font/';
const VALID_FONTS = [
'geist-latin-ext.woff2',
'geist-mono-latin-ext.woff2',
'geist-latin.woff2',
'geist-mono-latin.woff2'
];
const FONT_HEADERS = {
'Content-Type': 'font/woff2',
'Cache-Control': 'public, max-age=31536000, immutable'
};
function getDevOverlayFontMiddleware() {
return async function devOverlayFontMiddleware(req, res, next) {
try {
const { pathname } = new URL(`http://n${req.url}`);
if (!pathname.startsWith(FONT_PREFIX)) {
return next();
}
const fontFile = pathname.replace(FONT_PREFIX, '');
if (!VALID_FONTS.includes(fontFile)) {
return _middlewareresponse.middlewareResponse.notFound(res);
}
const fontPath = _path.default.resolve(__dirname, fontFile);
const fileExists = await checkFileExists(fontPath);
if (!fileExists) {
return _middlewareresponse.middlewareResponse.notFound(res);
}
const fontData = await _promises.readFile(fontPath);
Object.entries(FONT_HEADERS).forEach(([key, value])=>{
res.setHeader(key, value);
});
res.end(fontData);
} catch (err) {
_log.error('Failed to serve font:', err instanceof Error ? err.message : err);
return _middlewareresponse.middlewareResponse.internalServerError(res);
}
};
}
async function checkFileExists(filePath) {
try {
await _promises.access(filePath, _fs.constants.F_OK);
return true;
} catch {
return false;
}
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=get-dev-overlay-font-middleware.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/next-devtools/server/font/get-dev-overlay-font-middleware.ts"],"sourcesContent":["import type { ServerResponse, IncomingMessage } from 'http'\nimport path from 'path'\nimport * as fs from 'fs/promises'\nimport { constants } from 'fs'\nimport * as Log from '../../../build/output/log'\nimport { middlewareResponse } from '../middleware-response'\n\nconst FONT_PREFIX = '/__nextjs_font/'\n\nconst VALID_FONTS = [\n 'geist-latin-ext.woff2',\n 'geist-mono-latin-ext.woff2',\n 'geist-latin.woff2',\n 'geist-mono-latin.woff2',\n]\n\nconst FONT_HEADERS = {\n 'Content-Type': 'font/woff2',\n 'Cache-Control': 'public, max-age=31536000, immutable',\n} as const\n\nexport function getDevOverlayFontMiddleware() {\n return async function devOverlayFontMiddleware(\n req: IncomingMessage,\n res: ServerResponse,\n next: () => void\n ): Promise<void> {\n try {\n const { pathname } = new URL(`http://n${req.url}`)\n\n if (!pathname.startsWith(FONT_PREFIX)) {\n return next()\n }\n\n const fontFile = pathname.replace(FONT_PREFIX, '')\n if (!VALID_FONTS.includes(fontFile)) {\n return middlewareResponse.notFound(res)\n }\n\n const fontPath = path.resolve(__dirname, fontFile)\n const fileExists = await checkFileExists(fontPath)\n\n if (!fileExists) {\n return middlewareResponse.notFound(res)\n }\n\n const fontData = await fs.readFile(fontPath)\n Object.entries(FONT_HEADERS).forEach(([key, value]) => {\n res.setHeader(key, value)\n })\n res.end(fontData)\n } catch (err) {\n Log.error(\n 'Failed to serve font:',\n err instanceof Error ? err.message : err\n )\n return middlewareResponse.internalServerError(res)\n }\n }\n}\n\nasync function checkFileExists(filePath: string): Promise<boolean> {\n try {\n await fs.access(filePath, constants.F_OK)\n return true\n } catch {\n return false\n }\n}\n"],"names":["getDevOverlayFontMiddleware","FONT_PREFIX","VALID_FONTS","FONT_HEADERS","devOverlayFontMiddleware","req","res","next","pathname","URL","url","startsWith","fontFile","replace","includes","middlewareResponse","notFound","fontPath","path","resolve","__dirname","fileExists","checkFileExists","fontData","fs","readFile","Object","entries","forEach","key","value","setHeader","end","err","Log","error","Error","message","internalServerError","filePath","access","constants","F_OK"],"mappings":";;;;+BAqBgBA;;;eAAAA;;;;;+DApBC;oEACG;oBACM;+DACL;oCACc;AAEnC,MAAMC,cAAc;AAEpB,MAAMC,cAAc;IAClB;IACA;IACA;IACA;CACD;AAED,MAAMC,eAAe;IACnB,gBAAgB;IAChB,iBAAiB;AACnB;AAEO,SAASH;IACd,OAAO,eAAeI,yBACpBC,GAAoB,EACpBC,GAAmB,EACnBC,IAAgB;QAEhB,IAAI;YACF,MAAM,EAAEC,QAAQ,EAAE,GAAG,IAAIC,IAAI,CAAC,QAAQ,EAAEJ,IAAIK,GAAG,EAAE;YAEjD,IAAI,CAACF,SAASG,UAAU,CAACV,cAAc;gBACrC,OAAOM;YACT;YAEA,MAAMK,WAAWJ,SAASK,OAAO,CAACZ,aAAa;YAC/C,IAAI,CAACC,YAAYY,QAAQ,CAACF,WAAW;gBACnC,OAAOG,sCAAkB,CAACC,QAAQ,CAACV;YACrC;YAEA,MAAMW,WAAWC,aAAI,CAACC,OAAO,CAACC,WAAWR;YACzC,MAAMS,aAAa,MAAMC,gBAAgBL;YAEzC,IAAI,CAACI,YAAY;gBACf,OAAON,sCAAkB,CAACC,QAAQ,CAACV;YACrC;YAEA,MAAMiB,WAAW,MAAMC,UAAGC,QAAQ,CAACR;YACnCS,OAAOC,OAAO,CAACxB,cAAcyB,OAAO,CAAC,CAAC,CAACC,KAAKC,MAAM;gBAChDxB,IAAIyB,SAAS,CAACF,KAAKC;YACrB;YACAxB,IAAI0B,GAAG,CAACT;QACV,EAAE,OAAOU,KAAK;YACZC,KAAIC,KAAK,CACP,yBACAF,eAAeG,QAAQH,IAAII,OAAO,GAAGJ;YAEvC,OAAOlB,sCAAkB,CAACuB,mBAAmB,CAAChC;QAChD;IACF;AACF;AAEA,eAAegB,gBAAgBiB,QAAgB;IAC7C,IAAI;QACF,MAAMf,UAAGgB,MAAM,CAACD,UAAUE,aAAS,CAACC,IAAI;QACxC,OAAO;IACT,EAAE,OAAM;QACN,OAAO;IACT;AACF","ignoreList":[0]}

View File

@@ -0,0 +1,3 @@
import type { ServerResponse, IncomingMessage } from 'http';
import type { Telemetry } from '../../telemetry/storage';
export declare function getNextErrorFeedbackMiddleware(telemetry: Telemetry): (req: IncomingMessage, res: ServerResponse, next: () => void) => Promise<void>;

View File

@@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "getNextErrorFeedbackMiddleware", {
enumerable: true,
get: function() {
return getNextErrorFeedbackMiddleware;
}
});
const _errorfeedback = require("../../telemetry/events/error-feedback");
const _middlewareresponse = require("./middleware-response");
function getNextErrorFeedbackMiddleware(telemetry) {
return async function(req, res, next) {
const { pathname, searchParams } = new URL(`http://n${req.url}`);
if (pathname !== '/__nextjs_error_feedback') {
return next();
}
try {
const errorCode = searchParams.get('errorCode');
const wasHelpful = searchParams.get('wasHelpful');
if (!errorCode || !wasHelpful) {
return _middlewareresponse.middlewareResponse.badRequest(res);
}
await telemetry.record((0, _errorfeedback.eventErrorFeedback)({
errorCode,
wasHelpful: wasHelpful === 'true'
}));
return _middlewareresponse.middlewareResponse.noContent(res);
} catch (error) {
return _middlewareresponse.middlewareResponse.internalServerError(res);
}
};
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=get-next-error-feedback-middleware.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/next-devtools/server/get-next-error-feedback-middleware.ts"],"sourcesContent":["import { eventErrorFeedback } from '../../telemetry/events/error-feedback'\nimport { middlewareResponse } from './middleware-response'\nimport type { ServerResponse, IncomingMessage } from 'http'\nimport type { Telemetry } from '../../telemetry/storage'\n\n// Handles HTTP requests to /__nextjs_error_feedback endpoint for collecting user feedback on error messages\nexport function getNextErrorFeedbackMiddleware(telemetry: Telemetry) {\n return async function (\n req: IncomingMessage,\n res: ServerResponse,\n next: () => void\n ): Promise<void> {\n const { pathname, searchParams } = new URL(`http://n${req.url}`)\n\n if (pathname !== '/__nextjs_error_feedback') {\n return next()\n }\n\n try {\n const errorCode = searchParams.get('errorCode')\n const wasHelpful = searchParams.get('wasHelpful')\n\n if (!errorCode || !wasHelpful) {\n return middlewareResponse.badRequest(res)\n }\n\n await telemetry.record(\n eventErrorFeedback({\n errorCode,\n wasHelpful: wasHelpful === 'true',\n })\n )\n\n return middlewareResponse.noContent(res)\n } catch (error) {\n return middlewareResponse.internalServerError(res)\n }\n }\n}\n"],"names":["getNextErrorFeedbackMiddleware","telemetry","req","res","next","pathname","searchParams","URL","url","errorCode","get","wasHelpful","middlewareResponse","badRequest","record","eventErrorFeedback","noContent","error","internalServerError"],"mappings":";;;;+BAMgBA;;;eAAAA;;;+BANmB;oCACA;AAK5B,SAASA,+BAA+BC,SAAoB;IACjE,OAAO,eACLC,GAAoB,EACpBC,GAAmB,EACnBC,IAAgB;QAEhB,MAAM,EAAEC,QAAQ,EAAEC,YAAY,EAAE,GAAG,IAAIC,IAAI,CAAC,QAAQ,EAAEL,IAAIM,GAAG,EAAE;QAE/D,IAAIH,aAAa,4BAA4B;YAC3C,OAAOD;QACT;QAEA,IAAI;YACF,MAAMK,YAAYH,aAAaI,GAAG,CAAC;YACnC,MAAMC,aAAaL,aAAaI,GAAG,CAAC;YAEpC,IAAI,CAACD,aAAa,CAACE,YAAY;gBAC7B,OAAOC,sCAAkB,CAACC,UAAU,CAACV;YACvC;YAEA,MAAMF,UAAUa,MAAM,CACpBC,IAAAA,iCAAkB,EAAC;gBACjBN;gBACAE,YAAYA,eAAe;YAC7B;YAGF,OAAOC,sCAAkB,CAACI,SAAS,CAACb;QACtC,EAAE,OAAOc,OAAO;YACd,OAAOL,sCAAkB,CAACM,mBAAmB,CAACf;QAChD;IACF;AACF","ignoreList":[0]}

View File

@@ -0,0 +1,11 @@
export declare function escapeApplescriptStringFragment(input: string): string;
export declare function launchEditor(fileName: string, line1: number, column1: number): void;
/**
* Open the file in editor if exists, otherwise return an error
* @param file `file:` URL, or absolute path or relative path. Relative paths must
* relative to `nextRootDirectory`.
*/
export declare function openFileInEditor(file: string, line1: number, column1: number, nextRootDirectory: string): Promise<{
found: boolean;
error: unknown | null;
}>;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,10 @@
import type { ServerResponse } from 'http';
export declare const middlewareResponse: {
noContent(res: ServerResponse): void;
badRequest(res: ServerResponse, reason?: string): void;
notFound(res: ServerResponse): void;
methodNotAllowed(res: ServerResponse): void;
internalServerError(res: ServerResponse, error?: unknown): void;
json(res: ServerResponse, data: any): void;
jsonString(res: ServerResponse, data: string): void;
};

View File

@@ -0,0 +1,55 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "middlewareResponse", {
enumerable: true,
get: function() {
return middlewareResponse;
}
});
const _util = require("util");
const middlewareResponse = {
noContent (res) {
res.statusCode = 204;
res.end('No Content');
},
badRequest (res, reason) {
res.statusCode = 400;
if (reason !== undefined) {
res.setHeader('Content-Type', 'text/plain');
res.end(reason);
} else {
res.end();
}
},
notFound (res) {
res.statusCode = 404;
res.end('Not Found');
},
methodNotAllowed (res) {
res.statusCode = 405;
res.end('Method Not Allowed');
},
internalServerError (res, error) {
res.statusCode = 500;
res.setHeader('Content-Type', 'text/plain');
res.end(error !== undefined ? (0, _util.inspect)(error, {
colors: false
}) : 'Internal Server Error');
},
json (res, data) {
res.setHeader('Content-Type', 'application/json').end(Buffer.from(JSON.stringify(data)));
},
jsonString (res, data) {
res.setHeader('Content-Type', 'application/json').end(Buffer.from(data));
}
};
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=middleware-response.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/next-devtools/server/middleware-response.ts"],"sourcesContent":["import type { ServerResponse } from 'http'\nimport { inspect } from 'util'\n\nexport const middlewareResponse = {\n noContent(res: ServerResponse) {\n res.statusCode = 204\n res.end('No Content')\n },\n badRequest(res: ServerResponse, reason?: string) {\n res.statusCode = 400\n if (reason !== undefined) {\n res.setHeader('Content-Type', 'text/plain')\n res.end(reason)\n } else {\n res.end()\n }\n },\n notFound(res: ServerResponse) {\n res.statusCode = 404\n res.end('Not Found')\n },\n methodNotAllowed(res: ServerResponse) {\n res.statusCode = 405\n res.end('Method Not Allowed')\n },\n internalServerError(res: ServerResponse, error?: unknown) {\n res.statusCode = 500\n res.setHeader('Content-Type', 'text/plain')\n res.end(\n error !== undefined\n ? inspect(error, { colors: false })\n : 'Internal Server Error'\n )\n },\n json(res: ServerResponse, data: any) {\n res\n .setHeader('Content-Type', 'application/json')\n .end(Buffer.from(JSON.stringify(data)))\n },\n jsonString(res: ServerResponse, data: string) {\n res.setHeader('Content-Type', 'application/json').end(Buffer.from(data))\n },\n}\n"],"names":["middlewareResponse","noContent","res","statusCode","end","badRequest","reason","undefined","setHeader","notFound","methodNotAllowed","internalServerError","error","inspect","colors","json","data","Buffer","from","JSON","stringify","jsonString"],"mappings":";;;;+BAGaA;;;eAAAA;;;sBAFW;AAEjB,MAAMA,qBAAqB;IAChCC,WAAUC,GAAmB;QAC3BA,IAAIC,UAAU,GAAG;QACjBD,IAAIE,GAAG,CAAC;IACV;IACAC,YAAWH,GAAmB,EAAEI,MAAe;QAC7CJ,IAAIC,UAAU,GAAG;QACjB,IAAIG,WAAWC,WAAW;YACxBL,IAAIM,SAAS,CAAC,gBAAgB;YAC9BN,IAAIE,GAAG,CAACE;QACV,OAAO;YACLJ,IAAIE,GAAG;QACT;IACF;IACAK,UAASP,GAAmB;QAC1BA,IAAIC,UAAU,GAAG;QACjBD,IAAIE,GAAG,CAAC;IACV;IACAM,kBAAiBR,GAAmB;QAClCA,IAAIC,UAAU,GAAG;QACjBD,IAAIE,GAAG,CAAC;IACV;IACAO,qBAAoBT,GAAmB,EAAEU,KAAe;QACtDV,IAAIC,UAAU,GAAG;QACjBD,IAAIM,SAAS,CAAC,gBAAgB;QAC9BN,IAAIE,GAAG,CACLQ,UAAUL,YACNM,IAAAA,aAAO,EAACD,OAAO;YAAEE,QAAQ;QAAM,KAC/B;IAER;IACAC,MAAKb,GAAmB,EAAEc,IAAS;QACjCd,IACGM,SAAS,CAAC,gBAAgB,oBAC1BJ,GAAG,CAACa,OAAOC,IAAI,CAACC,KAAKC,SAAS,CAACJ;IACpC;IACAK,YAAWnB,GAAmB,EAAEc,IAAY;QAC1Cd,IAAIM,SAAS,CAAC,gBAAgB,oBAAoBJ,GAAG,CAACa,OAAOC,IAAI,CAACF;IACpE;AACF","ignoreList":[0]}

View File

@@ -0,0 +1,10 @@
import type { ServerResponse, IncomingMessage } from 'http';
import type { Telemetry } from '../../telemetry/storage';
import type { Project } from '../../build/swc/types';
interface RestartDevServerMiddlewareConfig {
telemetry: Telemetry;
turbopackProject?: Project;
webpackCacheDirectories?: Set<string>;
}
export declare function getRestartDevServerMiddleware({ telemetry, turbopackProject, webpackCacheDirectories, }: RestartDevServerMiddlewareConfig): (req: IncomingMessage, res: ServerResponse, next: () => void) => Promise<void>;
export {};

View File

@@ -0,0 +1,78 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "getRestartDevServerMiddleware", {
enumerable: true,
get: function() {
return getRestartDevServerMiddleware;
}
});
const _utils = require("../../server/lib/utils");
const _middlewareresponse = require("./middleware-response");
const _cacheinvalidation = require("../../build/webpack/cache-invalidation");
const EVENT_DEV_OVERLAY_RESTART_SERVER = 'DEV_OVERLAY_RESTART_SERVER';
function getRestartDevServerMiddleware({ telemetry, turbopackProject, webpackCacheDirectories }) {
/**
* Some random value between 1 and Number.MAX_SAFE_INTEGER (inclusive). The same value is returned
* on every call to `__nextjs_server_status` until the server is restarted.
*
* Can be used to determine if two server status responses are from the same process or a
* different (restarted) process.
*/ const executionId = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER) + 1;
async function handleRestartRequest(req, res, searchParams) {
if (req.method !== 'POST') {
return _middlewareresponse.middlewareResponse.methodNotAllowed(res);
}
const shouldInvalidateFileSystemCache = searchParams.has('invalidateFileSystemCache');
if (shouldInvalidateFileSystemCache) {
if (webpackCacheDirectories != null) {
await Promise.all(Array.from(webpackCacheDirectories).map(_cacheinvalidation.invalidateFileSystemCache));
}
if (turbopackProject != null) {
await turbopackProject.invalidateFileSystemCache();
}
}
telemetry.record({
eventName: EVENT_DEV_OVERLAY_RESTART_SERVER,
payload: {
invalidateFileSystemCache: shouldInvalidateFileSystemCache
}
});
// TODO: Use flushDetached
await telemetry.flush();
// do this async to try to give the response a chance to send
// it's not really important if it doesn't though
setTimeout(()=>{
process.exit(_utils.RESTART_EXIT_CODE);
}, 0);
return _middlewareresponse.middlewareResponse.noContent(res);
}
async function handleServerStatus(req, res) {
if (req.method !== 'GET') {
return _middlewareresponse.middlewareResponse.methodNotAllowed(res);
}
return _middlewareresponse.middlewareResponse.json(res, {
executionId
});
}
return async function(req, res, next) {
const { pathname, searchParams } = new URL(`http://n${req.url}`);
switch(pathname){
case '/__nextjs_restart_dev':
return await handleRestartRequest(req, res, searchParams);
case '/__nextjs_server_status':
return await handleServerStatus(req, res);
default:
return next();
}
};
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=restart-dev-server-middleware.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,25 @@
import type { StackFrame } from '../../server/lib/parse-stack';
export type { StackFrame };
export interface IgnorableStackFrame extends StackFrame {
ignored: boolean;
}
export interface OriginalStackFramesRequest {
frames: readonly StackFrame[];
isServer: boolean;
isEdgeServer: boolean;
isAppDirectory: boolean;
}
export type OriginalStackFramesResponse = OriginalStackFrameResponseResult[];
export type OriginalStackFrameResponseResult = PromiseSettledResult<OriginalStackFrameResponse>;
export interface OriginalStackFrameResponse {
originalStackFrame: (StackFrame & {
ignored: boolean;
}) | null;
originalCodeFrame: string | null;
}
export declare function ignoreListAnonymousStackFramesIfSandwiched(responses: OriginalStackFramesResponse): void;
/**
* It looks up the code frame of the traced source.
* @note It ignores Next.js/React internals, as these can often be huge bundled files.
*/
export declare function getOriginalCodeFrame(frame: IgnorableStackFrame, source: string | null, colors?: boolean): string | null;

View File

@@ -0,0 +1,61 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
getOriginalCodeFrame: null,
ignoreListAnonymousStackFramesIfSandwiched: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
getOriginalCodeFrame: function() {
return getOriginalCodeFrame;
},
ignoreListAnonymousStackFramesIfSandwiched: function() {
return ignoreListAnonymousStackFramesIfSandwiched;
}
});
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
const _codeframe = require("next/dist/compiled/babel/code-frame");
const _isinternal = /*#__PURE__*/ _interop_require_default._(require("../../shared/lib/is-internal"));
const _sourcemaps = require("../../server/lib/source-maps");
function ignoreListAnonymousStackFramesIfSandwiched(responses) {
(0, _sourcemaps.ignoreListAnonymousStackFramesIfSandwiched)(responses, (response)=>{
return response.status === 'fulfilled' && response.value.originalStackFrame !== null && response.value.originalStackFrame.file === '<anonymous>';
}, (response)=>{
return response.status === 'fulfilled' && response.value.originalStackFrame !== null && response.value.originalStackFrame.ignored === true;
}, (response)=>{
return response.status === 'fulfilled' && response.value.originalStackFrame !== null ? response.value.originalStackFrame.methodName : '';
}, (response)=>{
;
response.value.originalStackFrame.ignored = true;
});
}
function getOriginalCodeFrame(frame, source, colors = process.stdout.isTTY) {
if (!source || (0, _isinternal.default)(frame.file)) {
return null;
}
return (0, _codeframe.codeFrameColumns)(source, {
start: {
// 1-based, but -1 means start line without highlighting
line: frame.line1 ?? -1,
// 1-based, but 0 means whole line without column highlighting
column: frame.column1 ?? 0
}
}, {
forceColor: colors
});
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=shared.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/next-devtools/server/shared.ts"],"sourcesContent":["import { codeFrameColumns } from 'next/dist/compiled/babel/code-frame'\nimport isInternal from '../../shared/lib/is-internal'\nimport type { StackFrame } from '../../server/lib/parse-stack'\nimport { ignoreListAnonymousStackFramesIfSandwiched as ignoreListAnonymousStackFramesIfSandwichedGeneric } from '../../server/lib/source-maps'\n\nexport type { StackFrame }\n\nexport interface IgnorableStackFrame extends StackFrame {\n ignored: boolean\n}\n\nexport interface OriginalStackFramesRequest {\n frames: readonly StackFrame[]\n isServer: boolean\n isEdgeServer: boolean\n isAppDirectory: boolean\n}\n\nexport type OriginalStackFramesResponse = OriginalStackFrameResponseResult[]\n\nexport type OriginalStackFrameResponseResult =\n PromiseSettledResult<OriginalStackFrameResponse>\n\nexport interface OriginalStackFrameResponse {\n originalStackFrame: (StackFrame & { ignored: boolean }) | null\n originalCodeFrame: string | null\n}\n\nexport function ignoreListAnonymousStackFramesIfSandwiched(\n responses: OriginalStackFramesResponse\n): void {\n ignoreListAnonymousStackFramesIfSandwichedGeneric(\n responses,\n (response) => {\n return (\n response.status === 'fulfilled' &&\n response.value.originalStackFrame !== null &&\n response.value.originalStackFrame.file === '<anonymous>'\n )\n },\n (response) => {\n return (\n response.status === 'fulfilled' &&\n response.value.originalStackFrame !== null &&\n response.value.originalStackFrame.ignored === true\n )\n },\n (response) => {\n return response.status === 'fulfilled' &&\n response.value.originalStackFrame !== null\n ? response.value.originalStackFrame.methodName\n : ''\n },\n (response) => {\n ;(\n response as PromiseFulfilledResult<OriginalStackFrameResponse>\n ).value.originalStackFrame!.ignored = true\n }\n )\n}\n\n/**\n * It looks up the code frame of the traced source.\n * @note It ignores Next.js/React internals, as these can often be huge bundled files.\n */\nexport function getOriginalCodeFrame(\n frame: IgnorableStackFrame,\n source: string | null,\n colors: boolean = process.stdout.isTTY\n): string | null {\n if (!source || isInternal(frame.file)) {\n return null\n }\n\n return codeFrameColumns(\n source,\n {\n start: {\n // 1-based, but -1 means start line without highlighting\n line: frame.line1 ?? -1,\n // 1-based, but 0 means whole line without column highlighting\n column: frame.column1 ?? 0,\n },\n },\n { forceColor: colors }\n )\n}\n"],"names":["getOriginalCodeFrame","ignoreListAnonymousStackFramesIfSandwiched","responses","ignoreListAnonymousStackFramesIfSandwichedGeneric","response","status","value","originalStackFrame","file","ignored","methodName","frame","source","colors","process","stdout","isTTY","isInternal","codeFrameColumns","start","line","line1","column","column1","forceColor"],"mappings":";;;;;;;;;;;;;;;IAiEgBA,oBAAoB;eAApBA;;IArCAC,0CAA0C;eAA1CA;;;;2BA5BiB;qEACV;4BAEyF;AAyBzG,SAASA,2CACdC,SAAsC;IAEtCC,IAAAA,sDAAiD,EAC/CD,WACA,CAACE;QACC,OACEA,SAASC,MAAM,KAAK,eACpBD,SAASE,KAAK,CAACC,kBAAkB,KAAK,QACtCH,SAASE,KAAK,CAACC,kBAAkB,CAACC,IAAI,KAAK;IAE/C,GACA,CAACJ;QACC,OACEA,SAASC,MAAM,KAAK,eACpBD,SAASE,KAAK,CAACC,kBAAkB,KAAK,QACtCH,SAASE,KAAK,CAACC,kBAAkB,CAACE,OAAO,KAAK;IAElD,GACA,CAACL;QACC,OAAOA,SAASC,MAAM,KAAK,eACzBD,SAASE,KAAK,CAACC,kBAAkB,KAAK,OACpCH,SAASE,KAAK,CAACC,kBAAkB,CAACG,UAAU,GAC5C;IACN,GACA,CAACN;;QAEGA,SACAE,KAAK,CAACC,kBAAkB,CAAEE,OAAO,GAAG;IACxC;AAEJ;AAMO,SAAST,qBACdW,KAA0B,EAC1BC,MAAqB,EACrBC,SAAkBC,QAAQC,MAAM,CAACC,KAAK;IAEtC,IAAI,CAACJ,UAAUK,IAAAA,mBAAU,EAACN,MAAMH,IAAI,GAAG;QACrC,OAAO;IACT;IAEA,OAAOU,IAAAA,2BAAgB,EACrBN,QACA;QACEO,OAAO;YACL,wDAAwD;YACxDC,MAAMT,MAAMU,KAAK,IAAI,CAAC;YACtB,8DAA8D;YAC9DC,QAAQX,MAAMY,OAAO,IAAI;QAC3B;IACF,GACA;QAAEC,YAAYX;IAAO;AAEzB","ignoreList":[0]}