Repository navigation
fix(logger): correct production detection in Vite browser builds - #1499
Closed
penielgold-hub wants to merge 1 commit into
Closed
penielgold-hub wants to merge 1 commit into
penielgold-hub wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a remaining production-environment detection defect in the canonical logger associated with #1218.
PR #826 previously consolidated the duplicate logger implementations by making
src/utils/logger.tsre-export the canonical logger fromdesign-system/src/utils/logger.ts.However, the shared logger attempted to access
import.meta.env.MODEthroughnew Function(). This approach cannot accessimport.metacorrectly and therefore fails to detect Vite production mode when the browser has no globalprocessobject.Changes Made
new Function()environment-detection logic.process.env.NODE_ENVdetection, which Vite substitutes during production builds.debug,info,warn, anderror.globalThis.process.Regression Test
The new test builds the canonical logger using Vite in production mode, imports the generated ESM bundle, and simulates a browser environment without
process.It verifies that:
logger.debug()is suppressed in production.logger.info()is suppressed in production.logger.warn()is suppressed in production.logger.error()continues to log normally.The regression test failed before the correction and passed afterward, confirming the defect and its resolution.
Test Results
git diff --check: PassedKnown Limitations
NODE_ENV. Vite's customMODEvalue can differ fromNODE_ENV, particularly in staging configurations.Scope
The changes are limited to:
design-system/src/utils/logger.tssrc/utils/__tests__/logger.production-build.test.tsNo unrelated application files were modified.
Related Issue
Related to #1218.
The original logger consolidation was already implemented in PR #826. This PR addresses the remaining production-detection defect in that shared implementation.