Skip to content

Commit

Permalink
(Maybe) Fixes less#3187 (couldn't repo, but found bug)
Browse files Browse the repository at this point in the history
- Fixes multiple Node.js plugins not being loaded
  • Loading branch information
matthew-dean committed Jun 24, 2018
1 parent 3c081ff commit 6ce370d
Show file tree
Hide file tree
Showing 7 changed files with 456 additions and 94 deletions.
5 changes: 4 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ module.exports = function (grunt) {
command: [
'node bin/lessc --clean-css="--s1 --advanced" test/less/lazy-eval.less tmp/lazy-eval.css',
'cd lib',
'node ../bin/lessc --clean-css="--s1 --advanced" ../test/less/lazy-eval.less ../tmp/lazy-eval.css'
'node ../bin/lessc --clean-css="--s1 --advanced" ../test/less/lazy-eval.less ../tmp/lazy-eval.css',
'cd ..',
// Test multiple plugins
'node bin/lessc --plugin=clean-css="--s1 --advanced" --plugin=autoprefix="ie 11,Edge >= 13,Chrome >= 47,Firefox >= 45,iOS >= 9.2,Safari >= 9" test/less/lazy-eval.less tmp/lazy-eval.css'
].join(' && ')
},
"sourcemap-test": {
Expand Down
272 changes: 229 additions & 43 deletions dist/less.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions dist/less.min.js

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions lib/less-node/plugin-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ var path = require("path"),
*/
var PluginLoader = function(less) {
this.less = less;
this.require = require;
this.requireRelative = function(prefix) {
this.require = function(prefix) {
prefix = path.dirname(prefix);
return function(id) {
var str = id.substr(0, 2);
Expand All @@ -25,7 +24,6 @@ var PluginLoader = function(less) {
PluginLoader.prototype = new AbstractPluginLoader();

PluginLoader.prototype.loadPlugin = function(filename, basePath, context, environment, fileManager) {
var self = this;
var prefix = filename.slice(0, 1);
var explicit = prefix === "." || prefix === "/" || filename.slice(-3).toLowerCase() === ".js";
if (!explicit) {
Expand All @@ -36,7 +34,6 @@ PluginLoader.prototype.loadPlugin = function(filename, basePath, context, enviro
fileManager.loadFile(filename, basePath, context, environment).then(
function(data) {
try {
self.require = self.requireRelative(data.filename);
fulfill(data);
}
catch (e) {
Expand Down
6 changes: 5 additions & 1 deletion lib/less/environment/abstract-plugin-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ var functionRegistry = require("../functions/function-registry"),
LessError = require('../less-error');

var AbstractPluginLoader = function() {
// Implemented by Node.js plugin loader
this.require = function() {
return null;
}
};

function error(msg, type) {
Expand Down Expand Up @@ -63,7 +67,7 @@ AbstractPluginLoader.prototype.evalPlugin = function(contents, context, imports,

try {
loader = new Function("module", "require", "registerPlugin", "functions", "tree", "less", "fileInfo", contents);
loader(localModule, this.require, registerPlugin, registry, this.less.tree, this.less, fileInfo);
loader(localModule, this.require(filename), registerPlugin, registry, this.less.tree, this.less, fileInfo);
} catch (e) {
return new this.less.LessError(e, imports, filename);
}
Expand Down
Loading

0 comments on commit 6ce370d

Please sign in to comment.