@forge/cli
13.4.0-next.7-experimental-ccd514313.4.0-next.13-experimental-3dcad97
out/command-line/proxy.js+
out/command-line/proxy.jsNew file+71
Index: package/out/command-line/proxy.js
===================================================================
--- package/out/command-line/proxy.js
+++ package/out/command-line/proxy.js
@@ -0,0 +1,71 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.ProxySetupError = void 0;
+exports.setupProxy = setupProxy;
+const tslib_1 = require("tslib");
+const cli_shared_1 = require("@forge/cli-shared");
+const http_proxy_agent_1 = require("http-proxy-agent");
+const https_proxy_agent_1 = require("https-proxy-agent");
+const http_1 = tslib_1.__importDefault(require("http"));
+const https_1 = tslib_1.__importDefault(require("https"));
+const undici_1 = require("undici");
+const cached_config_service_1 = require("../service/cached-config-service");
+class ProxySetupError extends cli_shared_1.UserError {
+ constructor() {
+ super(cli_shared_1.Text.settings.proxy.setupError);
+ }
+}
+exports.ProxySetupError = ProxySetupError;
+function parseProxyUrl(proxyUrl) {
+ try {
+ const parsedUrl = new URL(proxyUrl);
+ if (parsedUrl.protocol === 'http:' || parsedUrl.protocol === 'https:') {
+ return parsedUrl;
+ }
+ }
+ catch (e) {
+ return undefined;
+ }
+}
+function setupProxy() {
+ const environmentProxyUrl = process.env[cached_config_service_1.FORGE_PROXY_ENV_VAR];
+ const proxyUrl = environmentProxyUrl?.trim()
+ ? environmentProxyUrl
+ : cli_shared_1.CachedConf.getCache(cli_shared_1.CONFIG_PROJECT_NAME).get('proxy');
+ if (proxyUrl && proxyUrl.trim()) {
+ const proxy = parseProxyUrl(proxyUrl);
+ if (!proxy) {
+ if (environmentProxyUrl?.trim()) {
+ throw new ProxySetupError();
+ }
+ return undefined;
+ }
+ try {
+ let httpAgent;
+ let httpsAgent;
+ let undiciProxyAgent;
+ if (process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0') {
+ httpAgent = new http_proxy_agent_1.HttpProxyAgent(proxyUrl, { rejectUnauthorized: false });
+ httpsAgent = new https_proxy_agent_1.HttpsProxyAgent(proxyUrl, { rejectUnauthorized: false });
+ undiciProxyAgent = new undici_1.ProxyAgent({
+ uri: proxyUrl,
+ requestTls: { rejectUnauthorized: false },
+ proxyTls: { rejectUnauthorized: false }
+ });
+ }
+ else {
+ httpAgent = new http_proxy_agent_1.HttpProxyAgent(proxyUrl);
+ httpsAgent = new https_proxy_agent_1.HttpsProxyAgent(proxyUrl);
+ undiciProxyAgent = new undici_1.ProxyAgent(proxyUrl);
+ }
+ http_1.default.globalAgent = httpAgent;
+ https_1.default.globalAgent = httpsAgent;
+ (0, undici_1.setGlobalDispatcher)(undiciProxyAgent);
+ return { httpAgent, httpsAgent, undiciProxyAgent, proxy };
+ }
+ catch (e) {
+ throw new ProxySetupError();
+ }
+ }
+}
+//# sourceMappingURL=proxy.js.map
\ No newline at end of file