diff --git a/node_modules/@npmcli/git/package.json b/node_modules/@npmcli/git/package.json index d3a9cf19e6a33..0e01efaf2fbce 100644 --- a/node_modules/@npmcli/git/package.json +++ b/node_modules/@npmcli/git/package.json @@ -1,6 +1,6 @@ { "name": "@npmcli/git", - "version": "2.0.5", + "version": "2.0.6", "main": "lib/index.js", "files": [ "lib/*.js" @@ -33,7 +33,7 @@ "mkdirp": "^1.0.3", "npm-pick-manifest": "^6.0.0", "promise-inflight": "^1.0.1", - "promise-retry": "^1.1.1", + "promise-retry": "^2.0.1", "semver": "^7.3.2", "unique-filename": "^1.1.1", "which": "^2.0.2" diff --git a/node_modules/err-code/.eslintrc.json b/node_modules/err-code/.eslintrc.json index f34b41d96cca8..4829595a424ed 100644 --- a/node_modules/err-code/.eslintrc.json +++ b/node_modules/err-code/.eslintrc.json @@ -1,7 +1,7 @@ { "root": true, "extends": [ - "@satazor/eslint-config/es5", + "@satazor/eslint-config/es6", "@satazor/eslint-config/addons/node" ] } \ No newline at end of file diff --git a/node_modules/err-code/.npmignore b/node_modules/err-code/.npmignore deleted file mode 100644 index a22dcdd470ff8..0000000000000 --- a/node_modules/err-code/.npmignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -npm-debug.* diff --git a/node_modules/err-code/.travis.yml b/node_modules/err-code/.travis.yml index f85680370fa3c..b29cf66a2b3b3 100644 --- a/node_modules/err-code/.travis.yml +++ b/node_modules/err-code/.travis.yml @@ -1,5 +1,4 @@ language: node_js node_js: - - "0.12" - "4" - - "5" + - "6" diff --git a/node_modules/err-code/README.md b/node_modules/err-code/README.md index e0234e90a3f81..5afdab00c9348 100644 --- a/node_modules/err-code/README.md +++ b/node_modules/err-code/README.md @@ -1,6 +1,6 @@ # err-code -[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url] +[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url] [![Greenkeeper badge][greenkeeper-image]][greenkeeper-url] [npm-url]:https://npmjs.org/package/err-code [downloads-image]:http://img.shields.io/npm/dm/err-code.svg @@ -9,16 +9,21 @@ [travis-image]:http://img.shields.io/travis/IndigoUnited/js-err-code/master.svg [david-dm-url]:https://david-dm.org/IndigoUnited/js-err-code [david-dm-image]:https://img.shields.io/david/IndigoUnited/js-err-code.svg -[david-dm-dev-url]:https://david-dm.org/IndigoUnited/js-err-code#info=devDependencies +[david-dm-dev-url]:https://david-dm.org/IndigoUnited/js-err-code?type=dev [david-dm-dev-image]:https://img.shields.io/david/dev/IndigoUnited/js-err-code.svg +[greenkeeper-image]:https://badges.greenkeeper.io/IndigoUnited/js-err-code.svg +[greenkeeper-url]:https://greenkeeper.io/ Create new error instances with a code and additional properties. ## Installation -`$ npm install err-code` - `NPM` -`$ bower install err-code` - `bower` +```console +$ npm install err-code +// or +$ bower install err-code +``` The browser file is named index.umd.js which supports CommonJS, AMD and globals (errCode). @@ -48,18 +53,11 @@ throw errcode(new Error('My message'), 'ESOMECODE'); throw errcode(new Error('My message'), 'ESOMECODE', { detail: 'Additional information about the error' }); // fill error with message + props throw errcode(new Error('My message'), { detail: 'Additional information about the error' }); +``` +## Pre-existing fields -// You may also pass a string in the first argument and an error will be automatically created -// for you, though the stack trace will contain err-code in it. - -// create error with message + code -throw errcode('My message', 'ESOMECODE'); -// create error with message + code + props -throw errcode('My message', 'ESOMECODE', { detail: 'Additional information about the error' }); -// create error with message + props -throw errcode('My message', { detail: 'Additional information about the error' }); -``` +If the passed `Error` already has a `.code` field, or fields specified in the third argument to `errcode` they will be overwritten, unless the fields are read only or otherwise throw during assignment in which case a new object will be created that shares a prototype chain with the original `Error`. The `.stack` and `.message` properties will be carried over from the original error and `.code` or any passed properties will be set on it. ## Tests diff --git a/node_modules/err-code/index.js b/node_modules/err-code/index.js index 1a0a69f626688..9ff3e9c5de4c2 100644 --- a/node_modules/err-code/index.js +++ b/node_modules/err-code/index.js @@ -1,22 +1,47 @@ 'use strict'; -function createError(msg, code, props) { - var err = msg instanceof Error ? msg : new Error(msg); - var key; +function assign(obj, props) { + for (const key in props) { + Object.defineProperty(obj, key, { + value: props[key], + enumerable: true, + configurable: true, + }); + } + + return obj; +} + +function createError(err, code, props) { + if (!err || typeof err === 'string') { + throw new TypeError('Please pass an Error to err-code'); + } + + if (!props) { + props = {}; + } if (typeof code === 'object') { props = code; - } else if (code != null) { - err.code = code; + code = undefined; } - if (props) { - for (key in props) { - err[key] = props[key]; - } + if (code != null) { + props.code = code; } - return err; + try { + return assign(err, props); + } catch (_) { + props.message = err.message; + props.stack = err.stack; + + const ErrClass = function () {}; + + ErrClass.prototype = Object.create(Object.getPrototypeOf(err)); + + return assign(new ErrClass(), props); + } } module.exports = createError; diff --git a/node_modules/err-code/index.umd.js b/node_modules/err-code/index.umd.js index d1dbdf73358f1..41007269d3d03 100644 --- a/node_modules/err-code/index.umd.js +++ b/node_modules/err-code/index.umd.js @@ -1,26 +1,51 @@ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.errCode = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o { + describe('string as first argument', () => { + it('should throw an error', () => { + expect(() => { errcode('my message'); }).to.throwError((err) => { + expect(err).to.be.a(TypeError); + }); + }); + }); -describe('errcode', function () { - describe('string as first argument', function () { - it('should create an error object without code', function () { - var err = errcode('my message'); + describe('error as first argument', () => { + it('should accept an error and do nothing', () => { + const myErr = new Error('my message'); + const err = errcode(myErr); - expect(err).to.be.an(Error); + expect(err).to.be(myErr); expect(err.hasOwnProperty(err.code)).to.be(false); }); - it('should create an error object with code', function () { - var err = errcode('my message', 'ESOME'); + it('should accept an error and add a code', () => { + const myErr = new Error('my message'); + const err = errcode(myErr, 'ESOME'); - expect(err).to.be.an(Error); + expect(err).to.be(myErr); expect(err.code).to.be('ESOME'); }); - it('should create an error object with code and properties', function () { - var err = errcode('my message', 'ESOME', { foo: 'bar', bar: 'foo' }); + it('should accept an error object and add code & properties', () => { + const myErr = new Error('my message'); + const err = errcode(myErr, 'ESOME', { foo: 'bar', bar: 'foo' }); expect(err).to.be.an(Error); expect(err.code).to.be('ESOME'); @@ -28,65 +39,121 @@ describe('errcode', function () { expect(err.bar).to.be('foo'); }); - it('should create an error object without code but with properties', function () { - var err = errcode('my message', { foo: 'bar', bar: 'foo' }); + it('should create an error object without code but with properties', () => { + const myErr = new Error('my message'); + const err = errcode(myErr, { foo: 'bar', bar: 'foo' }); expect(err).to.be.an(Error); expect(err.code).to.be(undefined); expect(err.foo).to.be('bar'); expect(err.bar).to.be('foo'); }); - }); - describe('error as first argument', function () { - it('should accept an error and do nothing', function () { - var myErr = new Error('my message'); - var err = errcode(myErr); + it('should set a non-writable field', () => { + const myErr = new Error('my message'); - expect(err).to.be(myErr); - expect(err.hasOwnProperty(err.code)).to.be(false); + Object.defineProperty(myErr, 'code', { + value: 'derp', + writable: false, + }); + const err = errcode(myErr, 'ERR_WAT'); + + expect(err).to.be.an(Error); + expect(err.stack).to.equal(myErr.stack); + expect(err.code).to.be('ERR_WAT'); }); - it('should accept an error and add a code', function () { - var myErr = new Error('my message'); - var err = errcode(myErr, 'ESOME'); + it('should add a code to frozen object', () => { + const myErr = new Error('my message'); + const err = errcode(Object.freeze(myErr), 'ERR_WAT'); - expect(err).to.be(myErr); - expect(err.code).to.be('ESOME'); + expect(err).to.be.an(Error); + expect(err.stack).to.equal(myErr.stack); + expect(err.code).to.be('ERR_WAT'); }); - it('should accept an error object and add code & properties', function () { - var myErr = new Error('my message'); - var err = errcode(myErr, 'ESOME', { foo: 'bar', bar: 'foo' }); + it('should to set a field that throws at assignment time', () => { + const myErr = new Error('my message'); + + Object.defineProperty(myErr, 'code', { + enumerable: true, + set() { + throw new Error('Nope!'); + }, + get() { + return 'derp'; + }, + }); + const err = errcode(myErr, 'ERR_WAT'); expect(err).to.be.an(Error); - expect(err.code).to.be('ESOME'); - expect(err.foo).to.be('bar'); - expect(err.bar).to.be('foo'); + expect(err.stack).to.equal(myErr.stack); + expect(err.code).to.be('ERR_WAT'); }); - it('should create an error object without code but with properties', function () { - var myErr = new Error('my message'); - var err = errcode(myErr, { foo: 'bar', bar: 'foo' }); + it('should retain error type', () => { + const myErr = new TypeError('my message'); - expect(err).to.be.an(Error); - expect(err.code).to.be(undefined); - expect(err.foo).to.be('bar'); - expect(err.bar).to.be('foo'); + Object.defineProperty(myErr, 'code', { + value: 'derp', + writable: false, + }); + const err = errcode(myErr, 'ERR_WAT'); + + expect(err).to.be.a(TypeError); + expect(err.stack).to.equal(myErr.stack); + expect(err.code).to.be('ERR_WAT'); }); - }); - it('should allow passing null & undefined in the first argument', function () { - var err; + it('should add a code to a class that extends Error', () => { + class CustomError extends Error { + set code(val) { + throw new Error('Nope!'); + } + } + + const myErr = new CustomError('my message'); + + Object.defineProperty(myErr, 'code', { + value: 'derp', + writable: false, + configurable: false, + }); + const err = errcode(myErr, 'ERR_WAT'); + + expect(err).to.be.a(CustomError); + expect(err.stack).to.equal(myErr.stack); + expect(err.code).to.be('ERR_WAT'); - err = errcode(null, 'ESOME'); - expect(err).to.be.an(Error); - expect(err.message).to.be('null'); - expect(err.code).to.be('ESOME'); + // original prototype chain should be intact + expect(() => { + const otherErr = new CustomError('my message'); - err = errcode(undefined, 'ESOME'); - expect(err).to.be.an(Error); - expect(err.message).to.be(''); - expect(err.code).to.be('ESOME'); + otherErr.code = 'derp'; + }).to.throwError(); + }); + + it('should support errors that are not Errors', () => { + const err = errcode({ + message: 'Oh noes!', + }, 'ERR_WAT'); + + expect(err.message).to.be('Oh noes!'); + expect(err.code).to.be('ERR_WAT'); + }); + }); + + describe('falsy first arguments', () => { + it('should not allow passing null as the first argument', () => { + expect(() => { errcode(null); }).to.throwError((err) => { + expect(err).to.be.a(TypeError); + }); + }); + + it('should not allow passing undefined as the first argument', () => { + expect(() => { errcode(undefined); }).to.throwError((err) => { + expect(err).to.be.a(TypeError); + }); + }); }); }); diff --git a/node_modules/libnpmversion/package.json b/node_modules/libnpmversion/package.json index b19edd84171f1..8930d69a43f10 100644 --- a/node_modules/libnpmversion/package.json +++ b/node_modules/libnpmversion/package.json @@ -1,6 +1,6 @@ { "name": "libnpmversion", - "version": "1.0.8", + "version": "1.0.10", "main": "lib/index.js", "files": [ "lib/*.js" @@ -28,7 +28,7 @@ "tap": "^14.11.0" }, "dependencies": { - "@npmcli/git": "^2.0.4", + "@npmcli/git": "^2.0.6", "@npmcli/run-script": "^1.8.2", "read-package-json-fast": "^2.0.1", "semver": "^7.3.4", diff --git a/node_modules/promise-retry/.npmignore b/node_modules/promise-retry/.npmignore deleted file mode 100644 index a22dcdd470ff8..0000000000000 --- a/node_modules/promise-retry/.npmignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -npm-debug.* diff --git a/node_modules/promise-retry/.travis.yml b/node_modules/promise-retry/.travis.yml index f85680370fa3c..e2d26a9cad62b 100644 --- a/node_modules/promise-retry/.travis.yml +++ b/node_modules/promise-retry/.travis.yml @@ -1,5 +1,4 @@ language: node_js node_js: - - "0.12" - - "4" - - "5" + - "10" + - "12" diff --git a/node_modules/promise-retry/README.md b/node_modules/promise-retry/README.md index c50328374e564..587de5c0b1841 100644 --- a/node_modules/promise-retry/README.md +++ b/node_modules/promise-retry/README.md @@ -1,6 +1,6 @@ # node-promise-retry -[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url] +[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url] [![Greenkeeper badge][greenkeeper-image]][greenkeeper-url] [npm-url]:https://npmjs.org/package/promise-retry [downloads-image]:http://img.shields.io/npm/dm/promise-retry.svg @@ -9,8 +9,10 @@ [travis-image]:http://img.shields.io/travis/IndigoUnited/node-promise-retry/master.svg [david-dm-url]:https://david-dm.org/IndigoUnited/node-promise-retry [david-dm-image]:https://img.shields.io/david/IndigoUnited/node-promise-retry.svg -[david-dm-dev-url]:https://david-dm.org/IndigoUnited/node-promise-retry#info=devDependencies +[david-dm-dev-url]:https://david-dm.org/IndigoUnited/node-promise-retry?type=dev [david-dm-dev-image]:https://img.shields.io/david/dev/IndigoUnited/node-promise-retry.svg +[greenkeeper-image]:https://badges.greenkeeper.io/IndigoUnited/node-promise-retry.svg +[greenkeeper-url]:https://greenkeeper.io/ Retries a function that returns a promise, leveraging the power of the [retry](https://github.com/tim-kos/node-retry) module to the promises world. @@ -39,8 +41,8 @@ The `options` argument is an object which maps to the [retry](https://github.com The `fn` function will receive a `retry` function as its first argument that should be called with an error whenever you want to retry `fn`. The `retry` function will always throw an error. -If there's retries left, it will throw a special `retry` error that will be handled internally to call `fn` again. -If there's no retries left, it will throw the actual error passed to it. +If there are retries left, it will throw a special `retry` error that will be handled internally to call `fn` again. +If there are no retries left, it will throw the actual error passed to it. If you prefer, you can pass the options first using the alternative function signature `promiseRetry([options], fn)`. diff --git a/node_modules/promise-retry/index.js b/node_modules/promise-retry/index.js index 092f2756868e0..5df48ae91602d 100644 --- a/node_modules/promise-retry/index.js +++ b/node_modules/promise-retry/index.js @@ -31,7 +31,7 @@ function promiseRetry(fn, options) { err = err.retried; } - throw errcode('Retrying', 'EPROMISERETRY', { retried: err }); + throw errcode(new Error('Retrying'), 'EPROMISERETRY', { retried: err }); }, number); }) .then(resolve, function (err) { diff --git a/node_modules/promise-retry/package.json b/node_modules/promise-retry/package.json index 4292524ab5380..6842de823fd19 100644 --- a/node_modules/promise-retry/package.json +++ b/node_modules/promise-retry/package.json @@ -1,6 +1,6 @@ { "name": "promise-retry", - "version": "1.1.1", + "version": "2.0.1", "description": "Retries a function that returns a promise, leveraging the power of the retry module.", "main": "index.js", "scripts": { @@ -24,14 +24,14 @@ "license": "MIT", "devDependencies": { "expect.js": "^0.3.1", - "mocha": "^3.0.0", - "sleep-promise": "^2.0.0" + "mocha": "^8.0.1", + "sleep-promise": "^8.0.1" }, "dependencies": { - "err-code": "^1.0.0", - "retry": "^0.10.0" + "err-code": "^2.0.2", + "retry": "^0.12.0" }, "engines": { - "node": ">=0.12" + "node": ">=10" } } diff --git a/node_modules/retry/.npmignore b/node_modules/retry/.npmignore index e7726a071b7f3..432f2855d6839 100644 --- a/node_modules/retry/.npmignore +++ b/node_modules/retry/.npmignore @@ -1,2 +1,3 @@ /node_modules/* npm-debug.log +coverage diff --git a/node_modules/retry/.travis.yml b/node_modules/retry/.travis.yml new file mode 100644 index 0000000000000..bcde2122b9006 --- /dev/null +++ b/node_modules/retry/.travis.yml @@ -0,0 +1,15 @@ +language: node_js +node_js: + - "4" +before_install: + - pip install --user codecov +after_success: + - codecov --file coverage/lcov.info --disable search +# travis encrypt [subdomain]:[api token]@[room id] +# notifications: +# email: false +# campfire: +# rooms: +# secure: xyz +# on_failure: always +# on_success: always diff --git a/node_modules/retry/Makefile b/node_modules/retry/Makefile index eee21a99dfc9e..1968d8ff8b07b 100644 --- a/node_modules/retry/Makefile +++ b/node_modules/retry/Makefile @@ -1,8 +1,5 @@ SHELL := /bin/bash -test: - @node test/runner.js - release-major: test npm version major -m "Release %s" git push @@ -18,5 +15,4 @@ release-patch: test git push npm publish -.PHONY: test - +.PHONY: test release-major release-minor release-patch diff --git a/node_modules/retry/README.md b/node_modules/retry/README.md index eee05f7bb6153..16e28ec267d6d 100644 --- a/node_modules/retry/README.md +++ b/node_modules/retry/README.md @@ -1,3 +1,8 @@ + +[![Build Status](https://secure.travis-ci.org/tim-kos/node-retry.png?branch=master)](http://travis-ci.org/tim-kos/node-retry "Check this project's build status on TravisCI") +[![codecov](https://codecov.io/gh/tim-kos/node-retry/branch/master/graph/badge.svg)](https://codecov.io/gh/tim-kos/node-retry) + + # retry Abstraction for exponential and custom retry strategies for failed operations. @@ -60,7 +65,8 @@ var operation = retry.operation({ Creates a new `RetryOperation` object. `options` is the same as `retry.timeouts()`'s `options`, with two additions: * `forever`: Whether to retry forever, defaults to `false`. -* `unref`: Wether to [unref](https://nodejs.org/api/timers.html#timers_unref) the setTimeout's, defaults to `false`. +* `unref`: Whether to [unref](https://nodejs.org/api/timers.html#timers_unref) the setTimeout's, defaults to `false`. +* `maxRetryTime`: The maximum time (in milliseconds) that the retried operation is allowed to run. Default is `Infinity`. ### retry.timeouts([options]) @@ -69,7 +75,7 @@ milliseconds. If `options` is an array, a copy of that array is returned. `options` is a JS object that can contain any of the following keys: -* `retries`: The maximum amount of times to retry the operation. Default is `10`. +* `retries`: The maximum amount of times to retry the operation. Default is `10`. Seting this to `1` means `do it once, then retry it once`. * `factor`: The exponential factor to use. Default is `2`. * `minTimeout`: The number of milliseconds before starting the first retry. Default is `1000`. * `maxTimeout`: The maximum number of milliseconds between two retries. Default is `Infinity`. @@ -143,8 +149,10 @@ If `forever` is true, the following changes happen: #### retryOperation.errors() -Returns an array of all errors that have been passed to -`retryOperation.retry()` so far. +Returns an array of all errors that have been passed to `retryOperation.retry()` so far. The +returning array has the errors ordered chronologically based on when they were passed to +`retryOperation.retry()`, which means the first passed error is at index zero and the last is +at the last index. #### retryOperation.mainError() @@ -185,6 +193,10 @@ the current attempt number. Allows you to stop the operation being retried. Useful for aborting the operation on a fatal error etc. +#### retryOperation.reset() + +Resets the internal state of the operation object, so that you can call `attempt()` again as if this was a new operation object. + #### retryOperation.attempts() Returns an int representing the number of attempts it took to call `fn` before it was successful. diff --git a/node_modules/retry/lib/retry.js b/node_modules/retry/lib/retry.js index 77428cfd0006f..dcb5768072794 100644 --- a/node_modules/retry/lib/retry.js +++ b/node_modules/retry/lib/retry.js @@ -4,7 +4,8 @@ exports.operation = function(options) { var timeouts = exports.timeouts(options); return new RetryOperation(timeouts, { forever: options && options.forever, - unref: options && options.unref + unref: options && options.unref, + maxRetryTime: options && options.maxRetryTime }); }; @@ -75,9 +76,9 @@ exports.wrap = function(obj, options, methods) { var method = methods[i]; var original = obj[method]; - obj[method] = function retryWrapper() { + obj[method] = function retryWrapper(original) { var op = exports.operation(options); - var args = Array.prototype.slice.call(arguments); + var args = Array.prototype.slice.call(arguments, 1); var callback = args.pop(); args.push(function(err) { @@ -93,7 +94,7 @@ exports.wrap = function(obj, options, methods) { op.attempt(function() { original.apply(obj, args); }); - }; + }.bind(obj, original); obj[method].options = options; } }; diff --git a/node_modules/retry/lib/retry_operation.js b/node_modules/retry/lib/retry_operation.js index 2b3db8e177697..1e564696fe7e0 100644 --- a/node_modules/retry/lib/retry_operation.js +++ b/node_modules/retry/lib/retry_operation.js @@ -4,14 +4,17 @@ function RetryOperation(timeouts, options) { options = { forever: options }; } + this._originalTimeouts = JSON.parse(JSON.stringify(timeouts)); this._timeouts = timeouts; this._options = options || {}; + this._maxRetryTime = options && options.maxRetryTime || Infinity; this._fn = null; this._errors = []; this._attempts = 1; this._operationTimeout = null; this._operationTimeoutCb = null; this._timeout = null; + this._operationStart = null; if (this._options.forever) { this._cachedTimeouts = this._timeouts.slice(0); @@ -19,6 +22,11 @@ function RetryOperation(timeouts, options) { } module.exports = RetryOperation; +RetryOperation.prototype.reset = function() { + this._attempts = 1; + this._timeouts = this._originalTimeouts; +} + RetryOperation.prototype.stop = function() { if (this._timeout) { clearTimeout(this._timeout); @@ -36,6 +44,11 @@ RetryOperation.prototype.retry = function(err) { if (!err) { return false; } + var currentTime = new Date().getTime(); + if (err && currentTime - this._operationStart >= this._maxRetryTime) { + this._errors.unshift(new Error('RetryOperation timeout occurred')); + return false; + } this._errors.push(err); @@ -60,7 +73,7 @@ RetryOperation.prototype.retry = function(err) { self._operationTimeoutCb(self._attempts); }, self._operationTimeout); - if (this._options.unref) { + if (self._options.unref) { self._timeout.unref(); } } @@ -94,6 +107,8 @@ RetryOperation.prototype.attempt = function(fn, timeoutOps) { }, self._operationTimeout); } + this._operationStart = new Date().getTime(); + this._fn(this._attempts); }; diff --git a/node_modules/retry/package.json b/node_modules/retry/package.json index 5ac60c858009f..73c7259707aee 100644 --- a/node_modules/retry/package.json +++ b/node_modules/retry/package.json @@ -3,7 +3,7 @@ "name": "retry", "description": "Abstraction for exponential and custom retry strategies for failed operations.", "license": "MIT", - "version": "0.10.1", + "version": "0.12.0", "homepage": "https://github.com/tim-kos/node-retry", "repository": { "type": "git", @@ -14,11 +14,19 @@ }, "main": "index", "engines": { - "node": "*" + "node": ">= 4" }, "dependencies": {}, "devDependencies": { "fake": "0.2.0", - "far": "0.0.1" + "istanbul": "^0.4.5", + "tape": "^4.8.0" + }, + "scripts": { + "test": "./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape ./test/integration/*.js", + "release:major": "env SEMANTIC=major npm run release", + "release:minor": "env SEMANTIC=minor npm run release", + "release:patch": "env SEMANTIC=patch npm run release", + "release": "npm version ${SEMANTIC:-patch} -m \"Release %s\" && git push && git push --tags && npm publish" } } diff --git a/node_modules/retry/test/integration/test-retry-operation.js b/node_modules/retry/test/integration/test-retry-operation.js index 916936424f073..e351bb683ed44 100644 --- a/node_modules/retry/test/integration/test-retry-operation.js +++ b/node_modules/retry/test/integration/test-retry-operation.js @@ -3,6 +3,45 @@ var assert = common.assert; var fake = common.fake.create(); var retry = require(common.dir.lib + '/retry'); +(function testReset() { + var error = new Error('some error'); + var operation = retry.operation([1, 2, 3]); + var attempts = 0; + + var finalCallback = fake.callback('finalCallback'); + fake.expectAnytime(finalCallback); + + var expectedFinishes = 1; + var finishes = 0; + + var fn = function() { + operation.attempt(function(currentAttempt) { + attempts++; + assert.equal(currentAttempt, attempts); + if (operation.retry(error)) { + return; + } + + finishes++ + assert.equal(expectedFinishes, finishes); + assert.strictEqual(attempts, 4); + assert.strictEqual(operation.attempts(), attempts); + assert.strictEqual(operation.mainError(), error); + + if (finishes < 2) { + attempts = 0; + expectedFinishes++; + operation.reset(); + fn() + } else { + finalCallback(); + } + }); + }; + + fn(); +})(); + (function testErrors() { var operation = retry.operation(); @@ -53,7 +92,6 @@ var retry = require(common.dir.lib + '/retry'); })(); (function testRetry() { - var times = 3; var error = new Error('some error'); var operation = retry.operation([1, 2, 3]); var attempts = 0; @@ -132,7 +170,7 @@ var retry = require(common.dir.lib + '/retry'); var endTime = new Date().getTime(); var minTime = startTime + (delay * 3); var maxTime = minTime + 20 // add a little headroom for code execution time - assert(endTime > minTime) + assert(endTime >= minTime) assert(endTime < maxTime) assert.strictEqual(attempts, 4); assert.strictEqual(operation.attempts(), attempts); @@ -174,3 +212,47 @@ var retry = require(common.dir.lib + '/retry'); fn(); })(); + +(function testMaxRetryTime() { + var error = new Error('some error'); + var maxRetryTime = 30; + var operation = retry.operation({ + minTimeout: 1, + maxRetryTime: maxRetryTime + }); + var attempts = 0; + + var finalCallback = fake.callback('finalCallback'); + fake.expectAnytime(finalCallback); + + var longAsyncFunction = function (wait, callback){ + setTimeout(callback, wait); + }; + + var fn = function() { + var startTime = new Date().getTime(); + operation.attempt(function(currentAttempt) { + attempts++; + assert.equal(currentAttempt, attempts); + + if (attempts !== 2) { + if (operation.retry(error)) { + return; + } + } else { + var curTime = new Date().getTime(); + longAsyncFunction(maxRetryTime - (curTime - startTime - 1), function(){ + if (operation.retry(error)) { + assert.fail('timeout should be occurred'); + return; + } + + assert.strictEqual(operation.mainError(), error); + finalCallback(); + }); + } + }); + }; + + fn(); +})(); diff --git a/node_modules/retry/test/integration/test-retry-wrap.js b/node_modules/retry/test/integration/test-retry-wrap.js index 7ca8bc7eb596b..3d2b6bfa6436d 100644 --- a/node_modules/retry/test/integration/test-retry-wrap.js +++ b/node_modules/retry/test/integration/test-retry-wrap.js @@ -14,17 +14,17 @@ function getLib() { (function wrapAll() { var lib = getLib(); retry.wrap(lib); - assert.equal(lib.fn1.name, 'retryWrapper'); - assert.equal(lib.fn2.name, 'retryWrapper'); - assert.equal(lib.fn3.name, 'retryWrapper'); + assert.equal(lib.fn1.name, 'bound retryWrapper'); + assert.equal(lib.fn2.name, 'bound retryWrapper'); + assert.equal(lib.fn3.name, 'bound retryWrapper'); }()); (function wrapAllPassOptions() { var lib = getLib(); retry.wrap(lib, {retries: 2}); - assert.equal(lib.fn1.name, 'retryWrapper'); - assert.equal(lib.fn2.name, 'retryWrapper'); - assert.equal(lib.fn3.name, 'retryWrapper'); + assert.equal(lib.fn1.name, 'bound retryWrapper'); + assert.equal(lib.fn2.name, 'bound retryWrapper'); + assert.equal(lib.fn3.name, 'bound retryWrapper'); assert.equal(lib.fn1.options.retries, 2); assert.equal(lib.fn2.options.retries, 2); assert.equal(lib.fn3.options.retries, 2); @@ -33,17 +33,17 @@ function getLib() { (function wrapDefined() { var lib = getLib(); retry.wrap(lib, ['fn2', 'fn3']); - assert.notEqual(lib.fn1.name, 'retryWrapper'); - assert.equal(lib.fn2.name, 'retryWrapper'); - assert.equal(lib.fn3.name, 'retryWrapper'); + assert.notEqual(lib.fn1.name, 'bound retryWrapper'); + assert.equal(lib.fn2.name, 'bound retryWrapper'); + assert.equal(lib.fn3.name, 'bound retryWrapper'); }()); (function wrapDefinedAndPassOptions() { var lib = getLib(); retry.wrap(lib, {retries: 2}, ['fn2', 'fn3']); - assert.notEqual(lib.fn1.name, 'retryWrapper'); - assert.equal(lib.fn2.name, 'retryWrapper'); - assert.equal(lib.fn3.name, 'retryWrapper'); + assert.notEqual(lib.fn1.name, 'bound retryWrapper'); + assert.equal(lib.fn2.name, 'bound retryWrapper'); + assert.equal(lib.fn3.name, 'bound retryWrapper'); assert.equal(lib.fn2.options.retries, 2); assert.equal(lib.fn3.options.retries, 2); }()); @@ -63,6 +63,30 @@ function getLib() { assert.ok(callbackCalled); }()); +(function runWrappedSeveralWithoutError() { + var callbacksCalled = 0; + var lib = { + fn1: function (a, callback) { + assert.equal(a, 1); + assert.equal(typeof callback, 'function'); + callback(); + }, + fn2: function (a, callback) { + assert.equal(a, 2); + assert.equal(typeof callback, 'function'); + callback(); + } + }; + retry.wrap(lib, {}, ['fn1', 'fn2']); + lib.fn1(1, function() { + callbacksCalled++; + }); + lib.fn2(2, function() { + callbacksCalled++; + }); + assert.equal(callbacksCalled, 2); +}()); + (function runWrappedWithError() { var callbackCalled; var lib = {method: function(callback) { diff --git a/node_modules/retry/test/runner.js b/node_modules/retry/test/runner.js deleted file mode 100644 index e0ee2f570fe3c..0000000000000 --- a/node_modules/retry/test/runner.js +++ /dev/null @@ -1,5 +0,0 @@ -var far = require('far').create(); - -far.add(__dirname); -far.include(/\/test-.*\.js$/); -far.execute(); diff --git a/package-lock.json b/package-lock.json index 56e55442cfa78..2f5e6c8b26f22 100644 --- a/package-lock.json +++ b/package-lock.json @@ -390,7 +390,7 @@ "libnpmpublish": "^4.0.0", "libnpmsearch": "^3.1.0", "libnpmteam": "^2.0.2", - "libnpmversion": "^1.0.8", + "libnpmversion": "^1.0.10", "make-fetch-happen": "^8.0.14", "minipass": "^3.1.3", "minipass-pipeline": "^1.2.4", @@ -758,9 +758,9 @@ } }, "node_modules/@npmcli/git": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@npmcli/git/-/git-2.0.5.tgz", - "integrity": "sha512-4ckijQvgopUgSdjXZXto8+gJiksX4u79SwNtzTxYonx6vh00dh/lAL1cwE5nrj6B9Pe3H1BOS48+049SmBtxIw==", + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/@npmcli/git/-/git-2.0.6.tgz", + "integrity": "sha512-a1MnTfeRPBaKbFY07fd+6HugY1WAkKJzdiJvlRub/9o5xz2F/JtPacZZapx5zRJUQFIzSL677vmTSxEcDMrDbg==", "inBundle": true, "dependencies": { "@npmcli/promise-spawn": "^1.1.0", @@ -768,7 +768,7 @@ "mkdirp": "^1.0.3", "npm-pick-manifest": "^6.0.0", "promise-inflight": "^1.0.1", - "promise-retry": "^1.1.1", + "promise-retry": "^2.0.1", "semver": "^7.3.2", "unique-filename": "^1.1.1", "which": "^2.0.2" @@ -2173,9 +2173,9 @@ } }, "node_modules/err-code": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/err-code/-/err-code-1.1.2.tgz", - "integrity": "sha1-BuARbTAo9q70gGhJ6w6mp0iuaWA=", + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/err-code/-/err-code-2.0.3.tgz", + "integrity": "sha512-2bmlRpNKBxT/CRmPOlyISQpNj+qSeYvcym/uT0Jx2bMOlKLtSy1ZmLuVxSEKKyor/N5yhvp/ZiG1oE3DEYMSFA==", "inBundle": true }, "node_modules/error-ex": { @@ -4393,12 +4393,12 @@ } }, "node_modules/libnpmversion": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/libnpmversion/-/libnpmversion-1.0.8.tgz", - "integrity": "sha512-WrLLHx+y+0or9IycspDOWVCMde/NGo1AU97CHidjB7DeOjtbfjCOGwqem8z+WsgCnLHjwcvMaP63l7cJG2i9pg==", + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/libnpmversion/-/libnpmversion-1.0.10.tgz", + "integrity": "sha512-2+HLMyCISKLkGndy2JpEDR8bzcYP+J16IA4PF7XBmwczlJXCPNWzAVsK8i0vVHDZWofdfcfzWuUwFqijkgojLw==", "inBundle": true, "dependencies": { - "@npmcli/git": "^2.0.4", + "@npmcli/git": "^2.0.6", "@npmcli/run-script": "^1.8.2", "read-package-json-fast": "^2.0.1", "semver": "^7.3.4", @@ -5689,16 +5689,16 @@ "inBundle": true }, "node_modules/promise-retry": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/promise-retry/-/promise-retry-1.1.1.tgz", - "integrity": "sha1-ZznpaOMFHaIM5kl/srUPaRHfPW0=", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/promise-retry/-/promise-retry-2.0.1.tgz", + "integrity": "sha512-y+WKFlBR8BGXnsNlIHFGPZmyDf3DFMoLhaflAnyZgV6rG6xu+JwesTo2Q9R6XwYmtmwAFCkAk3e35jEdoeh/3g==", "inBundle": true, "dependencies": { - "err-code": "^1.0.0", - "retry": "^0.10.0" + "err-code": "^2.0.2", + "retry": "^0.12.0" }, "engines": { - "node": ">=0.12" + "node": ">=10" } }, "node_modules/promzard": { @@ -6156,12 +6156,12 @@ } }, "node_modules/retry": { - "version": "0.10.1", - "resolved": "https://registry.npmjs.org/retry/-/retry-0.10.1.tgz", - "integrity": "sha1-52OI0heZLCUnUCQdPTlW/tmNj/Q=", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz", + "integrity": "sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs=", "inBundle": true, "engines": { - "node": "*" + "node": ">= 4" } }, "node_modules/rimraf": { @@ -10038,16 +10038,16 @@ } }, "@npmcli/git": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@npmcli/git/-/git-2.0.5.tgz", - "integrity": "sha512-4ckijQvgopUgSdjXZXto8+gJiksX4u79SwNtzTxYonx6vh00dh/lAL1cwE5nrj6B9Pe3H1BOS48+049SmBtxIw==", + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/@npmcli/git/-/git-2.0.6.tgz", + "integrity": "sha512-a1MnTfeRPBaKbFY07fd+6HugY1WAkKJzdiJvlRub/9o5xz2F/JtPacZZapx5zRJUQFIzSL677vmTSxEcDMrDbg==", "requires": { "@npmcli/promise-spawn": "^1.1.0", "lru-cache": "^6.0.0", "mkdirp": "^1.0.3", "npm-pick-manifest": "^6.0.0", "promise-inflight": "^1.0.1", - "promise-retry": "^1.1.1", + "promise-retry": "^2.0.1", "semver": "^7.3.2", "unique-filename": "^1.1.1", "which": "^2.0.2" @@ -11088,9 +11088,9 @@ "integrity": "sha512-6u0VYSCo/OW6IoD5WCLLy9JUGARbamfSavcNXry/eu8aHVFei6CD3Sw+VGX5alea1i9pgPHW0mbu6Xj0uBh7gA==" }, "err-code": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/err-code/-/err-code-1.1.2.tgz", - "integrity": "sha1-BuARbTAo9q70gGhJ6w6mp0iuaWA=" + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/err-code/-/err-code-2.0.3.tgz", + "integrity": "sha512-2bmlRpNKBxT/CRmPOlyISQpNj+qSeYvcym/uT0Jx2bMOlKLtSy1ZmLuVxSEKKyor/N5yhvp/ZiG1oE3DEYMSFA==" }, "error-ex": { "version": "1.3.2", @@ -12700,11 +12700,11 @@ } }, "libnpmversion": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/libnpmversion/-/libnpmversion-1.0.8.tgz", - "integrity": "sha512-WrLLHx+y+0or9IycspDOWVCMde/NGo1AU97CHidjB7DeOjtbfjCOGwqem8z+WsgCnLHjwcvMaP63l7cJG2i9pg==", + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/libnpmversion/-/libnpmversion-1.0.10.tgz", + "integrity": "sha512-2+HLMyCISKLkGndy2JpEDR8bzcYP+J16IA4PF7XBmwczlJXCPNWzAVsK8i0vVHDZWofdfcfzWuUwFqijkgojLw==", "requires": { - "@npmcli/git": "^2.0.4", + "@npmcli/git": "^2.0.6", "@npmcli/run-script": "^1.8.2", "read-package-json-fast": "^2.0.1", "semver": "^7.3.4", @@ -13648,12 +13648,12 @@ "integrity": "sha1-mEcocL8igTL8vdhoEputEsPAKeM=" }, "promise-retry": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/promise-retry/-/promise-retry-1.1.1.tgz", - "integrity": "sha1-ZznpaOMFHaIM5kl/srUPaRHfPW0=", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/promise-retry/-/promise-retry-2.0.1.tgz", + "integrity": "sha512-y+WKFlBR8BGXnsNlIHFGPZmyDf3DFMoLhaflAnyZgV6rG6xu+JwesTo2Q9R6XwYmtmwAFCkAk3e35jEdoeh/3g==", "requires": { - "err-code": "^1.0.0", - "retry": "^0.10.0" + "err-code": "^2.0.2", + "retry": "^0.12.0" } }, "promzard": { @@ -14006,9 +14006,9 @@ "dev": true }, "retry": { - "version": "0.10.1", - "resolved": "https://registry.npmjs.org/retry/-/retry-0.10.1.tgz", - "integrity": "sha1-52OI0heZLCUnUCQdPTlW/tmNj/Q=" + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz", + "integrity": "sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs=" }, "rimraf": { "version": "3.0.2", diff --git a/package.json b/package.json index 95f6b6f495db0..08e5cf411a7e2 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "libnpmpublish": "^4.0.0", "libnpmsearch": "^3.1.0", "libnpmteam": "^2.0.2", - "libnpmversion": "^1.0.8", + "libnpmversion": "^1.0.10", "make-fetch-happen": "^8.0.14", "minipass": "^3.1.3", "minipass-pipeline": "^1.2.4",