Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dotenvx/dotenvx
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.28.0
Choose a base ref
...
head repository: dotenvx/dotenvx
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.29.0
Choose a head ref
  • 16 commits
  • 15 files changed
  • 2 contributors

Commits on Mar 29, 2024

  1. enable npm provenance

    SuperchupuDev authored Mar 29, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    252141f View commit details

Commits on Apr 3, 2024

  1. Merge pull request #147 from SuperchupuDev/ci/enable-npm-provenance

    enable npm provenance
    motdotla authored Apr 3, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    d4a1962 View commit details
  2. roll --env and --env-file into their own options collection

    motdotla committed Apr 3, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    d0b1bfe View commit details
  3. remove

    motdotla committed Apr 3, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    e17e288 View commit details

Commits on Apr 4, 2024

  1. runDefault now takes order of flags in mind - whether --env or --env-…

    …file
    motdotla committed Apr 4, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    182f60a View commit details
  2. adjust tests

    motdotla committed Apr 4, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    15f649d View commit details
  3. additional informational output if using --env flag

    motdotla committed Apr 4, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    13e5c07 View commit details
  4. undici vuln fix

    motdotla committed Apr 4, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    615e929 View commit details
  5. changelog 🪵

    motdotla committed Apr 4, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    7495285 View commit details
  6. if only --env flag passed then expectation is still to look for .env …

    …file. but if --env-file flag passed then do not look for .env file
    motdotla committed Apr 4, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ff1a7a3 View commit details
  7. runDefault additionally handles .env.vault files

    motdotla committed Apr 4, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    310c516 View commit details
  8. remove runVault

    motdotla committed Apr 4, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    aaa311b View commit details
  9. move to run

    motdotla committed Apr 4, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    0b992c5 View commit details
  10. update CHANGELOG

    motdotla committed Apr 4, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    0817dc2 View commit details
  11. Merge pull request #155 from dotenvx/overload-vault

    roll --env, --env-file, and --env-vault-file into their own options collection
    motdotla authored Apr 4, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    433bee5 View commit details
  12. 0.29.0

    motdotla committed Apr 4, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    a2653d2 View commit details
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -177,6 +177,8 @@ jobs:
npm:
needs: release
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
# Setup .npmrc file to publish to npm
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,11 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v0.28.0...main)
## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v0.29.0...main)

## 0.29.0

* respect order for `--env-vault-file`, `--env-file` and `--env` flags (for example: `dotenvx run --env "HELLO=one" --env-file=.env` will prioritize `--env` flag. Add `--overload` here to prioritize `--env-file` or reverse the order.). you can now mix and match multiple flags in any complex order you wish and dotenvx will respect it. ([#155](https://github.com/dotenvx/dotenvx/pull/155))

## 0.28.0

10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.28.0",
"version": "0.29.0",
"name": "@dotenvx/dotenvx",
"description": "a better dotenv–from the creator of `dotenv`",
"author": "@motdotla",
@@ -57,6 +57,7 @@
"tap": "^18.7.0"
},
"publishConfig": {
"access": "public"
"access": "public",
"provenance": true
}
}
91 changes: 38 additions & 53 deletions src/cli/actions/run.js
Original file line number Diff line number Diff line change
@@ -3,8 +3,7 @@ const execa = require('execa')
const which = require('which')
const logger = require('./../../shared/logger')

const RunDefault = require('./../../lib/services/runDefault')
const RunVault = require('./../../lib/services/runVault')
const Run = require('./../../lib/services/run')

const REPORT_ISSUE_LINK = 'https://github.com/dotenvx/dotenvx/issues/new'

