Commit ed9555101efc8af94befac40922306516f8e2ddf
Committed by
GitHub
Merge pull request #4577 from vparomskiy/master
enhance widget extension loading
Showing
2 changed files
with
33 additions
and
6 deletions
@@ -134,6 +134,7 @@ export class ResourcesService { | @@ -134,6 +134,7 @@ export class ResourcesService { | ||
134 | try { | 134 | try { |
135 | modules = this.extractNgModules(module); | 135 | modules = this.extractNgModules(module); |
136 | } catch (e) { | 136 | } catch (e) { |
137 | + console.error(e); | ||
137 | } | 138 | } |
138 | if (modules && modules.length) { | 139 | if (modules && modules.length) { |
139 | import('@angular/compiler').then( | 140 | import('@angular/compiler').then( |
@@ -172,22 +173,44 @@ export class ResourcesService { | @@ -172,22 +173,44 @@ export class ResourcesService { | ||
172 | (e) => { | 173 | (e) => { |
173 | this.loadedModules[url].error(new Error(`Unable to load module from url: ${url}`)); | 174 | this.loadedModules[url].error(new Error(`Unable to load module from url: ${url}`)); |
174 | delete this.loadedModules[url]; | 175 | delete this.loadedModules[url]; |
176 | + console.error(`Unable to load module from url: ${url}`, e); | ||
175 | } | 177 | } |
176 | ); | 178 | ); |
177 | return subject.asObservable(); | 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 | return modules; | 207 | return modules; |
189 | } | 208 | } |
190 | 209 | ||
210 | + private isPrimitive(test) { | ||
211 | + return test !== Object(test); | ||
212 | + } | ||
213 | + | ||
191 | private loadResourceByType(type: 'css' | 'js', url: string): Observable<any> { | 214 | private loadResourceByType(type: 'css' | 'js', url: string): Observable<any> { |
192 | const subject = new ReplaySubject(); | 215 | const subject = new ReplaySubject(); |
193 | this.loadedResources[url] = subject; | 216 | this.loadedResources[url] = subject; |
@@ -70,6 +70,8 @@ import * as TbCore from '@core/public-api'; | @@ -70,6 +70,8 @@ import * as TbCore from '@core/public-api'; | ||
70 | import * as TbShared from '@shared/public-api'; | 70 | import * as TbShared from '@shared/public-api'; |
71 | import * as TbHomeComponents from '@home/components/public-api'; | 71 | import * as TbHomeComponents from '@home/components/public-api'; |
72 | import * as _moment from 'moment'; | 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 | declare const SystemJS; | 76 | declare const SystemJS; |
75 | 77 | ||
@@ -77,6 +79,7 @@ export const modulesMap: {[key: string]: any} = { | @@ -77,6 +79,7 @@ export const modulesMap: {[key: string]: any} = { | ||
77 | '@angular/animations': SystemJS.newModule(AngularAnimations), | 79 | '@angular/animations': SystemJS.newModule(AngularAnimations), |
78 | '@angular/core': SystemJS.newModule(AngularCore), | 80 | '@angular/core': SystemJS.newModule(AngularCore), |
79 | '@angular/common': SystemJS.newModule(AngularCommon), | 81 | '@angular/common': SystemJS.newModule(AngularCommon), |
82 | + '@angular/common/http': SystemJS.newModule(HttpClientModule), | ||
80 | '@angular/forms': SystemJS.newModule(AngularForms), | 83 | '@angular/forms': SystemJS.newModule(AngularForms), |
81 | '@angular/flex-layout': SystemJS.newModule(AngularFlexLayout), | 84 | '@angular/flex-layout': SystemJS.newModule(AngularFlexLayout), |
82 | '@angular/platform-browser': SystemJS.newModule(AngularPlatformBrowser), | 85 | '@angular/platform-browser': SystemJS.newModule(AngularPlatformBrowser), |
@@ -87,6 +90,7 @@ export const modulesMap: {[key: string]: any} = { | @@ -87,6 +90,7 @@ export const modulesMap: {[key: string]: any} = { | ||
87 | '@angular/cdk/layout': SystemJS.newModule(AngularCdkLayout), | 90 | '@angular/cdk/layout': SystemJS.newModule(AngularCdkLayout), |
88 | '@angular/cdk/overlay': SystemJS.newModule(AngularCdkOverlay), | 91 | '@angular/cdk/overlay': SystemJS.newModule(AngularCdkOverlay), |
89 | '@angular/cdk/portal': SystemJS.newModule(AngularCdkPortal), | 92 | '@angular/cdk/portal': SystemJS.newModule(AngularCdkPortal), |
93 | + '@angular/cdk/drag-drop': SystemJS.newModule(DragDropModule), | ||
90 | '@angular/material/autocomplete': SystemJS.newModule(AngularMaterialAutocomplete), | 94 | '@angular/material/autocomplete': SystemJS.newModule(AngularMaterialAutocomplete), |
91 | '@angular/material/badge': SystemJS.newModule(AngularMaterialBadge), | 95 | '@angular/material/badge': SystemJS.newModule(AngularMaterialBadge), |
92 | '@angular/material/bottom-sheet': SystemJS.newModule(AngularMaterialBottomSheet), | 96 | '@angular/material/bottom-sheet': SystemJS.newModule(AngularMaterialBottomSheet), |