]> git.ardis.lu - envpass/commitdiff
Manually narrow the return type of `parseEnv`
authorArdis Lu <ardisglu@gmail.com>
Wed, 22 Jul 2026 07:35:47 +0000 (00:35 -0700)
committerArdis Lu <ardisglu@gmail.com>
Wed, 22 Jul 2026 07:35:47 +0000 (00:35 -0700)
`Record<string, string>` clarifies that `value` can never be `undefined`, whereas `NodeJS.Dict<string>` 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

src/command.js

index f0935d0dad7dd0b54c5d3d0568b52cf28b258639..454e06f110bab607dd3d2e9d8663dfd462515733 100644 (file)
@@ -41,6 +41,7 @@ export async function encrypt(options = {}) {
     logger = {}
   } = options;
 
+  /** @type {Record<string, string>} */
   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;
This page took 0.044058 seconds and 4 git commands to generate.