X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FConfiguration.ts;h=d994422b07bf91e176fd7d36bc680318fadabc4c;hb=61e0f0426f3b5ffb6738bc1f6b61ff9ed789377b;hp=6b8023ab0b2911cb7bf54ef38d21aaaddcfb0c67;hpb=6501eda9e69fff639911308b3f2de26593ae18c9;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 6b8023ab..d994422b 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -1,5 +1,6 @@ import { type FSWatcher, readFileSync, watch } from 'node:fs'; import { dirname, join, resolve } from 'node:path'; +import { env } from 'node:process'; import { fileURLToPath } from 'node:url'; import chalk from 'chalk'; @@ -41,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; @@ -104,7 +110,7 @@ export class Configuration { } public static workerPoolInUse(): boolean { - return [WorkerProcessType.dynamicPool, WorkerProcessType.staticPool].includes( + return [WorkerProcessType.dynamicPool, WorkerProcessType.fixedPool].includes( Configuration.getConfigurationSection(ConfigurationSection.worker) .processType!, ); @@ -117,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); } @@ -171,7 +173,7 @@ export class Configuration { } if (isCFEnvironment() === true) { delete uiServerConfiguration.options?.host; - uiServerConfiguration.options!.port = parseInt(process.env.PORT!); + uiServerConfiguration.options!.port = parseInt(env.PORT!); } return uiServerConfiguration; } @@ -329,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`, )}`, ); @@ -385,17 +387,17 @@ export class Configuration { `Use '${ConfigurationSection.worker}' section to define the worker pool minimum size instead`, ); Configuration.warnDeprecatedConfigurationKey( - 'workerPoolSize;', + 'workerPoolSize', undefined, `Use '${ConfigurationSection.worker}' section to define the worker pool maximum size instead`, ); Configuration.warnDeprecatedConfigurationKey( - 'workerPoolMaxSize;', + 'workerPoolMaxSize', undefined, `Use '${ConfigurationSection.worker}' section to define the worker pool maximum size instead`, ); Configuration.warnDeprecatedConfigurationKey( - 'workerPoolStrategy;', + 'workerPoolStrategy', undefined, `Use '${ConfigurationSection.worker}' section to define the worker pool strategy instead`, ); @@ -404,6 +406,16 @@ export class Configuration { ConfigurationSection.worker, 'Not publicly exposed to end users', ); + if ( + Configuration.getConfigurationData()?.worker?.processType === + ('staticPool' as WorkerProcessType) + ) { + console.error( + `${chalk.green(configurationLogPrefix())} ${chalk.red( + `Deprecated configuration 'staticPool' value usage in worker section 'processType' field. Use '${WorkerProcessType.fixedPool}' value instead`, + )}`, + ); + } // log section Configuration.warnDeprecatedConfigurationKey( 'logEnabled', @@ -464,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`, )}`, ); @@ -491,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}` : '' }`, @@ -501,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}` : '' }`, @@ -524,7 +536,7 @@ export class Configuration { Configuration.configurationFile, FileType.Configuration, error as NodeJS.ErrnoException, - Configuration.logPrefix(), + configurationLogPrefix(), ); } } @@ -549,7 +561,7 @@ export class Configuration { Configuration.configurationFile, FileType.Configuration, error as NodeJS.ErrnoException, - Configuration.logPrefix(), + configurationLogPrefix(), ); } }