Skip to content

Conversation

theoephraim
Copy link
Member

This PR is a first implementation of a new @import decorator, which allows explicitly importing more data sources (.env files). This will be especially useful in large projects where you want to break up a large .env file, or in a monorepo, where you want shared info at the root, or to pick specific items from a relevant sibling service - single source of truth!!

This also starts opening up the door for pre-made schemas for popular platforms and libraries -- e.g. all the env vars injected by vercel, or the env vars that a particular tool/library will be looking for.

--
In order to do this, we did a lot of refactoring around data sources, and moved the logic of automatically loading .env.* files into a new "directory data source". This is so that we can explicitly import a directory, and have all the appropriate files loaded. This also forced me to rework how @envFlag is handled.

Some notes:

  • Data sources now always have a parent chain and there is a single root source
  • all auto-imported sources within a directory are a child of the directory source (.env, .env.*)
  • We realized that Next.js by default does not load .env.local in test mode. We contemplated mimicking this behaviour, but ultimately decided to follow Vite's lead (and load it), but provide a way to explicitly follow that pattern with # @disable=forEnv(test)
  • We allow multiple envFlag values to exist now, so that if you are importing from another service, you could have something like WEB_ENV and API_ENV, and still pull the staging api url into a dev web build. This works by walking up the parent chain

Next steps for imports:

  • allow imports over http, and via npm (either locally from node_modules or remotely)
  • allow renaming keys while importing them
  • figure out how to handle importing a key that depends on another that is not imported (we may import implicitly?)

Copy link

changeset-bot bot commented Sep 13, 2025

🦋 Changeset detected

Latest commit: a518f3f

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

This PR includes changesets to release 5 packages
Name Type
@env-spec/parser Patch
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

Copy link

cloudflare-workers-and-pages bot commented Sep 13, 2025

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 a518f3f Commit Preview URL

Branch Preview URL
Sep 19 2025, 05:45 AM

@theoephraim theoephraim marked this pull request as draft September 13, 2025 21:04
Copy link

socket-security bot commented Sep 18, 2025

Copy link

pkg-pr-new bot commented Sep 18, 2025

Open in StackBlitz

@env-spec/parser

npm i https://pkg.pr.new/dmno-dev/varlock/@env-spec/parser@147

varlock

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

@varlock/astro-integration

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

@varlock/nextjs-integration

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

@varlock/vite-integration

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

commit: a518f3f

@theoephraim theoephraim marked this pull request as ready for review September 18, 2025 00:21
@github-actions github-actions bot added the docs label Sep 18, 2025
cursor[bot]

This comment was marked as spam.

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 :shipit:

give the docs I added a once over and feel free to edit!

@theoephraim theoephraim merged commit 9d9c8de into main Sep 19, 2025
11 of 12 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