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
77 lines (60 loc) • 2.26 kB
JavaScript
import { readdir, readFile, writeFile } from 'fs/promises';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
async function fixImportsInFile(filePath) {
try {
const content = await readFile(filePath, 'utf-8');
// Regular expression to match relative imports without .js extension
// Matches: import ... from './path' or from '../path'
const importRegex = /(import\s+(?:[\s\S]*?)\s+from\s+['"])(\.\.?\/[^'"]+?)(?<!\.js)(['"];)/g;
let modified = false;
const newContent = content.replace(importRegex, (match, prefix, importPath, suffix) => {
// Skip if it's importing a directory index (ends with /)
if (importPath.endsWith('/')) {
return match;
}
// Skip if it already has an extension
if (importPath.match(/\.\w+$/)) {
return match;
}
modified = true;
return `${prefix}${importPath}.js${suffix}`;
});
if (modified) {
await writeFile(filePath, newContent, 'utf-8');
console.log(`✅ Fixed imports in: ${filePath}`);
}
return modified;
} catch (error) {
console.error(`Error processing ${filePath}:`, error);
return false;
}
}
async function processDirectory(dir) {
const entries = await readdir(dir, { withFileTypes: true });
let totalFixed = 0;
for (const entry of entries) {
const fullPath = join(dir, entry.name);
if (entry.isDirectory() && !entry.name.includes('node_modules')) {
totalFixed += await processDirectory(fullPath);
} else if (entry.isFile() && entry.name.endsWith('.js') && !entry.name.endsWith('.d.ts')) {
const fixed = await fixImportsInFile(fullPath);
if (fixed) totalFixed++;
}
}
return totalFixed;
}
async function main() {
const distPath = join(__dirname, '..', 'dist');
console.log('🔧 Fixing ES module imports...');
const totalFixed = await processDirectory(distPath);
if (totalFixed > 0) {
console.log(`\n✨ Fixed imports in ${totalFixed} file(s)`);
} else {
console.log('\n✨ All imports are already correct');
}
}
main().catch(console.error);