diff --git a/index.js b/index.js index 1965a87..72051a9 100644 --- a/index.js +++ b/index.js @@ -34,7 +34,7 @@ module.exports = function(options) { // This searches up from the specified package.json file, making sure // the config option behaves as expected. See issue #56. var searchFor = path.join('node_modules', name); - return require(findup(searchFor, {cwd: path.dirname(config)})); + return require(findup(searchFor, {cwd: path.dirname(config)}) || name); }; } else { requireFn = require; diff --git a/package.json b/package.json index f3bd629..7901e60 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.9.0", "description": "Automatically load any gulp plugins in your package.json", "scripts": { - "test": "mocha" + "test": "NODE_PATH=test/global_modules mocha" }, "files": [ "index.js" @@ -25,7 +25,8 @@ "Sindre Sorhus", "Julien Fontanet ", "Callum Macrae", - "Hutson Betts" + "Hutson Betts", + "Christian Maniewski" ], "license": "MIT", "dependencies": { diff --git a/test/global_modules/gulp-test-global/index.js b/test/global_modules/gulp-test-global/index.js new file mode 100644 index 0000000..ea41b01 --- /dev/null +++ b/test/global_modules/gulp-test-global/index.js @@ -0,0 +1 @@ +module.exports = function () {}; diff --git a/test/index.js b/test/index.js index 51d8af7..3b3e1e8 100644 --- a/test/index.js +++ b/test/index.js @@ -204,3 +204,13 @@ describe('requiring from another directory', function() { assert.ok(typeof plugins.test === 'function'); }); }); + +describe('requiring from global directory', function() { + it('allows you to use the NODE_PATH directory', function() { + if (process.env.NODE_PATH !== 'test/global_modules') { + throw new Error('No NODE_PATH found. Please run the tests using npm test.'); + } + var plugins = require('../')(); + assert.ok(typeof plugins.testGlobal === 'function'); + }); +}); diff --git a/test/package.json b/test/package.json index 418c622..4092489 100644 --- a/test/package.json +++ b/test/package.json @@ -1,5 +1,6 @@ { "dependencies": { - "gulp-test": "*" + "gulp-test": "*", + "gulp-test-global": "*" } }