-
Notifications
You must be signed in to change notification settings - Fork 157
Feature/env mode control #552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/env mode control #552
Conversation
WalkthroughEnvironment detection throughout the codebase is centralized by introducing utility functions in Changes
Poem
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure ✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Hey @erickmmolina thank you for opening this pull request! 👋 We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted. Details: |
|
Tip For best results, initiate chat on the files or code changes. @github-actions[bot] I see that there's an issue with the PR title not following the Conventional Commits specification. The current title "Feature/env mode control" needs to be prefixed with an appropriate type. Based on the PR content, this appears to be adding a new feature, so the title should be changed to: To update the PR title:
This format helps with automated versioning and changelog generation. The Conventional Commits specification makes it easier to track what kind of changes are being made in each PR. Hope this helps! Let me know if you need any further assistance. ʕ •ᴥ•ʔ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/env.js (1)
19-86: Environment detection utilities look solid, but could be more DRYThe implementation of utility functions for environment detection is a good approach for centralizing this logic. However, there's significant code duplication across the four functions that could be refactored.
Consider refactoring to use a single helper function:
-// Utility functions to check environment -function isDevelopment() { - // First check the custom environment variable from runtime - if (isBrowser() && window?.[PUBLIC_ENV_KEY]?.NEXT_PUBLIC_APP_ENV) { - return window[PUBLIC_ENV_KEY].NEXT_PUBLIC_APP_ENV === "development"; - } - - // Then check process.env - if (process.env.NEXT_PUBLIC_APP_ENV) { - return process.env.NEXT_PUBLIC_APP_ENV === "development"; - } - - // Fall back to NODE_ENV - return process.env.NODE_ENV === "development"; -} - -function isProduction() { - // First check the custom environment variable from runtime - if (isBrowser() && window?.[PUBLIC_ENV_KEY]?.NEXT_PUBLIC_APP_ENV) { - return window[PUBLIC_ENV_KEY].NEXT_PUBLIC_APP_ENV === "production"; - } - - // Then check process.env - if (process.env.NEXT_PUBLIC_APP_ENV) { - return process.env.NEXT_PUBLIC_APP_ENV === "production"; - } - - // Fall back to NODE_ENV - return process.env.NODE_ENV === "production"; -} - -function isTest() { - // First check the custom environment variable from runtime - if (isBrowser() && window?.[PUBLIC_ENV_KEY]?.NEXT_PUBLIC_APP_ENV) { - return window[PUBLIC_ENV_KEY].NEXT_PUBLIC_APP_ENV === "test"; - } - - // Then check process.env - if (process.env.NEXT_PUBLIC_APP_ENV) { - return process.env.NEXT_PUBLIC_APP_ENV === "test"; - } - - // Fall back to NODE_ENV - return process.env.NODE_ENV === "test"; -} - -function isStaging() { - // First check the custom environment variable from runtime - if (isBrowser() && window?.[PUBLIC_ENV_KEY]?.NEXT_PUBLIC_APP_ENV) { - return window[PUBLIC_ENV_KEY].NEXT_PUBLIC_APP_ENV === "staging"; - } - - // Then check process.env - if (process.env.NEXT_PUBLIC_APP_ENV) { - return process.env.NEXT_PUBLIC_APP_ENV === "staging"; - } - - // Fall back to NODE_ENV - return process.env.NODE_ENV === "staging"; -} +// Helper function to check environment +function checkEnvironment(envName) { + // First check the custom environment variable from runtime + if (isBrowser() && window?.[PUBLIC_ENV_KEY]?.NEXT_PUBLIC_APP_ENV) { + return window[PUBLIC_ENV_KEY].NEXT_PUBLIC_APP_ENV === envName; + } + + // Then check process.env + if (process.env.NEXT_PUBLIC_APP_ENV) { + return process.env.NEXT_PUBLIC_APP_ENV === envName; + } + + // Fall back to NODE_ENV + return process.env.NODE_ENV === envName; +} + +// Environment utility functions +const isDevelopment = () => checkEnvironment("development"); +const isProduction = () => checkEnvironment("production"); +const isTest = () => checkEnvironment("test"); +const isStaging = () => checkEnvironment("staging");
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
src/app/api/trpc/[trpc]/route.ts(2 hunks)src/app/layout.tsx(2 hunks)src/components/onboarding/signin/index.tsx(2 hunks)src/env.js(3 hunks)src/trpc/react.tsx(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/components/onboarding/signin/index.tsx (1)
src/env.js (2)
envUtils(81-86)envUtils(81-86)
src/trpc/react.tsx (1)
src/env.js (2)
envUtils(81-86)envUtils(81-86)
🔇 Additional comments (10)
src/env.js (2)
145-145: Good addition of NEXT_PUBLIC_APP_ENV to the client schemaAdding this environment variable to the schema with proper validation ensures consistency and provides more flexibility for environment control.
195-195: Ensures runtime access to NEXT_PUBLIC_APP_ENVThe addition to
experimental__runtimeEnvcorrectly enables access to this variable at runtime through the helper function.src/trpc/react.tsx (2)
10-10: Good import of envUtilsImporting the envUtils module for centralized environment detection.
26-26: Properly replaced direct NODE_ENV check with utility functionUsing
envUtils.isDevelopment()instead of directly checkingprocess.env.NODE_ENValigns with the centralized environment detection approach.src/components/onboarding/signin/index.tsx (2)
30-30: Good import of envUtilsImporting the envUtils module for centralized environment detection.
51-52: Properly uses environment utilities for development defaultsUsing
envUtils.isDevelopment()for setting default form values ensures consistency with the rest of the application.src/app/api/trpc/[trpc]/route.ts (2)
4-4: Updated import to include envUtilsGood addition of envUtils to the imports.
25-25: Replaced direct NODE_ENV check with utility functionUsing
envUtils.isDevelopment()instead of directly checkingenv.NODE_ENValigns with the centralized environment detection approach.src/app/layout.tsx (2)
5-5: Good addition of centralized environment utility.This import aligns with the PR objective of centralizing environment detection logic across the codebase. Using a dedicated utility module is a good practice for consistent environment checks.
46-46: Properly implemented environment check.The refactoring from direct
NODE_ENVchecks toenvUtils.isDevelopment()ensures consistent environment detection throughout the application. This abstraction makes environment-specific behavior more maintainable and allows for more sophisticated environment detection logic in the future.
Summary by CodeRabbit
New Features
Refactor