Skip to content
Snippets Groups Projects
Unverified Commit 11e30a08 authored by Sebastian Poxhofer's avatar Sebastian Poxhofer Committed by GitHub
Browse files

refactor: move getChildProcessEnv to break dependency loop (#23144)

parent 2c8d565c
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,6 @@ import {
removeDockerContainer,
sideCarImage,
} from './docker';
import { getChildProcessEnv } from './env';
import { getHermitEnvs, isHermit } from './hermit';
import type {
DockerOptions,
......@@ -20,37 +19,7 @@ import type {
Opt,
RawExecOptions,
} from './types';
export function getChildEnv({
extraEnv,
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,
...forcedEnv,
};
const result: Record<string, string> = {};
for (const [key, val] of Object.entries(combinedEnv)) {
if (is.string(val)) {
result[key] = `${val}`;
}
}
return result;
}
import { getChildEnv } from './utils';
function dockerEnvVars(extraEnv: ExtraEnv, childEnv: ExtraEnv): string[] {
const extraEnvKeys = Object.keys(extraEnv);
......
import is from '@sindresorhus/is';
import { GlobalConfig } from '../../config/global';
import { getChildProcessEnv } from './env';
import type { ExecOptions } from './types';
export function getChildEnv({
extraEnv,
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,
...forcedEnv,
};
const result: Record<string, string> = {};
for (const [key, val] of Object.entries(combinedEnv)) {
if (is.string(val)) {
result[key] = `${val}`;
}
}
return result;
}
import { mocked } from '../../../test/util';
import { getOptions } from '../../config/options';
import * as _exec from '../exec';
import * as _execUtils from '../exec/utils';
import * as template from '.';
jest.mock('../exec');
jest.mock('../exec/utils');
const exec = mocked(_exec);
const execUtils = mocked(_execUtils);
describe('util/template/index', () => {
beforeEach(() => {
exec.getChildEnv.mockReturnValue({
execUtils.getChildEnv.mockReturnValue({
CUSTOM_FOO: 'foo',
HOME: '/root',
});
......
......@@ -2,7 +2,7 @@ import is from '@sindresorhus/is';
import handlebars from 'handlebars';
import { GlobalConfig } from '../../config/global';
import { logger } from '../../logger';
import { getChildEnv } from '../exec';
import { getChildEnv } from '../exec/utils';
handlebars.registerHelper('encodeURIComponent', encodeURIComponent);
handlebars.registerHelper('decodeURIComponent', decodeURIComponent);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment