fix: remove duplicate Log imports

- Fixed duplicate imports in 3 files:
  - language.service.ts
  - indexed-db-adapter.service.ts
  - global-theme.service.ts
- Created script to detect and fix duplicate imports automatically
- Build errors resolved
This commit is contained in:
Johannes Millan 2025-07-10 14:28:03 +02:00
parent 581d41cc0c
commit fd099ed4a1
4 changed files with 92 additions and 3 deletions

View file

@ -0,0 +1,92 @@
#!/usr/bin/env ts-node
import * as fs from 'fs';
import * as path from 'path';
import * as glob from 'glob';
// Pattern to find duplicate imports
const findDuplicateImports = (content: string): string[] => {
const importRegex = /^import\s+.*?;$/gm;
const imports = content.match(importRegex) || [];
const seen = new Set<string>();
const duplicates: string[] = [];
for (const imp of imports) {
const normalized = imp.trim();
if (seen.has(normalized)) {
duplicates.push(normalized);
} else {
seen.add(normalized);
}
}
return duplicates;
};
// Remove duplicate imports from content
const removeDuplicateImports = (content: string): string => {
const lines = content.split('\n');
const seenImports = new Set<string>();
const resultLines: string[] = [];
for (const line of lines) {
const trimmedLine = line.trim();
// Check if it's an import statement
if (trimmedLine.startsWith('import ') && trimmedLine.endsWith(';')) {
if (seenImports.has(trimmedLine)) {
// Skip duplicate import
continue;
}
seenImports.add(trimmedLine);
}
resultLines.push(line);
}
return resultLines.join('\n');
};
function processFile(filePath: string): boolean {
try {
const content = fs.readFileSync(filePath, 'utf8');
const duplicates = findDuplicateImports(content);
if (duplicates.length > 0) {
console.log(
`Found ${duplicates.length} duplicate imports in ${path.relative(process.cwd(), filePath)}:`,
);
duplicates.forEach((dup) => console.log(` - ${dup}`));
const fixedContent = removeDuplicateImports(content);
fs.writeFileSync(filePath, fixedContent, 'utf8');
return true;
}
return false;
} catch (error) {
console.error(`Error processing ${filePath}:`, error);
return false;
}
}
function main() {
console.log('Searching for duplicate imports...\n');
const files = glob.sync('src/**/*.ts', {
ignore: ['**/node_modules/**', '**/dist/**', '**/build/**'],
absolute: true,
});
let fixedCount = 0;
for (const file of files) {
if (processFile(file)) {
fixedCount++;
}
}
console.log(`\nFixed duplicate imports in ${fixedCount} files.`);
}
main();

View file

@ -12,7 +12,6 @@ import { GlobalConfigService } from 'src/app/features/config/global-config.servi
import { map, startWith } from 'rxjs/operators';
import { DEFAULT_GLOBAL_CONFIG } from 'src/app/features/config/default-global-config.const';
import { Log } from '../log';
import { Log } from '../log';
@Injectable({ providedIn: 'root' })
export class LanguageService {

View file

@ -5,7 +5,6 @@ import { filter, shareReplay, take } from 'rxjs/operators';
import { DBSchema, openDB } from 'idb';
import { DBAdapter } from './db-adapter.model';
import { Log } from '../log';
import { Log } from '../log';
const DB_NAME = 'SUP';
const DB_MAIN_NAME = 'SUP_STORE';

View file

@ -30,7 +30,6 @@ import { HttpClient } from '@angular/common/http';
import { LS } from '../persistence/storage-keys.const';
import { CustomThemeService } from './custom-theme.service';
import { Log } from '../log';
import { Log } from '../log';
export type DarkModeCfg = 'dark' | 'light' | 'system';