From 393a231858b1ee1399d80c37f74fce0fb5f9b0b7 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Fri, 1 Nov 2024 18:01:51 +0200 Subject: [PATCH] Improve angular esbuild in production mode by removing slow performance sideEffects check code. Remove ts-transformer-keys -> replace with object.keys(). --- ui-ngx/package.json | 1 - ui-ngx/patches/@angular+build+18.2.10.patch | 19 ++++++++++- ui-ngx/src/app/core/utils.ts | 8 ++++- .../vc/entity-version-diff.component.ts | 2 +- .../map/map-provider-settings.component.ts | 19 ++++++----- .../settings/map/map-settings.component.ts | 29 +++++++++------- ...rip-animation-widget-settings.component.ts | 33 +++++++++++-------- .../json-form/json-form.component.ts | 2 +- ui-ngx/yarn.lock | 5 --- 9 files changed, 73 insertions(+), 45 deletions(-) diff --git a/ui-ngx/package.json b/ui-ngx/package.json index 36bae3bbe0..ee2eb448f1 100644 --- a/ui-ngx/package.json +++ b/ui-ngx/package.json @@ -105,7 +105,6 @@ "tinycolor2": "^1.6.0", "tinymce": "~6.8.5", "tooltipster": "^4.2.8", - "ts-transformer-keys": "^0.4.4", "tslib": "^2.7.0", "tv4": "^1.3.0", "typeface-roboto": "^1.1.13", diff --git a/ui-ngx/patches/@angular+build+18.2.10.patch b/ui-ngx/patches/@angular+build+18.2.10.patch index 378822001b..17b84e45c6 100644 --- a/ui-ngx/patches/@angular+build+18.2.10.patch +++ b/ui-ngx/patches/@angular+build+18.2.10.patch @@ -12,7 +12,7 @@ index 625c621..4fc8bd8 100755 } async diagnoseFiles(modes = DiagnosticModes.All) { diff --git a/node_modules/@angular/build/src/tools/esbuild/angular/compiler-plugin.js b/node_modules/@angular/build/src/tools/esbuild/angular/compiler-plugin.js -index b1bb6ea..e946fd1 100755 +index b1bb6ea..c76b4c6 100755 --- a/node_modules/@angular/build/src/tools/esbuild/angular/compiler-plugin.js +++ b/node_modules/@angular/build/src/tools/esbuild/angular/compiler-plugin.js @@ -79,7 +79,7 @@ function createCompilerPlugin(pluginOptions, styleOptions) { @@ -24,3 +24,20 @@ index b1bb6ea..e946fd1 100755 }, environment_options_1.maxWorkers, cacheStore?.createCache('jstransformer')); // Setup defines based on the values used by the Angular compiler-cli build.initialOptions.define ??= {}; +@@ -377,12 +377,14 @@ function createCompilerPlugin(pluginOptions, styleOptions) { + async function hasSideEffects(path) { + if (!pluginOptions.advancedOptimizations) { + return undefined; ++ } else { ++ return true; + } +- const { sideEffects } = await build.resolve(path, { ++ /*const { sideEffects } = await build.resolve(path, { + kind: 'import-statement', + resolveDir: build.initialOptions.absWorkingDir ?? '', + }); +- return sideEffects; ++ return sideEffects;*/ + } + }, + }; diff --git a/ui-ngx/src/app/core/utils.ts b/ui-ngx/src/app/core/utils.ts index de7b44b1e9..43030a19f6 100644 --- a/ui-ngx/src/app/core/utils.ts +++ b/ui-ngx/src/app/core/utils.ts @@ -895,4 +895,10 @@ export const convertKeysToCamelCase = (obj: Record): Record _.camelCase(key)); }; -export const unwrapModule = (module: any) : any => 'default' in module ? module.default : module; +export const unwrapModule = (module: any) : any => { + if ('default' in module && Object.keys(module).length === 1) { + return module.default; + } else { + return module; + } +}; diff --git a/ui-ngx/src/app/modules/home/components/vc/entity-version-diff.component.ts b/ui-ngx/src/app/modules/home/components/vc/entity-version-diff.component.ts index 9bb0a37066..2e09e54251 100644 --- a/ui-ngx/src/app/modules/home/components/vc/entity-version-diff.component.ts +++ b/ui-ngx/src/app/modules/home/components/vc/entity-version-diff.component.ts @@ -121,7 +121,7 @@ export class EntityVersionDiffComponent extends PageComponent implements OnInit, this.popoverComponent.updatePosition(); } setTimeout(() => { - this.differ = new aceDiff.default( + this.differ = new aceDiff( { element: this.diffViewerElmRef.nativeElement, mode: 'ace/mode/json', diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/map/map-provider-settings.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/map/map-provider-settings.component.ts index 4207804f0e..0f0fe7cc76 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/map/map-provider-settings.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/map/map-provider-settings.component.ts @@ -29,6 +29,10 @@ import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { TranslateService } from '@ngx-translate/core'; import { + defaultGoogleMapProviderSettings, + defaultHereMapProviderSettings, + defaultImageMapProviderSettings, + defaultOpenStreetMapProviderSettings, defaultTencentMapProviderSettings, GoogleMapProviderSettings, HereMapProviderSettings, ImageMapProviderSettings, @@ -39,7 +43,6 @@ import { TencentMapProviderSettings } from '@home/components/widget/lib/maps/map-models'; import { extractType } from '@core/utils'; -//import { keys } from 'ts-transformer-keys'; import { IAliasController } from '@core/api/widget-api.models'; @Component({ @@ -128,13 +131,11 @@ export class MapProviderSettingsComponent extends PageComponent implements OnIni writeValue(value: MapProviderSettings): void { this.modelValue = value; const provider = value?.provider; - // TODO: ts-transformer - - /*const googleProviderSettings = extractType(value, keys()); - const openstreetProviderSettings = extractType(value, keys()); - const hereProviderSettings = extractType(value, keys()); - const imageMapProviderSettings = extractType(value, keys()); - const tencentMapProviderSettings = extractType(value, keys()); + const googleProviderSettings = extractType(value, Object.keys(defaultGoogleMapProviderSettings) as (keyof GoogleMapProviderSettings)[]); + const openstreetProviderSettings = extractType(value, Object.keys(defaultOpenStreetMapProviderSettings) as (keyof OpenStreetMapProviderSettings)[]); + const hereProviderSettings = extractType(value, Object.keys(defaultHereMapProviderSettings) as (keyof HereMapProviderSettings)[]); + const imageMapProviderSettings = extractType(value, Object.keys(defaultImageMapProviderSettings) as (keyof ImageMapProviderSettings)[]); + const tencentMapProviderSettings = extractType(value, Object.keys(defaultTencentMapProviderSettings) as (keyof TencentMapProviderSettings)[]); this.providerSettingsFormGroup.patchValue( { provider, @@ -144,7 +145,7 @@ export class MapProviderSettingsComponent extends PageComponent implements OnIni imageMapProviderSettings, tencentMapProviderSettings }, {emitEvent: false} - );*/ + ); this.updateValidators(false); } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/map/map-settings.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/map/map-settings.component.ts index 0a9462e397..2bd3a78560 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/map/map-settings.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/map/map-settings.component.ts @@ -17,11 +17,11 @@ import { Component, forwardRef, Input, OnInit } from '@angular/core'; import { ControlValueAccessor, + NG_VALIDATORS, + NG_VALUE_ACCESSOR, UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, - NG_VALIDATORS, - NG_VALUE_ACCESSOR, Validator } from '@angular/forms'; import { PageComponent } from '@shared/components/page.component'; @@ -31,6 +31,13 @@ import { TranslateService } from '@ngx-translate/core'; import { CircleSettings, CommonMapSettings, + defaultCircleSettings, + defaultCommonMapSettings, + defaultMapEditorSettings, + defaultMapProviderSettings, + defaultMarkerClusteringSettings, + defaultMarkersSettings, + defaultPolygonSettings, MapEditorSettings, MapProviders, MapProviderSettings, @@ -41,7 +48,6 @@ import { UnitedMapSettings } from '@home/components/widget/lib/maps/map-models'; import { extractType } from '@core/utils'; -// import { keys } from 'ts-transformer-keys'; import { IAliasController } from '@core/api/widget-api.models'; import { Widget } from '@shared/models/widget.models'; @@ -140,13 +146,12 @@ export class MapSettingsComponent extends PageComponent implements OnInit, Contr writeValue(value: UnitedMapSettings): void { this.modelValue = value; - // TODO: ts-transformer - /* const mapProviderSettings = extractType(value, keys()); - const commonMapSettings = extractType(value, keys()); - const markersSettings = extractType(value, keys()); - const polygonSettings = extractType(value, keys()); - const circleSettings = extractType(value, keys()); - const mapEditorSettings = extractType(value, keys()); + const mapProviderSettings = extractType(value, Object.keys(defaultMapProviderSettings) as (keyof MapProviderSettings)[]); + const commonMapSettings = extractType(value, Object.keys(defaultCommonMapSettings) as (keyof CommonMapSettings)[]); + const markersSettings = extractType(value, Object.keys(defaultMarkersSettings) as (keyof MarkersSettings)[]); + const polygonSettings = extractType(value, Object.keys(defaultPolygonSettings) as (keyof PolygonSettings)[]); + const circleSettings = extractType(value, Object.keys(defaultCircleSettings) as (keyof CircleSettings)[]); + const mapEditorSettings = extractType(value, Object.keys(defaultMapEditorSettings) as (keyof MapEditorSettings)[]); const formValue = { mapProviderSettings, commonMapSettings, @@ -158,9 +163,9 @@ export class MapSettingsComponent extends PageComponent implements OnInit, Contr if (this.routeMap) { formValue.routeMapSettings = extractType(value, ['strokeWeight', 'strokeOpacity']); } else { - formValue.markerClusteringSettings = extractType(value, keys()); + formValue.markerClusteringSettings = extractType(value, Object.keys(defaultMarkerClusteringSettings) as (keyof MarkerClusteringSettings)[]); } - this.mapSettingsFormGroup.patchValue( formValue, {emitEvent: false} ); */ + this.mapSettingsFormGroup.patchValue( formValue, {emitEvent: false} ); this.updateValidators(false); } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/map/trip-animation-widget-settings.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/map/trip-animation-widget-settings.component.ts index 7e1f99b489..ab4ab92e17 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/map/trip-animation-widget-settings.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/map/trip-animation-widget-settings.component.ts @@ -21,16 +21,22 @@ import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { CircleSettings, + CommonMapSettings, + defaultCircleSettings, + defaultCommonMapSettings, + defaultMapProviderSettings, + defaultMarkersSettings, + defaultPolygonSettings, + defaultTripAnimationPathSettings, + defaultTripAnimationPointSettings, defaultTripAnimationSettings, MapProviderSettings, + MarkersSettings, PointsSettings, PolygonSettings, - PolylineSettings, - TripAnimationCommonSettings, - TripAnimationMarkerSettings + PolylineSettings } from 'src/app/modules/home/components/widget/lib/maps/map-models'; import { extractType } from '@core/utils'; -// import { keys } from 'ts-transformer-keys'; @Component({ selector: 'tb-trip-animation-widget-settings', @@ -69,22 +75,21 @@ export class TripAnimationWidgetSettingsComponent extends WidgetSettingsComponen } protected prepareInputSettings(settings: WidgetSettings): WidgetSettings { - // TODO: ts-transformer - /*const mapProviderSettings = extractType(settings, keys()); - const commonMapSettings = extractType(settings, keys()); - const markersSettings = extractType(settings, keys()); - const pathSettings = extractType(settings, keys()); - const pointSettings = extractType(settings, keys()); - const polygonSettings = extractType(settings, keys()); - const circleSettings = extractType(settings, keys());*/ + const mapProviderSettings = extractType(settings, Object.keys(defaultMapProviderSettings) as (keyof MapProviderSettings)[]); + const commonMapSettings = extractType(settings, Object.keys(defaultCommonMapSettings) as (keyof CommonMapSettings)[]); + const markersSettings = extractType(settings, Object.keys(defaultMarkersSettings) as (keyof MarkersSettings)[]); + const pathSettings = extractType(settings, Object.keys(defaultTripAnimationPathSettings) as (keyof PolylineSettings)[]); + const pointSettings = extractType(settings, Object.keys(defaultTripAnimationPointSettings) as (keyof PointsSettings)[]); + const polygonSettings = extractType(settings, Object.keys(defaultPolygonSettings) as (keyof PolygonSettings)[]); + const circleSettings = extractType(settings, Object.keys(defaultCircleSettings) as (keyof CircleSettings)[]); return { - /*mapProviderSettings, + mapProviderSettings, commonMapSettings, markersSettings, pathSettings, pointSettings, polygonSettings, - circleSettings*/ + circleSettings }; } diff --git a/ui-ngx/src/app/shared/components/json-form/json-form.component.ts b/ui-ngx/src/app/shared/components/json-form/json-form.component.ts index 697ef3254a..682a88ba98 100644 --- a/ui-ngx/src/app/shared/components/json-form/json-form.component.ts +++ b/ui-ngx/src/app/shared/components/json-form/json-form.component.ts @@ -272,7 +272,7 @@ export class JsonFormComponent implements ControlValueAccessor, Validator, OnCha (modules) => { const react = unwrapModule(modules[0]); const reactDomClient = unwrapModule(modules[2]); - const jsonFormReact = modules[3].default; + const jsonFormReact = unwrapModule(modules[3]); this.reactRoot = reactDomClient.createRoot(this.reactRootElmRef.nativeElement); this.reactRoot.render(react.createElement(jsonFormReact, this.formProps)); } diff --git a/ui-ngx/yarn.lock b/ui-ngx/yarn.lock index cb602e6103..28b7cb2bd0 100644 --- a/ui-ngx/yarn.lock +++ b/ui-ngx/yarn.lock @@ -10239,11 +10239,6 @@ ts-node@^10.0.0, ts-node@^10.9.2: v8-compile-cache-lib "^3.0.1" yn "3.1.1" -ts-transformer-keys@^0.4.4: - version "0.4.4" - resolved "https://registry.yarnpkg.com/ts-transformer-keys/-/ts-transformer-keys-0.4.4.tgz#c185508b3ae9b79236aac58f788c85ca3ac807d7" - integrity sha512-LrqgvaFvar01/5mbunRyeLTSIkqoC2xfcpL/90aDY6vR07DGyH+UaYGdIEsUudnlAw2Sr0pxFgdZvE0QIyI4qA== - tsconfig-paths@^3.15.0: version "3.15.0" resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz#5299ec605e55b1abb23ec939ef15edaf483070d4"