Skip to content

Add support for loading multiple .env files sequentially#20

Draft
Copilot wants to merge 3 commits into
masterfrom
copilot/add-support-for-loading-multiple-envs
Draft

Add support for loading multiple .env files sequentially#20
Copilot wants to merge 3 commits into
masterfrom
copilot/add-support-for-loading-multiple-envs

Conversation

Copilot AI commented May 31, 2026

Copy link
Copy Markdown

Users could only specify a single .env file path. This adds support for arrays of paths loaded in order, with later files overriding keys from earlier ones while preserving unique keys from all files.

Changes

  • ConfigurationOptions — new absolutePaths?: string[] and relativePaths?: string[] options alongside the existing single-path options
  • resolveOptionsFilepaths — new function (exported from index) that expands all path options (single + array) into an ordered PathLike[]
  • configure — iterates all resolved paths, merging parsed key-values via Object.assign so later files win on conflicts

Usage

const env = configure(AppEnvironment, {
  relativePaths: [
    '.env',
    '.env.local',
    `.env.${process.env.NODE_ENV}`,
  ],
});

Copilot AI linked an issue May 31, 2026 that may be closed by this pull request
Copilot AI added 2 commits May 31, 2026 15:17
- Add `absolutePaths` and `relativePaths` array options to `ConfigurationOptions`
- Add `resolveOptionsFilepaths` function that returns an array of resolved paths
- Export `resolveOptionsFilepaths` from the package index
- Update `configure` to iterate all resolved paths, merging env vars (later files override earlier)
- Add `multi-first.env` and `multi-second.env` test fixtures
- Add unit tests for `resolveOptionsFilepaths` and integration tests for multi-env loading in `configure`
Copilot AI changed the title [WIP] Add support for loading multiple .env files Add support for loading multiple .env files sequentially May 31, 2026
Copilot AI requested a review from DrewImm May 31, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for loadinng multiple .envs

2 participants