Files
Jamie Tanna a9c8f7431f fix(lint): extend prefer-is-helpers to catch more cases (#45474)
This now covers everything that isn't `isObject` or `typeof x === 'number'`.

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
2026-08-26 10:48:40 +00:00

55 lines
1.5 KiB
TypeScript

import { isNonEmptyString, isUndefined } from '@sindresorhus/is';
import { createGlobalProxyAgent } from 'global-agent';
import { logger } from './logger/index.ts';
import { addSecretForSanitizing } from './util/sanitize.ts';
import { parseUrl } from './util/url.ts';
const envVars = ['HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY'];
const proxyEnvVarsWithCredentials = ['HTTP_PROXY', 'HTTPS_PROXY'];
let agent = false;
function sanitizeProxyCredentials(envVar: string): void {
const uri = parseUrl(process.env[envVar]);
if (uri?.password) {
addSecretForSanitizing(uri.password, 'global');
}
}
export function bootstrap(): void {
envVars.forEach((envVar) => {
/* v8 ignore next -- env is case-insensitive on windows */
if (
isUndefined(process.env[envVar]) &&
!isUndefined(process.env[envVar.toLowerCase()])
) {
process.env[envVar] = process.env[envVar.toLowerCase()];
}
if (process.env[envVar]) {
logger.debug(`Detected ${envVar} value in env`);
process.env[envVar.toLowerCase()] = process.env[envVar];
}
});
proxyEnvVarsWithCredentials.forEach(sanitizeProxyCredentials);
if (
isNonEmptyString(process.env.HTTP_PROXY) ||
isNonEmptyString(process.env.HTTPS_PROXY)
) {
createGlobalProxyAgent({
environmentVariableNamespace: '',
});
agent = true;
} else {
// for testing only, does not reset global agent
agent = false;
}
}
// will be used by our http layer later
export function hasProxy(): boolean {
return agent === true;
}