From 580270999a0baf1655566181122c141905ce8832 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Tue, 14 Jul 2026 22:03:17 -0700 Subject: [PATCH] Add debug level logs --- src/command.js | 16 ++++++++++++++++ test/index.test.js | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/command.js b/src/command.js index 9cbff0e..f0935d0 100644 --- a/src/command.js +++ b/src/command.js @@ -42,6 +42,7 @@ export async function encrypt(options = {}) { } = options; const env = await readFile(inFile, { encoding: 'utf-8' }).then(parseEnv); + logger.debug?.('Environment variables read and parsed.'); if (Object.keys(env).length === 0) { logger.info?.('No environment variables found, aborting.'); return; @@ -68,18 +69,24 @@ export async function encrypt(options = {}) { } if (prf === null) { + logger.debug?.('PRF is required but not yet set, initiating passkey flow.'); const { url, prf: prfPromise } = await getPrf(getPrfOptions); + logger.debug?.(`Passkey flow initiated at ${url}.`); prf = await prfPromise; if (prf === null) { throw new InputError('Unable to get passkey.'); } + logger.debug?.('Passkey flow successfully completed and PRF set.'); } const encryptedValue = await encryptRaw({ prf, value }); encryptedEnv[envVar] = encryptedValue; + logger.debug?.(`Variable "${envVar}" handled.`); } + logger.debug?.('All environment variables handled.'); if (outFile) { await writeFile(outFile, toEnvString(encryptedEnv)); + logger.debug?.('Wrote environment variables to file.'); } } @@ -120,6 +127,7 @@ export async function decrypt(options = {}, { args = [] } = {}) { } = options; const env = await readFile(inFile, { encoding: 'utf-8' }).then(parseEnv); + logger.debug?.('Environment variables read and parsed.'); if (Object.keys(env).length === 0) { logger.info?.('No environment variables found, aborting.'); return; @@ -145,27 +153,35 @@ export async function decrypt(options = {}, { args = [] } = {}) { } if (prf === null) { + logger.debug?.('PRF is required but not yet set, initiating passkey flow.'); const { url, prf: prfPromise } = await getPrf(getPrfOptions); + logger.debug?.(`Passkey flow initiated at ${url}.`); prf = await prfPromise; if (prf === null) { throw new InputError('Unable to get passkey.'); } + logger.debug?.('Passkey flow successfully completed and PRF set.'); } const decryptedValue = await decryptRaw({ prf, value: parsedValue }); decryptedEnv[envVar] = decryptedValue; + logger.debug?.(`Variable "${envVar}" handled.`); } + logger.debug?.('All environment variables handled.'); if (injectInProcess) { for (const [envVar, value] of Object.entries(decryptedEnv)) { process.env[envVar] = value; } + logger.debug?.('Injected environment variables to process.env.'); } else { if (outFile) { await writeFile(outFile, toEnvString(decryptedEnv)); + logger.debug?.('Wrote environment variables to file.'); } } if (args.length > 0) { + logger.debug?.('Follow-on command found, executing in child process.'); execSync(args.join(' '), { stdio: 'inherit' }); } } \ No newline at end of file diff --git a/test/index.test.js b/test/index.test.js index 0108897..e93e6b4 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -25,7 +25,7 @@ suite('e2e', () => { const { page } = await setupPlaywright(t); const envFile = await setupEnv(t, STD_ENV); mockOpen(t, page); - assertConsole(t, { info: 6 }); + assertConsole(t, { debug: 6, info: 6, warn: 0, error: 0 }); await fileEqual(envFile, STD_ENV); await encrypt({ inFile: envFile }); -- 2.47.3