diff --git a/node_modules/graceful-fs/LICENSE b/node_modules/graceful-fs/LICENSE index 9d2c8036969be..e906a25acfb5e 100644 --- a/node_modules/graceful-fs/LICENSE +++ b/node_modules/graceful-fs/LICENSE @@ -1,6 +1,6 @@ The ISC License -Copyright (c) Isaac Z. Schlueter, Ben Noordhuis, and Contributors +Copyright (c) 2011-2022 Isaac Z. Schlueter, Ben Noordhuis, and Contributors Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/node_modules/graceful-fs/README.md b/node_modules/graceful-fs/README.md index 5273a50ad6a52..82d6e4daf0cdb 100644 --- a/node_modules/graceful-fs/README.md +++ b/node_modules/graceful-fs/README.md @@ -30,9 +30,19 @@ the directory. var fs = require('graceful-fs') // now go and do stuff with it... -fs.readFileSync('some-file-or-whatever') +fs.readFile('some-file-or-whatever', (err, data) => { + // Do stuff here. +}) ``` +## Sync methods + +This module cannot intercept or handle `EMFILE` or `ENFILE` errors from sync +methods. If you use sync methods which open file descriptors then you are +responsible for dealing with any errors. + +This is a known limitation, not a bug. + ## Global Patching If you want to patch the global fs module (or any other fs-like diff --git a/node_modules/graceful-fs/clone.js b/node_modules/graceful-fs/clone.js index 028356c96ed53..dff3cc8c504b4 100644 --- a/node_modules/graceful-fs/clone.js +++ b/node_modules/graceful-fs/clone.js @@ -2,12 +2,16 @@ module.exports = clone +var getPrototypeOf = Object.getPrototypeOf || function (obj) { + return obj.__proto__ +} + function clone (obj) { if (obj === null || typeof obj !== 'object') return obj if (obj instanceof Object) - var copy = { __proto__: obj.__proto__ } + var copy = { __proto__: getPrototypeOf(obj) } else var copy = Object.create(null) diff --git a/node_modules/graceful-fs/graceful-fs.js b/node_modules/graceful-fs/graceful-fs.js index de3df47fd5552..8d5b89e4fa7fd 100644 --- a/node_modules/graceful-fs/graceful-fs.js +++ b/node_modules/graceful-fs/graceful-fs.js @@ -54,7 +54,7 @@ if (!fs[gracefulQueue]) { return fs$close.call(fs, fd, function (err) { // This function uses the graceful-fs shared queue if (!err) { - retry() + resetQueue() } if (typeof cb === 'function') @@ -72,7 +72,7 @@ if (!fs[gracefulQueue]) { function closeSync (fd) { // This function uses the graceful-fs shared queue fs$closeSync.apply(fs, arguments) - retry() + resetQueue() } Object.defineProperty(closeSync, previousSymbol, { @@ -114,14 +114,13 @@ function patch (fs) { return go$readFile(path, options, cb) - function go$readFile (path, options, cb) { + function go$readFile (path, options, cb, startTime) { return fs$readFile(path, options, function (err) { if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) - enqueue([go$readFile, [path, options, cb]]) + enqueue([go$readFile, [path, options, cb], err, startTime || Date.now(), Date.now()]) else { if (typeof cb === 'function') cb.apply(this, arguments) - retry() } }) } @@ -135,14 +134,13 @@ function patch (fs) { return go$writeFile(path, data, options, cb) - function go$writeFile (path, data, options, cb) { + function go$writeFile (path, data, options, cb, startTime) { return fs$writeFile(path, data, options, function (err) { if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) - enqueue([go$writeFile, [path, data, options, cb]]) + enqueue([go$writeFile, [path, data, options, cb], err, startTime || Date.now(), Date.now()]) else { if (typeof cb === 'function') cb.apply(this, arguments) - retry() } }) } @@ -157,14 +155,35 @@ function patch (fs) { return go$appendFile(path, data, options, cb) - function go$appendFile (path, data, options, cb) { + function go$appendFile (path, data, options, cb, startTime) { return fs$appendFile(path, data, options, function (err) { if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) - enqueue([go$appendFile, [path, data, options, cb]]) + enqueue([go$appendFile, [path, data, options, cb], err, startTime || Date.now(), Date.now()]) + else { + if (typeof cb === 'function') + cb.apply(this, arguments) + } + }) + } + } + + var fs$copyFile = fs.copyFile + if (fs$copyFile) + fs.copyFile = copyFile + function copyFile (src, dest, flags, cb) { + if (typeof flags === 'function') { + cb = flags + flags = 0 + } + return go$copyFile(src, dest, flags, cb) + + function go$copyFile (src, dest, flags, cb, startTime) { + return fs$copyFile(src, dest, flags, function (err) { + if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) + enqueue([go$copyFile, [src, dest, flags, cb], err, startTime || Date.now(), Date.now()]) else { if (typeof cb === 'function') cb.apply(this, arguments) - retry() } }) } @@ -172,36 +191,46 @@ function patch (fs) { var fs$readdir = fs.readdir fs.readdir = readdir + var noReaddirOptionVersions = /^v[0-5]\./ function readdir (path, options, cb) { - var args = [path] - if (typeof options !== 'function') { - args.push(options) - } else { - cb = options - } - args.push(go$readdir$cb) + if (typeof options === 'function') + cb = options, options = null - return go$readdir(args) + var go$readdir = noReaddirOptionVersions.test(process.version) + ? function go$readdir (path, options, cb, startTime) { + return fs$readdir(path, fs$readdirCallback( + path, options, cb, startTime + )) + } + : function go$readdir (path, options, cb, startTime) { + return fs$readdir(path, options, fs$readdirCallback( + path, options, cb, startTime + )) + } - function go$readdir$cb (err, files) { - if (files && files.sort) - files.sort() + return go$readdir(path, options, cb) - if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) - enqueue([go$readdir, [args]]) + function fs$readdirCallback (path, options, cb, startTime) { + return function (err, files) { + if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) + enqueue([ + go$readdir, + [path, options, cb], + err, + startTime || Date.now(), + Date.now() + ]) + else { + if (files && files.sort) + files.sort() - else { - if (typeof cb === 'function') - cb.apply(this, arguments) - retry() + if (typeof cb === 'function') + cb.call(this, err, files) + } } } } - function go$readdir (args) { - return fs$readdir.apply(fs, args) - } - if (process.version.substr(0, 4) === 'v0.8') { var legStreams = legacy(fs) ReadStream = legStreams.ReadStream @@ -324,14 +353,13 @@ function patch (fs) { return go$open(path, flags, mode, cb) - function go$open (path, flags, mode, cb) { + function go$open (path, flags, mode, cb, startTime) { return fs$open(path, flags, mode, function (err, fd) { if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) - enqueue([go$open, [path, flags, mode, cb]]) + enqueue([go$open, [path, flags, mode, cb], err, startTime || Date.now(), Date.now()]) else { if (typeof cb === 'function') cb.apply(this, arguments) - retry() } }) } @@ -343,12 +371,78 @@ function patch (fs) { function enqueue (elem) { debug('ENQUEUE', elem[0].name, elem[1]) fs[gracefulQueue].push(elem) + retry() +} + +// keep track of the timeout between retry() calls +var retryTimer + +// reset the startTime and lastTime to now +// this resets the start of the 60 second overall timeout as well as the +// delay between attempts so that we'll retry these jobs sooner +function resetQueue () { + var now = Date.now() + for (var i = 0; i < fs[gracefulQueue].length; ++i) { + // entries that are only a length of 2 are from an older version, don't + // bother modifying those since they'll be retried anyway. + if (fs[gracefulQueue][i].length > 2) { + fs[gracefulQueue][i][3] = now // startTime + fs[gracefulQueue][i][4] = now // lastTime + } + } + // call retry to make sure we're actively processing the queue + retry() } function retry () { + // clear the timer and remove it to help prevent unintended concurrency + clearTimeout(retryTimer) + retryTimer = undefined + + if (fs[gracefulQueue].length === 0) + return + var elem = fs[gracefulQueue].shift() - if (elem) { - debug('RETRY', elem[0].name, elem[1]) - elem[0].apply(null, elem[1]) + var fn = elem[0] + var args = elem[1] + // these items may be unset if they were added by an older graceful-fs + var err = elem[2] + var startTime = elem[3] + var lastTime = elem[4] + + // if we don't have a startTime we have no way of knowing if we've waited + // long enough, so go ahead and retry this item now + if (startTime === undefined) { + debug('RETRY', fn.name, args) + fn.apply(null, args) + } else if (Date.now() - startTime >= 60000) { + // it's been more than 60 seconds total, bail now + debug('TIMEOUT', fn.name, args) + var cb = args.pop() + if (typeof cb === 'function') + cb.call(null, err) + } else { + // the amount of time between the last attempt and right now + var sinceAttempt = Date.now() - lastTime + // the amount of time between when we first tried, and when we last tried + // rounded up to at least 1 + var sinceStart = Math.max(lastTime - startTime, 1) + // backoff. wait longer than the total time we've been retrying, but only + // up to a maximum of 100ms + var desiredDelay = Math.min(sinceStart * 1.2, 100) + // it's been long enough since the last retry, do it again + if (sinceAttempt >= desiredDelay) { + debug('RETRY', fn.name, args) + fn.apply(null, args.concat([startTime])) + } else { + // if we can't do this job yet, push it to the end of the queue + // and let the next iteration check again + fs[gracefulQueue].push(elem) + } + } + + // schedule our next run if one isn't already scheduled + if (retryTimer === undefined) { + retryTimer = setTimeout(retry, 0) } } diff --git a/node_modules/graceful-fs/package.json b/node_modules/graceful-fs/package.json index 32518904d9741..a28910e1d6bc8 100644 --- a/node_modules/graceful-fs/package.json +++ b/node_modules/graceful-fs/package.json @@ -1,19 +1,19 @@ { - "_from": "graceful-fs@4.2.4", - "_id": "graceful-fs@4.2.4", + "_from": "graceful-fs@4.2.10", + "_id": "graceful-fs@4.2.10", "_inBundle": false, - "_integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==", + "_integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==", "_location": "/graceful-fs", "_phantomChildren": {}, "_requested": { "type": "version", "registry": true, - "raw": "graceful-fs@4.2.4", + "raw": "graceful-fs@4.2.10", "name": "graceful-fs", "escapedName": "graceful-fs", - "rawSpec": "4.2.4", + "rawSpec": "4.2.10", "saveSpec": null, - "fetchSpec": "4.2.4" + "fetchSpec": "4.2.10" }, "_requiredBy": [ "#USER", @@ -41,15 +41,14 @@ "/test-exclude/load-json-file", "/write-file-atomic" ], - "_resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz", - "_shasum": "2256bde14d3632958c465ebc96dc467ca07a29fb", - "_spec": "graceful-fs@4.2.4", - "_where": "/Users/ruyadorno/Documents/workspace/cli", + "_resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz", + "_shasum": "147d3a006da4ca3ce14728c7aefc287c367d7a6c", + "_spec": "graceful-fs@4.2.10", + "_where": "/Users/darcyclarke/Documents/Repos/npm/v6", "bugs": { "url": "https://github.com/isaacs/node-graceful-fs/issues" }, "bundleDependencies": false, - "dependencies": {}, "deprecated": false, "description": "A drop-in replacement for fs, making various improvements.", "devDependencies": { @@ -94,9 +93,10 @@ }, "scripts": { "postpublish": "git push origin --follow-tags", + "posttest": "nyc report", "postversion": "npm publish", "preversion": "npm test", - "test": "node test.js | tap -" + "test": "nyc --silent node test.js | tap -c -" }, - "version": "4.2.4" + "version": "4.2.10" } diff --git a/node_modules/graceful-fs/polyfills.js b/node_modules/graceful-fs/polyfills.js index a5808d23f132e..46dea36cc490f 100644 --- a/node_modules/graceful-fs/polyfills.js +++ b/node_modules/graceful-fs/polyfills.js @@ -14,10 +14,14 @@ try { process.cwd() } catch (er) {} -var chdir = process.chdir -process.chdir = function(d) { - cwd = null - chdir.call(process, d) +// This check is needed until node.js 12 is required +if (typeof process.chdir === 'function') { + var chdir = process.chdir + process.chdir = function (d) { + cwd = null + chdir.call(process, d) + } + if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir) } module.exports = patch @@ -67,13 +71,13 @@ function patch (fs) { fs.lstatSync = statFixSync(fs.lstatSync) // if lchmod/lchown do not exist, then make them no-ops - if (!fs.lchmod) { + if (fs.chmod && !fs.lchmod) { fs.lchmod = function (path, mode, cb) { if (cb) process.nextTick(cb) } fs.lchmodSync = function () {} } - if (!fs.lchown) { + if (fs.chown && !fs.lchown) { fs.lchown = function (path, uid, gid, cb) { if (cb) process.nextTick(cb) } @@ -90,32 +94,38 @@ function patch (fs) { // CPU to a busy looping process, which can cause the program causing the lock // contention to be starved of CPU by node, so the contention doesn't resolve. if (platform === "win32") { - fs.rename = (function (fs$rename) { return function (from, to, cb) { - var start = Date.now() - var backoff = 0; - fs$rename(from, to, function CB (er) { - if (er - && (er.code === "EACCES" || er.code === "EPERM") - && Date.now() - start < 60000) { - setTimeout(function() { - fs.stat(to, function (stater, st) { - if (stater && stater.code === "ENOENT") - fs$rename(from, to, CB); - else - cb(er) - }) - }, backoff) - if (backoff < 100) - backoff += 10; - return; - } - if (cb) cb(er) - }) - }})(fs.rename) + fs.rename = typeof fs.rename !== 'function' ? fs.rename + : (function (fs$rename) { + function rename (from, to, cb) { + var start = Date.now() + var backoff = 0; + fs$rename(from, to, function CB (er) { + if (er + && (er.code === "EACCES" || er.code === "EPERM") + && Date.now() - start < 60000) { + setTimeout(function() { + fs.stat(to, function (stater, st) { + if (stater && stater.code === "ENOENT") + fs$rename(from, to, CB); + else + cb(er) + }) + }, backoff) + if (backoff < 100) + backoff += 10; + return; + } + if (cb) cb(er) + }) + } + if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename) + return rename + })(fs.rename) } // if read() returns EAGAIN, then just try it again. - fs.read = (function (fs$read) { + fs.read = typeof fs.read !== 'function' ? fs.read + : (function (fs$read) { function read (fd, buffer, offset, length, position, callback_) { var callback if (callback_ && typeof callback_ === 'function') { @@ -132,11 +142,12 @@ function patch (fs) { } // This ensures `util.promisify` works as it does for native `fs.read`. - read.__proto__ = fs$read + if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read) return read })(fs.read) - fs.readSync = (function (fs$readSync) { return function (fd, buffer, offset, length, position) { + fs.readSync = typeof fs.readSync !== 'function' ? fs.readSync + : (function (fs$readSync) { return function (fd, buffer, offset, length, position) { var eagCounter = 0 while (true) { try { @@ -195,7 +206,7 @@ function patch (fs) { } function patchLutimes (fs) { - if (constants.hasOwnProperty("O_SYMLINK")) { + if (constants.hasOwnProperty("O_SYMLINK") && fs.futimes) { fs.lutimes = function (path, at, mt, cb) { fs.open(path, constants.O_SYMLINK, function (er, fd) { if (er) { @@ -229,7 +240,7 @@ function patch (fs) { return ret } - } else { + } else if (fs.futimes) { fs.lutimes = function (_a, _b, _c, cb) { if (cb) process.nextTick(cb) } fs.lutimesSync = function () {} } @@ -306,8 +317,10 @@ function patch (fs) { return function (target, options) { var stats = options ? orig.call(fs, target, options) : orig.call(fs, target) - if (stats.uid < 0) stats.uid += 0x100000000 - if (stats.gid < 0) stats.gid += 0x100000000 + if (stats) { + if (stats.uid < 0) stats.uid += 0x100000000 + if (stats.gid < 0) stats.gid += 0x100000000 + } return stats; } } diff --git a/package-lock.json b/package-lock.json index 5d3011dc1b116..d1dd1cbd68919 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3211,9 +3211,9 @@ } }, "graceful-fs": { - "version": "4.2.4", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz", - "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==" + "version": "4.2.10", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz", + "integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==" }, "growl": { "version": "1.10.5", diff --git a/package.json b/package.json index a4ed51ff5e994..9298cd2a79d74 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "fs-write-stream-atomic": "~1.0.10", "gentle-fs": "^2.3.1", "glob": "^7.2.3", - "graceful-fs": "^4.2.4", + "graceful-fs": "^4.2.10", "has-unicode": "~2.0.1", "hosted-git-info": "^2.8.9", "iferr": "^1.0.2",