Skip to content

[Feature Request] Shared defaults for every schema in a repository #1146

Description

@timche

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions