Skip to content

Commit 07701dc

Browse files
Myles Borinsisaacs
Myles Borins
authored andcommitted
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.
1 parent 45c57aa commit 07701dc

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

fs.js

+21
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,27 @@ var mod = require("module")
66
var pre = '(function (exports, require, module, __filename, __dirname) { '
77
var post = '});'
88
var src = pre + process.binding('natives').fs + post
9+
var deprecation = ''
10+
11+
var printDeprecation = ['var prefix = \'(\' + [process.release.name, process.pid].join(\':\') + \')\';',
12+
'var printDeprecation = function(msg, warned) {',
13+
' if (process.noDeprecation)',
14+
' return true;',
15+
' if (warned)',
16+
' return warned;',
17+
' if (process.throwDeprecation)',
18+
' throw new Error(prefix + msg);',
19+
' else if (process.traceDeprecation)',
20+
' console.trace(msg);',
21+
' else',
22+
' console.error(prefix + msg);',
23+
' return true;',
24+
'};'].join('\n');
25+
26+
var deprecrationRequire = /const printDeprecation = require\(\'internal\/util\'\).printDeprecationMessage;/
27+
28+
src = src.replace(deprecrationRequire, printDeprecation);
29+
930
var vm = require('vm')
1031
var fn = vm.runInThisContext(src)
1132
fn(exports, require, module, __filename, __dirname)

0 commit comments

Comments
 (0)