From 32573178227cacc2eb58230a7d164181c29120b2 Mon Sep 17 00:00:00 2001 From: Oscar Funes Date: Thu, 9 Nov 2017 15:14:27 -0600 Subject: [PATCH 1/2] fix infinite recursion on unload and restore --- .travis.yml | 4 ++++ index.js | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 001d832..419abd9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,10 @@ node_js: - "0.12" - "0.10" - "iojs" + - "node" + - "lts/argon" + - "lts/boron" + - "lts/carbon" script: - "npm run-script cover" diff --git a/index.js b/index.js index ec4795b..613d84c 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,35 @@ var path = require('path'), isAbsolute = require('path-is-absolute'), resolve = require('resolve'); +/** + * Array.includes polyfill + * @param {string[]} array + * @param {string} searchElement + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes#Polyfill + */ +function includes(array, searchElement, fromIndex) { + var len = array.length >>> 0; + + if (len === 0) { + return false; + } + + var n = fromIndex | 0; + var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); + + function sameValueZero(x, y) { + return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y)); + } + + while (k < len) { + if (sameValueZero(array[k], searchElement)) { + return true; + } + k++; + } + + return false; +} /** * Gets a reference to a unique instance of a given module. @@ -17,6 +46,7 @@ function getFresh(name, cb) { var orig, fresh; orig = snapshot(name); + unload(name); fresh = require(name); @@ -48,12 +78,16 @@ function reload(name) { * @param module module name or absolute path * @returns {boolean} true if the module was removed or false if not */ -function unload(module) { +function unload(module, stack) { var path = require.resolve(module); + stack = stack || []; if (require.cache[path] && require.cache[path].children) { require.cache[path].children.forEach(function (child) { - unload(child.id); + if (!includes(stack, child.id)) { + stack.push(path); + unload(child.id, stack); + } }); } @@ -75,9 +109,15 @@ function snapshot(module) { * Add a module entry back into the cache * @param module module cache object */ -function restore(module) { +function restore(module, stack) { + stack = stack || []; require.cache[module.id] = module; - module.children.forEach(restore); + module.children.forEach(function (child) { + if (!includes(stack, child.id)) { + stack.push(child.id); + restore(child, stack); + } + }); } function normalize(fn) { From 8085bd96bf0a1c2965416a312be9e530b18ddb8c Mon Sep 17 00:00:00 2001 From: Oscar Funes Date: Thu, 9 Nov 2017 15:16:03 -0600 Subject: [PATCH 2/2] package-lock.json update --- package-lock.json | 326 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 290 insertions(+), 36 deletions(-) diff --git a/package-lock.json b/package-lock.json index ca91d73..b5e066e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2,6 +2,7 @@ "name": "freshy", "version": "1.0.3", "lockfileVersion": 1, + "requires": true, "dependencies": { "abbrev": { "version": "1.0.9", @@ -32,7 +33,10 @@ "version": "1.0.9", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.9.tgz", "integrity": "sha1-c9g7wmP4bpf4zE9rrhsOkKfSLIY=", - "dev": true + "dev": true, + "requires": { + "sprintf-js": "1.0.3" + } }, "async": { "version": "0.9.2", @@ -50,17 +54,32 @@ "version": "1.1.8", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", - "dev": true + "dev": true, + "requires": { + "balanced-match": "1.0.0", + "concat-map": "0.0.1" + } }, "caller": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/caller/-/caller-0.0.1.tgz", "integrity": "sha1-83odbqEOgp2UchrimpC7T7Uqt2c=", + "requires": { + "tape": "2.3.3" + }, "dependencies": { "tape": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/tape/-/tape-2.3.3.tgz", - "integrity": "sha1-Lnzgox3wn41oUWZKcYQuDKUFevc=" + "integrity": "sha1-Lnzgox3wn41oUWZKcYQuDKUFevc=", + "requires": { + "deep-equal": "0.1.2", + "defined": "0.0.0", + "inherits": "2.0.3", + "jsonify": "0.0.0", + "resumer": "0.0.0", + "through": "2.3.8" + } } } }, @@ -68,7 +87,14 @@ "version": "1.1.3", "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", - "dev": true + "dev": true, + "requires": { + "ansi-styles": "2.2.1", + "escape-string-regexp": "1.0.5", + "has-ansi": "2.0.0", + "strip-ansi": "3.0.1", + "supports-color": "2.0.0" + } }, "cli-width": { "version": "1.1.1", @@ -86,7 +112,12 @@ "version": "1.6.0", "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.0.tgz", "integrity": "sha1-CqxmL9Ur54lk1VMvaUeE5wEQrPc=", - "dev": true + "dev": true, + "requires": { + "inherits": "2.0.3", + "readable-stream": "2.2.11", + "typedarray": "0.0.6" + } }, "core-util-is": { "version": "1.0.2", @@ -98,13 +129,19 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/d/-/d-1.0.0.tgz", "integrity": "sha1-dUu1v+VUUdpppYuU1F9MWwRi1Y8=", - "dev": true + "dev": true, + "requires": { + "es5-ext": "0.10.23" + } }, "debug": { "version": "2.6.8", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", "integrity": "sha1-5zFTHKLt4n0YgiJCfaF4IdaP9Pw=", - "dev": true + "dev": true, + "requires": { + "ms": "2.0.0" + } }, "debuglog": { "version": "1.0.1", @@ -132,6 +169,10 @@ "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-0.6.4.tgz", "integrity": "sha1-gUKEkalC7xiwSSBW7aOADu5X1h0=", "dev": true, + "requires": { + "esutils": "1.1.6", + "isarray": "0.0.1" + }, "dependencies": { "isarray": { "version": "0.0.1", @@ -145,37 +186,71 @@ "version": "0.10.23", "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.23.tgz", "integrity": "sha1-dXi1G+l0IHpUh4IbVlOMIk5Oezg=", - "dev": true + "dev": true, + "requires": { + "es6-iterator": "2.0.1", + "es6-symbol": "3.1.1" + } }, "es6-iterator": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.1.tgz", "integrity": "sha1-jjGcnwRTv1ddN0lAplWSDlnKVRI=", - "dev": true + "dev": true, + "requires": { + "d": "1.0.0", + "es5-ext": "0.10.23", + "es6-symbol": "3.1.1" + } }, "es6-map": { "version": "0.1.5", "resolved": "https://registry.npmjs.org/es6-map/-/es6-map-0.1.5.tgz", "integrity": "sha1-kTbgUD3MBqMBaQ8LsU/042TpSfA=", - "dev": true + "dev": true, + "requires": { + "d": "1.0.0", + "es5-ext": "0.10.23", + "es6-iterator": "2.0.1", + "es6-set": "0.1.5", + "es6-symbol": "3.1.1", + "event-emitter": "0.3.5" + } }, "es6-set": { "version": "0.1.5", "resolved": "https://registry.npmjs.org/es6-set/-/es6-set-0.1.5.tgz", "integrity": "sha1-0rPsXU2ADO2BjbU40ol02wpzzLE=", - "dev": true + "dev": true, + "requires": { + "d": "1.0.0", + "es5-ext": "0.10.23", + "es6-iterator": "2.0.1", + "es6-symbol": "3.1.1", + "event-emitter": "0.3.5" + } }, "es6-symbol": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.1.tgz", "integrity": "sha1-vwDvT9q2uhtG7Le2KbTH7VcVzHc=", - "dev": true + "dev": true, + "requires": { + "d": "1.0.0", + "es5-ext": "0.10.23" + } }, "es6-weak-map": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/es6-weak-map/-/es6-weak-map-2.0.2.tgz", "integrity": "sha1-XjqzIlH/0VOKH45f+hNXdy+S2W8=", - "dev": true + "dev": true, + "requires": { + "d": "1.0.0", + "es5-ext": "0.10.23", + "es6-iterator": "2.0.1", + "es6-symbol": "3.1.1" + } }, "escape-string-regexp": { "version": "1.0.5", @@ -188,6 +263,12 @@ "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.3.3.tgz", "integrity": "sha1-8CQBb1qI4Eb9EgBQVek5gC5sXyM=", "dev": true, + "requires": { + "esprima": "1.1.1", + "estraverse": "1.5.1", + "esutils": "1.0.0", + "source-map": "0.1.43" + }, "dependencies": { "esprima": { "version": "1.1.1", @@ -213,13 +294,43 @@ "version": "3.6.0", "resolved": "https://registry.npmjs.org/escope/-/escope-3.6.0.tgz", "integrity": "sha1-4Bl16BJ4GhY6ba392AOY3GTIicM=", - "dev": true + "dev": true, + "requires": { + "es6-map": "0.1.5", + "es6-weak-map": "2.0.2", + "esrecurse": "4.1.0", + "estraverse": "4.2.0" + } }, "eslint": { "version": "0.24.1", "resolved": "https://registry.npmjs.org/eslint/-/eslint-0.24.1.tgz", "integrity": "sha1-VKUICYVbllVyHG8u5Xs1HtzigQE=", - "dev": true + "dev": true, + "requires": { + "chalk": "1.1.3", + "concat-stream": "1.6.0", + "debug": "2.6.8", + "doctrine": "0.6.4", + "escape-string-regexp": "1.0.5", + "escope": "3.6.0", + "espree": "2.2.5", + "estraverse": "4.2.0", + "estraverse-fb": "1.3.1", + "globals": "8.18.0", + "inquirer": "0.8.5", + "is-my-json-valid": "2.16.0", + "js-yaml": "3.8.4", + "minimatch": "2.0.10", + "mkdirp": "0.5.1", + "object-assign": "2.1.1", + "optionator": "0.5.0", + "path-is-absolute": "1.0.1", + "strip-json-comments": "1.0.4", + "text-table": "0.2.0", + "user-home": "1.1.1", + "xml-escape": "1.0.0" + } }, "espree": { "version": "2.2.5", @@ -232,6 +343,10 @@ "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.1.0.tgz", "integrity": "sha1-RxO2U2rffyrE8yfVWed1a/9kgiA=", "dev": true, + "requires": { + "estraverse": "4.1.1", + "object-assign": "4.1.1" + }, "dependencies": { "estraverse": { "version": "4.1.1", @@ -269,7 +384,11 @@ "version": "0.3.5", "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", "integrity": "sha1-34xp7vFkeSPHFXuc6DhAYQsCzDk=", - "dev": true + "dev": true, + "requires": { + "d": "1.0.0", + "es5-ext": "0.10.23" + } }, "fast-levenshtein": { "version": "1.0.7", @@ -282,6 +401,10 @@ "resolved": "https://registry.npmjs.org/figures/-/figures-1.7.0.tgz", "integrity": "sha1-y+Hjr/zxzUS4DK3+0o3Hk6lwHS4=", "dev": true, + "requires": { + "escape-string-regexp": "1.0.5", + "object-assign": "4.1.1" + }, "dependencies": { "object-assign": { "version": "4.1.1", @@ -296,12 +419,20 @@ "resolved": "https://registry.npmjs.org/fileset/-/fileset-0.1.8.tgz", "integrity": "sha1-UGuRqTluqn4y+0KoQHfHoMc2t0E=", "dev": true, + "requires": { + "glob": "3.2.11", + "minimatch": "0.4.0" + }, "dependencies": { "minimatch": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.4.0.tgz", "integrity": "sha1-vSx9Bg0sjI/Xzefx8u0tWycP2xs=", - "dev": true + "dev": true, + "requires": { + "lru-cache": "2.7.3", + "sigmund": "1.0.1" + } } } }, @@ -315,19 +446,30 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/generate-object-property/-/generate-object-property-1.2.0.tgz", "integrity": "sha1-nA4cQDCM6AT0eDYYuTf6iPmdUNA=", - "dev": true + "dev": true, + "requires": { + "is-property": "1.0.2" + } }, "glob": { "version": "3.2.11", "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.11.tgz", "integrity": "sha1-Spc/Y1uRkPcV0QmH1cAP0oFevj0=", "dev": true, + "requires": { + "inherits": "2.0.3", + "minimatch": "0.3.0" + }, "dependencies": { "minimatch": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.3.0.tgz", "integrity": "sha1-J12O2qxPG7MyZHIInnlJyDlGmd0=", - "dev": true + "dev": true, + "requires": { + "lru-cache": "2.7.3", + "sigmund": "1.0.1" + } } } }, @@ -341,13 +483,20 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-1.3.0.tgz", "integrity": "sha1-npsTCpPjiUkTItl1zz7BgYw3zjQ=", - "dev": true + "dev": true, + "requires": { + "optimist": "0.3.7", + "uglify-js": "2.3.6" + } }, "has-ansi": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", - "dev": true + "dev": true, + "requires": { + "ansi-regex": "2.1.1" + } }, "inherits": { "version": "2.0.3", @@ -359,6 +508,16 @@ "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-0.8.5.tgz", "integrity": "sha1-29dAz2yjtzEpamPOb22WGFHzNt8=", "dev": true, + "requires": { + "ansi-regex": "1.1.1", + "chalk": "1.1.3", + "cli-width": "1.1.1", + "figures": "1.7.0", + "lodash": "3.10.1", + "readline2": "0.1.1", + "rx": "2.5.3", + "through": "2.3.8" + }, "dependencies": { "ansi-regex": { "version": "1.1.1", @@ -372,7 +531,13 @@ "version": "2.16.0", "resolved": "https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.16.0.tgz", "integrity": "sha1-8Hndm/2uZe4gOKrorLyGqxCeNpM=", - "dev": true + "dev": true, + "requires": { + "generate-function": "2.0.0", + "generate-object-property": "1.2.0", + "jsonpointer": "4.0.1", + "xtend": "4.0.1" + } }, "is-property": { "version": "1.0.2", @@ -391,6 +556,20 @@ "resolved": "https://registry.npmjs.org/istanbul/-/istanbul-0.2.16.tgz", "integrity": "sha1-hwVFoNT0tM4WEDnp6AWpjCxwC9k=", "dev": true, + "requires": { + "abbrev": "1.0.9", + "async": "0.9.2", + "escodegen": "1.3.3", + "esprima": "1.2.5", + "fileset": "0.1.8", + "handlebars": "1.3.0", + "js-yaml": "3.8.4", + "mkdirp": "0.5.1", + "nopt": "3.0.6", + "resolve": "0.7.4", + "which": "1.0.9", + "wordwrap": "0.0.3" + }, "dependencies": { "esprima": { "version": "1.2.5", @@ -411,6 +590,10 @@ "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.8.4.tgz", "integrity": "sha1-UgtFZPhlc7qWZir4Woyvp7S1pvY=", "dev": true, + "requires": { + "argparse": "1.0.9", + "esprima": "3.1.3" + }, "dependencies": { "esprima": { "version": "3.1.3", @@ -435,7 +618,11 @@ "version": "0.2.5", "resolved": "https://registry.npmjs.org/levn/-/levn-0.2.5.tgz", "integrity": "sha1-uo0znQykphDjo/FFucr0iAcVUFQ=", - "dev": true + "dev": true, + "requires": { + "prelude-ls": "1.1.2", + "type-check": "0.3.2" + } }, "lodash": { "version": "3.10.1", @@ -453,7 +640,10 @@ "version": "2.0.10", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-2.0.10.tgz", "integrity": "sha1-jQh8OcazjAAbl/ynzm0OHoCvusc=", - "dev": true + "dev": true, + "requires": { + "brace-expansion": "1.1.8" + } }, "minimist": { "version": "0.0.8", @@ -465,7 +655,10 @@ "version": "0.5.1", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "dev": true + "dev": true, + "requires": { + "minimist": "0.0.8" + } }, "ms": { "version": "2.0.0", @@ -483,7 +676,10 @@ "version": "3.0.6", "resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz", "integrity": "sha1-xkZdvwirzU2zWTF/eaxopkayj/k=", - "dev": true + "dev": true, + "requires": { + "abbrev": "1.0.9" + } }, "object-assign": { "version": "2.1.1", @@ -495,13 +691,24 @@ "version": "0.3.7", "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.3.7.tgz", "integrity": "sha1-yQlBrVnkJzMokjB00s8ufLxuwNk=", - "dev": true + "dev": true, + "requires": { + "wordwrap": "0.0.3" + } }, "optionator": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.5.0.tgz", "integrity": "sha1-t1qJlaLUF98ltuTjhi9QqohlE2g=", - "dev": true + "dev": true, + "requires": { + "deep-is": "0.1.3", + "fast-levenshtein": "1.0.7", + "levn": "0.2.5", + "prelude-ls": "1.1.2", + "type-check": "0.3.2", + "wordwrap": "0.0.3" + } }, "path-is-absolute": { "version": "1.0.1", @@ -529,13 +736,26 @@ "version": "2.2.11", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.2.11.tgz", "integrity": "sha512-h+8+r3MKEhkiVrwdKL8aWs1oc1VvBu33ueshOvS26RsZQ3Amhx/oO3TKe4lApSV9ueY6as8EAh7mtuFjdlhg9Q==", - "dev": true + "dev": true, + "requires": { + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "1.0.0", + "process-nextick-args": "1.0.7", + "safe-buffer": "5.0.1", + "string_decoder": "1.0.2", + "util-deprecate": "1.0.2" + } }, "readline2": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/readline2/-/readline2-0.1.1.tgz", "integrity": "sha1-mUQ7pug7gw7zBRv9fcJBqCco1Wg=", "dev": true, + "requires": { + "mute-stream": "0.0.4", + "strip-ansi": "2.0.1" + }, "dependencies": { "ansi-regex": { "version": "1.1.1", @@ -547,19 +767,28 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-2.0.1.tgz", "integrity": "sha1-32LBqpTtLxFOHQ8h/R1QSCt5pg4=", - "dev": true + "dev": true, + "requires": { + "ansi-regex": "1.1.1" + } } } }, "resolve": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.3.3.tgz", - "integrity": "sha1-ZVkHw0aahoDcLeOidaj91paR8OU=" + "integrity": "sha1-ZVkHw0aahoDcLeOidaj91paR8OU=", + "requires": { + "path-parse": "1.0.5" + } }, "resumer": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/resumer/-/resumer-0.0.0.tgz", - "integrity": "sha1-8ej0YeQGS6Oegq883CqMiT0HZ1k=" + "integrity": "sha1-8ej0YeQGS6Oegq883CqMiT0HZ1k=", + "requires": { + "through": "2.3.8" + } }, "rx": { "version": "2.5.3", @@ -584,7 +813,10 @@ "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.1.43.tgz", "integrity": "sha1-wkvBRspRfBRx9drL4lcbK3+eM0Y=", "dev": true, - "optional": true + "optional": true, + "requires": { + "amdefine": "1.0.1" + } }, "sprintf-js": { "version": "1.0.3", @@ -596,13 +828,19 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.2.tgz", "integrity": "sha1-sp4fThEl+pehA4K4pTNze3SR4Xk=", - "dev": true + "dev": true, + "requires": { + "safe-buffer": "5.0.1" + } }, "strip-ansi": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "dev": true + "dev": true, + "requires": { + "ansi-regex": "2.1.1" + } }, "strip-json-comments": { "version": "1.0.4", @@ -621,6 +859,14 @@ "resolved": "https://registry.npmjs.org/tape/-/tape-2.4.3.tgz", "integrity": "sha1-cgxDU2DxdHdOMDqlK0+e7DITZtg=", "dev": true, + "requires": { + "deep-equal": "0.2.2", + "defined": "0.0.0", + "inherits": "2.0.3", + "jsonify": "0.0.0", + "resumer": "0.0.0", + "through": "2.3.8" + }, "dependencies": { "deep-equal": { "version": "0.2.2", @@ -645,7 +891,10 @@ "version": "0.3.2", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", "integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=", - "dev": true + "dev": true, + "requires": { + "prelude-ls": "1.1.2" + } }, "typedarray": { "version": "0.0.6", @@ -659,6 +908,11 @@ "integrity": "sha1-+gmEdwtCi3qbKoBY9GNV0U/vIRo=", "dev": true, "optional": true, + "requires": { + "async": "0.2.10", + "optimist": "0.3.7", + "source-map": "0.1.43" + }, "dependencies": { "async": { "version": "0.2.10",