From 43dfdb1d1f0501c951e2a847e53f45bd8f2e7001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Ka=C5=A1tovsk=C3=BD?= Date: Tue, 9 Jan 2024 10:02:14 +0100 Subject: [PATCH] Tweak dev env detection (#1044) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ALL-3453: tweak dev env detection Co-authored-by: Filip Kaštovský --- CHANGELOG.md | 15 +++++++++++++++ package.json | 2 +- src/service/logger/logger.development.ts | 10 +++++----- src/util/env.ts | 2 +- yarn.lock | 12 ++++++------ 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8486cfa8..85c8715f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,21 @@ +## [4.2.1] - 2024.1.9 + +### Updated + +- Assert development environment if `NODE_ENV` is not set + +### Fixed + +- Use globalThis instead of `process.env` for setting `TatumDevelopmentLogger`'s `isWelcomeDisabled` flag + ## [4.2.0] - 2024.1.8 +### Added + - Added logging support + +### Updated + - Updated dependencies ## [4.1.37] - 2024.1.5 diff --git a/package.json b/package.json index 2d362093c..c3f6fd09f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tatumio/tatum", - "version": "4.2.0", + "version": "4.2.1", "description": "Tatum JS SDK", "author": "Tatum", "repository": "https://github.com/tatumio/tatum-js", diff --git a/src/service/logger/logger.development.ts b/src/service/logger/logger.development.ts index 919168047..4b7ef0a09 100644 --- a/src/service/logger/logger.development.ts +++ b/src/service/logger/logger.development.ts @@ -8,15 +8,15 @@ interface TatumDevelopmentLoggerOptions { } export class TatumDevelopmentLogger implements Logger { - private static readonly DISABLE_WELCOME = 'TTM_DISABLE_WELCOME' + private static readonly DISABLE_WELCOME = '__TTM_DISABLE_WELCOME__' private static isWelcomeDisabled(): boolean { - if (!EnvUtils.isProcessAvailable()) return false - return process.env[TatumDevelopmentLogger.DISABLE_WELCOME] === 'true' + const anyGlobal = globalThis as unknown as { __TTM_DISABLE_WELCOME__: boolean } + return !!anyGlobal[TatumDevelopmentLogger.DISABLE_WELCOME] } private static disableWelcome(): void { - if (!EnvUtils.isProcessAvailable()) return - process.env[TatumDevelopmentLogger.DISABLE_WELCOME] = 'true' + const anyGlobal = globalThis as unknown as { __TTM_DISABLE_WELCOME__: boolean } + anyGlobal[TatumDevelopmentLogger.DISABLE_WELCOME] = true } private readonly options: TatumDevelopmentLoggerOptions diff --git a/src/util/env.ts b/src/util/env.ts index 7ad713e55..83cc6d758 100644 --- a/src/util/env.ts +++ b/src/util/env.ts @@ -2,6 +2,6 @@ export const EnvUtils = { isBrowser: () => typeof window !== 'undefined', isProcessAvailable: () => typeof process !== 'undefined', isDevelopment: () => - (EnvUtils.isProcessAvailable() && process?.env?.NODE_ENV === 'development') || + (EnvUtils.isProcessAvailable() && (!process.env?.NODE_ENV || process.env?.NODE_ENV === 'development')) || (EnvUtils.isBrowser() && ['localhost', '127.0.0.1', '[::1]'].includes(window.location.hostname)), } diff --git a/yarn.lock b/yarn.lock index 29810a6b0..5d0202eae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -143,9 +143,9 @@ integrity sha512-85ttAOMLsr53VgXkTbkx8oA6YTfT4q7/HzXSLEYmjcSTJPMPQtvq1BD79Byep5xMUYbGRzEpDsjUf3dyp54IKw== "@babel/helpers@^7.23.7": - version "7.23.7" - resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.23.7.tgz#eb543c36f81da2873e47b76ee032343ac83bba60" - integrity sha512-6AMnjCoC8wjqBzDHkuqpa7jAKwvMo4dC+lr/TFBz+ucfulO1XMpDnwWPGBNwClOKZ8h6xn5N81W/R5OrcKtCbQ== + version "7.23.8" + resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.23.8.tgz#fc6b2d65b16847fd50adddbd4232c76378959e34" + integrity sha512-KDqYz4PiOWvDFrdHLPhKtCThtIcKVy6avWD2oG4GEvyQ+XDZwHD4YQd+H2vNMnq2rkdxsDkU82T+Vk8U/WXHRQ== dependencies: "@babel/template" "^7.22.15" "@babel/traverse" "^7.23.7" @@ -1264,9 +1264,9 @@ dotenv@^16.0.3: integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ== electron-to-chromium@^1.4.601: - version "1.4.623" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.623.tgz#0f7400114ac3425500e9244d2b0e9c3107c331cb" - integrity sha512-lKoz10iCYlP1WtRYdh5MvocQPWVRoI7ysp6qf18bmeBgR8abE6+I2CsfyNKztRDZvhdWc+krKT6wS7Neg8sw3A== + version "1.4.625" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.625.tgz#a9a1d18ee911f9074a9c42d9e84b1c79b29f4059" + integrity sha512-DENMhh3MFgaPDoXWrVIqSPInQoLImywfCwrSmVl3cf9QHzoZSiutHwGaB/Ql3VkqcQV30rzgdM+BjKqBAJxo5Q== emittery@^0.13.1: version "0.13.1"