Skip to content

Fix @import and @disable not seeing values from local env files#507

Merged
theoephraim merged 7 commits intomainfrom
fix/early-resolve-import-disable
Mar 30, 2026
Merged

Fix @import and @disable not seeing values from local env files#507
theoephraim merged 7 commits intomainfrom
fix/early-resolve-import-disable

Conversation

@theoephraim
Copy link
Copy Markdown
Member

@theoephraim theoephraim commented Mar 30, 2026

Summary

  • Bug: @import(enabled=eq($VAR, ...)) and @disable(not(eq($VAR, ...))) on imported files could not see values from .env, .env.local, .env.ENV, or .env.ENV.local — only the .env.schema default was visible during early resolution
  • Fix: Separates finishInit() (parsing, config item registration, @currentEnv) from _processImports() (import processing). DirectoryDataSource now loads all auto-loaded files first, then processes imports in a second pass once all values are available
  • Also adds early resolution of @disable decorator dependencies, which was previously only done for @import enabled conditions
  • Errors if a later-loaded file (env-specific or imported) tries to redefine an early-resolved item with a conflicting value — preventing silent contradictions. Non-conflicting redefinitions (same value, decorators-only, unrelated items) are allowed.

Test plan

  • 19 new tests in early-resolve-order.test.ts:
    • @import(enabled=...) with values from .env, .env.local, .env.ENV, .env.ENV.local + negative case
    • @import in .env.ENV enabled by .env.ENV.local + negative case
    • @disable(...) with values from .env, .env.local, .env.ENV, .env.ENV.local + negative case
    • Error when env-specific/imported file redefines @currentEnv item, @import enabled dep, or @disable dep with a different value
    • No error for: unrelated items, same value, decorators-only (no value)
  • All 327 existing tests pass — no regressions

🤖 Generated with Claude Code

…files

Previously, import conditions (enabled=eq($VAR, ...)) and imported file
@disable decorators were evaluated during .env.schema's initialization,
before .env, .env.local, and env-specific files were loaded. Variables
set in those files were invisible to early resolution.

The fix separates finishInit() (parsing, @disable, config item registration,
@currentEnv) from _processImports() (import processing). DirectoryDataSource
now loads all auto-loaded files first, then processes imports in a second pass
once all values are available. For non-directory usage (addChild, standalone
root), both steps run immediately as before.

Also adds early resolution of @disable decorator dependencies, which was
previously only done for @import enabled conditions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 30, 2026

🦋 Changeset detected

Latest commit: 0bd0d4d

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

This PR includes changesets to release 13 packages
Name Type
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/hashicorp-vault-plugin Patch
@varlock/infisical-plugin Patch
@varlock/pass-plugin Patch
@varlock/proton-pass-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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 30, 2026

Open in StackBlitz

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

commit: 0bd0d4d

theoephraim and others added 2 commits March 29, 2026 22:54
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
If a config item was already resolved during early initialization (for
@currentEnv, @import enabled, or @disable conditions), a later data source
redefining it would silently contradict the decision already made. Now
this produces a schema error.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@theoephraim theoephraim requested a review from philmillman March 30, 2026 06:23
Only error when a later file sets a different value for an early-resolved
item. No error when the file sets the same value, adds only decorators
(no value), or defines unrelated items.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
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 - test cases will be helpful

theoephraim and others added 2 commits March 30, 2026 13:28
…deduplicate child setup

- Fix bug where env-specific files loaded after a deferred import sets
  @currentEnv would never have their own imports processed
- Extract shared child-setup logic into _initChild() to deduplicate
  addChild() and _addChildWithoutImports()
- Fix misleading comment in setRootDataSource

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Loop over VALUE_SOURCE_FILES array to generate @import enabled and
@disable tests for each file type (.env, .env.local, .env.dev,
.env.dev.local) instead of repeating the test body 4 times. Always
include @currentEnv setup to keep the schema helper simple.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@theoephraim theoephraim force-pushed the fix/early-resolve-import-disable branch from 514d8b6 to 9955b17 Compare March 30, 2026 20:39
Covers the case where @currentEnv is set by an imported file and the
resulting env-specific file (.env.dev) itself has an @import that needs
to be processed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@theoephraim theoephraim merged commit 76c17f8 into main Mar 30, 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