Config: move feature flags out of the source into env - #218
Merged
Baskarayelu merged 2 commits intoAug 28, 2026
Merged
Conversation
No feature-flag infrastructure existed. Add lib/featureFlags.ts: flags are keyed by name, mapped to a NEXT_PUBLIC_FEATURE_* env var, and isFeatureEnabled() treats exactly the string "true" as enabled -- unset/empty/anything else defaults closed, so a flag never needs every environment to explicitly opt out. Documented in .env.example.
The README states every runtime env var is read through lib/config.ts -- "never access process.env directly in business logic" -- but featureFlags.ts did exactly that. Move flag definitions and reading into config.ts (alongside sentryDsn/stellarNetwork, same sane-default-then-env-override pattern) and make featureFlags.ts a thin isFeatureEnabled() convenience wrapper over config.featureFlags.
Contributor
Author
|
Pushed a follow-up commit: the first version read `process.env` directly in `featureFlags.ts`, which violates this repo's own stated convention (README: "All runtime env vars are read through `lib/config.ts` — never access `process.env` directly in business logic"). Moved the flag definitions and reading into `lib/config.ts` alongside `sentryDsn`/`stellarNetwork`, and `featureFlags.ts` is now a thin `isFeatureEnabled()` wrapper over `config.featureFlags`. Tests updated to match (module-load-time env stubbing via `vi.stubEnv` + `vi.resetModules()`, matching `lib/config.test.ts`'s existing pattern). |
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.
Note on scope
No feature flags existed in the codebase to move -- there was no flag infrastructure at all. Added the infrastructure itself: flags keyed by name, backed by env vars, defaulting closed.
Change
`lib/featureFlags.ts`:
Documented the example flag's env var in `.env.example`.
Tests
`lib/featureFlags.test.ts`: disabled when unset, enabled only for the exact string `"true"`, disabled for other truthy-looking values (`"1"`, `"TRUE"`, `"yes"`, `"false"`, `""`).
`npx vitest run lib/featureFlags.test.ts`: 3 passed. `npx tsc --noEmit` / `npx eslint` on changed files: clean.
Related to #107