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

y-server-load-plugins

v0.0.2

Published

Automatically load any y-server plugins in your package.json

Downloads

2

Readme

y-server-load-plugins

npm

Loads y-server plugins from package dependencies and attaches them to an object of your choice.

Install

$ npm install --save-dev y-server-load-plugins

Usage

Given a package.json file that has some dependencies within:

{
    "dependencies": {
        "y-server-plugin-ejs": "^0.0.2",
        "y-server-plugin-error": "^0.0.3",
        "y-server-plugin-mock": "^0.0.6",
        "y-server-plugin-proxy": "^0.0.2",
        "y-server-plugin-static": "^0.0.2",
        "y-server-plugin-template": "^0.0.3"
    }
}

Adding this into your y-server.config.js:

var yServerLoadPlugins = require('y-server-load-plugins');
var plugins = yServerLoadPlugins();

Or, even shorter:

var plugins = require('y-server-load-plugins')();

Will result in the following happening (roughly, plugins are lazy loaded but in practice you won't notice any difference):

plugins.static = require('y-server-plugin-static');
plugins.template = require('y-server-plugin-template');

This frees you up from having to manually require each y-server plugin.

Options

You can pass in an object of options that are shown below: (the values for the keys are the defaults,most same to the y-server-load-plugins):

yServerLoadPlugins({
    DEBUG: false, // when set to true, the plugin will log info to console. Useful for bug reporting and issue debugging
    pattern: ['y-server-plugin-*'], // the glob(s) to search for
    overridePattern: true, // When true, overrides the built-in patterns. Otherwise, extends built-in patterns matcher list.
    config: 'package.json', // where to find the plugins, by default searched up from process.cwd()
    scope: ['dependencies', 'devDependencies', 'peerDependencies'], // which keys in the config to look  context
    lazy: true, // whether the plugins should be lazy loaded on demand
    renameFn: function (name) { ... }, // a function to handle the renaming of plugins (the default works)
    postRequireTransforms: {}, // see documentation below
});

Multiple config locations

While it's possile to grab plugins from another location, often times you may want to extend from another package that enables you to keep your own package.json free from duplicates, but still add in your own plugins that are needed for your project. Since the config option accepts an object, you can merge together multiple locations using the lodash.merge package:

var merge = require('lodash.merge');

var packages = merge(
  require('dep/package.json'),
  require('./package.json')
);

// Utilities
var $ = yServerLoadPlugins({
  config: packages
});

postRequireTransforms

This enables you to transform the plugin after it has been required by y-server-load-plugins.

For example, one particular plugin (let's say, y-server-plugins-foo), might need you to call a function to configure it before it is used. So you would end up with:

var $ = require('y-server-load-plugins')();
$.foo = $.foo.configure(...);

This is a bit messy. Instead you can pass a postRequireTransforms object which will enable you to do this:

var $ = require('y-server-load-plugins')({
  postRequireTransforms: {
    foo: function(foo) {
      return foo.configure(...);
    }
  }
});

$.foo // is already configured

Everytime a plugin is loaded, we check to see if a transform is defined, and if so, we call that function, passing in the loaded plugin. Whatever this function returns is then used as the value that's returned by y-server-load-plugins.

For 99% of y-server-plugins you will not need this behaviour, but for the odd plugin it's a nice way of keeping your code cleaner.

Override Pattern

Configuring the pattern option would override the built-in ['y-server-plugins-*'. If overridePattern: false, the configured pattern will now extends the built-in matching.

Changelog

0.0.1
  • initial release