Commit ed9555101efc8af94befac40922306516f8e2ddf

Authored by Igor Kulikov
Committed by GitHub
2 parents 6ee12de3 668cfb49

Merge pull request #4577 from vparomskiy/master

enhance widget extension loading
... ... @@ -134,6 +134,7 @@ export class ResourcesService {
134 134 try {
135 135 modules = this.extractNgModules(module);
136 136 } catch (e) {
  137 + console.error(e);
137 138 }
138 139 if (modules && modules.length) {
139 140 import('@angular/compiler').then(
... ... @@ -172,22 +173,44 @@ export class ResourcesService {
172 173 (e) => {
173 174 this.loadedModules[url].error(new Error(`Unable to load module from url: ${url}`));
174 175 delete this.loadedModules[url];
  176 + console.error(`Unable to load module from url: ${url}`, e);
175 177 }
176 178 );
177 179 return subject.asObservable();
178 180 }
179 181
180   - private extractNgModules(module: any, modules: Type<any>[] = [] ): Type<any>[] {
181   - if (module && 'ɵmod' in module) {
182   - modules.push(module);
183   - } else {
184   - for (const k of Object.keys(module)) {
185   - this.extractNgModules(module[k], modules);
  182 + private extractNgModules(module: any, modules: Type<any>[] = []): Type<any>[] {
  183 + try {
  184 + let potentialModules = [module];
  185 + let currentScanDepth = 0;
  186 +
  187 + while(potentialModules.length && currentScanDepth < 10) {
  188 + let newPotentialModules = [];
  189 + for (const module of potentialModules) {
  190 + if (module && 'ɵmod' in module) {
  191 + modules.push(module);
  192 + } else {
  193 + for (const k of Object.keys(module)) {
  194 + if(!this.isPrimitive(module[k])) {
  195 + newPotentialModules.push(module[k]);
  196 + }
  197 + }
  198 + }
  199 + }
  200 +
  201 + potentialModules = newPotentialModules;
  202 + currentScanDepth++;
186 203 }
  204 + } catch(e) {
  205 + console.log('Could not load NgModule', e);
187 206 }
188 207 return modules;
189 208 }
190 209
  210 + private isPrimitive(test) {
  211 + return test !== Object(test);
  212 + }
  213 +
191 214 private loadResourceByType(type: 'css' | 'js', url: string): Observable<any> {
192 215 const subject = new ReplaySubject();
193 216 this.loadedResources[url] = subject;
... ...
... ... @@ -70,6 +70,8 @@ import * as TbCore from '@core/public-api';
70 70 import * as TbShared from '@shared/public-api';
71 71 import * as TbHomeComponents from '@home/components/public-api';
72 72 import * as _moment from 'moment';
  73 +import * as DragDropModule from "@angular/cdk/drag-drop";
  74 +import * as HttpClientModule from "@angular/common/http";
73 75
74 76 declare const SystemJS;
75 77
... ... @@ -77,6 +79,7 @@ export const modulesMap: {[key: string]: any} = {
77 79 '@angular/animations': SystemJS.newModule(AngularAnimations),
78 80 '@angular/core': SystemJS.newModule(AngularCore),
79 81 '@angular/common': SystemJS.newModule(AngularCommon),
  82 + '@angular/common/http': SystemJS.newModule(HttpClientModule),
80 83 '@angular/forms': SystemJS.newModule(AngularForms),
81 84 '@angular/flex-layout': SystemJS.newModule(AngularFlexLayout),
82 85 '@angular/platform-browser': SystemJS.newModule(AngularPlatformBrowser),
... ... @@ -87,6 +90,7 @@ export const modulesMap: {[key: string]: any} = {
87 90 '@angular/cdk/layout': SystemJS.newModule(AngularCdkLayout),
88 91 '@angular/cdk/overlay': SystemJS.newModule(AngularCdkOverlay),
89 92 '@angular/cdk/portal': SystemJS.newModule(AngularCdkPortal),
  93 + '@angular/cdk/drag-drop': SystemJS.newModule(DragDropModule),
90 94 '@angular/material/autocomplete': SystemJS.newModule(AngularMaterialAutocomplete),
91 95 '@angular/material/badge': SystemJS.newModule(AngularMaterialBadge),
92 96 '@angular/material/bottom-sheet': SystemJS.newModule(AngularMaterialBottomSheet),
... ...