From d3f4d3175b351f48122161ec05225d6656fae3d0 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Mon, 13 Jul 2026 23:13:27 -0700 Subject: [PATCH] Do not emit end user-facing logs Logs intended to improve the final UX should be a separate concern handled by the CLI or the library consumer. Library logs should only be related to debugging the library itself. This separation allows the code closest to the user to provide more tailored instructions (e.g., i18n) to the user. --- src/command.js | 10 +--------- test/index.test.js | 8 +++++--- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/command.js b/src/command.js index 218f002..9cbff0e 100644 --- a/src/command.js +++ b/src/command.js @@ -1,4 +1,4 @@ -import { parseEnv, styleText } from 'node:util'; +import { parseEnv } from 'node:util'; import { readFile, writeFile } from 'node:fs/promises'; import { execSync } from 'node:child_process'; /** @import { PathLike } from 'node:fs'; */ @@ -69,9 +69,6 @@ export async function encrypt(options = {}) { if (prf === null) { const { url, prf: prfPromise } = await getPrf(getPrfOptions); - if (!getPrfOptions.autoOpen) { - logger.info?.(`Open this page in a web browser to complete the passkey flow: ${url}`); - } prf = await prfPromise; if (prf === null) { throw new InputError('Unable to get passkey.'); @@ -84,7 +81,6 @@ export async function encrypt(options = {}) { if (outFile) { await writeFile(outFile, toEnvString(encryptedEnv)); } - logger.info?.(styleText('green', '🎉 Successfully encrypted environment variables!')); } /** @@ -150,9 +146,6 @@ export async function decrypt(options = {}, { args = [] } = {}) { if (prf === null) { const { url, prf: prfPromise } = await getPrf(getPrfOptions); - if (!getPrfOptions.autoOpen) { - logger.info?.(`Open this page in a web browser to complete the passkey flow: ${url}`); - } prf = await prfPromise; if (prf === null) { throw new InputError('Unable to get passkey.'); @@ -172,7 +165,6 @@ export async function decrypt(options = {}, { args = [] } = {}) { await writeFile(outFile, toEnvString(decryptedEnv)); } } - logger.info?.(styleText('green', '🎉 Successfully decrypted environment variables!')); if (args.length > 0) { execSync(args.join(' '), { stdio: 'inherit' }); } diff --git a/test/index.test.js b/test/index.test.js index d6dbb81..0108897 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -25,12 +25,14 @@ suite('e2e', () => { const { page } = await setupPlaywright(t); const envFile = await setupEnv(t, STD_ENV); mockOpen(t, page); - assertConsole(t, { info: 2 }); + assertConsole(t, { info: 6 }); await fileEqual(envFile, STD_ENV); - await encrypt({ inFile: envFile, logger: console }); + await encrypt({ inFile: envFile }); + await encrypt({ inFile: envFile, logger: console, alreadyEncryptedValue: 'log' }); await fileNotEqual(envFile, STD_ENV); - await decrypt({ inFile: envFile, logger: console }); + await decrypt({ inFile: envFile }); + await decrypt({ inFile: envFile, logger: console, notEncryptedValue: 'log' }); await fileEqual(envFile, STD_ENV); }); test('does nothing to empty .env file', async (t) => { -- 2.47.3