@rxap/schematics-ts-morph
Version:
This package provides utilities for manipulating TypeScript code using ts-morph, particularly for Angular and NestJS projects. It offers functions to add, coerce, and modify code elements like classes, methods, decorators, and imports. The package also in
27 lines • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoerceImports = CoerceImports;
/**
* @deprecated import from @rxap/ts-morph
*/
function CoerceImports(sourceFile, structures) {
for (const structure of Array.isArray(structures) ? structures : [structures]) {
const moduleSpecifier = structure.moduleSpecifier.endsWith('.ts') ? structure.moduleSpecifier.replace(/\.ts$/, '') : structure.moduleSpecifier;
const namedImports = structure.namedImports;
if (!moduleSpecifier ||
!(Array.isArray(namedImports) && namedImports.every((named) => typeof named === 'string')) ||
!sourceFile.getImportDeclaration(moduleSpecifier)) {
sourceFile.addImportDeclaration(structure);
}
else {
const importDeclaration = sourceFile.getImportDeclaration(moduleSpecifier);
const existingImports = importDeclaration.getNamedImports();
for (const named of namedImports) {
if (!existingImports.some((existing) => existing.getName() === named)) {
importDeclaration.addNamedImport(named);
}
}
}
}
}
//# sourceMappingURL=coerce-imports.js.map