@weverson_na/prisma-generator-nestjs-dto
Version:
Advanced Prisma Generator with Smart Merge v2: Creates DTO and Entity classes with AST-based preservation, intelligent import management, and modular architecture for NestJS
40 lines (39 loc) • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ImportMerger = void 0;
class ImportMerger {
ensureImportsFromDeclaration(file, imp) {
const moduleSpecifier = imp.getModuleSpecifierValue();
for (const named of imp.getNamedImports()) {
this.ensureImport(file, named.getName(), moduleSpecifier);
}
}
ensureImport(file, named, moduleSpecifier) {
const imp = file.getImportDeclaration((d) => d.getModuleSpecifierValue() === moduleSpecifier);
if (!imp) {
file.addImportDeclaration({ namedImports: [named], moduleSpecifier });
}
else if (!imp.getNamedImports().some((n) => n.getName() === named)) {
imp.addNamedImport(named);
}
}
removeImport(file, named, moduleSpecifier) {
const imp = file.getImportDeclaration((d) => d.getModuleSpecifierValue() === moduleSpecifier);
if (!imp)
return;
const stillUsed = this.isImportStillUsed(file, named);
if (stillUsed)
return;
imp.getNamedImports().forEach((n) => {
if (n.getName() === named)
n.remove();
});
if (imp.getNamedImports().length === 0) {
imp.remove();
}
}
isImportStillUsed(file, importName) {
return file.getFullText().includes(importName);
}
}
exports.ImportMerger = ImportMerger;