mirror of
https://github.com/less/less.js.git
synced 2026-02-13 00:15:06 -05:00
Make @import (plugin) environment-dependant
Shifts some logic around and extends some of the management classes in such a way that plugins loaded via an `@import (plugin) "..."` declaration are only loaded in environments that have support for loading plugins. (i.e. Node.js)
This commit is contained in:
@@ -5,6 +5,28 @@ var path = require("path");
|
||||
var PluginLoader = function(less) {
|
||||
this.less = less;
|
||||
};
|
||||
PluginLoader.prototype.tryImportPlugin = function(resolvedFileName) {
|
||||
var plugin;
|
||||
try {
|
||||
plugin = require(resolvedFileName);
|
||||
if (plugin) {
|
||||
// support plugins being a function
|
||||
// so that the plugin can be more usable programmatically
|
||||
if (typeof plugin === "function") {
|
||||
plugin = new plugin();
|
||||
}
|
||||
if (plugin.minVersion) {
|
||||
if (this.compareVersion(plugin.minVersion, this.less.version) < 0) {
|
||||
console.log("plugin " + name + " requires version " + this.versionToString(plugin.minVersion));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return plugin;
|
||||
}
|
||||
} catch(e) {}
|
||||
|
||||
return null;
|
||||
};
|
||||
PluginLoader.prototype.tryLoadPlugin = function(name, argument) {
|
||||
var plugin = this.tryRequirePlugin(name);
|
||||
if (plugin) {
|
||||
|
||||
Reference in New Issue
Block a user