From c93bcad0cde6c514310e5341cc6c78e289eac4ee Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Fri, 27 Jun 2025 08:37:01 -0700 Subject: [PATCH 1/9] default `quiet` to true --- lib/main.js | 10 +++++----- tests/test-config-vault.js | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/main.js b/lib/main.js index 64daea9b..2c387799 100644 --- a/lib/main.js +++ b/lib/main.js @@ -48,10 +48,10 @@ function parse (src) { } function _parseVault (options) { - const vaultPath = _vaultPath(options) + options = options || {} - // Parse .env.vault - options.path = vaultPath + const vaultPath = _vaultPath(options) + options.path = vaultPath // parse .env.vault const result = DotenvModule.configDotenv(options) if (!result.parsed) { const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`) @@ -190,7 +190,7 @@ function _resolveHome (envPath) { function _configVault (options) { const debug = Boolean(options && options.debug) - const quiet = Boolean(options && options.quiet) + const quiet = options && 'quiet' in options ? options.quiet : true if (debug || !quiet) { _log('Loading env from encrypted .env.vault') @@ -212,7 +212,7 @@ function configDotenv (options) { const dotenvPath = path.resolve(process.cwd(), '.env') let encoding = 'utf8' const debug = Boolean(options && options.debug) - const quiet = Boolean(options && options.quiet) + const quiet = options && 'quiet' in options ? options.quiet : true if (options && options.encoding) { encoding = options.encoding diff --git a/tests/test-config-vault.js b/tests/test-config-vault.js index 3656a5d2..99f7eda6 100644 --- a/tests/test-config-vault.js +++ b/tests/test-config-vault.js @@ -34,13 +34,13 @@ t.test('logs when no path is set', ct => { ct.ok(logStub.called) }) -t.test('DOES log by default', ct => { +t.test('does not log by default', ct => { ct.plan(1) logStub = sinon.stub(console, 'log') dotenv.config({ path: testPath }) - ct.ok(logStub.called) + ct.ok(logStub.notCalled) }) t.test('does not log if quiet flag passed', ct => { @@ -61,13 +61,13 @@ t.test('logs if debug set', ct => { ct.ok(logStub.called) }) -t.test('logs when testPath calls to .env.vault directly (interpret what the user meant)', ct => { +t.test('does not log when testPath calls to .env.vault directly (interpret what the user meant)', ct => { ct.plan(1) logStub = sinon.stub(console, 'log') dotenv.config({ path: `${testPath}.vault` }) - ct.ok(logStub.called) + ct.ok(logStub.notCalled) }) t.test('logs when testPath calls to .env.vault directly (interpret what the user meant) and debug true', ct => { From d24dbfcb6794bb2d38ae1189e9ea568ad8d2317f Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Fri, 27 Jun 2025 08:38:37 -0700 Subject: [PATCH 2/9] =?UTF-8?q?changelog=20=F0=9F=AA=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e95bac7d..284f4a6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,13 @@ 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/motdotla/dotenv/compare/v16.6.0...master) +## [Unreleased](https://github.com/motdotla/dotenv/compare/v16.6.1...master) + +## [16.6.1](https://github.com/motdotla/dotenv/compare/v16.6.0...v16.6.1) (2025-06-27) + +### Changed + +- Default `quiet` to true – hiding the runtime log message ([#874](https://github.com/motdotla/dotenv/pull/874)) ## [16.6.0](https://github.com/motdotla/dotenv/compare/v16.5.0...v16.6.0) (2025-06-26) From fa67c0295ec8ade62a9f431c704cb4cb206efe03 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Fri, 27 Jun 2025 09:06:38 -0700 Subject: [PATCH 3/9] test quiet: false --- tests/test-config-vault.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/test-config-vault.js b/tests/test-config-vault.js index 99f7eda6..0eda5227 100644 --- a/tests/test-config-vault.js +++ b/tests/test-config-vault.js @@ -43,7 +43,7 @@ t.test('does not log by default', ct => { ct.ok(logStub.notCalled) }) -t.test('does not log if quiet flag passed', ct => { +t.test('does log if quiet flag passed true', ct => { ct.plan(1) logStub = sinon.stub(console, 'log') @@ -52,6 +52,15 @@ t.test('does not log if quiet flag passed', ct => { ct.ok(logStub.notCalled) }) +t.test('does log if quiet flag false', ct => { + ct.plan(1) + + logStub = sinon.stub(console, 'log') + + dotenv.config({ path: testPath, quiet: false }) + ct.ok(logStub.called) +}) + t.test('logs if debug set', ct => { ct.plan(1) From a791032e9b7cdab91ccf52a8509984dbda702c93 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Fri, 27 Jun 2025 09:07:59 -0700 Subject: [PATCH 4/9] add test --- tests/test-config-vault.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/test-config-vault.js b/tests/test-config-vault.js index 0eda5227..6b8b84b8 100644 --- a/tests/test-config-vault.js +++ b/tests/test-config-vault.js @@ -43,7 +43,7 @@ t.test('does not log by default', ct => { ct.ok(logStub.notCalled) }) -t.test('does log if quiet flag passed true', ct => { +t.test('does not log if quiet flag passed true', ct => { ct.plan(1) logStub = sinon.stub(console, 'log') @@ -61,6 +61,15 @@ t.test('does log if quiet flag false', ct => { ct.ok(logStub.called) }) +t.test('does log if quiet flag present and undefined/null', ct => { + ct.plan(1) + + logStub = sinon.stub(console, 'log') + + dotenv.config({ path: testPath, quiet: undefined }) + ct.ok(logStub.called) +}) + t.test('logs if debug set', ct => { ct.plan(1) From c88608441628757304823e39aaf7cb7e0ad28e5c Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Fri, 27 Jun 2025 09:13:26 -0700 Subject: [PATCH 5/9] send coverage to text as well --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2c54f286..abb20ea9 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "lint": "standard", "pretest": "npm run lint && npm run dts-check", "test": "tap run --allow-empty-coverage --disable-coverage --timeout=60000", - "test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=lcov", + "test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=text --coverage-report=lcov", "prerelease": "npm test", "release": "standard-version" }, From ec72534ffabe39b3ac252564b2d753c72ca74977 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Fri, 27 Jun 2025 09:18:42 -0700 Subject: [PATCH 6/9] add to test coverage --- tests/test-config-vault.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test-config-vault.js b/tests/test-config-vault.js index 6b8b84b8..550bbce9 100644 --- a/tests/test-config-vault.js +++ b/tests/test-config-vault.js @@ -408,3 +408,13 @@ t.test('raises error if some other uncaught decryption error', ct => { ct.end() }) + +t.test('_parseVault when empty args', ct => { + ct.plan(1) + + try { + dotenv._parseVault() + } catch (e) { + ct.equal(e.message, 'NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment DOTENV_VAULT_DEVELOPMENT in your .env.vault file.') + } +}) From e6799e62f6fd40681a310d19fedeb31886e39287 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Fri, 27 Jun 2025 09:25:41 -0700 Subject: [PATCH 7/9] add tests --- lib/main.js | 7 ++++++- tests/test-config.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 2c387799..91cabe47 100644 --- a/lib/main.js +++ b/lib/main.js @@ -266,7 +266,12 @@ function configDotenv (options) { try { const relative = path.relative(process.cwd(), filePath) shortPaths.push(relative) - } catch {} + } catch (e) { + if (debug) { + _debug(`Failed to load ${filePath} ${e.message}`) + } + lastError = e + } } _log(`injecting env (${keysCount}) from ${shortPaths.join(',')}`) diff --git a/tests/test-config.js b/tests/test-config.js index 029d29ba..943cfabc 100644 --- a/tests/test-config.js +++ b/tests/test-config.js @@ -250,3 +250,37 @@ t.test('logs any errors parsing when in debug and override mode', ct => { logStub.restore() }) + +t.test('deals with file:// path', ct => { + const logStub = sinon.stub(console, 'log') + + const testPath = 'file:///tests/.env' + const env = dotenv.config({ path: testPath }) + + ct.equal(env.parsed.BASIC, undefined) + ct.equal(process.env.BASIC, undefined) + ct.equal(env.error.message, "ENOENT: no such file or directory, open 'file:///tests/.env'") + + ct.ok(logStub.notCalled) + + logStub.restore() + + ct.end() +}) + +t.test('deals with file:// path and debug true', ct => { + const logStub = sinon.stub(console, 'log') + + const testPath = 'file:///tests/.env' + const env = dotenv.config({ path: testPath, debug: true }) + + ct.equal(env.parsed.BASIC, undefined) + ct.equal(process.env.BASIC, undefined) + ct.equal(env.error.message, "ENOENT: no such file or directory, open 'file:///tests/.env'") + + ct.ok(logStub.called) + + logStub.restore() + + ct.end() +}) From 86ce00120f40905c8505c1299b51e2869c6f31aa Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Fri, 27 Jun 2025 09:34:26 -0700 Subject: [PATCH 8/9] force failure of path.relative in test --- tests/test-config.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test-config.js b/tests/test-config.js index 943cfabc..7e458f2b 100644 --- a/tests/test-config.js +++ b/tests/test-config.js @@ -284,3 +284,22 @@ t.test('deals with file:// path and debug true', ct => { ct.end() }) + +t.test('path.relative fails somehow', ct => { + const logStub = sinon.stub(console, 'log') + const pathRelativeStub = sinon.stub(path, 'relative').throws(new Error('fail')) + + const testPath = 'file:///tests/.env' + const env = dotenv.config({ path: testPath, debug: true }) + + ct.equal(env.parsed.BASIC, undefined) + ct.equal(process.env.BASIC, undefined) + ct.equal(env.error.message, 'fail') + + ct.ok(logStub.called) + + logStub.restore() + pathRelativeStub.restore() + + ct.end() +}) From 5270faf63ebe3c46aecbef34dab4d58780f5b7ee Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Fri, 27 Jun 2025 09:39:50 -0700 Subject: [PATCH 9/9] =?UTF-8?q?changelog=20=F0=9F=AA=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 284f4a6e..f240c186 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ All notable changes to this project will be documented in this file. See [standa ### Changed - Default `quiet` to true – hiding the runtime log message ([#874](https://github.com/motdotla/dotenv/pull/874)) +- NOTICE: 17.0.0 will be released with quiet defaulting to false. Use `config({ quiet: true })` to suppress. +- 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. ## [16.6.0](https://github.com/motdotla/dotenv/compare/v16.5.0...v16.6.0) (2025-06-26)