Description
A way to apply shared defaults to every schema in a repository (common imports, root decorators, generator options), without repeating them in each .env.schema.
Motivation
Following the monorepo guide (one schema per package, imports for what each needs), every package schema tends to start with the same header, for example:
# @import(../../.env.shared)
# @import(../../.env.secrets, enabled=forEnv(development))
# @generateTsTypes(path=./env.d.ts, auto=forEnv(development, test))
# ---
The relative paths differ by depth, and a change to the shared setup (a new generator option, a different auth import) means editing every schema. Varlock deliberately does not walk up to parent directories, which is reasonable as a default, so this would need an explicit opt-in.
Proposed Solution
For example, a varlock.defaults entry in the root package.json (or a root .env.defaults file that schemas opt into) listing imports and root decorators applied to every schema varlock loads within the repository, before the schema's own header, so a schema can still override any of them.
{
"varlock": {
"defaults": {
"imports": [".env.shared", { "path": ".env.secrets", "enabled": "forEnv(development)" }],
"generateTsTypes": { "path": "./env.d.ts", "auto": "forEnv(development, test)" }
}
}
}
The exact shape matters less than having one place for it.
Alternatives
- Keep the repeated header in each schema (works, drifts).
- A single root schema with tags and
varlock.loadPath/filter per package, which loses per-package ownership of vars.
Additional Information
Pairs with importing workspace packages by name (#1140), which would remove the depth-dependent relative paths as well.
Description
A way to apply shared defaults to every schema in a repository (common imports, root decorators, generator options), without repeating them in each
.env.schema.Motivation
Following the monorepo guide (one schema per package, imports for what each needs), every package schema tends to start with the same header, for example:
The relative paths differ by depth, and a change to the shared setup (a new generator option, a different auth import) means editing every schema. Varlock deliberately does not walk up to parent directories, which is reasonable as a default, so this would need an explicit opt-in.
Proposed Solution
For example, a
varlock.defaultsentry in the rootpackage.json(or a root.env.defaultsfile that schemas opt into) listing imports and root decorators applied to every schema varlock loads within the repository, before the schema's own header, so a schema can still override any of them.{ "varlock": { "defaults": { "imports": [".env.shared", { "path": ".env.secrets", "enabled": "forEnv(development)" }], "generateTsTypes": { "path": "./env.d.ts", "auto": "forEnv(development, test)" } } } }The exact shape matters less than having one place for it.
Alternatives
varlock.loadPath/filterper package, which loses per-package ownership of vars.Additional Information
Pairs with importing workspace packages by name (#1140), which would remove the depth-dependent relative paths as well.