Skip to content

Add conditional imports with enabled parameter#273

Merged
theoephraim merged 7 commits intomainfrom
copilot/add-conditional-imports-feature
Feb 6, 2026
Merged

Add conditional imports with enabled parameter#273
theoephraim merged 7 commits intomainfrom
copilot/add-conditional-imports-feature

Conversation

Copy link
Contributor

Copilot AI commented Feb 6, 2026

Implementation Plan for Conditional Imports Feature

  • Explore codebase and understand current @import implementation
  • Update @import decorator definition to support named parameter enabled
  • Modify import processing logic to evaluate enabled condition before creating child data sources
  • Handle early resolution of dependencies within the enabled condition
  • Create comprehensive tests for conditional imports
  • Test basic enabled=true and enabled=false scenarios
  • Test enabled with function calls (e.g., eq(SOME_VAR, "value"))
  • Test early dependency resolution
  • Test error cases (invalid enabled values)
  • Run all tests to ensure no regressions
  • Manual verification of the feature
  • Run code review
  • Run security checks
  • Remove accidentally committed .env files
  • Update documentation
  • Add changeset
  • Create PR guidelines for future agents
  • Fix linting errors
  • Resolve merge conflict with main branch

Summary

Successfully implemented conditional imports for varlock's env-spec files. The feature allows importing files based on boolean conditions using the enabled parameter.

Key Features:

  • ✅ Support for static boolean values (enabled=true, enabled=false)
  • ✅ Support for dynamic conditions using functions (enabled=eq($ENV, "dev"))
  • ✅ Early resolution of variable dependencies in conditions
  • ✅ Proper error handling for invalid enabled values
  • ✅ Works with partial imports (import specific keys)
  • ✅ Works with forEnv() and other resolver functions
  • ✅ Compatible with home directory (~) and absolute path imports from main branch

Example Usage:

# @import(./.env.dev, enabled=eq($ENV, "dev"))
# @import(./.env.prod, enabled=eq($ENV, "prod"))
# ---
ENV=dev

Documentation:

  • Updated /reference/root-decorators.mdx to document the enabled parameter
  • Added comprehensive "Conditional imports" section to /guides/import.mdx with multiple usage examples
  • Created changeset file for version tracking (.changeset/conditional-imports.md)
  • Created PR guidelines document (.github/agents/pr-guidelines.md) for future contributors

Test Results:

  • All 154 tests passing (152 passed, 2 todo)
  • 0 security vulnerabilities found
  • Manual testing confirmed feature works correctly
  • All linting checks passing
  • Successfully merged with main branch changes (home directory and absolute path support)

Merge Resolution:

Successfully resolved merge conflict between conditional imports feature and main branch changes:

  • Kept conditional import logic (early resolution of enabled parameter)
  • Integrated new path resolution logic from main (home directory ~ and absolute paths)
  • All tests passing after merge

Security Summary:

No security vulnerabilities were discovered during implementation. CodeQL analysis returned 0 alerts.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature Request] Conditional imports</issue_title>
<issue_description>### Description

Allow importing a file only if a condition is met. For example:

# @import(./.env.some-file, enabled=eq(SOME_VAR, "some val")
# ---

Proposed Solution

Add a new enabled property to the @import decorator which will decide whether or not to proceed based on some boolean. This may need to trigger earlier resolution of any other vars which are dependencies within the condition.

Alternatives

Currently, you could always import the file and use @disabled

Alternatively, we could think about introducing a higher level if block concept, that could enable/disable multiple arbitrary lines within the env file. Not sure it is worth the complexity.</issue_description>

<agent_instructions>this will need to trigger early resolution of any dependencies within the enabled value</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@changeset-bot
Copy link

changeset-bot bot commented Feb 6, 2026

🦋 Changeset detected

Latest commit: da0a748

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

This PR includes changesets to release 6 packages
Name Type
varlock Minor
@varlock/astro-integration Major
@varlock/nextjs-integration Major
@varlock/vite-integration Major
@varlock/1password-plugin Major
@varlock/google-secret-manager-plugin Major

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

Copilot AI changed the title [WIP] Add conditional imports feature with enabled property Add conditional imports with enabled parameter Feb 6, 2026
Copilot AI requested a review from theoephraim February 6, 2026 06:16
Copy link
Member

