Skip to content

Conversation

@adelrodriguez
Copy link
Collaborator

@adelrodriguez adelrodriguez commented Feb 1, 2026

Greptile Overview

Greptile Summary

Centralized environment variable handling by creating a new @tooling/env package with two key utilities: ensureEnv() for Vite configs and getRuntimeEnv() for runtime environment access.

Key Changes:

  • Created @tooling/env package with ensureEnv() function that loads environment variables and validates them at build config time using jiti for dynamic imports
  • Added getRuntimeEnv() helper in @init/env that consistently merges import.meta.env and process.env across all environments
  • Updated all app configs (app, web, desktop, extension) to use ensureEnv(mode) for early environment validation
  • Replaced manual environment object spreading ({ ...import.meta.env, ...process.env }) with getRuntimeEnv() across all env.ts files
  • Updated presets to use getRuntimeEnv() for client-side environment access

Benefits:

  • Consistent environment variable handling across Vite, Astro, WXT, and Tauri configs
  • Early validation catches environment issues at config time instead of runtime
  • Eliminates duplicate code patterns for environment merging
  • Centralized tooling makes it easier to maintain and update environment handling logic

Confidence Score: 5/5

  • Safe to merge - well-structured refactoring with consistent patterns applied across all apps
  • Clean refactoring that centralizes environment handling without changing behavior. The implementation is consistent across all apps, follows DRY principles, and improves maintainability
  • No files require special attention

Important Files Changed

Filename Overview
tooling/env/src/vite.ts Added ensureEnv utility to load environment variables in Vite configs using jiti for runtime import
packages/env/src/runtime.ts Created getRuntimeEnv helper to merge import.meta.env and process.env consistently
packages/env/src/presets.ts Updated presets to use getRuntimeEnv() consistently for client-side environment access
apps/app/vite.config.ts Wrapped config in function to call ensureEnv(mode) for early environment validation
apps/web/astro.config.ts Added ensureEnv() call at config initialization for Astro environment loading
apps/desktop/vite.config.ts Wrapped config in function to call ensureEnv(mode) for Tauri environment validation

Sequence Diagram

sequenceDiagram
    participant ViteConfig as Vite Config
    participant EnsureEnv as ensureEnv()
    participant LoadEnv as Vite loadEnv()
    participant Jiti as jiti.import()
    participant EnvFile as env.ts
    participant CreateEnv as createEnv()
    participant GetRuntimeEnv as getRuntimeEnv()
    
    ViteConfig->>EnsureEnv: Call ensureEnv(mode)
    EnsureEnv->>LoadEnv: Load .env files
    LoadEnv-->>EnsureEnv: Return env vars
    EnsureEnv->>EnsureEnv: Object.assign(process.env, env)
    EnsureEnv->>Jiti: Import env.ts dynamically
    Jiti->>EnvFile: Execute env.ts
    EnvFile->>CreateEnv: Call createEnv()
    CreateEnv->>GetRuntimeEnv: Get runtime environment
    GetRuntimeEnv->>GetRuntimeEnv: Merge import.meta.env and process.env
    GetRuntimeEnv-->>CreateEnv: Return merged env
    CreateEnv->>CreateEnv: Validate environment variables
    CreateEnv-->>EnvFile: Return validated env
    EnvFile-->>Jiti: Module loaded
    Jiti-->>EnsureEnv: Import complete
    EnsureEnv-->>ViteConfig: Env validated
Loading

@coderabbitai
Copy link

coderabbitai bot commented Feb 1, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor_centralize_environment_variable_handling_with_tooling/env

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@adelrodriguez adelrodriguez marked this pull request as ready for review February 1, 2026 17:15
Copy link
Collaborator Author

adelrodriguez commented Feb 1, 2026

@adelrodriguez adelrodriguez merged commit 9ac4966 into main Feb 1, 2026
8 checks passed
@adelrodriguez adelrodriguez deleted the refactor_centralize_environment_variable_handling_with_tooling/env branch February 1, 2026 19:27
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