make sure plugins can be loaded from the current directory if lessc is installed globally

This commit is contained in:
Luke Page
2014-10-19 19:09:23 +01:00
parent c3831e10d6
commit 65702f80a3

View File

@@ -1,3 +1,4 @@
var path = require("path");
/**
* Node Plugin Loader
*/
@@ -47,6 +48,25 @@ PluginLoader.prototype.versionToString = function(version) {
return versionString;
};
PluginLoader.prototype.tryRequirePlugin = function(name) {
// is at the same level as the less.js module
try {
return require("../../../" + name);
}
catch(e) {
}
// is installed as a sub dependency of the current folder
try {
return require(path.join(process.cwd(), "node_modules", name));
}
catch(e) {
}
// is referenced relative to the current directory
try {
return require(path.join(process.cwd(), name));
}
catch(e) {
}
// unlikely - would have to be a dependency of where this code was running (less.js)...
if (name[0] !== '.') {
try {
return require(name);
@@ -54,11 +74,6 @@ PluginLoader.prototype.tryRequirePlugin = function(name) {
catch(e) {
}
}
try {
return require("../../../" + name);
}
catch(e) {
}
};
PluginLoader.prototype.printUsage = function(plugins) {
for(var i = 0; i < plugins.length; i++) {