Skip to content

Commit 424c32d

Browse files
authored
Merge pull request #874 from motdotla/default-quiet-to-true
default `quiet` to true
2 parents 064edcb + 5270faf commit 424c32d

File tree

5 files changed

+107
-13
lines changed

5 files changed

+107
-13
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22

33
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.
44

5-
## [Unreleased](https://github.com/motdotla/dotenv/compare/v16.6.0...master)
5+
## [Unreleased](https://github.com/motdotla/dotenv/compare/v16.6.1...master)
6+
7+
## [16.6.1](https://github.com/motdotla/dotenv/compare/v16.6.0...v16.6.1) (2025-06-27)
8+
9+
### Changed
10+
11+
- Default `quiet` to true – hiding the runtime log message ([#874](https://github.com/motdotla/dotenv/pull/874))
12+
- NOTICE: 17.0.0 will be released with quiet defaulting to false. Use `config({ quiet: true })` to suppress.
13+
- And check out the new [dotenvx](https://github.com/dotenvx/dotenvx). As coding workflows evolve and agents increasingly handle secrets, encrypted .env files offer a much safer way to deploy both agents and code together with secure secrets.
614

715
## [16.6.0](https://github.com/motdotla/dotenv/compare/v16.5.0...v16.6.0) (2025-06-26)
816

lib/main.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ function parse (src) {
4848
}
4949

5050
function _parseVault (options) {
51-
const vaultPath = _vaultPath(options)
51+
options = options || {}
5252

53-
// Parse .env.vault
54-
options.path = vaultPath
53+
const vaultPath = _vaultPath(options)
54+
options.path = vaultPath // parse .env.vault
5555
const result = DotenvModule.configDotenv(options)
5656
if (!result.parsed) {
5757
const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`)
@@ -190,7 +190,7 @@ function _resolveHome (envPath) {
190190

191191
function _configVault (options) {
192192
const debug = Boolean(options && options.debug)
193-
const quiet = Boolean(options && options.quiet)
193+
const quiet = options && 'quiet' in options ? options.quiet : true
194194

195195
if (debug || !quiet) {
196196
_log('Loading env from encrypted .env.vault')
@@ -212,7 +212,7 @@ function configDotenv (options) {
212212
const dotenvPath = path.resolve(process.cwd(), '.env')
213213
let encoding = 'utf8'
214214
const debug = Boolean(options && options.debug)
215-
const quiet = Boolean(options && options.quiet)
215+
const quiet = options && 'quiet' in options ? options.quiet : true
216216

217217
if (options && options.encoding) {
218218
encoding = options.encoding
@@ -266,7 +266,12 @@ function configDotenv (options) {
266266
try {
267267
const relative = path.relative(process.cwd(), filePath)
268268
shortPaths.push(relative)
269-
} catch {}
269+
} catch (e) {
270+
if (debug) {
271+
_debug(`Failed to load ${filePath} ${e.message}`)
272+
}
273+
lastError = e
274+
}
270275
}
271276

272277
_log(`injecting env (${keysCount}) from ${shortPaths.join(',')}`)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"lint": "standard",
2424
"pretest": "npm run lint && npm run dts-check",
2525
"test": "tap run --allow-empty-coverage --disable-coverage --timeout=60000",
26-
"test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=lcov",
26+
"test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=text --coverage-report=lcov",
2727
"prerelease": "npm test",
2828
"release": "standard-version"
2929
},

tests/test-config-vault.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ t.test('logs when no path is set', ct => {
3434
ct.ok(logStub.called)
3535
})
3636

37-
t.test('DOES log by default', ct => {
37+
t.test('does not log by default', ct => {
3838
ct.plan(1)
3939

4040
logStub = sinon.stub(console, 'log')
4141

4242
dotenv.config({ path: testPath })
43-
ct.ok(logStub.called)
43+
ct.ok(logStub.notCalled)
4444
})
4545

46-
t.test('does not log if quiet flag passed', ct => {
46+
t.test('does not log if quiet flag passed true', ct => {
4747
ct.plan(1)
4848

4949
logStub = sinon.stub(console, 'log')
@@ -52,6 +52,24 @@ t.test('does not log if quiet flag passed', ct => {
5252
ct.ok(logStub.notCalled)
5353
})
5454

55+
t.test('does log if quiet flag false', ct => {
56+
ct.plan(1)
57+
58+
logStub = sinon.stub(console, 'log')
59+
60+
dotenv.config({ path: testPath, quiet: false })
61+
ct.ok(logStub.called)
62+
})
63+
64+
t.test('does log if quiet flag present and undefined/null', ct => {
65+
ct.plan(1)
66+
67+
logStub = sinon.stub(console, 'log')
68+
69+
dotenv.config({ path: testPath, quiet: undefined })
70+
ct.ok(logStub.called)
71+
})
72+
5573
t.test('logs if debug set', ct => {
5674
ct.plan(1)
5775

@@ -61,13 +79,13 @@ t.test('logs if debug set', ct => {
6179
ct.ok(logStub.called)
6280
})
6381

64-
t.test('logs when testPath calls to .env.vault directly (interpret what the user meant)', ct => {
82+
t.test('does not log when testPath calls to .env.vault directly (interpret what the user meant)', ct => {
6583
ct.plan(1)
6684

6785
logStub = sinon.stub(console, 'log')
6886

6987
dotenv.config({ path: `${testPath}.vault` })
70-
ct.ok(logStub.called)
88+
ct.ok(logStub.notCalled)
7189
})
7290

7391
t.test('logs when testPath calls to .env.vault directly (interpret what the user meant) and debug true', ct => {
@@ -390,3 +408,13 @@ t.test('raises error if some other uncaught decryption error', ct => {
390408

391409
ct.end()
392410
})
411+
412+
t.test('_parseVault when empty args', ct => {
413+
ct.plan(1)
414+
415+
try {
416+
dotenv._parseVault()
417+
} catch (e) {
418+
ct.equal(e.message, 'NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment DOTENV_VAULT_DEVELOPMENT in your .env.vault file.')
419+
}
420+
})

tests/test-config.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,56 @@ t.test('logs any errors parsing when in debug and override mode', ct => {
250250

251251
logStub.restore()
252252
})
253+
254+
t.test('deals with file:// path', ct => {
255+
const logStub = sinon.stub(console, 'log')
256+
257+
const testPath = 'file:///tests/.env'
258+
const env = dotenv.config({ path: testPath })
259+
260+
ct.equal(env.parsed.BASIC, undefined)
261+
ct.equal(process.env.BASIC, undefined)
262+
ct.equal(env.error.message, "ENOENT: no such file or directory, open 'file:///tests/.env'")
263+
264+
ct.ok(logStub.notCalled)
265+
266+
logStub.restore()
267+
268+
ct.end()
269+
})
270+
271+
t.test('deals with file:// path and debug true', ct => {
272+
const logStub = sinon.stub(console, 'log')
273+
274+
const testPath = 'file:///tests/.env'
275+
const env = dotenv.config({ path: testPath, debug: true })
276+
277+
ct.equal(env.parsed.BASIC, undefined)
278+
ct.equal(process.env.BASIC, undefined)
279+
ct.equal(env.error.message, "ENOENT: no such file or directory, open 'file:///tests/.env'")
280+
281+
ct.ok(logStub.called)
282+
283+
logStub.restore()
284+
285+
ct.end()
286+
})
287+
288+
t.test('path.relative fails somehow', ct => {
289+
const logStub = sinon.stub(console, 'log')
290+
const pathRelativeStub = sinon.stub(path, 'relative').throws(new Error('fail'))
291+
292+
const testPath = 'file:///tests/.env'
293+
const env = dotenv.config({ path: testPath, debug: true })
294+
295+
ct.equal(env.parsed.BASIC, undefined)
296+
ct.equal(process.env.BASIC, undefined)
297+
ct.equal(env.error.message, 'fail')
298+
299+
ct.ok(logStub.called)
300+
301+
logStub.restore()
302+
pathRelativeStub.restore()
303+
304+
ct.end()
305+
})

0 commit comments

Comments
 (0)