From cf5e4fc5d343634875a0d491e0a38ace0f9f3cc0 Mon Sep 17 00:00:00 2001 From: Parsha Pourkhomami Date: Tue, 22 Aug 2017 23:27:43 -0700 Subject: [PATCH 1/2] Add missing arguments to loadFile and loadFileSync Less's import-manager.js calls loadFile with a "callback" argument [1] and file-manager.js calls loadFileSync with an "encoding" argument [2], without which operating in synchronous mode (using the syncImport less option) is broken. [1] https://github.com/less/less.js/blob/4a0026ebf6d4c783365d3701ac796c18dcc9d30f/lib/less/import-manager.js#L119 [2] https://github.com/less/less.js/blob/4a0026ebf6d4c783365d3701ac796c18dcc9d30f/lib/less-node/file-manager.js#L32 --- lib/npm-file-manager.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/npm-file-manager.js b/lib/npm-file-manager.js index 0eb44a8..5c8771e 100644 --- a/lib/npm-file-manager.js +++ b/lib/npm-file-manager.js @@ -47,7 +47,7 @@ module.exports = function(less) { }); }; - NpmFileManager.prototype.loadFile = function(filename, currentDirectory, options, environment) { + NpmFileManager.prototype.loadFile = function(filename, currentDirectory, options, environment, callback) { try { filename = this.resolve(filename, currentDirectory); } @@ -58,17 +58,17 @@ module.exports = function(less) { } ); } - return FileManager.prototype.loadFile.call(this, filename, "", options, environment); + return FileManager.prototype.loadFile.call(this, filename, "", options, environment, callback); }; - NpmFileManager.prototype.loadFileSync = function(filename, currentDirectory, options, environment) { + NpmFileManager.prototype.loadFileSync = function(filename, currentDirectory, options, environment, encoding) { try { filename = this.resolve(filename, currentDirectory); } catch(e) { return { error: e }; } - return FileManager.prototype.loadFileSync.call(this, filename, "", options, environment); + return FileManager.prototype.loadFileSync.call(this, filename, "", options, environment, encoding); }; NpmFileManager.prototype.tryAppendExtension = function(path, ext) { From 5fcc7addb65cfeb789c8ab55a8f8b736d7b3501b Mon Sep 17 00:00:00 2001 From: Parsha Pourkhomami Date: Wed, 23 Aug 2017 01:02:40 -0700 Subject: [PATCH 2/2] Fix loadFile error handling in sync mode When running in sync mode (syncImport option), loadFile should call the callback instead of returning a promise. This change implements logic similar to [1]. [1] https://github.com/less/less.js/blob/49cbe520f6b38b4b8797dcba491501c0c461c7f5/lib/less-node/file-manager.js#L31 --- lib/npm-file-manager.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/npm-file-manager.js b/lib/npm-file-manager.js index 5c8771e..628b687 100644 --- a/lib/npm-file-manager.js +++ b/lib/npm-file-manager.js @@ -48,10 +48,15 @@ module.exports = function(less) { }; NpmFileManager.prototype.loadFile = function(filename, currentDirectory, options, environment, callback) { + options = options || {}; try { filename = this.resolve(filename, currentDirectory); } catch(e) { + if (options.syncImport) { + callback(e); + return; + } return new PromiseConstructor( function(fullfill, reject) { reject(e);