import * as path from 'path' ; import { APP_ROOT } from '../../constants' ; import { getDockerPipePath } from '../docker/docker-proxy' ; const BIN_OVERRIDE_DIR = 'path' ; const RUBY_OVERRIDE_DIR = 'gems' ; const PYTHON_OVERRIDE_DIR = 'pythonpath' ; const NODE_PREPEND_SCRIPT = [ 'js' , 'prepend-node.js' ] ; const JAVA_AGENT_JAR = 'java-agent.jar' ; export const OVERRIDES_DIR = path . join ( APP_ROOT , 'overrides' ) ; export const OVERRIDE_BIN_PATH = path . join ( OVERRIDES_DIR , BIN_OVERRIDE_DIR ) ; export const OVERRIDE_JAVA_AGENT = path . join ( OVERRIDES_DIR , JAVA_AGENT_JAR ) ; export function getTerminalEnvVars ( proxyPort , httpsConfig , currentEnv , targetEnvConfig = { } , options = { dockerEnabled : false } ) { const { overridePath , targetPlatform , httpToolkitIp } = { httpToolkitIp : '127.0.0.1' , overridePath : OVERRIDES_DIR , targetPlatform : process . platform , ... targetEnvConfig } ; const pathVarSeparator = targetPlatform === 'win32' ? ';' : ':' ; const joinPath = targetPlatform === 'win32' ? path . win32 . join : path . posix . join ; const proxyUrl = `http://${ httpToolkitIp }:${ proxyPort }` ; const dockerHost = `${ targetPlatform === 'win32' ? 'npipe' : 'unix' }://${ getDockerPipePath ( proxyPort , targetPlatform ) }` ; const rubyGemsPath = joinPath ( overridePath , RUBY_OVERRIDE_DIR ) ; const pythonPath = joinPath ( overridePath , PYTHON_OVERRIDE_DIR ) ; const nodePrependScript = joinPath ( overridePath , ... NODE_PREPEND_SCRIPT ) ; const nodePrependOption = `--require ${ nodePrependScript . includes ( ' ' ) ? `"${ nodePrependScript }"` : nodePrependScript }` ; const javaAgentOption = `-javaagent:"${ joinPath ( overridePath , JAVA_AGENT_JAR ) }"=${ httpToolkitIp }|${ proxyPort }|${ httpsConfig . certPath }` ; const binPath = joinPath ( overridePath , BIN_OVERRIDE_DIR ) ; return { 'http_proxy' : proxyUrl , 'HTTP_PROXY' : proxyUrl , 'https_proxy' : proxyUrl , 'HTTPS_PROXY' : proxyUrl , 'GLOBAL_AGENT_HTTP_PROXY' : proxyUrl , 'CGI_HTTP_PROXY' : proxyUrl , 'npm_config_proxy' : proxyUrl , 'npm_config_https_proxy' : proxyUrl , 'npm_config_scripts_prepend_node_path' : 'false' , 'GOPROXY' : proxyUrl , 'SSL_CERT_FILE' : httpsConfig . certPath , 'NODE_EXTRA_CA_CERTS' : httpsConfig . certPath , 'REQUESTS_CA_BUNDLE' : httpsConfig . certPath , 'PERL_LWP_SSL_CA_FILE' : httpsConfig . certPath , 'GIT_SSL_CAINFO' : httpsConfig . certPath , 'CARGO_HTTP_CAINFO' : httpsConfig . certPath , 'CURL_CA_BUNDLE' : httpsConfig . certPath , 'HTTP_TOOLKIT_ACTIVE' : 'true' , 'PATH' : `${ binPath }${ pathVarSeparator }${ currentEnv == 'runtime-inherit' ? '$PATH' : currentEnv . PATH }` , 'RUBYLIB' : currentEnv === 'runtime-inherit' ? `${ rubyGemsPath }:$RUBYLIB` : ! ! currentEnv . RUBYLIB ? `${ rubyGemsPath }:${ currentEnv . RUBYLIB }` : rubyGemsPath , 'PYTHONPATH' : currentEnv === 'runtime-inherit' ? `${ pythonPath }:$PYTHONPATH` : currentEnv . PYTHONPATH ? `${ pythonPath }:${ currentEnv . PYTHONPATH }` : pythonPath , 'NODE_OPTIONS' : currentEnv === 'runtime-inherit' ? `$NODE_OPTIONS ${ nodePrependOption }` : nodePrependOption , 'JAVA_TOOL_OPTIONS' : currentEnv === 'runtime-inherit' ? `$JAVA_TOOL_OPTIONS ${ javaAgentOption }` : currentEnv . JAVA_TOOL_OPTIONS ? `${ currentEnv . JAVA_TOOL_OPTIONS } ${ javaAgentOption }` : javaAgentOption , ... ( options . dockerEnabled ? { 'DOCKER_HOST' : dockerHost , 'DOCKER_BUILDKIT' : '0' } : { } ) } ; }