node/deps/npm/node_modules/@npmcli/git/lib/spawn.js
Ruy Adorno 94405650ae
deps: upgrade npm to 7.10.0
PR-URL: https://github.com/nodejs/node/pull/38254
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2021-04-16 21:03:58 -04:00

38 lines
1.1 KiB
JavaScript

const spawn = require('@npmcli/promise-spawn')
const promiseRetry = require('promise-retry')
const shouldRetry = require('./should-retry.js')
const whichGit = require('./which.js')
const makeOpts = require('./opts.js')
const procLog = require('./proc-log.js')
module.exports = (gitArgs, opts = {}) => {
const gitPath = whichGit(opts)
if (gitPath instanceof Error) { return Promise.reject(gitPath) }
const log = opts.log || procLog
let retry = opts.retry
if (retry === null || retry === undefined) {
retry = {
retries: opts.fetchRetries || 2,
factor: opts.fetchRetryFactor || 10,
maxTimeout: opts.fetchRetryMaxtimeout || 60000,
minTimeout: opts.fetchRetryMintimeout || 1000
}
}
return promiseRetry((retry, number) => {
if (number !== 1) {
log.silly('pacote', `Retrying git command: ${
gitArgs.join(' ')} attempt # ${number}`)
}
return spawn(gitPath, gitArgs, makeOpts(opts))
.catch(er => {
if (!shouldRetry(er.stderr, number)) {
throw er
}
retry(er)
})
}, retry)
}