UNPKG

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

122 lines • 5.08 kB
/** * NextJS Configuration & Setup Module * * Handles configuration detection and basic setup for Next.js applications. * This module provides the foundation for all other NextJS debugging capabilities. */ export class NextJSConfigSetup { page; config; appRouterInfo; async attachToPage(page) { this.page = page; await this.detectNextJSConfig(); await this.setupBasicMonitoring(); } async getConfig() { return this.config || null; } async getAppRouterInfo() { return this.appRouterInfo || null; } async detectNextJSConfig() { if (!this.page) return; const config = await this.page.evaluate(() => { const nextData = window.__NEXT_DATA__; const buildManifest = window.__BUILD_MANIFEST; const reactVersion = window.React?.version; // Detect Next.js version from various sources let version = 'unknown'; if (nextData?.buildId) { version = nextData.buildId.includes('development') ? 'development' : 'production'; } // Try to get version from script tag const versionScript = document.querySelector('script[src*="_next/static/chunks/"]'); if (versionScript) { const match = versionScript.getAttribute('src')?.match(/\/([0-9]+\.[0-9]+\.[0-9]+)\//); if (match) version = match[1]; } const isAppRouter = !!window.__next_app__; const rendering = isAppRouter ? 'App Router' : 'Pages Router'; return { framework: 'Next.js', version, rendering, buildMode: (nextData?.buildId?.includes('development') ? 'development' : 'production'), config: { reactStrictMode: !!window.__NEXT_DATA__?.props?.pageProps?.reactStrictMode, experimental: nextData?.experimental || [], images: nextData?.images || {}, basePath: nextData?.basePath || '', assetPrefix: nextData?.assetPrefix || '', i18n: nextData?.i18n, redirects: nextData?.redirects || [], rewrites: nextData?.rewrites || [] } }; }); this.config = config; await this.detectAppRouterInfo(); } async detectAppRouterInfo() { if (!this.page || !this.config || this.config.rendering !== 'App Router') { this.appRouterInfo = undefined; return; } const appRouterInfo = await this.page.evaluate(() => { const nextData = window.__NEXT_DATA__; const router = window.__next_app__?.router; if (!router) return null; return { currentRoute: router.asPath || window.location.pathname, params: router.query || {}, searchParams: Object.fromEntries(new URLSearchParams(window.location.search)), layoutNesting: 1, // Default - could be enhanced parallelRoutes: [], interceptedRoutes: 0, routeGroups: [], dynamicSegments: [] }; }); this.appRouterInfo = appRouterInfo || undefined; } async setupBasicMonitoring() { if (!this.page) return; // Set up basic Next.js monitoring await this.page.evaluate(() => { // Monitor route changes if (window.__next_app__?.router) { const router = window.__next_app__.router; const originalPush = router.push; router.push = function (...args) { console.debug('Next.js Route Change:', args[0]); return originalPush.apply(this, args); }; } // Monitor hydration if (window.__NEXT_DATA__) { const observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { if (mutation.type === 'childList' && mutation.addedNodes.length > 0) { for (let i = 0; i < mutation.addedNodes.length; i++) { const node = mutation.addedNodes[i]; if (node.nodeType === Node.ELEMENT_NODE) { const element = node; if (element.hasAttribute('data-nextjs-scroll-focus-boundary')) { console.debug('Next.js Hydration Event'); } } } } }); }); observer.observe(document.body, { childList: true, subtree: true }); } }); } } //# sourceMappingURL=nextjs-config-setup.js.map