UNPKG

@davidlj95/ngx-meta

Version:

Set your Angular site's metadata: standard meta tags, Open Graph, Twitter Cards, JSON-LD structured data and more. Supports SSR (and Angular Universal). Use a service. Use routes' data. Set it up in a flash! 🚀

46 lines • 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateImports = void 0; const typescript_1 = require("typescript"); const change_1 = require("../../external-utils/schematics/angular/utility/change"); const is_defined_1 = require("../../utils/is-defined"); const maybe_get_new_identifier_from_old_identifier_1 = require("./maybe-get-new-identifier-from-old-identifier"); const updateImports = (sourceFile, filePath, logger) => { const importStatements = sourceFile.statements.filter(typescript_1.isImportDeclaration); const libraryImportStatements = importStatements.filter((importStatement) => (0, typescript_1.isStringLiteral)(importStatement.moduleSpecifier) && importStatement.moduleSpecifier.text.startsWith('@davidlj95/ngx-meta')); /* istanbul ignore next - perf opt */ if (!libraryImportStatements.length) { return []; } const libraryNamedImports = libraryImportStatements .map((importStatement) => { var _a; /* istanbul ignore next - quite safe */ return ((_a = importStatement.importClause) === null || _a === void 0 ? void 0 : _a.namedBindings) && (0, typescript_1.isNamedImports)(importStatement.importClause.namedBindings) ? importStatement.importClause.namedBindings : undefined; }) .filter(is_defined_1.isDefined); if (libraryNamedImports.length != libraryImportStatements.length) { logger.warn([ `Some non-named imports of the library detected in ${filePath}`, 'This is not the recommended usage. You should use named imports for tree-shaking purposes', ].join('\n')); } return libraryNamedImports .map((libraryNamedImport) => libraryNamedImport.elements .map((element) => { const identifier = element.name.text; const maybeNewIdentifier = (0, maybe_get_new_identifier_from_old_identifier_1.maybeGetNewIdentifierFromOldIdentifier)(identifier); if (!maybeNewIdentifier) { return; } return new change_1.ReplaceChange(filePath, element.getStart(), identifier, maybeNewIdentifier); }) .filter(is_defined_1.isDefined)) .flatMap((x) => x); }; exports.updateImports = updateImports; //# sourceMappingURL=update-imports.js.map