Feature request - env var related hooks #10691
Replies: 1 comment
-
Hi theoephraim, Your feature request about env var hooks is very practical. Managing environment variables across a monorepo, especially when using external tools like varlock, can be complex. Having Turbo run a command to fetch environment variables along with caching metadata would simplify config and reduce duplication. It would allow Turbo to better understand how environment variables affect caching without manual listing in config files. Running this command per project and using the results in task scheduling and caching logic seems like a flexible and powerful idea. If the Turbo team is open to it, your help with specifying and implementing this feature could speed up its progress. Thanks for sharing this idea—better env var handling would be very helpful for many users. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Background
https://varlock.dev is a tool that loads and manages environment variables. It allows users to embed schema info in .env files using
@decorator
style comments, and then load and validate those env vars. This means you always have a full schema of all of the env vars your application may interact with. These vars may be set by being passed in when you run your CLI command, from the schema itself, or being fetched using instructions within the schema.In a monorepo, we may want to set some vars at the root level, and then have child repos load more vars specific to that service. Currently turbo would only care about the vars that have been set when passed into the parent turbo command.
It's also very easy to forget that env vars get swallowed (not passed through) by turbo unless they are explicitly listed in
turbo.json
.It would be great if turbo exposed some hooks so that it could reach out to varlock (or a similar tool) to get the resolved env vars, along with metadata that indicates how those vars should affect caching, rather than having to duplicate lists of vars in turbo config files.
Proposal
I haven't thought it all through yet, but I could imagine turbo config having a field where one could specify a command to run that will fetch env vars. These could be returned with additional metadata about caching - ie keys to pass through and whether they should affect caching. Turbo could then run this command, potentially within each child project, while deciding which tasks to run and how to pass through env vars.
I would be happy to help spec this out further, and implement it if there is some willingness to implement such a feature.
We've already got a fairly compelling Next.js integration, so having this all play nicely with turborepo too would be great.
Beta Was this translation helpful? Give feedback.
All reactions