Skip to content

Commit

Permalink
demonstrate reverse expansion for now
Browse files Browse the repository at this point in the history
  • Loading branch information
motdotla committed Nov 16, 2024
1 parent 266dbfc commit eb7ad1d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 0 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -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}
14 changes: 14 additions & 0 deletions tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

0 comments on commit eb7ad1d

Please sign in to comment.