Files
Sebastian Poxhofer c32e2391a0 refactor(linters): add prefer-coerce-object rule (#45493)
Refs #45216

The object counterpart to `prefer-coerce-array`: `x ?? {}` becomes
`coerceObject(x)`. The rule flags a `??` whose default is a bare `{}`
literal, so a populated default or an asserted `({} as Foo)` still
passes; a `x ?? y ?? {}` chain maps onto `coerceObject(x, y)`.

Every hit across `lib/` converted cleanly, so no disable comments were
needed.
2026-08-28 09:27:59 +00:00

34 lines
828 B
TypeScript

import * as memCache from './cache/memory/index.ts';
import { coerceObject } from './object.ts';
let customEnv: Record<string, string> = {};
export function setCustomEnv(envObj: Record<string, string>): void {
customEnv = envObj;
}
export function getCustomEnv(): Record<string, string> {
return customEnv;
}
export function setUserEnv(envObj: Record<string, string> | undefined): void {
memCache.set('userEnv', envObj);
}
export function getUserEnv(): Record<string, string> {
return coerceObject(memCache.get('userEnv'));
}
/**
* Combination of process.env, customEnvVariables and user configured env
*
* Precedence: userEnv > customEnvVariables > process.env
*/
export function getEnv(): Record<string, string | undefined> {
return {
...process.env,
...getCustomEnv(),
...getUserEnv(),
};
}