@@ -89,77 +88,53 @@ async function run () {
const options = this.opts()
logger.debug(`options: ${JSON.stringify(options)}`)

// load from .env.vault file
if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
try {
const {
envVaultFile,
parsed,
injected,
preExisted,
uniqueInjectedKeys
} = new RunVault(options.envVaultFile, options.env, process.env.DOTENV_KEY, options.overload).run()

logger.verbose(`loading env from encrypted ${envVaultFile} (${path.resolve(envVaultFile)})`)
logger.debug(`decrypting encrypted env from ${envVaultFile} (${path.resolve(envVaultFile)})`)

// debug parsed
logger.debug(parsed)

// verbose/debug injected key/value
for (const [key, value] of Object.entries(injected)) {
logger.verbose(`${key} set`)
logger.debug(`${key} set to ${value}`)
}

// verbose/debug preExisted key/value
for (const [key, value] of Object.entries(preExisted)) {
logger.verbose(`${key} pre-exists (protip: use --overload to override)`)
logger.debug(`${key} pre-exists as ${value} (protip: use --overload to override)`)
}
const envs = this.envs

logger.successv(`injecting env (${uniqueInjectedKeys.length}) from encrypted ${envVaultFile}`)
} catch (error) {
logger.error(error.message)
if (error.help) {
logger.help(error.help)
}
}
} else {
try {
const {
files,
processedEnvs,
readableStrings,
readableFilepaths,
uniqueInjectedKeys
} = new RunDefault(options.envFile, options.env, options.overload).run()
} = new Run(envs, options.overload, process.env.DOTENV_KEY).run()

for (const processedEnv of processedEnvs) {
if (processedEnv.type === 'envVaultFile') {
logger.verbose(`loading env from encrypted ${processedEnv.filepath} (${path.resolve(processedEnv.filepath)})`)
logger.debug(`decrypting encrypted env from ${processedEnv.filepath} (${path.resolve(processedEnv.filepath)})`)
}

for (const file of files) {
const filepath = file.filepath
if (processedEnv.type === 'envFile') {
logger.verbose(`loading env from ${processedEnv.filepath} (${path.resolve(processedEnv.filepath)})`)
}

logger.verbose(`loading env from ${filepath} (${path.resolve(filepath)})`)
if (processedEnv.type === 'env') {
logger.verbose(`loading env from string (${processedEnv.string})`)
}

if (file.error) {
if (file.error.code === 'MISSING_ENV_FILE') {
logger.warnv(file.error)
logger.help(`? in development: add one with [echo "HELLO=World" > ${filepath}] and re-run [dotenvx run -- ${commandArgs.join(' ')}]`)
if (processedEnv.error) {
if (processedEnv.error.code === 'MISSING_ENV_FILE') {
logger.warnv(processedEnv.error)
logger.help(`? in development: add one with [echo "HELLO=World" > ${processedEnv.filepath}] and re-run [dotenvx run -- ${commandArgs.join(' ')}]`)
logger.help('? for production: set [DOTENV_KEY] on your server and re-deploy')
logger.help('? for ci: set [DOTENV_KEY] on your ci and re-build')
} else {
logger.warnv(file.error)
logger.warnv(processedEnv.error)
}
} else {
// debug parsed
const parsed = file.parsed
const parsed = processedEnv.parsed
logger.debug(parsed)

// verbose/debug injected key/value
const injected = file.injected
const injected = processedEnv.injected
for (const [key, value] of Object.entries(injected)) {
logger.verbose(`${key} set`)
logger.debug(`${key} set to ${value}`)
}

// verbose/debug preExisted key/value
const preExisted = file.preExisted
const preExisted = processedEnv.preExisted
for (const [key, value] of Object.entries(preExisted)) {
logger.verbose(`${key} pre-exists (protip: use --overload to override)`)
logger.debug(`${key} pre-exists as ${value} (protip: use --overload to override)`)
@@ -168,10 +143,20 @@ async function run () {
}

let msg = `injecting env (${uniqueInjectedKeys.length})`
if (readableFilepaths.length > 0) {
msg += ` from ${readableFilepaths}`
if (readableFilepaths.length > 0 && readableStrings.length > 0) {
msg += ` from ${readableFilepaths.join(', ')}, and --env flag${readableStrings.length > 1 ? 's' : ''}`
} else if (readableFilepaths.length > 0) {
msg += ` from ${readableFilepaths.join(', ')}`
} else if (readableStrings.length > 0) {
msg += ` from --env flag${readableStrings.length > 1 ? 's' : ''}`
}

logger.successv(msg)
} catch (error) {
logger.error(error.message)
if (error.help) {
logger.help(error.help)
}
}

// Extract command and arguments after '--'
22 changes: 18 additions & 4 deletions src/cli/dotenvx.js
Original file line number Diff line number Diff line change
@@ -15,6 +15,15 @@ if (notice.update) {
logger.warn(`Update available ${notice.packageVersion}${notice.latestVersion} [see changelog](dotenvx.com/changelog)`)
}

// for use with run
const envs = []
function collectEnvs (type) {
return function (value, previous) {
envs.push({ type, value })
return previous.concat([value])
}
}

// global log levels
program
.option('-l, --log-level <level>', 'set log level', 'info')
@@ -52,14 +61,19 @@ program
.version(packageJson.version)

// dotenvx run -- node index.js
const runAction = require('./actions/run')
program.command('run')
.description('inject env at runtime [dotenvx run -- yourcommand]')
.addHelpText('after', examples.run)
.option('-f, --env-file <paths...>', 'path(s) to your env file(s)', '.env')
.option('-fv, --env-vault-file <path>', 'path to your .env.vault file', '.env.vault')
.option('-e, --env <strings...>', 'environment variable(s) set as string (example: "HELLO=World")')
.option('-e, --env <strings...>', 'environment variable(s) set as string (example: "HELLO=World")', collectEnvs('env'), [])
.option('-f, --env-file <paths...>', 'path(s) to your env file(s)', collectEnvs('envFile'), [])
.option('-fv, --env-vault-file <paths...>', 'path(s) to your .env.vault file(s)', collectEnvs('envVaultFile'), [])
.option('-o, --overload', 'override existing env variables')
.action(require('./actions/run'))
.action(function (...args) {
this.envs = envs

runAction.apply(this, args)
})

// dotenvx encrypt
program.command('encrypt')
11 changes: 2 additions & 9 deletions src/lib/helpers/parseExpandAndEval.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ const dotenv = require('dotenv')
const dotenvExpand = require('dotenv-expand')
const dotenvEval = require('./dotenvEval')

function parseExpandAndEval (src, overload) {
function parseExpandAndEval (src) {
// parse
const parsed = dotenv.parse(src)

@@ -13,16 +13,9 @@ function parseExpandAndEval (src, overload) {
}
const evaled = dotenvEval.eval(inputParsed).parsed

// consider moving this logic straight into dotenv-expand
let evalParsed = {}
if (overload) {
evalParsed = { ...process.env, ...evaled }
} else {
evalParsed = { ...evaled, ...process.env }
}
const expandPlease = {
processEnv: {},
parsed: evalParsed
parsed: { ...process.env, ...evaled } // always treat as overload, then later in the code the inject method takes care of actually setting on process.env via overload or not. this functions job is just to determine what the value would be
}
const expanded = dotenvExpand.expand(expandPlease).parsed

Loading