Skip to content

@required - env() helper#136

Merged
philmillman merged 2 commits intomainfrom
conditional-require
Sep 4, 2025
Merged

@required - env() helper#136
philmillman merged 2 commits intomainfrom
conditional-require

Conversation

@theoephraim
Copy link
Copy Markdown
Member

@theoephraim theoephraim commented Aug 27, 2025

First steps towards #119

This adds a new helper to set item required-ness based on the current env (as set by @envFlag)

Some notes:

  • not sure about the env() name, could be ifEnv isEnv forEnv
  • value can be a single env, or multiple
  • works for both @required and @optional
  • if the value is dynamic, we must respect that in type generation

In an ideal world, we'd handle any arbitrary logic here, and likely unify our resolver functions (which are used for item values) with our decorator values. However this introduces a lot of complexity, because now items can be dependent on each other in new ways, and the resolution process would need to handle that.

For now, we are using a much more limited subset. Using the envFlag is totally safe, because we always resolve that up front, so it does not introduce any new ordering / dependency issues. We likely want to add a few more helpers here, but they will likely have additional limitations, which will allow us to keep things a bit simpler.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Aug 27, 2025

🦋 Changeset detected

Latest commit: 65c9466

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

This PR includes changesets to release 4 packages
Name Type
varlock Patch
@varlock/astro-integration Patch
@varlock/nextjs-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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Aug 27, 2025

Open in StackBlitz

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

commit: 65c9466

@philmillman
Copy link
Copy Markdown
Member

I think I like forEnv(...) as it seems the most semantic

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.

🚢

@philmillman philmillman merged commit 851aaf0 into main Sep 4, 2025
8 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