Permalink
Browse files

Change require to sort of work like people expect

  • Loading branch information...
1 parent 5fa402d commit 64fdf2b6bb92652c4ac073c0fefcd867bab4992c @baudehlo committed Mar 18, 2013
Showing with 12 additions and 1 deletion.
  1. +12 −1 plugins.js
View
@@ -119,9 +119,20 @@ plugins._load_and_compile_plugin = function(name) {
}
throw "Loading plugin " + name + " failed: " + last_err;
}
+ var custom_require = function _haraka_require (module) {
+ if (!/^\./.test(module)) {
+ return require(module);
+ }
+
+ if (path.existsSync(__dirname + '/' + module + '.js') || path.existsSync(__dirname + '/' + module)) {
+ return require(module);
+ }
+
+ return require(path.dirname(fp[i]) + '/' + module);
+ }
var code = '"use strict";' + rf;
var sandbox = {
- require: require,
+ require: custom_require,
__filename: fp[i],
__dirname: path.dirname(fp[i]),
exports: plugin,

0 comments on commit 64fdf2b

Please sign in to comment.