first commit
This commit is contained in:
62
node_modules/less/lib/less-node/plugin-loader.js
generated
vendored
Normal file
62
node_modules/less/lib/less-node/plugin-loader.js
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
import path from 'path';
|
||||
import { createRequire } from 'module';
|
||||
import AbstractPluginLoader from '../less/environment/abstract-plugin-loader.js';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
/**
|
||||
* Node Plugin Loader
|
||||
*/
|
||||
const PluginLoader = function(less) {
|
||||
this.less = less;
|
||||
this.require = prefix => {
|
||||
prefix = path.dirname(prefix);
|
||||
return id => {
|
||||
const str = id.slice(0, 2);
|
||||
if (str === '..' || str === './') {
|
||||
return require(path.join(prefix, id));
|
||||
}
|
||||
else {
|
||||
return require(id);
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
PluginLoader.prototype = Object.assign(new AbstractPluginLoader(), {
|
||||
loadPlugin(filename, basePath, context, environment, fileManager) {
|
||||
const prefix = filename.slice(0, 1);
|
||||
const explicit = prefix === '.' || prefix === '/' || filename.slice(-3).toLowerCase() === '.js';
|
||||
if (!explicit) {
|
||||
context.prefixes = ['less-plugin-', ''];
|
||||
}
|
||||
|
||||
if (context.syncImport) {
|
||||
return fileManager.loadFileSync(filename, basePath, context, environment);
|
||||
}
|
||||
|
||||
return new Promise((fulfill, reject) => {
|
||||
fileManager.loadFile(filename, basePath, context, environment).then(
|
||||
data => {
|
||||
try {
|
||||
fulfill(data);
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e);
|
||||
reject(e);
|
||||
}
|
||||
}
|
||||
).catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
loadPluginSync(filename, basePath, context, environment, fileManager) {
|
||||
context.syncImport = true;
|
||||
return this.loadPlugin(filename, basePath, context, environment, fileManager);
|
||||
}
|
||||
});
|
||||
|
||||
export default PluginLoader;
|
||||
|
||||
Reference in New Issue
Block a user