🐊Putout loader for plugins and processors.
npm i @putout/engine-loader
Loader supports two kinds of plugins:
Simplest type of plugin support by @putout/engine-runner, contains one rule.
Nested contains one or more rules:
module.exports.rules = {
'remove-unused-variables': require('@putout/plugin-remove-unused-variables'),
};When you need to get things working with Yarn PnP, and using custom plugins formatters or processers, add env variable
PUTOUT_YARN_PNP with name of a package that contains dependencies you need.
const {loadPlugins} = require('@putout/engine-loader');
const pluginNames = [
'remove-unusede-variables',
];
const rules = {
'remove-unused-variables': 'on',
};
const plugins = loadPlugins({
cache: true, //default
pluginNames,
rules,
});You can use babel plugins with help of babel/ prefix.
Example Let's use two plugins:
babel-plugin-transform-inline-consecutive-adds@babel/plugin-codemod-object-assign-to-object-spread
@putout/engine-loader will gues the prefix of plugin :).
const pluginNames = [
'babel/transform-inline-consecutive-adds',
'babel/codemod-object-assign-to-object-spread',
];
const plugins = loadPlugins({
pluginNames,
});const {loadProcessors} = require('@putout/engine-loader');
const optionalLoad = async (a) => await import(a);
const plugins = await loadProcessorsAsync({
processors: [
['javascript', 'on'],
['markdown', 'off'],
],
}, optionalLoad);Gives ability to create loader for processor or formatter.
const {createAsyncLoader} = require('@putout/engine-loader');
const {loadProcessor} = createAsyncLoader('processor');
await loadProcessors('markdown');
// loads @putout/processor-markdown
await loadProcess('json', () => {
return Promise.resolve(`will be called instead of 'import'`);
});
// loads @putout/processor-json using custom loaderMIT