From: Ardis Lu Date: Wed, 22 Jul 2026 07:35:47 +0000 (-0700) Subject: Manually narrow the return type of `parseEnv` X-Git-Tag: v0.1.4~3 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=8374efadfc751aa2a5db43cff96109ffb230690b;p=envpass Manually narrow the return type of `parseEnv` `Record` clarifies that `value` can never be `undefined`, whereas `NodeJS.Dict` allows `undefined`. This change allows the deletion of an unreachable and untestable code branch without raising type errors. The new return type matches the actual type used in the Node.js codebase [0]. [0] https://github.com/nodejs/node/blob/fbab4586118ccd225d06706fe6502e063354b765/lib/util.js#L485-L493 --- diff --git a/src/command.js b/src/command.js index f0935d0..454e06f 100644 --- a/src/command.js +++ b/src/command.js @@ -41,6 +41,7 @@ export async function encrypt(options = {}) { logger = {} } = options; + /** @type {Record} */ const env = await readFile(inFile, { encoding: 'utf-8' }).then(parseEnv); logger.debug?.('Environment variables read and parsed.'); if (Object.keys(env).length === 0) { @@ -51,12 +52,6 @@ export async function encrypt(options = {}) { let prf = null; /** @type {Env} */const encryptedEnv = Object.create(null); for (const [envVar, value] of Object.entries(env)) { - if (value === undefined) { - logger.info?.(`Environment variable "${envVar}" is unset, skipping encryption.`); - encryptedEnv[envVar] = ''; - continue; - } - const parsedValue = parseEnvpassEncrypted(value); if (parsedValue !== null) { encryptedEnv[envVar] = parsedValue;