Add .env file imports to project env writes#68
Conversation
|
Warning Review limit reached
More reviews will be available in 33 minutes. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughThis PR adds dotenv file support to the Prisma CLI's 🚥 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. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
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 |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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 `@packages/cli/src/controllers/app-env-file.ts`:
- Around line 44-56: The thrown CliError for existingKeys should tell the user
to split the input by conflict type or use split-file placeholders rather than
running the full-file command; update the error's fix and nextSteps (in the
block that constructs the CliError when existingKeys is non-empty) to reference
existingKeys and formatKeyList(existingKeys)/formatScopeLabel(resolved.scope)
and instruct creating two files (one for new keys and one for updates) or
providing a "<file>.existing" and "<file>.new" placeholder before running
`prisma-cli project env update --file`, and make the analogous change in the
other similar error block (the one around lines 129-141) so both preflight
errors give explicit split-by-conflict guidance using the reported keys.
In `@packages/cli/src/lib/app/env-file.ts`:
- Around line 140-147: The catch block around validateKey currently swallows the
original validation error; change the catch clause to capture the error (e.g.,
catch (err)) and include the original validation message when throwing
usageError so the real reason from validateKey is preserved (reference
validateKey, usageError, key, filePath, line, command); ensure the thrown
usageError combines your existing contextual text with err.message (or passes
err as a cause) so over-length and other specific validation failures are
reported accurately.
In `@packages/cli/tests/app-env-vars.test.ts`:
- Around line 139-147: The test currently uses try/catch around
parseEnvFileContents("EMPTY=\n", ".env", "add") without asserting that an error
was thrown, allowing false-positive passes; update the test to explicitly assert
the throw path (e.g., wrap the call in an expect(...).toThrow()/toThrowError or
add a failing assertion immediately after the call and before the catch) so that
parseEnvFileContents is required to throw, then keep the existing assertions
inside the catch to validate error.code, error.summary, and that the serialized
error does not contain "secret".
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 49dc5090-d488-48b9-99ab-48f05d28779c
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (14)
README.mddocs/product/command-spec.mdpackages/cli/README.mdpackages/cli/package.jsonpackages/cli/src/commands/env.tspackages/cli/src/controllers/app-env-api.tspackages/cli/src/controllers/app-env-file.tspackages/cli/src/controllers/app-env.tspackages/cli/src/lib/app/env-file.tspackages/cli/src/presenters/app-env.tspackages/cli/src/shell/command-meta.tspackages/cli/src/types/app-env.tspackages/cli/tests/app-env-vars.test.tspackages/cli/tests/app-env.test.ts
Overview
Adds dotenv file imports to
project env addandproject env updateso agents and humans can bulk-create or bulk-replace environment variables while keeping write scopes explicit.Changes
project env addandproject env updateto accept either a single assignment or--file <path>, with mutual-exclusion validation inpackages/cli/src/commands/env.tsandpackages/cli/src/controllers/app-env.ts.packages/cli/src/lib/app/env-file.ts, usingdotenv.parsewhile separately validating duplicate keys, key shape, empty values,exportprefixes, quoted values, and multiline values without logging secrets.packages/cli/src/controllers/app-env-file.ts, including exact-scope preflight for add conflicts and update misses, sequential API writes, value-safe metadata output, and partial-failure recovery metadata.packages/cli/src/controllers/app-env-api.tsto keep the main env controller below the local review size gate.Why
Using
--filepreserves the existingadd/updatesemantics instead of introducing a new import verb or upsert behavior. The implementation keeps scope explicit, avoids echoing values, validates before mutation, and reports partial state when true atomic bulk writes are unavailable from the Management API.Validation
pnpm --filter @prisma/cli testpnpm --filter @prisma/cli buildgit diff --checktmp-code-reviewandthermonuclear-review; resolved the strict file-size/controller-structure finding before opening this PR.