Repository navigation
feat(vite): self-deduplicating Cloudflare plugin — no more env-var guard in vite configs - #1183
Open
sam-goodwin wants to merge 1 commit into
Open
sam-goodwin wants to merge 1 commit into
sam-goodwin wants to merge 1 commit into
Conversation
…stand down against the orchestrated instance
Apps that also build standalone declare `cloudflare({...})` in their own
vite.config.ts; alchemy-orchestrated runs inject a second, fully
resolved instance. The config-file instance previously had to guard
itself with the ALCHEMY_CLOUDFLARE_VITE_INJECTED env-var ternary or two
same-named plugin stacks would load (name-resolved cross-plugin lookups
hit the wrong instance; dev boots a bindings-less second workerd).
The plugin now dedups itself: orchestrated call sites (alchemy's
viteDev/viteBuild, the Astro integration, the Waku cloudflare target)
pass `injected: true`, which stamps a marker property on the instance's
plugin objects; a non-injected instance carries an `apply` clause that
scans the merged config's plugin tree for the marker and stands down.
Vite evaluates `apply` before a plugin enters the pipeline, so a
standing-down instance runs no hooks, boots no workerd, and never
appears in configResolved.plugins — name lookups can only find the
injected instance. Detection rides on the plugin objects (not module
state) because the two instances may come from different copies of the
module (app node_modules vs orchestrator).
The env var is still set for existing configs that guard on it (their
ternary yields null, equally correct); new configs need no guard — the
vite-fixture's config now declares the plugin unguarded to pin the
behavior end to end.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
|
Install the packages built from this commit: Alchemyalchemy bun add https://pkg.ing/alchemy/5bc6eca@alchemy.run/better-auth bun add https://pkg.ing/@alchemy.run/better-auth/5bc6eca@alchemy.run/cloudflare-runtime bun add https://pkg.ing/@alchemy.run/cloudflare-runtime/5bc6eca@alchemy.run/cloudflare-frameworks bun add https://pkg.ing/@alchemy.run/cloudflare-frameworks/5bc6eca@alchemy.run/pr-package bun add https://pkg.ing/@alchemy.run/pr-package/5bc6ecaDistilled@distilled.cloud/core bun add https://pkg.ing/@distilled.cloud/core/26852f0@distilled.cloud/aws bun add https://pkg.ing/@distilled.cloud/aws/26852f0@distilled.cloud/axiom bun add https://pkg.ing/@distilled.cloud/axiom/26852f0@distilled.cloud/cloudflare bun add https://pkg.ing/@distilled.cloud/cloudflare/26852f0@distilled.cloud/neon bun add https://pkg.ing/@distilled.cloud/neon/26852f0@distilled.cloud/planetscale bun add https://pkg.ing/@distilled.cloud/planetscale/26852f0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #1129: the Cloudflare Vite plugin now deduplicates itself, so apps that also build standalone can declare it unguarded — the
ALCHEMY_CLOUDFLARE_VITE_INJECTEDenv-var ternary is no longer needed.Orchestrated call sites (alchemy's
viteDev/viteBuild, the Astro integration, the Waku cloudflare target) passinjected: true, which stamps a marker property on that instance's plugin objects. A non-injected instance carries anapplyclause that scans the merged config's plugin tree for the marker and stands down:Why this shape:
applybefore a plugin enters the pipeline — a standing-down instance runs no hooks, boots no workerd, and never appears inconfigResolved.plugins, so the name-based cross-plugin lookups (distilled-cloudflare:options) can only find the injected instance.node_modulesvs orchestrator's), so a module-level flag would not be shared between them.null, which is equally correct. It's now documented as deprecated for new configs.Coverage: unit +
vite.resolveConfigintegration tests assert exactly one active plugin stack in every combination (plugin-dedup.test.ts), and the Website vite fixture'svite.config.tsnow declares the plugin unguarded — theVite,Vite.local, andViteRoutePrefixsuites (18 tests) only pass if the config-file instance stands down in both dev and live builds.🤖 Generated with Claude Code