ai-debug-local-mcp
Version:
🎯 ENHANCED AI GUIDANCE v4.1.2: Dramatically improved tool descriptions help AI users choose the right tools instead of 'close enough' options. Ultra-fast keyboard automation (10x speed), universal recording, multi-ecosystem debugging support, and compreh
209 lines • 8.8 kB
JavaScript
/**
* NextJS Core Configuration & Detection Module
*
* Phase 1 of NextJS Debug Engine Enhanced modularization following the proven
* 4-module architecture pattern. This module contains core NextJS detection,
* configuration analysis, and basic page information functionality.
*
* Contains core functionality:
* - NextJS framework detection and version identification
* - Configuration analysis and parsing
* - Page attachment and basic monitoring setup
* - Core page information gathering
*
* @module nextjs-core-config
* @since Cycle 23 - July 13, 2025
*/
export class NextJSCoreConfig {
page;
config;
constructor(page) {
this.page = page;
}
async attachToPage() {
// Attach to the page and set up basic monitoring
await this.detectNextJSConfig();
await this.injectBasicMonitoring();
}
async detectNextJSConfig() {
// Real implementation: NextJS configuration detection
const config = await this.page.evaluate(() => {
const nextData = window.__NEXT_DATA__;
const nextConfig = window.__NEXT_CONFIG__;
if (nextData?.buildId) {
const scripts = document.querySelectorAll('script[src*="_next/static"]');
const versionScript = Array.from(scripts).find(script => script.getAttribute('src')?.includes('webpack'));
let version = 'Unknown';
if (versionScript) {
const src = versionScript.getAttribute('src') || '';
const versionMatch = src.match(/\/_next\/static\/([^\/]+)\//);
if (versionMatch) {
version = versionMatch[1];
}
}
const rendering = nextData.page?.startsWith('/app') ||
document.querySelector('[data-nextjs-router="app"]') ?
'App Router' : 'Pages Router';
return {
framework: 'Next.js',
version,
rendering,
buildMode: (process.env.NODE_ENV === 'production' ? 'production' : 'development'),
config: {
reactStrictMode: nextConfig?.reactStrictMode || false,
experimental: nextConfig?.experimental ? Object.keys(nextConfig.experimental) : [],
images: nextConfig?.images,
basePath: nextConfig?.basePath,
assetPrefix: nextConfig?.assetPrefix,
i18n: nextConfig?.i18n,
redirects: nextConfig?.redirects,
rewrites: nextConfig?.rewrites
}
};
}
return null;
});
if (config) {
this.config = config;
}
}
async injectBasicMonitoring() {
// Real implementation: Basic NextJS monitoring injection
await this.page.addInitScript(() => {
// Set up basic NextJS monitoring
window.__NEXTJS_DEBUG__ = {
framework: 'Next.js',
debugger: 'AI Debug Local',
initialized: new Date().toISOString(),
// Core monitoring functions
init: function () {
console.log('NextJS Core Debug initialized');
this.monitorPageInfo();
},
monitorPageInfo: function () {
// Monitor basic page information
const nextData = window.__NEXT_DATA__;
if (nextData) {
this.pageInfo = {
page: nextData.page,
query: nextData.query,
buildId: nextData.buildId,
isFallback: nextData.isFallback,
dynamicIds: nextData.dynamicIds
};
}
}
};
// Initialize monitoring
window.__NEXTJS_DEBUG__.init();
});
}
async getPageInfo() {
// Real implementation: Comprehensive page information gathering
return await this.page.evaluate(() => {
const nextData = window.__NEXT_DATA__;
const router = window.__NEXT_ROUTER__ || window.next?.router;
if (!nextData) {
return { error: 'Not a Next.js application' };
}
const pageInfo = {
page: nextData.page,
query: nextData.query || {},
buildId: nextData.buildId,
isFallback: nextData.isFallback || false,
dynamicIds: nextData.dynamicIds || [],
locale: nextData.locale,
locales: nextData.locales,
defaultLocale: nextData.defaultLocale
};
// Determine rendering method
if (nextData.page?.startsWith('/_error')) {
pageInfo.renderingMethod = 'Error Page';
}
else if (nextData.props?.pageProps) {
pageInfo.renderingMethod = 'SSG (Static Site Generation)';
pageInfo.props = nextData.props.pageProps;
}
else if (router?.isSsr) {
pageInfo.renderingMethod = 'SSR (Server-Side Rendering)';
}
else if (document.querySelector('[data-nextjs-router="app"]')) {
pageInfo.renderingMethod = 'App Router RSC (React Server Components)';
// App Router specific info
const routerState = window.__NEXT_ROUTER_STATE__;
if (routerState) {
pageInfo.appRouter = {
tree: routerState.tree,
cache: routerState.cache,
prefetchCache: routerState.prefetchCache
};
}
}
else {
pageInfo.renderingMethod = 'CSR (Client-Side Rendering)';
}
// ISR detection
const revalidateHeader = document.querySelector('meta[name="next-revalidate"]');
if (revalidateHeader) {
pageInfo.revalidate = parseInt(revalidateHeader.getAttribute('content') || '0');
pageInfo.renderingMethod = 'ISR (Incremental Static Regeneration)';
}
return pageInfo;
});
}
async getConfig() {
// Return the detected configuration
return this.config || null;
}
async getAppRouterInfo() {
// Real implementation: App Router information gathering
return await this.page.evaluate(() => {
const router = window.__NEXT_ROUTER__ || window.next?.router;
if (!router)
return null;
const url = new URL(window.location.href);
const searchParams = {};
url.searchParams.forEach((value, key) => {
searchParams[key] = value;
});
// Extract dynamic segments from pathname
const pathname = url.pathname;
const dynamicSegments = pathname.split('/').filter(segment => segment.startsWith('[') && segment.endsWith(']'));
// Detect parallel routes (slots)
const parallelRoutes = Array.from(document.querySelectorAll('[data-parallel-route-key]'))
.map(el => el.getAttribute('data-parallel-route-key'))
.filter(Boolean);
// Count intercepted routes
const interceptedRoutes = document.querySelectorAll('[data-intercepted-route]').length;
// Detect route groups
const routeGroups = pathname.split('/').filter(segment => segment.startsWith('(') && segment.endsWith(')'));
return {
currentRoute: pathname,
params: router.query || {},
searchParams,
layoutNesting: document.querySelectorAll('[data-nextjs-layout]').length,
parallelRoutes,
interceptedRoutes,
routeGroups,
dynamicSegments
};
});
}
// Helper methods for configuration analysis
async getFrameworkVersion() {
return this.config?.version || 'Unknown';
}
async getRenderingType() {
return this.config?.rendering || 'Unknown';
}
async getBuildMode() {
return this.config?.buildMode || 'Unknown';
}
async isAppRouter() {
return this.config?.rendering === 'App Router';
}
async isPagesRouter() {
return this.config?.rendering === 'Pages Router';
}
}
//# sourceMappingURL=nextjs-core-config.js.map