@theoephraim theoephraim left a comment

Choose a reason for hiding this comment

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

@copilot - remove the extra .env files

Copy link
Contributor Author

Copilot AI commented Feb 6, 2026

@copilot - remove the extra .env files

Done! Removed the .env.dev and .env.prod files in commit 86f1c15.

@theoephraim
Copy link
Member

@copilot - update the docs, add a changeset. Also adjust the copilot instructions so that future PRs will do the same.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 6, 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 83b20a4 Commit Preview URL

Branch Preview URL
Feb 06 2026, 08:38 PM

Copy link
Contributor Author

Copilot AI commented Feb 6, 2026

@copilot - update the docs, add a changeset. Also adjust the copilot instructions so that future PRs will do the same.

Done! Updated documentation and added changeset in commit 2e06fee:

Documentation updates:

  • Updated /reference/root-decorators.mdx to document the enabled parameter for @import()
  • Added comprehensive "Conditional imports" section to /guides/import.mdx with multiple usage examples

Changeset:

  • Created .changeset/conditional-imports.md as a minor version bump with detailed feature description

PR Guidelines:

  • Created .github/agents/pr-guidelines.md with instructions for future PRs to include:
    • Documentation updates for new features
    • Changeset creation requirements
    • Common documentation locations
    • Checklist to avoid common mistakes

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 6, 2026

Open in StackBlitz

varlock

npm i https://pkg.pr.new/dmno-dev/varlock@273

@varlock/astro-integration

npm i https://pkg.pr.new/dmno-dev/varlock/@varlock/astro-integration@273

@varlock/nextjs-integration

npm i https://pkg.pr.new/dmno-dev/varlock/@varlock/nextjs-integration@273

@varlock/vite-integration

npm i https://pkg.pr.new/dmno-dev/varlock/@varlock/vite-integration@273

@varlock/1password-plugin

npm i https://pkg.pr.new/dmno-dev/varlock/@varlock/1password-plugin@273

@varlock/google-secret-manager-plugin

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

commit: da0a748

@philmillman
Copy link
Member

@copilot fix linting errors

Copy link
Contributor Author

Copilot AI commented Feb 6, 2026

@copilot fix linting errors

Fixed in commit 09dc749. Resolved 72 linting errors (trailing spaces and indentation issues) in data-source.ts. All tests passing and linting checks clean.

Copilot AI requested a review from philmillman February 6, 2026 15:49
@philmillman philmillman marked this pull request as ready for review February 6, 2026 16:02
@philmillman
Copy link
Member

@theoephraim I'll let you deal with this merge conflict since you have the full context

@theoephraim
Copy link
Member

@copilot - resolve the merge conflict

Copy link
Contributor Author

Copilot AI commented Feb 6, 2026

@copilot - resolve the merge conflict

Resolved in commit 68d591e. Successfully merged main branch changes (home directory and absolute path support) with conditional imports feature. The merge integrated:

From our branch:

  • Conditional import logic with enabled parameter
  • Early resolution of dependencies in enabled conditions

From main:

  • Support for ~ home directory paths
  • Support for absolute paths starting with /
  • Updated import statement (added os module)

All 154 tests passing and linting clean.

Copilot AI and others added 5 commits February 6, 2026 12:10
Co-authored-by: theoephraim <1158956+theoephraim@users.noreply.github.com>
Co-authored-by: theoephraim <1158956+theoephraim@users.noreply.github.com>
Co-authored-by: theoephraim <1158956+theoephraim@users.noreply.github.com>
Co-authored-by: theoephraim <1158956+theoephraim@users.noreply.github.com>
@theoephraim theoephraim force-pushed the copilot/add-conditional-imports-feature branch 2 times, most recently from 1fa4ed7 to 8b49b4c Compare February 6, 2026 20:31
@theoephraim theoephraim force-pushed the copilot/add-conditional-imports-feature branch from 8b49b4c to 83b20a4 Compare February 6, 2026 20:35
@theoephraim theoephraim requested review from philmillman and removed request for philmillman February 6, 2026 20:54
@theoephraim theoephraim merged commit 15b9c81 into main Feb 6, 2026
11 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.

[Feature Request] Conditional imports

3 participants