Skip to content

Conversation

@stvvt
Copy link

@stvvt stvvt commented Jun 3, 2024

Currently

const expanded = dotenvExpand.expand({
  parsed: {
    EXPAND_UNDEFINED: '${UNDEFINED}',
    EXPAND_SELF: '${EXPAND_SELF}',
    EXPAND_UNDEFINED_WITH_DEFAULT: '${UNDEFINED:-default}',
    EXPAND_SELF_WITH_DEFAULT: '${EXPAND_SELF_WITH_DEFAULT:-default}'
  }
})

console.log(expanded.parsed)

produces

{
  EXPAND_UNDEFINED: '',          // undefined vars are expanded to an empty string
  EXPAND_SELF: '${EXPAND_SELF}', // but not if undefined is self-referenced!
  EXPAND_UNDEFINED_WITH_DEFAULT: 'default', // default is respected
  EXPAND_SELF_WITH_DEFAULT: '${EXPAND_SELF_WITH_DEFAULT:-default}' // default is ignored
}

In short - shelf-referenced expansions leave the values unchanged.

This pull requests changes the result to

{
  EXPAND_UNDEFINED: '', // empty string, as before
  EXPAND_SELF: '', // empty string, because expanding undefined
  EXPAND_UNDEFINED_WITH_DEFAULT: 'default', // default is respected, as before
  EXPAND_SELF_WITH_DEFAULT: 'default' // default value is now respected
}

@luke-layerhealth
Copy link

@motdotla - sorry to bug you but this is causing issues with vite. Is there a chance this could get merged and released?

@motdotla motdotla merged commit 54bcda0 into motdotla:master Nov 13, 2024
@motdotla
Copy link
Owner

thank you @lsmurray !

@motdotla
Copy link
Owner

and thank you @stvvt for the PR!

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.

3 participants