From 07701dc98bc088e1a71f18a8f59a970e3354646f Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Thu, 11 Aug 2016 21:45:09 -0400 Subject: [PATCH] add support for node v7 node version 7 officially deprecates `fs.read` and `fs.readSync` This is done using `internal/util`. The unfortunate side affect being that `graceful-fs v3.x` explodes when running the code in `vm` as `internal/util` is not accessible from userland. This commit uses a regular expression to replaces the require of the specific internal util function with the source of that util function. As such `graceful-fs v3.x` will no longer explode in node v7. One advantage to this approach is that any future deprecation will not break graceful-fs. --- fs.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/fs.js b/fs.js index 64ad980..3b73f1c 100644 --- a/fs.js +++ b/fs.js @@ -6,6 +6,27 @@ var mod = require("module") var pre = '(function (exports, require, module, __filename, __dirname) { ' var post = '});' var src = pre + process.binding('natives').fs + post +var deprecation = '' + +var printDeprecation = ['var prefix = \'(\' + [process.release.name, process.pid].join(\':\') + \')\';', +'var printDeprecation = function(msg, warned) {', +' if (process.noDeprecation)', +' return true;', +' if (warned)', +' return warned;', +' if (process.throwDeprecation)', +' throw new Error(prefix + msg);', +' else if (process.traceDeprecation)', +' console.trace(msg);', +' else', +' console.error(prefix + msg);', +' return true;', +'};'].join('\n'); + +var deprecrationRequire = /const printDeprecation = require\(\'internal\/util\'\).printDeprecationMessage;/ + +src = src.replace(deprecrationRequire, printDeprecation); + var vm = require('vm') var fn = vm.runInThisContext(src) fn(exports, require, module, __filename, __dirname)