All files / src/util proc.ts

100% Statements 31/31
100% Branches 7/7
100% Functions 2/2
100% Lines 31/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 321x 1x 1x 1x 1x 4x 4x 2x 1x 1x 2x 2x 2x 4x 4x 4x 1x 1x 3x 3x 3x 3x 3x 3x 2x 1x 1x 2x 2x 3x 3x  
import { Logger } from "./log.js";
import { Maybe } from "purify-ts";
import { hideSecrets } from "./misc.js";
 
export function setExitCode(code: number, ignoreErrors: boolean, log: Logger) {
  let finalCode = 0;
  if (ignoreErrors) {
    if (code != 0) {
      log.warn(`Ignoring error code ${code.toString()}`);
    }
  } else {
    finalCode = code;
  }
  log.info(`Exit with code ${finalCode.toString()}`);
  process.exitCode = finalCode;
}
 
export function setEnv(
  key: string,
  value: Maybe<string>,
  append: boolean,
  log: Logger,
) {
  value.ifJust(value => {
    if (append && process.env[key]) {
      value = `${process.env[key]} ${value}`;
    }
    log.info(`Setting environment variable ${key} to "${hideSecrets(value)}"`);
    process.env[key] = value;
  });
}