Skip to content

fix(logger): correct production detection in Vite browser builds - #1499

Closed
penielgold-hub wants to merge 1 commit into
Disciplr-Org:mainfrom
penielgold-hub:fix/issue-1218-logger
Closed

penielgold-hub wants to merge 1 commit into
Disciplr-Org:mainfrom
penielgold-hub:fix/issue-1218-logger

Conversation

@penielgold-hub

Copy link
Copy Markdown

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.ts re-export the canonical logger from design-system/src/utils/logger.ts.

However, the shared logger attempted to access import.meta.env.MODE through new Function(). This approach cannot access import.meta correctly and therefore fails to detect Vite production mode when the browser has no global process object.

Changes Made

  • Removed the ineffective new Function() environment-detection logic.
  • Replaced it with Vite-compatible process.env.NODE_ENV detection, which Vite substitutes during production builds.
  • Preserved runtime compatibility with Node-based consumers.
  • Retained the existing logger API: debug, info, warn, and error.
  • Added a production-build regression test to verify correct browser behavior without 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

  • Frontend logger tests: 10 passed
  • New production-build regression test: 1 passed
  • Total: 11/11 tests passed
  • Test files: 2/2 passed
  • git diff --check: Passed

Known Limitations

  • Design-system Jest tests could not run because of an existing malformed package manifest.
  • Full TypeScript verification is blocked by unrelated syntax errors in design-system token files.
  • Production detection follows NODE_ENV. Vite's custom MODE value can differ from NODE_ENV, particularly in staging configurations.

Scope

The changes are limited to:

  1. design-system/src/utils/logger.ts
  2. src/utils/__tests__/logger.production-build.test.ts

No 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants