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
150 lines • 5.32 kB
JavaScript
/**
* NextJSConfigDetector - Detects and analyzes Next.js configuration
*
* This module is responsible for:
* - Detecting Next.js framework presence
* - Identifying App Router vs Pages Router
* - Extracting configuration details
* - Determining build mode and experimental features
*/
export class NextJSConfigDetector {
config;
/**
* Detect Next.js configuration from the page
*/
async detectConfig(page) {
try {
const configData = await 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';
// Try to get version from Next.js runtime
if (nextData?.buildId) {
version = nextData.nextExport ? '13+' : '12+';
}
// Check for build manifest
if (buildManifest) {
if (buildManifest.devFiles) {
version = '13+';
}
if (buildManifest.appDir) {
version = '13.4+';
}
}
// Detect if using App Router or Pages Router
let rendering = 'Pages Router';
// Check for App Router indicators
if (nextData?.page?.startsWith('/_not-found') ||
nextData?.page?.includes('app/') ||
window.__next_app__?.tree) {
rendering = 'App Router';
}
// Check if app directory is being used
if (buildManifest?.appDir ||
document.querySelector('[data-nextjs-scroll-focus-boundary]')) {
rendering = 'App Router';
}
// Detect build mode
const buildMode = process?.env?.NODE_ENV === 'production' ? 'production' : 'development';
// Extract config details
const config = {
reactStrictMode: !!window.__NEXT_STRICT_MODE__,
experimental: [],
images: nextData?.images || undefined,
basePath: nextData?.basePath || undefined,
assetPrefix: nextData?.assetPrefix || undefined,
i18n: nextData?.locale ? {
locale: nextData.locale,
locales: nextData.locales,
defaultLocale: nextData.defaultLocale
} : undefined
};
// Detect experimental features
if (window.__NEXT_DATA__?.appGip) {
config.experimental.push('appDir');
}
if (window.__SERVER_ACTIONS_ENABLED__) {
config.experimental.push('serverActions');
}
if (document.querySelector('[data-nextjs-ppr]')) {
config.experimental.push('ppr');
}
// Check for other experimental features from meta tags
const experimentalMeta = document.querySelector('meta[name="next-experimental"]');
if (experimentalMeta) {
const features = experimentalMeta.getAttribute('content')?.split(',') || [];
config.experimental.push(...features);
}
if (!nextData && !buildManifest) {
return null; // Not a Next.js app
}
return {
framework: 'Next.js',
version,
rendering,
buildMode,
config
};
});
if (configData) {
this.config = configData;
}
return configData;
}
catch (error) {
console.error('Error detecting Next.js config:', error);
return null;
}
}
/**
* Check if the current page is a Next.js application
*/
isNextJSApp() {
return this.config?.framework === 'Next.js';
}
/**
* Get the detected configuration
*/
getConfig() {
return this.config || null;
}
/**
* Get the rendering mode (App Router vs Pages Router)
*/
getRenderingMode() {
return this.config?.rendering || null;
}
/**
* Get the Next.js version
*/
getVersion() {
return this.config?.version || null;
}
/**
* Get the build mode
*/
getBuildMode() {
return this.config?.buildMode || null;
}
/**
* Check if a specific experimental feature is enabled
*/
hasExperimentalFeature(feature) {
return this.config?.config.experimental.includes(feature) || false;
}
/**
* Get all enabled experimental features
*/
getExperimentalFeatures() {
return this.config?.config.experimental || [];
}
/**
* Reset the detector state
*/
reset() {
this.config = undefined;
}
}
//# sourceMappingURL=nextjs-config-detector.js.map