Skip to content
Merged
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
3 changes: 2 additions & 1 deletion DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ graph LR;
encoding-->iconv-lite;
fdir-->picomatch;
fs-minipass-->minipass;
gar-promise-retry-->retry;
glob-->minimatch;
glob-->minipass;
glob-->path-scurry;
Expand Down Expand Up @@ -312,6 +313,7 @@ graph LR;
libnpmexec-->bin-links;
libnpmexec-->chalk;
libnpmexec-->ci-info;
libnpmexec-->gar-promise-retry["@gar/promise-retry"];
libnpmexec-->just-extend;
libnpmexec-->just-safe-set;
libnpmexec-->npm-package-arg;
Expand All @@ -323,7 +325,6 @@ graph LR;
libnpmexec-->npmcli-template-oss["@npmcli/template-oss"];
libnpmexec-->pacote;
libnpmexec-->proc-log;
libnpmexec-->promise-retry;
libnpmexec-->read;
libnpmexec-->semver;
libnpmexec-->signal-exit;
Expand Down
6 changes: 6 additions & 0 deletions node_modules/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
/*
!/.gitignore
# Allow all bundled deps
!/@gar/
/@gar/*
!/@gar/promise-retry
!/@gar/promise-retry/node_modules/
/@gar/promise-retry/node_modules/*
!/@gar/promise-retry/node_modules/retry
!/@isaacs/
/@isaacs/*
!/@isaacs/fs-minipass
Expand Down
19 changes: 19 additions & 0 deletions node_modules/@gar/promise-retry/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2014 IndigoUnited

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
28 changes: 28 additions & 0 deletions node_modules/@gar/promise-retry/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const retry = require('retry')

const isRetryError = (err) => err?.code === 'EPROMISERETRY' && Object.hasOwn(err, 'retried')

async function promiseRetry (fn, options = {}) {
const operation = retry.operation(options)

return new Promise(function (resolve, reject) {
operation.attempt(async number => {
try {
const result = await fn(err => {
throw Object.assign(new Error('Retrying'), { code: 'EPROMISERETRY', retried: err })
}, number)
return resolve(result)
} catch (err) {
if (isRetryError(err)) {
if (operation.retry(err.retried || new Error())) {
return
}
return reject(err.retried)
}
return reject(err)
}
})
})
}

module.exports = { promiseRetry }
21 changes: 21 additions & 0 deletions node_modules/@gar/promise-retry/node_modules/retry/License
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright (c) 2011:
Tim Koschützki (tim@debuggable.com)
Felix Geisendörfer (felix@debuggable.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var dns = require('dns');
var retry = require('../lib/retry');

function faultTolerantResolve(address, cb) {
var opts = {
retries: 2,
factor: 2,
minTimeout: 1 * 1000,
maxTimeout: 2 * 1000,
randomize: true
};
var operation = retry.operation(opts);

operation.attempt(function(currentAttempt) {
dns.resolve(address, function(err, addresses) {
if (operation.retry(err)) {
return;
}

cb(operation.mainError(), operation.errors(), addresses);
});
});
}

faultTolerantResolve('nodejs.org', function(err, errors, addresses) {
console.warn('err:');
console.log(err);

console.warn('addresses:');
console.log(addresses);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var retry = require('../lib/retry');

function attemptAsyncOperation(someInput, cb) {
var opts = {
retries: 2,
factor: 2,
minTimeout: 1 * 1000,
maxTimeout: 2 * 1000,
randomize: true
};
var operation = retry.operation(opts);

operation.attempt(function(currentAttempt) {
failingAsyncOperation(someInput, function(err, result) {

if (err && err.message === 'A fatal error') {
operation.stop();
return cb(err);
}

if (operation.retry(err)) {
return;
}

cb(operation.mainError(), operation.errors(), result);
});
});
}

attemptAsyncOperation('test input', function(err, errors, result) {
console.warn('err:');
console.log(err);

console.warn('result:');
console.log(result);
});

function failingAsyncOperation(input, cb) {
return setImmediate(cb.bind(null, new Error('A fatal error')));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib/retry');
100 changes: 100 additions & 0 deletions node_modules/@gar/promise-retry/node_modules/retry/lib/retry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
var RetryOperation = require('./retry_operation');

exports.operation = function(options) {
var timeouts = exports.timeouts(options);
return new RetryOperation(timeouts, {
forever: options && (options.forever || options.retries === Infinity),
unref: options && options.unref,
maxRetryTime: options && options.maxRetryTime
});
};

exports.timeouts = function(options) {
if (options instanceof Array) {
return [].concat(options);
}

var opts = {
retries: 10,
factor: 2,
minTimeout: 1 * 1000,
maxTimeout: Infinity,
randomize: false
};
for (var key in options) {
opts[key] = options[key];
}

if (opts.minTimeout > opts.maxTimeout) {
throw new Error('minTimeout is greater than maxTimeout');
}

var timeouts = [];
for (var i = 0; i < opts.retries; i++) {
timeouts.push(this.createTimeout(i, opts));
}

if (options && options.forever && !timeouts.length) {
timeouts.push(this.createTimeout(i, opts));
}

// sort the array numerically ascending
timeouts.sort(function(a,b) {
return a - b;
});

return timeouts;
};

exports.createTimeout = function(attempt, opts) {
var random = (opts.randomize)
? (Math.random() + 1)
: 1;

var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
timeout = Math.min(timeout, opts.maxTimeout);

return timeout;
};

exports.wrap = function(obj, options, methods) {
if (options instanceof Array) {
methods = options;
options = null;
}

if (!methods) {
methods = [];
for (var key in obj) {
if (typeof obj[key] === 'function') {
methods.push(key);
}
}
}

for (var i = 0; i < methods.length; i++) {
var method = methods[i];
var original = obj[method];

obj[method] = function retryWrapper(original) {
var op = exports.operation(options);
var args = Array.prototype.slice.call(arguments, 1);
var callback = args.pop();

args.push(function(err) {
if (op.retry(err)) {
return;
}
if (err) {
arguments[0] = op.mainError();
}
callback.apply(this, arguments);
});

op.attempt(function() {
original.apply(obj, args);
});
}.bind(obj, original);
obj[method].options = options;
}
};
Loading
Loading