Skip to content

Commit

Permalink
fix: use eval instead of require
Browse files Browse the repository at this point in the history
In most ENB packages used `mock-fs` to testing.

The `mock-fs` does not support `require` for `Node.js 4`: tschaub/mock-fs#43.

Because of this `node.runTechAndRequire()` will throw error:

```
Cannot find module 'path/to/file.js'
```
  • Loading branch information
blond committed Apr 20, 2016
1 parent f38b38b commit 97fa69b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/mock-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var path = require('path'),
CacheStorage = require('enb/lib/cache/cache-storage'),
Cache = require('enb/lib/cache/cache'),
asyncFs = require('enb').asyncFs,
clearRequire = require('clear-require');
safeEval = require('gulp-eval').eval;

module.exports = inherit({
__constructor: function (nodePath) {
Expand Down Expand Up @@ -224,8 +224,10 @@ module.exports = inherit({
return this._buildDefer.promise().then(function () {
return vow.all(tech.getTargets().map(function (targetName) {
var filename = _this.resolvePath(targetName);
clearRequire(filename);
return require(filename);

return asyncFs.read(filename, 'utf-8').then(function (source) {
return safeEval(source);
});
}, this));
}.bind(this));
}.bind(this));
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"dependencies": {
"clear-require": "1.0.1",
"gulp-eval": "1.0.0-0",
"inherit": "2.2.2",
"vow": "0.4.11"
},
Expand Down

0 comments on commit 97fa69b

Please sign in to comment.