diff --git a/fs.js b/fs.js index 64ad980..7e4db24 100644 --- a/fs.js +++ b/fs.js @@ -1,11 +1 @@ -// eeeeeevvvvviiiiiiillllll -// more evil than monkey-patching the native builtin? -// Not sure. - -var mod = require("module") -var pre = '(function (exports, require, module, __filename, __dirname) { ' -var post = '});' -var src = pre + process.binding('natives').fs + post -var vm = require('vm') -var fn = vm.runInThisContext(src) -fn(exports, require, module, __filename, __dirname) +module.exports = Object.create(require('fs')) diff --git a/graceful-fs.js b/graceful-fs.js index fb206b8..9f0e899 100644 --- a/graceful-fs.js +++ b/graceful-fs.js @@ -1,5 +1,3 @@ -// Monkey-patching the fs module. -// It's ugly, but there is simply no other way to do this. var fs = module.exports = require('./fs.js') var assert = require('assert') diff --git a/test/module-evil-hackery.js b/test/module-evil-hackery.js new file mode 100644 index 0000000..ce63666 --- /dev/null +++ b/test/module-evil-hackery.js @@ -0,0 +1,10 @@ +var test = require('tap').test +var realfs = require('fs') +var fs = require('../') + +test('module assignment should not leak', function (t) { + t.plan(1) + + fs.abc = 3 + t.equal(realfs.abc, undefined) +})