diff --git a/CHANGELOG.md b/CHANGELOG.md index ba8990f..6e8315b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,10 +20,6 @@ All notable changes to this project will be documented in this file. See [standa > This has always been dangerous (unexpected side effects) and is now removed. `process.env` should not hold values you want to expand. If for some reason you need equivalent abilities, use [dotenvx](https://github.com/dotenvx/dotenvx). You can ship an encrypted .env file with your code - allowing safe expansion at runtime - rather than relying on trying to expand pre-existing `process.env` values that could for good reason have a dollar sign in them (example a password). -* ⚠️ BREAKING: do NOT expand in reverse order ([#131](https://github.com/motdotla/dotenv-expand/pull/131)) - -> Instead, order your KEYS from first to last as they depend on each other for expansion - principle of least surprise. - ## [11.0.7](https://github.com/motdotla/dotenv-expand/compare/v11.0.6...v11.0.7) (2024-11-13) ### Changed diff --git a/tests/.env.test b/tests/.env.test index 687588d..4bb2ea5 100644 --- a/tests/.env.test +++ b/tests/.env.test @@ -82,3 +82,9 @@ PASSWORD_EXPAND_NESTED_NESTED=${PASSWORD_EXPAND_NESTED} USE_IF_SET=true ALTERNATE=${USE_IF_SET:+alternate} + +# https://github.com/motdotla/dotenv-expand/issues/123 +FIRST_PAGE_URL=${PROJECT_PUBLIC_HOST}/first-page +MOCK_SERVER_HOST=http://localhost:${MOCK_SERVER_PORT} +MOCK_SERVER_PORT=8090 +PROJECT_PUBLIC_HOST=${MOCK_SERVER_HOST} diff --git a/tests/main.js b/tests/main.js index 13a5e19..d305de1 100644 --- a/tests/main.js +++ b/tests/main.js @@ -598,3 +598,17 @@ t.test('expands alternate logic when not set', ct => { ct.end() }) + +// WARNING: this is a side effect of dotenv.config prior loading to process.env. THIS IS NOT ACCURATE behavior and is removed in [dotenvx](https://github.com/dotenvx/dotenvx) to match bash expectations. +// DO NOT RELY ON this, instead order your KEYS appropriately +t.test('expansion for https://github.com/motdotla/dotenv-expand/issues/123', ct => { + const dotenv = require('dotenv').config({ path: 'tests/.env.test' }) + dotenvExpand.expand(dotenv) + + ct.equal(process.env.FIRST_PAGE_URL, 'http://localhost:8090/first-page') + ct.equal(process.env.MOCK_SERVER_HOST, 'http://localhost:8090') + ct.equal(process.env.MOCK_SERVER_PORT, '8090') + ct.equal(process.env.PROJECT_PUBLIC_HOST, 'http://localhost:8090') + + ct.end() +})