Git Product home page Git Product logo

hodgepodge's Introduction

hodgepodge

Resolving hapi plugin dependencies since 2015

Build Status Coverage Status

Lead Maintainer - Devin Ivy

Usage

See also the API Reference

This version of hodgepodge is for hapi v17+

When you declare dependencies on a hapi plugin, whether by server.dependency() or by the dependencies plugin property, hapi does not actually defer plugin registration to resolve those dependencies. It just assures that those dependencies exist at the time the server is initialized. Hodgepodge actually reorders your plugin registrations so that they occur in an order that respects their dependencies, simply by paying attention to their listed dependencies.

Note

It's suggested to use hodgepodge only when it's really necessary– ideally plugin registration order should not matter. You may, for example, utilize the once plugin registration option or once/multiple plugin properties so that plugins may simply be registered by every other plugin that depends on them.

See "Handling plugin dependencies" for an in-depth look at taming inter-plugin dependencies.

const Hodgepodge = require('hodgepodge');

(async () => {

    const plugins = Hodgepodge.sort([
        pluginA, // pluginA.dependencies === 'pluginB'
        pluginB
    ]);

    // Now plugins looks like [pluginB, pluginA]
    // This ordering respects pluginA's dependency on pluginB

    await server.register(plugins);
})();

More

In a sense this is an alternative to the server.dependency(deps, [after]) pattern, which some find to be clunky. In contrast to use of server.dependency()'s after callback, dependencies are dealt with at the time of plugin registration rather than during server initialization (during onPreStart).

Due to this core difference in timing, it may be required that your plugin be registered using hodgepodge to ensure that plugin dependencies are resolved in time for the plugin to be used. In order to enforce this, wrap your plugin's dependencies in an object with a single property hodgepodge. When hodgepodge passes over your plugin, it will unwrap this property; but if hodgepodge is not used to register your plugin, hapi will fail when it tries to register your plugin because { hodgepodge: [] } is an invalid dependencies plugin property. This is by design, in case you want to enforce registration of your plugin using hodgepodge. If you do this, remember that hodgepodge is then a peerDependency of your project!

Hodgepodge throws an exception when there are circular dependencies, or if dependencies will otherwise not be met during registration.

Limitations

Because hodgepodge reorders serial plugin registrations rather than deferring plugin registration until dependencies are met, hodgepodge can only resolve dependencies among plugins that are registered at the same time.

hodgepodge's People

Contributors

devinivy avatar zemccartney avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.