Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Replace make-fetch-happen with got #2850

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const stream = require('stream')
const crypto = require('crypto')
const log = require('npmlog')
const semver = require('semver')
const fetch = require('make-fetch-happen')
const got = require('got')
const HttpProxyAgent = require('https-proxy-agent')
const HttpsProxyAgent = require('https-proxy-agent')
const processRelease = require('./process-release')
const win = process.platform === 'win32'
const streamPipeline = util.promisify(stream.pipeline)
Expand Down Expand Up @@ -149,8 +151,8 @@ async function install (fs, gyp, argv) {
try {
const res = await download(gyp, release.tarballUrl)

if (res.status !== 200) {
throw new Error(`${res.status} response downloading ${release.tarballUrl}`)
if (res.statusCode !== 200) {
throw new Error(`${res.statusCode} response downloading ${release.tarballUrl}`)
}

await streamPipeline(
Expand Down Expand Up @@ -214,7 +216,7 @@ async function install (fs, gyp, argv) {
throw new Error(`${res.status} status code downloading checksum`)
}

for (const line of (await res.text()).trim().split('\n')) {
for (const line of (await res.body).trim().split('\n')) {
const items = line.trim().split(/\s+/)
if (items.length !== 2) {
return
Expand Down Expand Up @@ -337,23 +339,30 @@ class ShaSum extends stream.Transform {
async function download (gyp, url) {
log.http('GET', url)

const cafile = gyp.opts.cafile

const requestOpts = {
headers: {
'User-Agent': `node-gyp v${gyp.version} (node ${process.version})`,
Connection: 'keep-alive'
},
proxy: gyp.opts.proxy,
noProxy: gyp.opts.noproxy
}

const cafile = gyp.opts.cafile
if (cafile) {
requestOpts.ca = await readCAFile(cafile)
agent: gyp.opts.proxy
? {
https: new HttpsProxyAgent(gyp.opts.proxy),
http: new HttpProxyAgent(gyp.opts.proxy)
} : {},
https: cafile
? {
certificateAuthority: await readCAFile(cafile)
} : {}
}

const res = await fetch(url, requestOpts)
const res = await got(url, requestOpts)
log.http(res.status, res.url)

// this is here to retain API-compatibility during v9
// TODO: remove for v10 release
res.text = () => res.body
return res
}

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
"dependencies": {
"env-paths": "^2.2.0",
"glob": "^7.1.4",
"got": "^11.8.6",
"graceful-fs": "^4.2.6",
"make-fetch-happen": "^11.0.3",
"http-proxy-agent": "^5.0.0",
"https-proxy-agent": "^5.0.1",
"nopt": "^6.0.0",
"npmlog": "^6.0.0",
"rimraf": "^3.0.2",
Expand Down