Skip to content

feat: inject the active environment via prismic/env/register#220

Draft
angeloashmore wants to merge 3 commits into
aa/env-wire-commandsfrom
aa/env-register
Draft

feat: inject the active environment via prismic/env/register#220
angeloashmore wants to merge 3 commits into
aa/env-wire-commandsfrom
aa/env-register

Conversation

@angeloashmore

@angeloashmore angeloashmore commented Jul 8, 2026

Copy link
Copy Markdown
Member

Resolves:

Note

Top of the stack: #218#219#220 (this PR). Merge #218 then #219 first — this PR targets #219's branch.

Because this PR's base is #219, its per-PR prerelease (prismic@pr-220) contains the full environments flow (A+B+C) and is the one to install for end-to-end testing.

Description

Adds the prismic/env/register export so a running app can follow the active environment, not just the CLI. A site adds one import to the top of its framework config:

// next.config.ts, nuxt.config.ts, or vite.config.ts (SvelteKit)
import "prismic/env/register";

The preload reads the active environment (from #218) and sets the framework's public environment variable before the app boots. gen setup adds the import automatically for Next.js, Nuxt, and SvelteKit (ESM configs only).

Two supporting changes make the import work in a real project:

  • gen setup adds prismic as a project dependency when it injects the import, so prismic/env/register resolves at runtime.
  • The CLI's update notice now points to the package manager (e.g. npm install prismic@latest) when prismic is a project dependency, instead of npx, which would fetch a fresh copy without changing the installed version. The npx message still shows when prismic is not installed locally.

Checklist

  • A comprehensive Linear ticket, providing sufficient context and details to facilitate the review of the PR, is linked to the PR.
  • If my changes require tests, I added them.
  • If my changes affect backward compatibility, it has been discussed.
  • If my changes require an update to the CONTRIBUTING.md guide, I updated it.

Preview

How to QA 1

prismic env set my-repo-staging

Run prismic gen setup and confirm it adds import "prismic/env/register" to the framework config and prismic to the project's dependencies. Then run npm run dev and confirm the app reads the active environment as NEXT_PUBLIC_ / NUXT_PUBLIC_ / PUBLIC_PRISMIC_ENVIRONMENT.

To check the update notice, install prismic in a project and confirm the notice suggests your package manager (e.g. npm install prismic@latest) rather than npx.

Footnotes

  1. Please use these labels when submitting a review:
    ❓ #ask: Ask a question.
    💡 #idea: Suggest an idea.
    ⚠️ #issue: Strongly suggest a change.
    🎉 #nice: Share a compliment.

Add the `prismic/env/register` export, which sets the framework's public
environment variable from the active environment at config-load time, and
wire `gen setup` to import it in the framework config for Next.js, Nuxt,
and SvelteKit.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
angeloashmore and others added 2 commits July 9, 2026 00:21
… notice

`gen setup` adds `prismic` as a project dependency when it injects the
`prismic/env/register` import, so the import resolves at runtime.

When `prismic` is installed as a project dependency, the update notice now
points to the package manager (e.g. `npm install prismic@latest`) instead
of `npx`, which would fetch a fresh copy without changing the installed
version.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The module used top-level `await`, which fails when a bundler loads a
config file that doesn't support it (e.g. Next.js loading
`next.config.ts`), throwing `ReferenceError: await is not defined`.
Resolve the active environment synchronously instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant