From b2c0174269cf52d48b2e61b7e18f246d661cc6af Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 29 Sep 2023 17:25:29 +0200 Subject: [PATCH] fix: ensure log prefix helper is initialized at configuration handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- rollup.config.mjs | 6 +++--- src/utils/Configuration.ts | 23 ++++++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/rollup.config.mjs b/rollup.config.mjs index 40f1d679..ec98513a 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -26,7 +26,7 @@ const availableParallelism = () => { const isDevelopmentBuild = env.BUILD === 'development'; const isAnalyzeBuild = env.ANALYZE; -const sourceMap = !!isDevelopmentBuild; +const sourcemap = !!isDevelopmentBuild; export default defineConfig({ input: ['./src/start.ts', './src/charging-station/ChargingStationWorker.ts'], @@ -35,7 +35,7 @@ export default defineConfig({ { dir: './dist', format: 'esm', - sourcemap: sourceMap, + sourcemap, plugins: [terser({ maxWorkers: Math.floor(availableParallelism() / 2) })], }, ], @@ -78,7 +78,7 @@ export default defineConfig({ typescript({ tsconfig: './tsconfig.json', compilerOptions: { - sourceMap, + sourceMap: sourcemap, }, }), del({ diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 53eb720f..d994422b 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -42,6 +42,11 @@ type ConfigurationSectionType = | WorkerConfiguration | UIServerConfiguration; +// Avoid ESM race condition at class initialization +const configurationLogPrefix = (): string => { + return logPrefix(' Simulator configuration |'); +}; + export class Configuration { public static configurationChangeCallback: () => Promise; @@ -118,10 +123,6 @@ export class Configuration { ); } - private static logPrefix = (): string => { - return logPrefix(' Simulator configuration |'); - }; - private static isConfigurationSectionCached(sectionName: ConfigurationSection): boolean { return Configuration.configurationSectionCache.has(sectionName); } @@ -330,7 +331,7 @@ export class Configuration { (stationTemplateUrl: StationTemplateUrl) => { if (!isUndefined(stationTemplateUrl?.['numberOfStation' as keyof StationTemplateUrl])) { console.error( - `${chalk.green(Configuration.logPrefix())} ${chalk.red( + `${chalk.green(configurationLogPrefix())} ${chalk.red( `Deprecated configuration key 'numberOfStation' usage for template file '${stationTemplateUrl.file}' in 'stationTemplateUrls'. Use 'numberOfStations' instead`, )}`, ); @@ -410,7 +411,7 @@ export class Configuration { ('staticPool' as WorkerProcessType) ) { console.error( - `${chalk.green(Configuration.logPrefix())} ${chalk.red( + `${chalk.green(configurationLogPrefix())} ${chalk.red( `Deprecated configuration 'staticPool' value usage in worker section 'processType' field. Use '${WorkerProcessType.fixedPool}' value instead`, )}`, ); @@ -475,7 +476,7 @@ export class Configuration { // uiServer section if (hasOwnProp(Configuration.getConfigurationData(), 'uiWebSocketServer')) { console.error( - `${chalk.green(Configuration.logPrefix())} ${chalk.red( + `${chalk.green(configurationLogPrefix())} ${chalk.red( `Deprecated configuration section 'uiWebSocketServer' usage. Use '${ConfigurationSection.uiServer}' instead`, )}`, ); @@ -502,7 +503,7 @@ export class Configuration { ) ) { console.error( - `${chalk.green(Configuration.logPrefix())} ${chalk.red( + `${chalk.green(configurationLogPrefix())} ${chalk.red( `Deprecated configuration key '${key}' usage in section '${sectionName}'${ logMsgToAppend.trim().length > 0 ? `. ${logMsgToAppend}` : '' }`, @@ -512,7 +513,7 @@ export class Configuration { !isUndefined(Configuration.getConfigurationData()?.[key as keyof ConfigurationData]) ) { console.error( - `${chalk.green(Configuration.logPrefix())} ${chalk.red( + `${chalk.green(configurationLogPrefix())} ${chalk.red( `Deprecated configuration key '${key}' usage${ logMsgToAppend.trim().length > 0 ? `. ${logMsgToAppend}` : '' }`, @@ -535,7 +536,7 @@ export class Configuration { Configuration.configurationFile, FileType.Configuration, error as NodeJS.ErrnoException, - Configuration.logPrefix(), + configurationLogPrefix(), ); } } @@ -560,7 +561,7 @@ export class Configuration { Configuration.configurationFile, FileType.Configuration, error as NodeJS.ErrnoException, - Configuration.logPrefix(), + configurationLogPrefix(), ); } } -- 2.34.1