mirror of
https://github.com/renovatebot/renovate.git
synced 2024-12-22 13:38:32 +00:00
2194142f78
Co-authored-by: Rhys Arkins <rhys@arkins.net> Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com> Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
38 lines
915 B
TypeScript
38 lines
915 B
TypeScript
import is from '@sindresorhus/is';
|
|
import { GlobalConfig } from '../../config/global';
|
|
import { getChildProcessEnv } from './env';
|
|
import type { ExecOptions } from './types';
|
|
|
|
export function getChildEnv({
|
|
extraEnv,
|
|
userConfiguredEnv,
|
|
env: forcedEnv = {},
|
|
}: ExecOptions): Record<string, string> {
|
|
const globalConfigEnv = GlobalConfig.get('customEnvVariables');
|
|
|
|
const inheritedKeys: string[] = [];
|
|
for (const [key, val] of Object.entries(extraEnv ?? {})) {
|
|
if (is.string(val)) {
|
|
inheritedKeys.push(key);
|
|
}
|
|
}
|
|
|
|
const parentEnv = getChildProcessEnv(inheritedKeys);
|
|
const combinedEnv = {
|
|
...extraEnv,
|
|
...parentEnv,
|
|
...globalConfigEnv,
|
|
...userConfiguredEnv,
|
|
...forcedEnv,
|
|
};
|
|
|
|
const result: Record<string, string> = {};
|
|
for (const [key, val] of Object.entries(combinedEnv)) {
|
|
if (is.string(val)) {
|
|
result[key] = `${val}`;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|