-
Notifications
You must be signed in to change notification settings - Fork 355
Skip .env.local creation when environment variables exist in process.env #193
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR improves the Convex CLI's environment variable handling by checking process.env
before creating .env.local
files, preventing unnecessary file creation when environment variables are already available in the shell environment.
Key changes include:
- Enhanced
writeConvexUrlToEnvFile
to checkprocess.env
for existing environment variables before file creation - Updated
writeDeploymentEnvVar
to skip file operations whenCONVEX_DEPLOYMENT
is already set in the environment - Added comprehensive test coverage for the new behavior
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
File | Description |
---|---|
npm-packages/convex/src/cli/lib/envvars.ts | Added process.env check to skip .env.local creation when variables exist |
npm-packages/convex/src/cli/lib/deployment.ts | Added early return when CONVEX_DEPLOYMENT exists in process.env |
npm-packages/convex/src/cli/lib/envvars.test.ts | New test file covering process.env behavior scenarios |
npm-packages/convex/src/cli/lib/deployment.test.ts | Added test for deployment env var skip behavior |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
@nipunn1313 could you take at look at this PR for me? I'd appreciate any feedback |
@delkopiso these values aren't secret, and they're needed by the frontend to know where to connect to. What's your use case, what's the flow you'd like to support here? |
I'll wait to hear what you're trying to support, if I were guessing I'd say
|
@thomasballinger my primary usecase is working on separate projects concurrently. I first ran into issues because the access token setup assumes a single account for all projects. Ultimately, there are two things I want to solve for:
I documented in #191 that setting CONVEX_DEPLOY_KEY didn't prevent the dev flow from trying to write the files. |
Hm, re multiple accounts that's just not something we're anticipating; can you add your single account to multiple teams instead? It sounds like you want to be logged into multiple accounts and have which account is used depend on the project; nothing like this planned but if there's a good reason you need multiple accounts it sounds like that's something to think about for the future. Re the first bullet
Every time someone checks your project repo out and runs convex, they get a new CONVEX_URL. It sounds like you want to take this environment variable and move it to another system. You have another way of telling the frontend/client/website what URL to use to talk to the backend. Are you saying that if the correct environment variables exist in I totally agree re CONVEX_DEPLOYMENT, that shouldn't be in .env.local; that's just a convenient place to put it to remember which project a repo checkout is associated with. Two potential alternative proposals here:
|
Summary
Fixes issue where Convex CLI always creates
.env.local
files even when required environment variables (CONVEX_DEPLOYMENT
,CONVEX_URL
, etc.) are already available in the shell environment. This was problematic for users who manage secrets with external tools, usedirenv
, or deploy in CI/CD environments.This PR contains two commits that together resolve the issue:
process.env
before creating.env.local
filesProblem Solved
Root Cause: The CLI only checked for environment variables in files (
.env.local
,.env
) but not in the shell environment (process.env
).Before:
.env.local
even whenCONVEX_DEPLOYMENT
was set viadirenv
, CI/CD, or shell exportsAfter:
process.env
and skips file creationFixes #191
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.