Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ function resolveRunOptions (parsed) {
defaultPath: true
}

if (envOptions.path != null) {
// Like config(), an empty path keeps the default .env.
if (envOptions.path) {
options.paths = [envOptions.path]
options.defaultPath = false
}
Expand Down
17 changes: 17 additions & 0 deletions tests/test-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ t.test('file flags reject missing or empty lists', ct => {
ct.end()
})

t.test('empty path environment variables load the default .env like config()', ct => {
const cwd = ct.testdir({ '.env': 'BASIC=default_basic\n' })
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.toUpperCase().startsWith('DOTENV_')))
delete env.BASIC
for (const name of ['DOTENV_PATH', 'DOTENV_CONFIG_PATH']) {
const result = cp.spawnSync(process.execPath, [
path.resolve(__dirname, '../dist/index.cjs'), 'run', '-q',
process.execPath, '-e', 'console.log(process.env.BASIC)'
], { cwd, encoding: 'utf8', env: { ...env, [name]: '' } })

ct.equal(result.status, 0, `${name}: ${result.stderr}`)
ct.equal(result.stdout, 'default_basic\n', `${name}: loads .env`)
ct.equal(result.stderr, '', `${name}: no error`)
}
ct.end()
})

t.test('preserves spaces, quotes, empty arguments, and shell metacharacters', ct => {
const args = ['two words', 'a"quote', '', 'trailing\\', 'a&b', 'x|y', '<input>', '%PATH%', '!name!', '(value)', '^caret']
const result = run([
Expand Down
Loading