From e084894cdc4b46d52d99be872f5f789fe83c3cc0 Mon Sep 17 00:00:00 2001 From: Mohammad Honarvar Date: Fri, 11 Oct 2024 21:01:40 +0330 Subject: [PATCH] refactor(logger): prevent side-effects --- packages/logger/src/logger.ts | 53 ++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/packages/logger/src/logger.ts b/packages/logger/src/logger.ts index 8c684aba..ed53e102 100644 --- a/packages/logger/src/logger.ts +++ b/packages/logger/src/logger.ts @@ -6,34 +6,35 @@ import type {AlwatrLogger} from './type.js'; __dev_mode__: packageTracer.add(__package_name__, __package_version__); const defaultDebugMode = /* #__PURE__ */ (() => { - return platformInfo.development || - (platformInfo.isCli - ? Boolean(process.env.DEBUG) - : typeof localStorage !== 'undefined' && localStorage.getItem('ALWATR_DEBUG') === '1'); + return ( + platformInfo.development || + (platformInfo.isCli ? Boolean(process.env.DEBUG) : typeof localStorage !== 'undefined' && localStorage.getItem('ALWATR_DEBUG') === '1') + ); })(); /** * Color list storage for logger. */ -const colorList = platformInfo.isCli - ? ['0;36', '0;35', '0;34', '0;33', '0;32'] // red and white omitted - : [ - '#35b997', - '#f05561', - '#ee224a', - '#91c13e', - '#22af4b', - '#f0e995', - '#0fe995', - '#0f89ca', - '#08b9a5', - '#fee851', - '#ee573d', - '#f9df30', - '#1da2dc', - '#f05123', - '#ee2524', - ]; +const colorList = /* #__PURE__ */ (() => + platformInfo.isCli + ? ['0;36', '0;35', '0;34', '0;33', '0;32'] // red and white omitted + : [ + '#35b997', + '#f05561', + '#ee224a', + '#91c13e', + '#22af4b', + '#f0e995', + '#0fe995', + '#0f89ca', + '#08b9a5', + '#fee851', + '#ee573d', + '#f9df30', + '#1da2dc', + '#f05123', + '#ee2524', + ])(); let _colorIndex = 0; const _getNextColor = (): string => { @@ -45,12 +46,12 @@ const _getNextColor = (): string => { return color; }; -const _style = { +const _style = /* #__PURE__ */ (() => ({ scope: platformInfo.isCli ? '\x1b[{{color}}m' : 'color: {{color}};', reset: platformInfo.isCli ? '\x1b[0m' : 'color: inherit;', -}; +}))(); -const _keySection = platformInfo.isCli ? '%s%s%s' : '%c%s%c'; +const _keySection = /* #__PURE__ */ (() => (platformInfo.isCli ? '%s%s%s' : '%c%s%c'))(); const _sanitizeDomain = (domain: string): string => { domain = domain.trim();