From b80d80b466dcda7416528851e2f93c5880249874 Mon Sep 17 00:00:00 2001 From: aminya Date: Wed, 22 Jul 2020 06:08:47 -0500 Subject: [PATCH] dynamic require from the cjs dist of less --- src/less-cache.coffee | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/less-cache.coffee b/src/less-cache.coffee index b6c8555..751eeff 100644 --- a/src/less-cache.coffee +++ b/src/less-cache.coffee @@ -107,7 +107,12 @@ class LessCache observeImportedFilePaths: (callback) -> importedPaths = [] - lessFs ?= require 'less/lib/less-node/fs.js' + # load or assign less and lessFs + if (less == null) + less = require 'less' + lessFs = less.fs + else if (lessFs == null) + lessFs = less.fs originalFsReadFileSync = lessFs.readFileSync lessFs.readFileSync = (filePath, args...) => relativeFilePath = @relativize(@resourcePath, filePath) if @resourcePath @@ -196,7 +201,12 @@ class LessCache parseLess: (filePath, contents) -> css = null options = filename: filePath, syncImport: true, paths: @importPaths - less ?= require('less') + # load or assign less and lessFs + if (less == null) + less = require 'less' + lessFs = less.fs + else if (lessFs == null) + lessFs = less.fs imports = @observeImportedFilePaths -> less.render contents, options, (error, result) -> if error?