Plugin loading fails when using syncImport
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 17k
- Forks
- 3.4k
- Avg merge
- 7h 42m
- Merged PRs (30d)
- 26
Description
Loading a plugin fails when less is using the syncImport option. The File manager seems to return the result instead of a promise in this case. It can be easily reproduced with the following code:
Example:
// pi.js
module.exports = {
install: function(less, pluginManager, functions) {
functions.add('pi', function() {
return Math.PI;
});
}
};
// index.js
var less = require('less');
less.render('@plugin "./pi.js"; @var pi()', { syncImport: true }, function (error, output) {
console.log(error, output);
});
Error:
TypeError: fileManager.loadFile(...).then is not a function
at /home/ydelange/less-bug/node_modules/less/lib/less-node/plugin-loader.js:34:72
at new Promise (<anonymous>)
at PluginLoader.loadPlugin (/home/ydelange/less-bug/node_modules/less/lib/less-node/plugin-loader.js:33:12)
at ImportManager.push (/home/ydelange/less-bug/node_modules/less/lib/less/import-manager.js:149:36)
at ImportVisitor.processImportNode (/home/ydelange/less-bug/node_modules/less/lib/less/visitors/import-visitor.js:88:28)
at ImportVisitor.visitImport (/home/ydelange/less-bug/node_modules/less/lib/less/visitors/import-visitor.js:50:22)
at Visitor.visit (/home/ydelange/less-bug/node_modules/less/lib/less/visitors/visitor.js:76:32)
at Visitor.visitArray (/home/ydelange/less-bug/node_modules/less/lib/less/visitors/visitor.js:102:22)
at Ruleset.accept (/home/ydelange/less-bug/node_modules/less/lib/less/tree/ruleset.js:40:30)
at Visitor.visit (/home/ydelange/less-bug/node_modules/less/lib/less/visitors/visitor.js:83:18)
Code that is causing it:
https://github.com/less/less.js/blob/master/lib/less-node/file-manager.js#L42
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the syncImport reproduction in index.js and inspect the linked code in lib/less-node/file-manager.js alongside the failing call in lib/less-node/plugin-loader.js. Run the example with the pi.js plugin and confirm that loading no longer raises the .then TypeError and the render callback receives its result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100