Skip to content

fix(cli): follow .env.example ordering and comments when writing .env.local - #3100

Merged
jorgemoya merged 2 commits into
canaryfrom
jorgemoya/ltrac-974-follow-envexample-when-setting-new-environment-variables
Jul 14, 2026
Merged

fix(cli): follow .env.example ordering and comments when writing .env.local#3100
jorgemoya merged 2 commits into
canaryfrom
jorgemoya/ltrac-974-follow-envexample-when-setting-new-environment-variables

Conversation

@jorgemoya

Copy link
Copy Markdown
Contributor

Linear: LTRAC-974

What/Why?

writeEnv emitted a flat, unordered list of KEY=VALUE pairs that looked nothing like the documented core/.env.example — no comments, arbitrary order, no signal about what still needs filling in. This uses .env.example as the source of truth for shape and ordering: keys are emitted in their documented order with each key's leading comment block preserved; documented-but-unset keys render as blank active keys (KEY=); and CLI-supplied keys not in the example are appended in a clearly separated trailing section. Existing .env.local values are preserved and reconciled against .env.example on re-runs (newly documented keys get added in canonical position without disturbing existing values).

Out of scope: deployment secrets in .bigcommerce/project.json / catalyst env add (tracked in LTRAC-975).

Testing

  • write-env.spec.ts (7 tests): ordering, comment preservation, blank-key rendering for missing keys, unknown-key passthrough, and the re-sync path.
  • typecheck and lint pass.

Migration

None.

@vercel

vercel Bot commented Jul 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
catalyst Ready Ready Preview, Comment Jul 14, 2026 5:28pm

Request Review

@changeset-bot

changeset-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 30b0a05

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@bigcommerce/catalyst Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Report

Comparing against baseline from 25d6471 (2026-07-14).

No bundle size changes detected.

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Unlighthouse Performance Comparison — Vercel

Comparing PR preview deployment Unlighthouse scores vs production Unlighthouse scores.

Summary Score

Aggregate score across all categories as reported by Unlighthouse.

Prod Desktop Prod Mobile Preview Desktop Preview Mobile
Score 90 93 92 95

Category Scores

Category Prod Desktop Prod Mobile Preview Desktop Preview Mobile
Performance 76 71 77 91
Accessibility 95 98 95 92
Best Practices 100 100 100 100
SEO 88 88 100 100

Core Web Vitals

Metric Prod Desktop Prod Mobile Preview Desktop Preview Mobile
LCP 3.6 s 5.4 s 3.6 s 3.4 s
CLS 0.001 0.184 0.001 0
FCP 1.2 s 1.2 s 1.1 s 1.1 s
TBT 10 ms 20 ms 0 ms 0 ms
Max Potential FID 60 ms 70 ms 50 ms 50 ms
Time to Interactive 3.7 s 5.4 s 3.6 s 3.6 s

Full Unlighthouse report →

@jorgemoya
jorgemoya marked this pull request as ready for review July 14, 2026 16:36
@jorgemoya
jorgemoya requested a review from a team as a code owner July 14, 2026 16:36
@jorgemoya
jorgemoya force-pushed the jorgemoya/ltrac-974-follow-envexample-when-setting-new-environment-variables branch from f3a30d0 to 9ae6f0d Compare July 14, 2026 16:36
jorgemoya and others added 2 commits July 14, 2026 12:27
….local

writeEnv previously emitted a flat, unordered list of KEY=VALUE pairs,
ignoring core/.env.example — the file that documents every variable with
comments, ordering, and sensible defaults. Generated .env.local files were
therefore inconsistent and undocumented, and channel link/create clobbered
any values the user had already set.

writeEnv now reads the project's own .env.example as the source of truth for
shape. It reproduces the documented ordering and per-key comment blocks,
substitutes CLI-supplied values in place, and leaves documented-but-unsupplied
keys as their example line (blank or default) so users still see what's
expected. CLI-only variables (e.g. access tokens not in .env.example) are
appended in a clearly separated trailing section.

Existing .env.local files are reconciled rather than overwritten: user-set
values are preserved unless the CLI explicitly supplies a new one, and newly
documented keys are added in their canonical position without disturbing the
ordering of unknown keys. Falls back to a flat merge when no .env.example is
present.

Refs LTRAC-974
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…mpty

`catalyst channel link` inlined its own .env.local dump instead of going
through writeEnv, so it skipped the .env.example ordering/comments and
overwrote the file rather than reconciling it. Route it through writeEnv
like `channel create --link`.

Also stop empty CLI-supplied values from clobbering existing on-disk
values: the channel init API returns blank placeholders for keys it does
not own (e.g. MAKESWIFT_SITE_API_KEY), which were wiping the user's real
value on re-run. An empty supplied value now falls back to the existing
.env.local value.

Refs LTRAC-974
Co-Authored-By: Claude <noreply@anthropic.com>
@jorgemoya
jorgemoya force-pushed the jorgemoya/ltrac-974-follow-envexample-when-setting-new-environment-variables branch from e97863c to 30b0a05 Compare July 14, 2026 17:27
@jorgemoya
jorgemoya enabled auto-merge July 14, 2026 17:30
@jorgemoya
jorgemoya added this pull request to the merge queue Jul 14, 2026
Merged via the queue into canary with commit 07cd41c Jul 14, 2026
24 of 25 checks passed
@jorgemoya
jorgemoya deleted the jorgemoya/ltrac-974-follow-envexample-when-setting-new-environment-variables branch July 14, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants