Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process multiple files in options.path, if provided. #805

Merged
merged 3 commits into from Feb 12, 2024

Conversation

thanosd
Copy link
Contributor

@thanosd thanosd commented Feb 7, 2024

I cleaned up the code a bit to first gather a list of files (that exist) in a uniform way. The logic is as close as to what existed:

  1. If options.path has one or more options use those.
  2. If none were provided, or none of them existed, use the default .env.

The next step is to parse and combine those values - flattening them. The sequence would be:

existing env -> options.path[0] (if exists) -> options.path[1] -> etc

There were two choices here:

  1. Move from left to right, and if something exists "first one wins" unless override is set.
  2. Start from options.path[0] and move right using first one wins (no overrides), then take the combo result and apply it to existing env honoring the override flag.

I went with (2) as I did not deem the override semantics made sense when collapsing multiple environment files - but let me know if you disagree.

Also cleaned up the docs to reflect this.

@motdotla
Copy link
Owner

@thanosd can you switch to

Move from left to right, and if something exists "first one wins" unless override is set.

that is what dotenvx is doing.

thank you for all your hard work here @thanosd. it's really contributing to making dotenv much better for everyone.

@thanosd
Copy link
Contributor Author

thanosd commented Feb 12, 2024

@motdotla Updated as requested. Little had to change in the code structure, as we need to hold a copy of the combined parsed object to return it.

@motdotla
Copy link
Owner

thank you. i should merged and released today.

Copy link

codecov bot commented Feb 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (master@85dbe87). Click here to learn what that means.

Additional details and impacted files
@@            Coverage Diff             @@
##             master      #805   +/-   ##
==========================================
  Coverage          ?   100.00%           
==========================================
  Files             ?         4           
  Lines             ?       193           
  Branches          ?         0           
==========================================
  Hits              ?       193           
  Misses            ?         0           
  Partials          ?         0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@motdotla motdotla merged commit fe5ac4d into motdotla:master Feb 12, 2024
4 of 8 checks passed
Vylpes pushed a commit to Vylpes/Droplet that referenced this pull request Apr 10, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [dotenv](https://github.com/motdotla/dotenv) | dependencies | patch | [`16.4.1` -> `16.4.5`](https://renovatebot.com/diffs/npm/dotenv/16.4.1/16.4.5) |

---

### Release Notes

<details>
<summary>motdotla/dotenv (dotenv)</summary>

### [`v16.4.5`](https://github.com/motdotla/dotenv/blob/HEAD/CHANGELOG.md#1645-2024-02-19)

[Compare Source](motdotla/dotenv@v16.4.4...v16.4.5)

##### Changed

-   🐞 fix recent regression when using `path` option. return to historical behavior: do not attempt to auto find `.env` if `path` set. (regression was introduced in `16.4.3`) [#&#8203;814](motdotla/dotenv#814)

### [`v16.4.4`](https://github.com/motdotla/dotenv/blob/HEAD/CHANGELOG.md#1644-2024-02-13)

[Compare Source](motdotla/dotenv@v16.4.3...v16.4.4)

##### Changed

-   🐞 Replaced chaining operator `?.` with old school `&&` (fixing node 12 failures) [#&#8203;812](motdotla/dotenv#812)

### [`v16.4.3`](https://github.com/motdotla/dotenv/blob/HEAD/CHANGELOG.md#1643-2024-02-12)

[Compare Source](motdotla/dotenv@v16.4.2...v16.4.3)

##### Changed

-   Fixed processing of multiple files in `options.path` [#&#8203;805](motdotla/dotenv#805)

### [`v16.4.2`](https://github.com/motdotla/dotenv/blob/HEAD/CHANGELOG.md#1642-2024-02-10)

[Compare Source](motdotla/dotenv@v16.4.1...v16.4.2)

##### Changed

-   Changed funding link in package.json to [`dotenvx.com`](https://dotenvx.com)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4wLjAiLCJ1cGRhdGVkSW5WZXIiOiIzNy4wLjAiLCJ0YXJnZXRCcmFuY2giOiJkZXZlbG9wIn0=-->

Reviewed-on: https://gitea.vylpes.xyz/RabbitLabs/Droplet/pulls/269
Reviewed-by: Vylpes <ethan@vylpes.com>
Co-authored-by: Renovate Bot <renovate@vylpes.com>
Co-committed-by: Renovate Bot <renovate@vylpes.com>
Vylpes pushed a commit to Vylpes/card-drop that referenced this pull request Apr 10, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [dotenv](https://github.com/motdotla/dotenv) | dependencies | minor | [`16.3.2` -> `16.4.5`](https://renovatebot.com/diffs/npm/dotenv/16.3.2/16.4.5) |

---

### Release Notes

<details>
<summary>motdotla/dotenv (dotenv)</summary>

### [`v16.4.5`](https://github.com/motdotla/dotenv/blob/HEAD/CHANGELOG.md#1645-2024-02-19)

[Compare Source](motdotla/dotenv@v16.4.4...v16.4.5)

##### Changed

-   🐞 fix recent regression when using `path` option. return to historical behavior: do not attempt to auto find `.env` if `path` set. (regression was introduced in `16.4.3`) [#&#8203;814](motdotla/dotenv#814)

### [`v16.4.4`](https://github.com/motdotla/dotenv/blob/HEAD/CHANGELOG.md#1644-2024-02-13)

[Compare Source](motdotla/dotenv@v16.4.3...v16.4.4)

##### Changed

-   🐞 Replaced chaining operator `?.` with old school `&&` (fixing node 12 failures) [#&#8203;812](motdotla/dotenv#812)

### [`v16.4.3`](https://github.com/motdotla/dotenv/blob/HEAD/CHANGELOG.md#1643-2024-02-12)

[Compare Source](motdotla/dotenv@v16.4.2...v16.4.3)

##### Changed

-   Fixed processing of multiple files in `options.path` [#&#8203;805](motdotla/dotenv#805)

### [`v16.4.2`](https://github.com/motdotla/dotenv/blob/HEAD/CHANGELOG.md#1642-2024-02-10)

[Compare Source](motdotla/dotenv@v16.4.1...v16.4.2)

##### Changed

-   Changed funding link in package.json to [`dotenvx.com`](https://dotenvx.com)

### [`v16.4.1`](https://github.com/motdotla/dotenv/blob/HEAD/CHANGELOG.md#1641-2024-01-24)

[Compare Source](motdotla/dotenv@v16.4.0...v16.4.1)

-   Patch support for array as `path` option [#&#8203;797](motdotla/dotenv#797)

### [`v16.4.0`](https://github.com/motdotla/dotenv/blob/HEAD/CHANGELOG.md#1640-2024-01-23)

[Compare Source](motdotla/dotenv@v16.3.2...v16.4.0)

-   Add `error.code` to error messages around `.env.vault` decryption handling [#&#8203;795](motdotla/dotenv#795)
-   Add ability to find `.env.vault` file when filename(s) passed as an array [#&#8203;784](motdotla/dotenv#784)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4wLjAiLCJ1cGRhdGVkSW5WZXIiOiIzNy4wLjAiLCJ0YXJnZXRCcmFuY2giOiJkZXZlbG9wIn0=-->

Reviewed-on: https://gitea.vylpes.xyz/External/card-drop/pulls/182
Co-authored-by: Renovate Bot <renovate@vylpes.com>
Co-committed-by: Renovate Bot <renovate@vylpes.com>
Vylpes pushed a commit to Vylpes/vylbot-app that referenced this pull request Apr 10, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [dotenv](https://github.com/motdotla/dotenv) | dependencies | patch | [`16.4.1` -> `16.4.5`](https://renovatebot.com/diffs/npm/dotenv/16.4.1/16.4.5) |

---

### Release Notes

<details>
<summary>motdotla/dotenv (dotenv)</summary>

### [`v16.4.5`](https://github.com/motdotla/dotenv/blob/HEAD/CHANGELOG.md#1645-2024-02-19)

[Compare Source](motdotla/dotenv@v16.4.4...v16.4.5)

##### Changed

-   🐞 fix recent regression when using `path` option. return to historical behavior: do not attempt to auto find `.env` if `path` set. (regression was introduced in `16.4.3`) [#&#8203;814](motdotla/dotenv#814)

### [`v16.4.4`](https://github.com/motdotla/dotenv/blob/HEAD/CHANGELOG.md#1644-2024-02-13)

[Compare Source](motdotla/dotenv@v16.4.3...v16.4.4)

##### Changed

-   🐞 Replaced chaining operator `?.` with old school `&&` (fixing node 12 failures) [#&#8203;812](motdotla/dotenv#812)

### [`v16.4.3`](https://github.com/motdotla/dotenv/blob/HEAD/CHANGELOG.md#1643-2024-02-12)

[Compare Source](motdotla/dotenv@v16.4.2...v16.4.3)

##### Changed

-   Fixed processing of multiple files in `options.path` [#&#8203;805](motdotla/dotenv#805)

### [`v16.4.2`](https://github.com/motdotla/dotenv/blob/HEAD/CHANGELOG.md#1642-2024-02-10)

[Compare Source](motdotla/dotenv@v16.4.1...v16.4.2)

##### Changed

-   Changed funding link in package.json to [`dotenvx.com`](https://dotenvx.com)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4wLjAiLCJ1cGRhdGVkSW5WZXIiOiIzNy4wLjAiLCJ0YXJnZXRCcmFuY2giOiJkZXZlbG9wIn0=-->

Reviewed-on: https://gitea.vylpes.xyz/RabbitLabs/vylbot-app/pulls/411
Co-authored-by: Renovate Bot <renovate@vylpes.com>
Co-committed-by: Renovate Bot <renovate@vylpes.com>
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.

None yet

2 participants