Files
ruflo/v2/scripts/fix-duplicate-imports.js
T
rUvandClaude Opus 4.5 1b6a1971f7 feat(v3): add comprehensive v3 implementation plans and swarm architecture
- Reorganize v3/ into implementation/ subfolders:
  - planning/, architecture/, migration/, integration/
  - security/, adrs/, research/, swarm-plans/

- Add 15-agent concurrent swarm implementation plans:
  - SWARM-OVERVIEW.md: Hierarchical mesh topology, 4 phases
  - AGENT-SPECIFICATIONS.md: 15 agent configs with capabilities
  - TDD-LONDON-SCHOOL-PLAN.md: Mock-first TDD methodology
  - BENCHMARK-OPTIMIZATION.md: Performance targets (2.49x-7.47x)
  - DEPLOYMENT-PLAN.md: Release strategy, CI/CD, rollback
  - GITHUB-ISSUE-TRACKING.md: Issue workflow with agent replies

- Update .claude/settings.json with proper hooks format
- Add bash aliases for claude --dangerously-skip-permissions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-04 15:40:51 +00:00

114 lines
3.3 KiB
JavaScript

#!/usr/bin/env node
/**
* Script to fix duplicate imports in the codebase
*/
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
async function removeDuplicateImports(filePath) {
try {
let content = await fs.readFile(filePath, 'utf-8');
let modified = false;
// Remove duplicate error handler imports
const errorHandlerRegex = /import\s+{\s*getErrorMessage\s*}\s+from\s+['"].*?error-handler\.js['"];\s*\n/g;
const matches = content.match(errorHandlerRegex);
if (matches && matches.length > 1) {
// Keep only the first import
let firstFound = false;
content = content.replace(errorHandlerRegex, (match) => {
if (!firstFound) {
firstFound = true;
return match;
}
modified = true;
return '';
});
}
// Remove duplicate fs imports
const fsImportRegex = /import\s+{\s*promises\s+as\s+fs\s*}\s+from\s+['"]node:fs['"];\s*\n/g;
const fsMatches = content.match(fsImportRegex);
if (fsMatches && fsMatches.length > 1) {
// Keep only the first import
let firstFound = false;
content = content.replace(fsImportRegex, (match) => {
if (!firstFound) {
firstFound = true;
return match;
}
modified = true;
return '';
});
}
// Fix duplicate type imports
const typeImportRegex = /import\s+type\s+{\s*([^}]+)\s*}\s+from\s+['"]([^'"]+)['"];\s*\n/g;
const typeImports = new Map();
content = content.replace(typeImportRegex, (match, types, from) => {
const key = from;
if (typeImports.has(key)) {
// Merge with existing import
const existing = typeImports.get(key);
const newTypes = types.split(',').map(t => t.trim());
const existingTypes = existing.split(',').map(t => t.trim());
const allTypes = [...new Set([...existingTypes, ...newTypes])];
typeImports.set(key, allTypes.join(', '));
modified = true;
return '';
} else {
typeImports.set(key, types);
return match;
}
});
if (modified) {
await fs.writeFile(filePath, content);
console.log(`✅ Fixed duplicate imports in: ${filePath}`);
}
} catch (error) {
console.error(`❌ Error processing ${filePath}:`, error.message);
}
}
async function findTypeScriptFiles(dir) {
const files = [];
const entries = await fs.readdir(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = join(dir, entry.name);
if (entry.isDirectory() && !entry.name.includes('node_modules') && !entry.name.includes('dist')) {
files.push(...await findTypeScriptFiles(fullPath));
} else if (entry.isFile() && entry.name.endsWith('.ts')) {
files.push(fullPath);
}
}
return files;
}
async function main() {
const srcDir = join(dirname(__dirname), 'src');
const files = await findTypeScriptFiles(srcDir);
console.log(`Found ${files.length} TypeScript files to check...`);
for (const file of files) {
await removeDuplicateImports(file);
}
console.log('✅ Duplicate import fixes complete!');
}
main().catch(console.error);