Skip to content

new auto-inferred VARLOCK_ENV#285

Merged
theoephraim merged 7 commits intomainfrom
varlock-env
Feb 27, 2026
Merged

new auto-inferred VARLOCK_ENV#285
theoephraim merged 7 commits intomainfrom
varlock-env

Conversation

@theoephraim
Copy link
Member

@theoephraim theoephraim commented Feb 10, 2026

This PR explores the idea of automatically inferring a VARLOCK_ENV that tries to just magically be set to the right thing.

The intention here is that you can use # @currentEnv=$VARLOCK_ENV without defining it and it will "Just Work".

To make this possible, we detect a bunch of known env vars based on various CI/deployment platforms and attempt to normalize them. While these magic vars will always be available, they do not automatically appear in your schema until they are used/referenced.

The full list of magic vars for now is:

  • VARLOCK_ENV - development, preview, staging, production, test
  • VARLOCK_IS_CI - true if we are in CI
  • VARLOCK_BRANCH - branch name being tested/deployed
  • VARLOCK_PR_NUMBER - PR number if this is a PR build
  • VARLOCK_COMMIT_SHA/VARLOCK_COMMIT_SHA - current commit sha long/short versions
  • VARLOCK_BUILD_URL - url where this will be deployed
  • VARLOCK_REPO - current repo in "owner/repo" format (e.g., dmno-dev/varlock)
  • VARLOCK_PLATFORM - current platform name (eg, "Github Actions", "Cloudflare")

Not all platforms populate all of these, so we would just populate whatever we can.

You may reference these vars and they will automatically appear in your schema. For others you want added to your schema, but don't necessarily reference anywhere else, we could let you just define them without a value (e.g., VARLOCK_BRANCH=).

Alternatively, we could have some kind of root decorator that explicitly adds these built-in vars to your schema.

# @useInferredVars(VARLOCK_ENV, VARLOCK_BRANCH)

Or a special infer() function which is only available on these vars. This is clean, although the automatic vars have more than just a value - description, type info, etc...

VARLOCK_ENV=infer()
VARLOCK_BRANCH=infer()

Open to ideas!


One other challenge here is that we may not always be able to infer when VARLOCK_ENV is test. This is because in some cases the test runner will automatically set NODE_ENV=test (or another similar env var) after varlock already loads the config. For example varlock run -- some-test-command .... It depends a bit on your test runner and the integration. For vite/vitest if you use the vite plugin instead of varlock run, it should work. The workaround when it cannot be set automatically is to just write VARLOCK_ENV=test varlock run -- your-test-cmd


Of course users can also be more explicit and construct their own env flag too - and we'll add a few more utility functions to make that more clear, especially with multi-line function calls now working.

@changeset-bot
Copy link

changeset-bot bot commented Feb 10, 2026

🦋 Changeset detected

Latest commit: 3f23eaf

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

This PR includes changesets to release 11 packages
Name Type
@varlock/ci-env-info Patch
varlock Patch
@varlock/astro-integration Patch
@varlock/nextjs-integration Patch
@varlock/vite-integration Patch
@varlock/1password-plugin Patch
@varlock/aws-secrets-plugin Patch
@varlock/azure-key-vault-plugin Patch
@varlock/bitwarden-plugin Patch
@varlock/google-secret-manager-plugin Patch
@varlock/infisical-plugin 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

@theoephraim theoephraim force-pushed the varlock-env branch 2 times, most recently from 4a952a2 to f2e3f12 Compare February 10, 2026 05:26
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 10, 2026

Open in StackBlitz

@varlock/ci-env-info

npm i https://pkg.pr.new/@varlock/ci-env-info@285

@env-spec/parser

npm i https://pkg.pr.new/@env-spec/parser@285

varlock

npm i https://pkg.pr.new/varlock@285

@varlock/1password-plugin

npm i https://pkg.pr.new/@varlock/1password-plugin@285

@varlock/aws-secrets-plugin

npm i https://pkg.pr.new/@varlock/aws-secrets-plugin@285

@varlock/azure-key-vault-plugin

npm i https://pkg.pr.new/@varlock/azure-key-vault-plugin@285

@varlock/bitwarden-plugin

npm i https://pkg.pr.new/@varlock/bitwarden-plugin@285

@varlock/google-secret-manager-plugin

npm i https://pkg.pr.new/@varlock/google-secret-manager-plugin@285

@varlock/infisical-plugin

npm i https://pkg.pr.new/@varlock/infisical-plugin@285

@varlock/astro-integration

npm i https://pkg.pr.new/@varlock/astro-integration@285

@varlock/nextjs-integration

npm i https://pkg.pr.new/@varlock/nextjs-integration@285

@varlock/vite-integration

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

commit: 8ff11d9

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.

Good to go once you've given it a final pass and resolved the conflicts @theoephraim

- Add reference/builtin-variables.mdx documenting all VARLOCK_* vars
- Add sidebar entry with "new" badge
- Add tip in environments guide pointing to VARLOCK_ENV auto-detect
- Fix ci-env-info README: correct import path, complete API fields, add
  varlock context and supported platforms list
- Fix ci-env-info package.json engine requirement

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 27, 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 3f23eaf Commit Preview URL

Branch Preview URL
Feb 27 2026, 06:48 AM

@github-actions github-actions bot added the docs label Feb 27, 2026
theoephraim and others added 4 commits February 26, 2026 18:33
When a user defines a VARLOCK_* var explicitly (e.g., VARLOCK_ENV= to
add decorators), the builtin auto-detection resolver now acts as a
fallback. Empty static values are skipped in favor of the internal
resolver, while explicit values (VARLOCK_ENV=production) still override.

- registerBuiltinVar now attaches internal def to existing items
- finishLoad scans for user-defined VARLOCK_* keys before processing
- valueResolver skips empty static resolvers when internal fallback exists
- Updated docs to clarify both usage patterns (reference vs direct define)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@theoephraim theoephraim merged commit 2d15354 into main Feb 27, 2026
15 checks passed
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