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-importer

v0.1.2

Published

Recursively imports a plugin tree in order of dependencies

Downloads

149

Readme

Plugin Importer

Recursively imports a plugin tree in order of dependencies

npm version npm downloads neostandard javascript style Module type: ESM Types in JS Follow @voxpelli@mastodon.social

Usage

Simple

import { resolvePlainPlugins } from 'plugin-importer';

const loadedPlugins = await resolvePlainPlugins([
  './test-dependency',
  'module-dependency',
], {
  meta: import.meta, // Ensures local paths are resolved in relation to this file
});

Powerful

import { loadPlugins, resolvePluginsInOrder } from 'plugin-importer';

/**
 * @param {unknown} module
 * @param {import('plugin-importer').ProcessPluginContext} context
 * @returns {SupersetOfPluginDefinition}
 */
function processPlugin (module, { normalizedPluginName, pluginDir }) {
  // Whatever other stuff you want to do to resolve the SupersetOfPluginDefinition
}

const pluginLoader = loadPlugins(processPlugin, {
  meta: import.meta, // Ensures local paths are resolved in relation to this file
});

// loadedPlugins will be an ordered array of SupersetOfPluginDefinition,in order of who depends on whom
const loadedPlugins = await resolvePluginsInOrder(
  [
    './test-dependency',
    'module-dependency',
  ],
  pluginLoader
);

Exports

Core exports

  • assertToBePluginDefinition(value) – throws if value isn't a valid PluginDefinition (and correctly narrows the type when used with TypeScript)
  • isPluginDefinition(value) – returns true if value is a valid PluginDefinition (and correctly narrows the type when used with TypeScript)
  • loadPlugins(processPlugin, [LoadPluginsOptions]) – creates the plugin loader responsible for loading a valid plugin
  • resolvePluginsInOrder(plugins, pluginLoader, [allowOptionalDependencies]) – resolves and loads plugins and returns them with the plugin depended upon first and the plugins depending on them last

Plain plugins exports

  • loadPlainPlugins([LoadPluginsOptions]) – like loadPlugins, but geared to load pure PluginDefinition rather than supersets
  • processPlainPlugin – the processPlugin that's used in loadPlainPlugins, should never be needed to be called diretcly
  • resolvePlainPlugins(dependencies, [LoadPluginsOptions]) – shortcut for calling resolvePluginsInOrder with loadPlainPlugins

Utils exports

  • getExtensionlessBasename(value) – like path.basename(value) but removes file extensions
  • importAbsolutePath(absolutePath) – like import(absolutePath) but made to easily work with absolute paths on Windows

Types

  • LoadPluginsOptions – the optional options for loadPlugins. Contains:
    • cwd – the working directory to load relative plugin paths from
    • meta – convenience option for setting cwd by giving an import.meta
    • prefix – a prefix that will be added to dependency names. Eg example-prefix would be added to foo to make example-prefix-foo and to @voxpelli to make @voxpelli/example-prefix, but eg. example-prefix-foo would not be prefixed as it already has the prefix and @voxpelli/foo would neither get prefixed. This is along the lines of what eslint does with eslint-config prefixes
  • PluginDefinition – the basic definition of a plugin. All loaded plugins are expected to conform to this or a superset of this.
  • ProcessPluginContext – the context given to processPlugin