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

@superhero/bootstrap

v4.1.0

Published

Bootstrap services with a set of default configurations.

Downloads

259

Readme

Bootstrap

A lightweight module for bootstrapping services with a flexible configuration and service locator design.

Features

  • Service Bootstrap: Bootstraps services based on a provided bootstrap map.
  • Configuration Injection: Supports passing configurations to the services being bootstrapped.
  • Service Locator Integration: Resolves services in the boostrap map dynamically through a service locator.
  • Error Handling: Error messages for invalid configurations or bootstrap failures.
  • Skips Disabled Services: Automatically skips services marked as false in the bootstrap map.

Installation

Install via npm:

npm install @superhero/bootstrap

Usage

Importing the Module

import bootstrap from '@superhero/bootstrap'

Example

import bootstrap  from '@superhero/bootstrap'
import Config     from '@superhero/config'
import locator    from '@superhero/locator'

// Locates a configuration manager
const config = new Config()

// Define your services
locator.set('serviceA', new class { bootstrap(options) { console.log('Bootstrapping serviceA', options) } })
locator.set('serviceB', new class { bootstrap(options) { console.log('Bootstrapping serviceB', options) } })

// Assign configurations
config.assign({ serviceA: { foo: 'bar' }, serviceB: { baz: 'qux' }})

// Define bootstrap map
const bootstrapMap = { serviceA: true, serviceB: true }

// Bootstrap services
await bootstrap(bootstrapMap, config, locator)
// Output:
// ⇢ Bootstrapping serviceA { "foo": "bar" }
// ⇢ Bootstrapping serviceB { "baz": "qux" }

API

bootstrap(bootstrapMap, configLocator, serviceLocator)

Bootstraps services based on the provided map, configuration locator, and service locator.

Parameters:

  • bootstrapMap (Object): A map of service IDs to service names or true/false values. Services marked false are skipped. Services marked tre use the ID as service name.
  • configLocator (Function|Object): A function or an object with a find method for resolving configurations.
  • serviceLocator (Function|Object): A function or an object with a locate method for resolving services.

Throws:

  • E_BOOTSTRAP_INVALID_MAP: If the bootstrapMap is not an object.
  • E_BOOTSTRAP_INVALID_CONFIG_LOCATOR: If the configLocator is invalid.
  • E_BOOTSTRAP_INVALID_SERVICE_LOCATOR: If the serviceLocator is invalid.
  • E_BOOTSTRAP: For any errors encountered during the bootstrap process.

Tests

This module includes a test suite to verify its functionality. Run the tests with:

npm test

Test Coverage

▶ @superhero/bootstrap
  ✔ Can bootstrap a simple process with no problem (4.395798ms)
  ✔ Skips services that are defined as "false" in the bootstrap map (0.515958ms)
  ✔ Configurations are passed along to the bootstrap (0.709367ms)

  ▶ Rejects
    ✔ Bootstrap process that throws (0.908382ms)
    ✔ Using an invalid bootstrapMap (0.692543ms)
    ✔ Using an invalid configLocator (0.277624ms)
    ✔ Using an invalid serviceLocator (0.257487ms)
    ✔ Service does not implement "bootstrap" (0.24099ms)
  ✔ Rejects (2.81272ms)
✔ @superhero/bootstrap (10.238997ms)

tests 8
suites 2
pass 8

----------------------------------------------------------------
file            | line % | branch % | funcs % | uncovered lines
----------------------------------------------------------------
index.js        | 100.00 |    88.46 |  100.00 | 
index.test.js   | 100.00 |   100.00 |   95.83 | 
----------------------------------------------------------------
all files       | 100.00 |    94.00 |   96.88 | 
----------------------------------------------------------------

License

This project is licensed under the MIT License.


Contributing

Feel free to submit issues or pull requests for improvements or additional features.