From 4bc9efc39aa160a3ae9ee023ecdb4de872396fe5 Mon Sep 17 00:00:00 2001 From: Pedro Enrique Date: Mon, 1 Sep 2025 17:24:08 +0200 Subject: [PATCH 1/2] fix: prevent local development env files from syncing to production Local development files (.env.development, .env.local, etc.) should never be synced to the production database. This was causing the CLI to prompt users to sync development-only environment variables to their cloud project. The fix adds a conditional check to only call HandleMissingProjectEnvs when not in local development mode (isLocalDev = false). Fixes issue where users were getting prompted to sync env vars from .env.development files to production. Co-authored-by: Amp Amp-Thread-ID: https://ampcode.com/threads/T-94a6a673-ef07-4dbd-95a8-8437d17bdd21 --- internal/envutil/envutil.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/envutil/envutil.go b/internal/envutil/envutil.go index 5a4776fe..703b8abf 100644 --- a/internal/envutil/envutil.go +++ b/internal/envutil/envutil.go @@ -66,7 +66,11 @@ func ProcessEnvFiles(ctx context.Context, logger logger.Logger, dir string, thep errsystem.WithContextMessage("Error parsing .env file")).ShowErrorAndExit() } - projectData = HandleMissingProjectEnvs(ctx, logger, le, projectData, theproject, apiUrl, token, force) + // Only sync env vars to production when not in local development mode + // Local development files (.env.development, .env.local, etc.) should never be synced to production + if !isLocalDev { + projectData = HandleMissingProjectEnvs(ctx, logger, le, projectData, theproject, apiUrl, token, force) + } envFile.Env = le return envFile, projectData } From 1c1d569e032ecc45577365c0a310016f224c6ccf Mon Sep 17 00:00:00 2001 From: Pedro Enrique Date: Mon, 1 Sep 2025 17:42:49 +0200 Subject: [PATCH 2/2] Fix messaging around env vars syncing with production --- internal/envutil/envutil.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/internal/envutil/envutil.go b/internal/envutil/envutil.go index 703b8abf..920587a9 100644 --- a/internal/envutil/envutil.go +++ b/internal/envutil/envutil.go @@ -69,7 +69,7 @@ func ProcessEnvFiles(ctx context.Context, logger logger.Logger, dir string, thep // Only sync env vars to production when not in local development mode // Local development files (.env.development, .env.local, etc.) should never be synced to production if !isLocalDev { - projectData = HandleMissingProjectEnvs(ctx, logger, le, projectData, theproject, apiUrl, token, force) + projectData = HandleMissingProjectEnvs(ctx, logger, le, projectData, theproject, apiUrl, token, force, envfilename) } envFile.Env = le return envFile, projectData @@ -153,7 +153,7 @@ func HandleMissingTemplateEnvs(logger logger.Logger, dir, envfilename string, le } // HandleMissingProjectEnvs handles missing envs in project -func HandleMissingProjectEnvs(ctx context.Context, logger logger.Logger, le []env.EnvLineComment, projectData *project.ProjectData, theproject *project.Project, apiUrl, token string, force bool) *project.ProjectData { +func HandleMissingProjectEnvs(ctx context.Context, logger logger.Logger, le []env.EnvLineComment, projectData *project.ProjectData, theproject *project.Project, apiUrl, token string, force bool, envFilename string) *project.ProjectData { if projectData == nil { projectData = &project.ProjectData{} @@ -175,14 +175,18 @@ func HandleMissingProjectEnvs(ctx context.Context, logger logger.Logger, le []en if !force { var title string var suffix string + var question string + envFileDisplayName := tui.Bold(filepath.Base(envFilename)) + switch { case len(keyvalue) < 3 && len(keyvalue) > 1: - suffix = "it" + suffix = "them" var colorized []string for key := range keyvalue { colorized = append(colorized, tui.Bold(key)) } - title = fmt.Sprintf("The environment variables %s from %s are not been set in the project.", strings.Join(colorized, ", "), tui.Bold(".env")) + title = fmt.Sprintf("The environment variables %s from %s are not set in your cloud project.", strings.Join(colorized, ", "), envFileDisplayName) + question = fmt.Sprintf("Would you like to sync %s to your cloud project now?", suffix) case len(keyvalue) == 1: var key string for _key := range keyvalue { @@ -190,13 +194,16 @@ func HandleMissingProjectEnvs(ctx context.Context, logger logger.Logger, le []en break } suffix = "it" - title = fmt.Sprintf("The environment variable %s from %s has not been set in the project.", tui.Bold(key), tui.Bold(".env")) + title = fmt.Sprintf("The environment variable %s from %s has not been set in your cloud project.", tui.Bold(key), envFileDisplayName) + question = fmt.Sprintf("Would you like to sync %s to your cloud project now?", suffix) default: suffix = "them" - title = fmt.Sprintf("There are %d environment variables from %s that are not set in the project.", len(keyvalue), tui.Bold(".env")) + title = fmt.Sprintf("There are %d environment variables from %s that are not set in your cloud project.", len(keyvalue), envFileDisplayName) + question = fmt.Sprintf("Would you like to sync %s to your cloud project now?", suffix) } fmt.Println(title) - force = tui.Ask(logger, "Would you like to set "+suffix+" now?", true) + fmt.Println(tui.Muted("(Choosing 'no' won't affect your local development - these variables will still work locally)")) + force = tui.Ask(logger, question, true) } if force { for key, val := range keyvalue {