feat: persist the active environment in .env.local#210
Conversation
|
|
||
| export default createCommand(config, async ({ values }) => { | ||
| const { force = false, repo: parentRepo = await getRepositoryName(), env } = values; | ||
| const { force = false, repo: parentRepo = await resolveRepositoryName(), env } = values; |
There was a problem hiding this comment.
Active env breaks --env resolution
Medium Severity
The parentRepo variable, now resolved by resolveRepositoryName(), can incorrectly default to an active environment's domain from .env.local instead of the production repository. This happens when --repo is not provided, causing resolveEnvironment to use the wrong base repository and potentially fail or target incorrect environments for prismic push and prismic pull.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 8820fb6. Configure here.
|
|
||
| /** The repository name to target by default, honoring the active environment. */ | ||
| export async function resolveRepositoryName(): Promise<string> { | ||
| return (await getActiveRepositoryName()) ?? (await getRepositoryName()); |
There was a problem hiding this comment.
Empty active env breaks repo
Medium Severity
resolveRepositoryName uses nullish coalescing, so an empty NEXT_PUBLIC_PRISMIC_ENVIRONMENT (or adapter equivalent) in .env.local is treated as the repository name instead of falling back to prismic.config.json, leading to invalid API hosts and broken commands.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 8820fb6. Configure here.
8820fb6 to
b7a5949
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b7a5949. Configure here.
|
|
||
| export default createCommand(config, async ({ values }) => { | ||
| const { force = false, repo: parentRepo = await getRepositoryName(), env } = values; | ||
| const { force = false, repo: parentRepo = await resolveRepositoryName(), env } = values; |
There was a problem hiding this comment.
--env uses active staging parent
Medium Severity
When --env is used without --repo and a staging environment is active, the parentRepo incorrectly resolves to the staging domain. This causes environment resolution to query the staging repository's API instead of the production one, leading to incorrect or failed lookups.
Reviewed by Cursor Bugbot for commit b7a5949. Configure here.
Add `prismic env list/set/unset/active` to manage the active environment, persisted as a framework-specific variable in `.env.local`. The CLI reads it as the default repository (after `--env` and `--repo`, before the config default), and generated Next.js and SvelteKit projects read it natively. Nuxt reads it through `@nuxtjs/prismic`. Resolves: #209 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
b7a5949 to
4a511c6
Compare


Resolves: #209
Description
Environments only had low-level controls:
--envworked per command but nothing persisted it, so a dev had to remember which environment they were in and repeat the flag. This adds a persisted, shared active environment.prismic env list— list environments, including production, marking the active oneprismic env set <name>— set the active environment (writes it to.env.local)prismic env unset— revert to production (removes it from.env.local)prismic env active— print the active environmentThe active environment is stored as one framework-specific variable in
.env.local, resolved by the adapter (NEXT_PUBLIC_PRISMIC_ENVIRONMENT,NUXT_PUBLIC_PRISMIC_ENVIRONMENT,VITE_PRISMIC_ENVIRONMENT). The CLI reads it as the default repository (after--envand--repo, before theprismic.config.jsondefault). Generated Next.js and SvelteKit projects read the same variable natively; Nuxt reads it through@nuxtjs/prismic. The names match Slice Machine, so existing.env.localfiles stay compatible.Checklist
Preview
How to QA 1
In a Next.js or SvelteKit project with environments:
prismic env list— production is marked active.prismic env set <environment>— writes the variable to.env.local;prismic env activereflects it, and content commands target it.prismic env unset— reverts to production.Note
Medium Risk
Default repository resolution now affects many API commands (push/pull/sync, tokens, webhooks), so a stale
.env.localcould target the wrong environment; changes are local-dev focused and--repo/--envstill override.Overview
Adds a
prismic envcommand group so local dev can keep a shared active environment instead of passing--envon every command.env list,env set,env unset, andenv activeread and write a framework-specific variable in.env.local(NEXT_PUBLIC_PRISMIC_ENVIRONMENT,NUXT_PUBLIC_PRISMIC_ENVIRONMENT, orVITE_PRISMIC_ENVIRONMENT). Setting production removes the variable. Adapters exposerepositoryEnvVar; newlib/env-filehelpers update the file.resolveRepositoryName()(active env fromprocess.env/.env.local, elseprismic.config.json) replacesgetRepositoryName()as the default target for push/pull/sync/status and locale, preview, token, and webhook commands.--env/--repostill override per invocation.Scaffolded Next.js and SvelteKit
prismiciotemplates prefer the same env var forrepositoryName, aligning the dev server with CLI and Slice Machine naming.Reviewed by Cursor Bugbot for commit 4a511c6. Bugbot is set up for automated code reviews on this repo. Configure here.
Footnotes
Please use these labels when submitting a review:
⚠️ #issue: Strongly suggest a change.
❓ #ask: Ask a question.
💡 #idea: Suggest an idea.
🎉 #nice: Share a compliment. ↩