Permalink
Browse files

Plugins: If minVersion >= 3.0.0, don't "pre-run" .setOptions() (#3247)

* dev – add .editorconfig
* AbstractPluginLoader – check for minVersion < 3 before running .setOptions() twice
* tests – separate unspecified minVersion test from minVersion: [2,0,0] test
  • Loading branch information...
calvinjuarez authored and matthew-dean committed Jul 3, 2018
1 parent 39ef69c commit d54251276aae794c6f6f796d6d9b0a40f79a00ee
View
@@ -0,0 +1,13 @@
# @see http://editorconfig.org/
# the buck stops here
root = true
# all files
[*]
end_of_line = LF
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
@@ -64,7 +64,8 @@ AbstractPluginLoader.prototype.evalPlugin = function(contents, context, imports,
try {
loader = new Function('module', 'require', 'registerPlugin', 'functions', 'tree', 'less', 'fileInfo', contents);
loader(localModule, this.require(filename), registerPlugin, registry, this.less.tree, this.less, fileInfo);
} catch (e) {
}
catch (e) {
return new LessError(e, imports, filename);
}
@@ -78,12 +79,16 @@ AbstractPluginLoader.prototype.evalPlugin = function(contents, context, imports,
}
if (pluginObj) {
// For 2.x back-compatibility - setOptions() before install()
pluginObj.imports = imports;
pluginObj.filename = filename;
result = this.trySetOptions(pluginObj, filename, shortname, pluginOptions);
if (result) {
return result;
// For < 3.x (or unspecified minVersion) - setOptions() before install()
if (!pluginObj.minVersion || this.compareVersion('3.0.0', pluginObj.minVersion) < 0) {
result = this.trySetOptions(pluginObj, filename, shortname, pluginOptions);
if (result) {
return result;
}
}
// Run on first load
View
@@ -120,9 +120,23 @@
test-atrule("@charset"; '"utf-8"');
test-atrule("@arbitrary"; "value after ()");
// no minVersion specified
@plugin (option1) "./plugin/plugin-set-options";
@plugin "./plugin/plugin-set-options";
@plugin (option2) "./plugin/plugin-set-options";
@plugin "./plugin/plugin-set-options";
@plugin (option3) "./plugin/plugin-set-options";
// specifies minVersion: [2,0,0]
@plugin (option1) "./plugin/plugin-set-options-v2";
@plugin "./plugin/plugin-set-options-v2";
@plugin (option2) "./plugin/plugin-set-options-v2";
@plugin "./plugin/plugin-set-options-v2";
@plugin (option3) "./plugin/plugin-set-options-v2";
// specifies minVersion: [3,0,0]
@plugin (option1) "./plugin/plugin-set-options-v3";
@plugin "./plugin/plugin-set-options-v3";
@plugin (option2) "./plugin/plugin-set-options-v3";
@plugin "./plugin/plugin-set-options-v3";
@plugin (option3) "./plugin/plugin-set-options-v3";
@@ -22,5 +22,6 @@ module.exports = {
manager.addVisitor(new Visitor());
// console.log(manager);
}
},
minVersion: [2,0,0]
};
@@ -0,0 +1,31 @@
var optionsStack = [
'option1',
undefined,
'option2',
undefined,
'option3'
];
var options, error;
registerPlugin({
install: function(less, pluginManager, functions) {
if (!options) {
error = 'setOptions() not called before install';
}
},
use: function() {
var pos = optionsStack.indexOf(options);
if (pos === -1) {
error = 'setOptions() not setting option "' + opt + '" correctly';
}
if (error) {
throw new Error(error);
}
},
setOptions: function(opts) {
options = opts;
},
minVersion: [2,0,0]
});
@@ -0,0 +1,31 @@
var optionsStack = [
'option1',
undefined,
'option2',
undefined,
'option3'
];
var options, error;
registerPlugin({
install: function(less, pluginManager, functions) {
if (options) {
error = 'setOptions() called before install';
}
},
use: function() {
var pos = optionsStack.indexOf(options);
if (pos === -1) {
error = 'setOptions() not setting option "' + opt + '" correctly';
}
if (error) {
throw new Error(error);
}
},
setOptions: function(opts) {
options = opts;
},
minVersion: [3,0,0]
});

0 comments on commit d542512

Please sign in to comment.