npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@putout/engine-loader

v15.0.1

Published

load plugins and prepare them to run

Downloads

62,946

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

When you want to make it disabled by default, use:

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

So when someone using your plugin, he needs to enable it:

{
    "rules": {
        "nested/remove-unused-variables": "on"
    },
    "plugins": ["nested"]
}

Env Variables

When you need to get things working with Yarn OnP, 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,
});

import

You can also use schema like this one:

import:escover/plugin
const plugins = loadPlugins({
    pluginNames: [
        'import:commonjs-putout-plugin',
    ],
});

loadPluginsAsync

Load ESM plugins:

const {loadPluginsAsync} = require('@putout/engine-loader');

const pluginNames = [
    'remove-unusede-variables',
];

const rules = {
    'remove-unused-variables': 'on',
};

const plugins = await loadPluginsAsync({
    cache: true, //default
    pluginNames,
    rules,
});

import

You can also use schema like this one:

import:escover/plugin
const plugins = await loadPluginsAsync({
    pluginNames: [
        'import:escover/plugin',
    ],
});

Or when used putoutAsync:

import {putoutAsync} from 'putout';

await putoutAsync(`module.exports.hello = 'world'`, {
    plugins: [
        'import:escover/plugin',
    ],
});

Which is the same as:

import {putoutAsync} from 'putout';
import * as plugin from 'escover/plugin';

await putoutAsync(`module.exports.hello = 'world'`, {
    plugins: [
        ['escover/plugin', plugin],
    ],
});

Or used inside .putout.json:

{
    "plugins": [
        "import:escover/plugin"
    ]
}

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'`);
});

validateRules

const {validateRules} = require('@putout/engine-loader');

const pluginNames = [];
const rules = {
    'remove-unused-variables': 'on',
};

validateRules({
    pluginNames,
    rules,
});

// throws since there is no plugin name passed that matches rule 'remove-unused-variables'

License

MIT