diff --git a/ts/tools/scripts/getKeys.mjs b/ts/tools/scripts/getKeys.mjs index 0ec9d45dd..659b710b3 100644 --- a/ts/tools/scripts/getKeys.mjs +++ b/ts/tools/scripts/getKeys.mjs @@ -176,15 +176,22 @@ async function readDotenv() { return []; } const dotenvFile = await fs.promises.readFile(dotenvPath, "utf8"); - const dotEnv = dotenvFile.split("\n").map((line) => { - const [key, ...value] = line.split("="); - if (key.includes("-")) { - throw new Error( - `Invalid dotenv key '${key}' for key vault. Keys cannot contain dashes.`, - ); - } - return [key, value.join("=")]; - }); + const dotEnv = dotenvFile + .split(/\r?\n/) + .filter((line) => { + const trimmed = line.trim(); + return trimmed !== "" && !trimmed.startsWith("#"); + }) + .map((line) => { + const [key, ...value] = line.split("="); + const trimmedKey = key.trim(); + if (trimmedKey.includes("-")) { + throw new Error( + `Invalid dotenv key '${trimmedKey}' for key vault. Keys cannot contain dashes.`, + ); + } + return [trimmedKey, value.join("=").trimEnd()]; + }); return dotEnv; }