JSPM

  • Created
  • Published
  • Downloads 19511
  • Score
    100M100P100Q149282F
  • License MIT

load plugins and prepare them to run

Package Exports

  • @putout/engine-loader
  • @putout/engine-loader/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@putout/engine-loader) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@putout/engine-loader NPM version

🐊Putout loader for plugins and processors.

Install

npm i @putout/engine-loader

Plugins

Loader supports two kinds of plugins:

Simple Plugin

Simplest type of plugin support by @putout/engine-runner, contains one rule.

Nested Plugin

Nested contains one or more rules:

module.exports.rules = {
    'remove-unused-variables': require('@putout/plugin-remove-unused-variables'),
};

Env Variables

When you need to get things working with Yarn PnP, and using custom plugins formatters or processors, add env variable PUTOUT_YARN_PNP with name of a package that contains dependencies you need.

API

loadPlugins

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,
});

Babel Plugins

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,
});

When you need to use imported babel plugin use babelPlugin:

import {babelPlugin} from '@putout/engine-loader';
import transformBlockScoping from '@babel/plugin-transform-block-scoping';

const plugins = loadPlugins({
    pluginNames: [
        ['babel/transform-inline-consecutive-adds', babelPlugin(transformBlockScoping, 'Optional message')],
    ],
});

loadProcessorsAsync

const {loadProcessors} = require('@putout/engine-loader');
const optionalLoad = async (a) => await import(a);

const plugins = await loadProcessorsAsync({
    processors: [
        ['javascript', 'on'],
        ['markdown', 'off'],
    ],
}, optionalLoad);

createAsyncLoader

Gives ability to create loader for processor or formatter.

const {createAsyncLoader} = require('@putout/engine-loader');
const {loadProcessor} = createAsyncLoader('processor');

// load @putout/processor-markdown
await loadProcessors('markdown');
// load @putout/processor-json using custom loader
await loadProcess('json', () => {
    return Promise.resolve(`will be called instead of 'import'`);
});

License

MIT