Merge pull request #4577 from vparomskiy/master

enhance widget extension loading
This commit is contained in:
Igor Kulikov 2021-05-28 12:48:59 +03:00 committed by GitHub
commit ed9555101e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 6 deletions

View File

@ -134,6 +134,7 @@ export class ResourcesService {
try {
modules = this.extractNgModules(module);
} catch (e) {
console.error(e);
}
if (modules && modules.length) {
import('@angular/compiler').then(
@ -172,22 +173,44 @@ export class ResourcesService {
(e) => {
this.loadedModules[url].error(new Error(`Unable to load module from url: ${url}`));
delete this.loadedModules[url];
console.error(`Unable to load module from url: ${url}`, e);
}
);
return subject.asObservable();
}
private extractNgModules(module: any, modules: Type<any>[] = [] ): Type<any>[] {
private extractNgModules(module: any, modules: Type<any>[] = []): Type<any>[] {
try {
let potentialModules = [module];
let currentScanDepth = 0;
while(potentialModules.length && currentScanDepth < 10) {
let newPotentialModules = [];
for (const module of potentialModules) {
if (module && 'ɵmod' in module) {
modules.push(module);
} else {
for (const k of Object.keys(module)) {
this.extractNgModules(module[k], modules);
if(!this.isPrimitive(module[k])) {
newPotentialModules.push(module[k]);
}
}
}
}
potentialModules = newPotentialModules;
currentScanDepth++;
}
} catch(e) {
console.log('Could not load NgModule', e);
}
return modules;
}
private isPrimitive(test) {
return test !== Object(test);
}
private loadResourceByType(type: 'css' | 'js', url: string): Observable<any> {
const subject = new ReplaySubject();
this.loadedResources[url] = subject;

View File

@ -70,6 +70,8 @@ import * as TbCore from '@core/public-api';
import * as TbShared from '@shared/public-api';
import * as TbHomeComponents from '@home/components/public-api';
import * as _moment from 'moment';
import * as DragDropModule from "@angular/cdk/drag-drop";
import * as HttpClientModule from "@angular/common/http";
declare const SystemJS;
@ -77,6 +79,7 @@ export const modulesMap: {[key: string]: any} = {
'@angular/animations': SystemJS.newModule(AngularAnimations),
'@angular/core': SystemJS.newModule(AngularCore),
'@angular/common': SystemJS.newModule(AngularCommon),
'@angular/common/http': SystemJS.newModule(HttpClientModule),
'@angular/forms': SystemJS.newModule(AngularForms),
'@angular/flex-layout': SystemJS.newModule(AngularFlexLayout),
'@angular/platform-browser': SystemJS.newModule(AngularPlatformBrowser),
@ -87,6 +90,7 @@ export const modulesMap: {[key: string]: any} = {
'@angular/cdk/layout': SystemJS.newModule(AngularCdkLayout),
'@angular/cdk/overlay': SystemJS.newModule(AngularCdkOverlay),
'@angular/cdk/portal': SystemJS.newModule(AngularCdkPortal),
'@angular/cdk/drag-drop': SystemJS.newModule(DragDropModule),
'@angular/material/autocomplete': SystemJS.newModule(AngularMaterialAutocomplete),
'@angular/material/badge': SystemJS.newModule(AngularMaterialBadge),
'@angular/material/bottom-sheet': SystemJS.newModule(AngularMaterialBottomSheet),