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 🙏

© 2025 – Pkg Stats / Ryan Hefner

inversify-typescript-cli

v0.0.11

Published

CLI for creating, editing and modifying an application using inversify dependency injection.

Readme

Inversify Typescript CLI

An opinionated command line interface for creating inversify modules and components.

Speeds up some of the boilerplate required to build apps with dependency injection.

This project is a work in progress. Contributions and feedback are welcome.

Getting Started

Install inversify-cli

yarn add inversify-cli

In the scripts section of your package.json file, assign a script to inversify-cli to create an alias

...
"scripts": {
  "cli": "inversify-cli"
},
...

NOTE: replace "cli" in all examples below with whatever string you use as the script name.

Optionally create an inversify-cli.json file in your project root.

inversify-cli.json

{
  "dir": "./src", // Folder to create the typescript files
  "componentTests": true // Enable generation of component tests
}

Initialize your project.

yarn cli init

Files will be created in the folder specified by inversify-cli.json.

Folder Structure

Inside your project folder you will have the following files and directories:

app.ts

This file exports an app function you can use to run your app.

container.ts

This file exports a container function which registers your module containers. It is set up to allow you to pass a config object to each module container.

harness.ts

This is a test harness that can be imported in your unit tests.

You can modify this class as you like to help simplify your testing. For example, I suggest adding a helper function that uses testdouble to rebind a reference with a mocked version. This helps isolate units of code.

interface.ts

This is the app interface file that contains the apps abstractions.

ref.ts

This is the ref file which contains an object with keys linked to symbols used to identify dependencies.

Add a module

Add a module with the command yarn cli module create <ModuleName>

A module container will be created and added to the application container.

Add a component

Add a component to a module with the command yarn cli component create <ModuleName> <ComponentName>

A component will be created and added to the module container.

Testing

To simplify unit testing you can use the harness to reference any component registered in the application container. Additionally, you can pass in a function that will let you get an instance of the container so that you can rebind any dependencies as you see fit.

Before your tests bootstrap your harness (referred to below as "h"). In your tests you can reference the component you are testing with h.sut (System Under Test).

import * as Fs from 'fs-extra';
import * as Path from 'path';
import { H } from './../../../harness';
import { ref } from './../../../ref';

describe('Sample Test', () => {

  let h: H<ClassUnderTest>;
  let dblFs: typeof Fs;
  let dblPath: typeof Path;

  beforeEach(() => h = new H<ClassUnderTest>(
    ref.ClassUnderTest,
    (harness) => {

      // Rebind some dependencies to a constant value
      // to avoid side effects in tests
      //dblFs = harness.container.rebind(ref.Fs).toConstant({});
      //dblPath = container.rebind(ref.Path).toConstantValue({});

    }
  ));

  describe('sampleMethod', () => {

    it('should return true', async () => {

      expect(h.sut.sampleMethod()).to.eql(true);

    });

  });

});

Wish List

  • Refactor the application to itself use inversify
  • Throw more informative errors
  • Add unit and e2e tests
  • Throw error if attempting to recreate a module or container that already exists