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

plugin-discovery

v1.2.0

Published

Discover plugins for your (CLI) tool.

Downloads

8

Readme

plugin-discovery

Discover plugins for your (CLI) tool.

This module will scan locations on the file system in an optimal manner, in search of your plugins.

Installation

npm i --save plugin-discovery

Usage

This plugin can be used in instance form, or statically, both async (recommended) and sync. There's an example in the example directory of this project.

const {PluginDiscovery} = require('plugin-discovery');

// Sync
let plugins = PluginDiscovery.discoverSync(config);

// Async
PluginDiscovery.discover(discoveryConfig).then(plugins => {
  // Go nuts! :)
})

Config

These options are available to configure.

const configOptions = {

  // Prefix of your plugins, e.g. my-prefix-foo
  prefix: 'my-prefix',

  // Strategy to use for the plugin's key. Read on for the options.
  dictionaryKeyStrategy: PluginDiscovery.constants.STRATEGY_PROPERTY,

  // Name of the property for strategies PROPERTY and METHOD.
  dictionaryKeyProperty: 'name',

  // Additional paths to look for plugins
  searchPaths: [__dirname + '/custom_path'],

  // Discover plugins in the global node_modules directory? (useful for CLI tools!)
  discoverGlobal: true,

  // Discover plugins in the current working directory?
  discoverCwd: true,

  // Import plugin based on named export? (e.g. module.exports.MyPlugin)
  importNamed: 'MyPlugin',

  // Import plugin based on named fallback export when not found after regular checks?
  namedFallback: 'MyPluginFallback',

  // Custom configurers. The key is used to allow for multiple configurers. 
  configurers: {
    myPlugin: (key, plugin, rootImport) => {
      // Configure for your own project here...
    }
  },

  // Internal method used to configure. Only override when you really know what you're doing.
  configure: (dictionaryKey, imported, root) => this.configure(dictionaryKey, imported, root)
};

Strategies

There are a couple of strategies available for determining what the key of your plugin will be in the produced plugin-dictionary.

All constants are available through: PluginDiscovery.constants.${constant}

STRATEGY_MODULE_NAME

Using this strategy, the key will simply be the entire module name, including the prefix.

STRATEGY_STRIP_PREFIX

Using this strategy, the key will simply be the entire module name, minus the prefix.

STRATEGY_PROPERTY

This strategy allows you to export the key of the plugin, in the plugin.

module.exports = {
  name  : 'my_plugin',
  plugin: MyPlugin
};

Note: this option requires you to also configure the dictionaryKeyProperty.

STRATEGY_METHOD

This strategy allows you to export the key of the plugin, using a method on the plugin export.

module.exports = {
  name  : () => 'my_plugin',
  plugin: MyPlugin
};

Note: this option requires you to also configure the dictionaryKeyProperty.

STRATEGY_CUSTOM

This strategy means that PluginDiscovery won't index your plugins at all. Instead, you are expected to do so yourself in the configure phase.

License

MIT