UNPKG

2.01 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var path_1 = tslib_1.__importDefault(require("path"));
5var abstract_plugin_loader_js_1 = tslib_1.__importDefault(require("../less/environment/abstract-plugin-loader.js"));
6/**
7 * Node Plugin Loader
8 */
9var PluginLoader = function (less) {
10 this.less = less;
11 this.require = function (prefix) {
12 prefix = path_1.default.dirname(prefix);
13 return function (id) {
14 var str = id.substr(0, 2);
15 if (str === '..' || str === './') {
16 return require(path_1.default.join(prefix, id));
17 }
18 else {
19 return require(id);
20 }
21 };
22 };
23};
24PluginLoader.prototype = Object.assign(new abstract_plugin_loader_js_1.default(), {
25 loadPlugin: function (filename, basePath, context, environment, fileManager) {
26 var prefix = filename.slice(0, 1);
27 var explicit = prefix === '.' || prefix === '/' || filename.slice(-3).toLowerCase() === '.js';
28 if (!explicit) {
29 context.prefixes = ['less-plugin-', ''];
30 }
31 if (context.syncImport) {
32 return fileManager.loadFileSync(filename, basePath, context, environment);
33 }
34 return new Promise(function (fulfill, reject) {
35 fileManager.loadFile(filename, basePath, context, environment).then(function (data) {
36 try {
37 fulfill(data);
38 }
39 catch (e) {
40 console.log(e);
41 reject(e);
42 }
43 }).catch(function (err) {
44 reject(err);
45 });
46 });
47 },
48 loadPluginSync: function (filename, basePath, context, environment, fileManager) {
49 context.syncImport = true;
50 return this.loadPlugin(filename, basePath, context, environment, fileManager);
51 }
52});
53exports.default = PluginLoader;
54//# sourceMappingURL=plugin-loader.js.map
\No newline at end of file