Skip to content

feat: add @varlock/cloudflare-integration package#480

Open
theoephraim wants to merge 5 commits intomainfrom
feature/cloudflare-integration
Open

feat: add @varlock/cloudflare-integration package#480
theoephraim wants to merge 5 commits intomainfrom
feature/cloudflare-integration

Conversation

@theoephraim
Copy link
Member

Summary

  • New @varlock/cloudflare-integration package that replaces bundling secrets into worker code with Cloudflare's native secrets/vars mechanism
  • varlockCloudflareVitePlugin() reads __VARLOCK_ENV from Cloudflare secret bindings at runtime via import { env } from 'cloudflare:workers'
  • varlock-wrangler CLI wraps wrangler to automatically upload non-sensitive values as vars and sensitive values as secrets on deploy
  • varlock-wrangler types generates correct Cloudflare Env types including varlock-managed env vars
  • resolvedEnvVars() helper for optionally injecting vars into miniflare bindings in local dev
  • Refactors base Vite plugin to remove Cloudflare-specific logic and add generic extension points (ssrEntryCode, ssrEdgeRuntime, ssrEntryModuleIds, ssrInjectModeDev)
  • Updated Cloudflare docs page

Test plan

  • vite dev works with varlockCloudflareVitePlugin() — env vars load correctly
  • Env var changes in dev are picked up on restart
  • varlock-wrangler deploy uploads vars and secrets correctly
  • varlock-wrangler types generates Env interface with varlock-managed vars
  • resolvedEnvVars() enables native env.MY_VAR access in miniflare dev
  • Non-cloudflare vite projects still work with base varlockVitePlugin()

🤖 Generated with Claude Code

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 24, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
varlock-website 5a87d42 Commit Preview URL

Branch Preview URL
Mar 25 2026, 05:25 AM

@changeset-bot
Copy link

changeset-bot bot commented Mar 24, 2026

🦋 Changeset detected

Latest commit: 5a87d42

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

This PR includes changesets to release 2 packages
Name Type
@varlock/cloudflare-integration Patch
@varlock/vite-integration 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

Copy link
Member

@philmillman philmillman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

one thing we might consider for the docs is calling out explicitly what the upgrade would look like for existing varlock/cloudflare users

@socket-security
Copy link

socket-security bot commented Mar 25, 2026

No dependency changes detected. Learn more about Socket for GitHub.

👍 No dependency changes detected in pull request

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 25, 2026

Open in StackBlitz

npm i https://pkg.pr.new/varlock@480
npm i https://pkg.pr.new/@varlock/cloudflare-integration@480
npm i https://pkg.pr.new/@varlock/vite-integration@480

commit: 5a87d42

theoephraim and others added 3 commits March 25, 2026 01:14
New package for Cloudflare Workers that replaces bundling secrets into
worker code with Cloudflare's native secrets/vars mechanism.

- `varlockCloudflareVitePlugin()` - Vite plugin that reads `__VARLOCK_ENV`
  from Cloudflare secret bindings at runtime via `cloudflare:workers`
- `varlock-wrangler` CLI - drop-in wrangler replacement that uploads
  non-sensitive values as vars and sensitive values as secrets on deploy,
  and generates correct types including varlock-managed env vars
- `resolvedEnvVars()` helper for injecting vars into miniflare bindings
  in local dev

Refactors the base Vite plugin to remove Cloudflare-specific logic and
add generic extension points (ssrEntryCode, ssrEdgeRuntime,
ssrEntryModuleIds, ssrInjectModeDev) that platform integrations can use.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- varlock-wrangler dev: injects env into miniflare via Unix named pipe
  (FIFO) so secrets never touch disk; watches .env files and restarts
  wrangler on changes; preserves color output
- varlock-wrangler types: passes env keys via --env-file for correct
  Env type generation
- @varlock/cloudflare-integration/init: standalone init module for
  non-Vite workers (reads __VARLOCK_ENV from CF bindings, patches
  console/response)
- Rewrite docs: show varlock-wrangler approach first, Vite second;
  move native env access section into Vite section
- Fix env file format: use single-quoted dotenv values to avoid
  escaping issues with JSON in __VARLOCK_ENV

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@theoephraim theoephraim force-pushed the feature/cloudflare-integration branch from 3d2a6de to 2c7942e Compare March 25, 2026 05:15
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@theoephraim theoephraim force-pushed the feature/cloudflare-integration branch from ba578fa to 8bf8ac9 Compare March 25, 2026 05:19
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@theoephraim theoephraim force-pushed the feature/cloudflare-integration branch from 8bf8ac9 to 5a87d42 Compare March 25, 2026 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants