From e009e3dbfee7a12750098725474c739933b27d86 Mon Sep 17 00:00:00 2001 From: LitoMore Date: Mon, 1 Jul 2019 16:05:55 +0800 Subject: [PATCH] Add proxy support for Node.js 10 and above (#48) --- lib/cli.js | 10 +++++++++- package.json | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/cli.js b/lib/cli.js index fdca486..d9c694d 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -3,4 +3,12 @@ require('.')(); // Override http networking to go through a proxy if one is configured. -require('global-tunnel-ng').initialize(); +const MAJOR_NODEJS_VERSION = parseInt(process.version.slice(1).split('.')[0], 10); + +if (MAJOR_NODEJS_VERSION >= 10) { + // `global-agent` works with Node.js v10 and above. + require('global-agent').bootstrap(); +} else { + // `global-tunnel-ng` works only with Node.js v10 and below. + require('global-tunnel-ng').initialize(); +} diff --git a/package.json b/package.json index c5b7a93..5133613 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "ansi-styles": "^3.2.0", "bin-version-check": "^3.0.0", "chalk": "^2.3.0", + "global-agent": "^2.0.0", "global-tunnel-ng": "^2.5.3", "latest-version": "^3.1.0", "log-symbols": "^2.1.0",