refactor: env management#738
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR centralizes environment variable definitions by introducing an EnvRegistry. Boilerplate configs declare env vars via ChangesEnvironment Registry and Rendering Architecture
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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. Comment |
Introduce a single source of truth for environment variables. Each feature will declare the vars it needs once (EnvVarDef[]) on its BatiConfig, and the `.env`, docker-compose `environment:` and Dockerfile `ENV` sinks are derived from the merged registry via renderDotenv / composeEnvEntries / serverEnvDefaults. Pure addition — nothing is wired to consume `config.env` yet. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Aggregate each selected boilerplate's `config.env` into one registry in the CLI, pass it through exec() -> build main() -> executeOperationTransform, and expose it on TransformerProps.env. No consumer yet; output is unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Declare each feature's env vars on its bati.config (auth0, sentry, sqlite, drizzle, kysely, prisma, google-analytics) and generate the whole .env from one shared transformer (renderDotenv) instead of seven per-feature $.env.ts. Behaviour is preserved: same keys/values/comments/order, the cloudflare and D1 exclusions become declarative `when` predicates, and projects with no env vars still get no .env file. Adds unit tests for the three sink emitters. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace the hardcoded auth0/sentry/database env lines (and their # BATI conditional comments) in the docker-compose.yml skeleton with a $docker-compose.yml.ts transform that injects services.app.environment from the merged registry via the new setComposeEnvironment helper. The boilerplate no longer knows about other features' vars. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…stry Replace the hardcoded auth0/sentry/database .when(...).env(...) blocks in the runner stage with a loop over serverEnvDefaults(props.env, meta). The runner stage no longer references specific features; adding a feature with env vars needs no change here. Drizzle's build-time DATABASE_URL (for drizzle:generate) stays as feature-specific build wiring. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Core now owns only the env-registry data model (types + envVarApplies) and the
generic primitives (appendToEnv, setComposeEnvironment). The per-sink rendering
policy lives with the boilerplate that owns the sink:
- shared/env.ts -> renderDotenv (.env)
- docker-compose/env.ts -> composeEnvEntries,
serverEnvDefaults (compose + Dockerfile)
The $ transformers import these via ../env (relative imports are allowed in
$-files). Renderer unit tests move next to the code (shared/docker-compose gain
a vitest test script + devDeps). Generated .env/compose/Dockerfile output is
unchanged (verified by generation).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The "empty secret" assertions read process.env.TEST_AUTH0_CLIENT_ID / TEST_SENTRY_DSN via devValueFrom; when those are set in the shell or .env.test the secret renders non-empty and the test fails. Clear them in beforeEach and restore in afterEach so the suite is hermetic. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
boilerplates/shared/env.spec.ts (1)
7-9: ⚡ Quick winReplace
as never[]with the required BATI.If casting style.This cast bypasses type intent and doesn’t follow the boilerplate casting convention required in this repo.
Use this read-only check to confirm remaining violations in boilerplate TS files:
#!/bin/bash rg -nP --type=ts '\bas\s+never\[\]' boilerplates rg -nP --type=ts 'BATI\.If<' boilerplatesAs per coding guidelines
boilerplates/**/*.ts: Use BATI.If with conditional type definition syntax for type casting in boilerplate TypeScript files:BATI.If<{'BATI.has("feature")': Type; _: FallbackType;}>.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@boilerplates/shared/env.spec.ts` around lines 7 - 9, In the meta function, replace the unsafe cast "as never[]" on the flags argument passed to new BatiSet with the repo-standard BATI.If conditional type cast; update the call in function meta(...flags: string[]): VikeMeta so that the flags parameter uses BATI.If<{ 'BATI.has("feature")': DesiredType; _: FallbackType; }> (per boilerplate convention) instead of as never[], ensuring you reference the BatiSet constructor and BATI.If typing to satisfy the boilerplate TS casting rule.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@boilerplates/sentry/bati.config.ts`:
- Line 11: Update the user-facing comment strings that mistakenly say "DNS" to
"DSN": find the config entries where the property comment equals "Sentry DNS.
Used for Error Reporting on the Server" (and the second occurrence at "Sentry
DNS. Used for Error Reporting on the Client") and change "DNS" to "DSN" so they
read "Sentry DSN. Used for Error Reporting on the Server/Client" respectively;
keep the rest of the comment text unchanged.
In `@boilerplates/shared-db/bati.config.ts`:
- Around line 9-21: The env generator in bati.config.ts currently emits a
DATABASE_URL entry unless meta.BATI.hasD1 is true, causing a duplicate when
Prisma also declares DATABASE_URL; update the condition in the env: (meta) =>
... logic to skip emitting the DATABASE_URL object when Prisma is enabled (e.g.
check meta.BATI.hasPrisma or the appropriate Prisma flag alongside
meta.BATI.hasD1) so the DATABASE_URL key is only added when neither D1 nor
Prisma are selected.
In `@packages/core/src/format.ts`:
- Line 1: The file registers Prettier standalone + plugin and a custom
typescriptViaBabel parser (parser "babel-ts") inside formatCode, causing TS/TSX
to be formatted by Prettier instead of the monorepo's Biome formatter policy;
remove the Prettier-specific wiring (imports of Prettier Plugin/standalone and
the typescriptViaBabel parser registration) and change formatCode to call the
monorepo Biome formatting API for TS/TSX files (use the Biome formatter
policy/formatter entrypoint used elsewhere in the repo), ensuring TypeScript/TSX
are routed to Biome rather than invoking Prettier and delete any references to
parser "babel-ts" and the custom typescriptViaBabel symbol.
---
Nitpick comments:
In `@boilerplates/shared/env.spec.ts`:
- Around line 7-9: In the meta function, replace the unsafe cast "as never[]" on
the flags argument passed to new BatiSet with the repo-standard BATI.If
conditional type cast; update the call in function meta(...flags: string[]):
VikeMeta so that the flags parameter uses BATI.If<{ 'BATI.has("feature")':
DesiredType; _: FallbackType; }> (per boilerplate convention) instead of as
never[], ensuring you reference the BatiSet constructor and BATI.If typing to
satisfy the boilerplate TS casting rule.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d6e075a3-a2de-4a31-9094-b77a981c9ded
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (42)
boilerplates/auth0/bati.config.tsboilerplates/auth0/files/$.env.tsboilerplates/auth0/files/$wrangler.jsonc.tsboilerplates/cloudflare/env.spec.tsboilerplates/cloudflare/env.tsboilerplates/cloudflare/files/$wrangler.jsonc.tsboilerplates/cloudflare/package.jsonboilerplates/cloudflare/tsconfig.jsonboilerplates/docker-compose/env.spec.tsboilerplates/docker-compose/env.tsboilerplates/docker-compose/files/$Dockerfile.tsboilerplates/docker-compose/files/$docker-compose.yml.tsboilerplates/docker-compose/files/docker-compose.ymlboilerplates/docker-compose/package.jsonboilerplates/drizzle/files/$.env.tsboilerplates/google-analytics/bati.config.tsboilerplates/google-analytics/files/$.env.tsboilerplates/kysely/files/$.env.tsboilerplates/prisma/bati.config.tsboilerplates/prisma/files/$.env.tsboilerplates/sentry/bati.config.tsboilerplates/sentry/files/$.env.tsboilerplates/shared-db/bati.config.tsboilerplates/shared/env.spec.tsboilerplates/shared/env.tsboilerplates/shared/files/$.env.tsboilerplates/shared/package.jsonboilerplates/sqlite/files/$.env.tspackages/build/src/index.tspackages/build/src/operations/transform.tspackages/cli/index.tspackages/core/src/config.tspackages/core/src/env-registry.tspackages/core/src/format.tspackages/core/src/index.tspackages/core/src/parse/yaml.tspackages/core/src/types.tspackages/core/src/utils/env.tspackages/core/tests/transform-yaml.spec.tspackages/features/src/helpers.tspackages/tests-utils/src/index.tspnpm-workspace.yaml
💤 Files with no reviewable changes (10)
- boilerplates/kysely/files/$.env.ts
- boilerplates/prisma/files/$.env.ts
- packages/core/src/utils/env.ts
- boilerplates/sentry/files/$.env.ts
- boilerplates/google-analytics/files/$.env.ts
- boilerplates/sqlite/files/$.env.ts
- boilerplates/auth0/files/$wrangler.jsonc.ts
- boilerplates/drizzle/files/$.env.ts
- boilerplates/docker-compose/files/docker-compose.yml
- boilerplates/auth0/files/$.env.ts
Summary by CodeRabbit
New Features
Refactor
Tests
Chores