1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.isComponentAlreadyDeclared = void 0;
|
4 | const core_1 = require("@angular/core");
|
5 | const reflectionCapabilities = new core_1.ɵReflectionCapabilities();
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const isComponentAlreadyDeclared = (componentToFind, moduleDeclarations, moduleImports) => {
|
12 | if (moduleDeclarations &&
|
13 | moduleDeclarations.some((declaration) => declaration === componentToFind)) {
|
14 |
|
15 | return true;
|
16 | }
|
17 | if (!moduleImports) {
|
18 | return false;
|
19 | }
|
20 | return moduleImports.some((importItem) => {
|
21 | const extractedNgModuleMetadata = extractNgModuleMetadata(importItem);
|
22 | if (!extractedNgModuleMetadata) {
|
23 |
|
24 | return false;
|
25 | }
|
26 | return (0, exports.isComponentAlreadyDeclared)(componentToFind, extractedNgModuleMetadata.declarations, extractedNgModuleMetadata.imports);
|
27 | });
|
28 | };
|
29 | exports.isComponentAlreadyDeclared = isComponentAlreadyDeclared;
|
30 | const extractNgModuleMetadata = (importItem) => {
|
31 | const target = importItem && importItem.ngModule ? importItem.ngModule : importItem;
|
32 | const decorators = reflectionCapabilities.annotations(target);
|
33 | if (!decorators || decorators.length === 0) {
|
34 | return null;
|
35 | }
|
36 | const ngModuleDecorator = decorators.find((decorator) => decorator instanceof core_1.NgModule);
|
37 | if (!ngModuleDecorator) {
|
38 | return null;
|
39 | }
|
40 | return ngModuleDecorator;
|
41 | };
|