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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@undermuz/inversify-generator

v1.0.3

Published

A lightweight CLI tool that automatically sets up InversifyJS in any JS or Nx-based project

Readme

@undermuz/inversify-generator

A lightweight CLI tool that automatically sets up InversifyJS in any Js or Nx-based project. It installs required dependencies, generates di structure, and configures a ready-to-use di setup.

👉 Learn more about the underlying DI framework at inversify.io.

npm GitHub


🚀 Features

  • Adds InversifyJS to any js project
  • Generates a complete di structure
  • Provides preset modules for common use cases (env, react)
  • Updates package.json with required dependencies
  • Works in Nx and non-Nx environments
  • Zero configuration required

🛠 Usage

Initialize InversifyJS

Run the generator inside your project:

# Simple react project
npx @undermuz/inversify-generator@latest init

# NX-like project
npx @undermuz/inversify-generator@latest init --project=./apps/web-app/src

By default, it installs di files into:

<cwd>/src
<cwd>/package.json

To specify a custom path:

npx @undermuz/inversify-generator init --project=apps/web-app/src

<cwd>/apps/web-app/src
<cwd>/package.json

Add a new module

After initialization, you can add new modules using:

npx @undermuz/inversify-generator add-module <name>

<cwd>/src/di/<name>

Examples:

# Add a "settings" module (uses default src)
npx @undermuz/inversify-generator add-module settings

# Add a "session" module
npx @undermuz/inversify-generator add-module session

# Specify custom app path (module directory will be created inside apps/web-app/src/di)
npx @undermuz/inversify-generator add-module dashboard --project=apps/web-app/src

The command will:

  • Create a new directory for the module inside the app's di/ directory
  • Generate types.ts
  • Generate provider.ts with provider
  • Generate module.ts with container module
  • Automatically update the main container.ts to include the new module

Add a preset module

After initialization, you can add predefined preset modules using:

npx @undermuz/inversify-generator add-preset-module <selector>

<cwd>/src/di/<selector>

<selector> supports nested preset paths (for example utils/cache, logger/logtape). Selectors that do not have their own preset.json are treated as preset groups and cannot be added directly.

Examples:

# Add the "env" preset module
npx @undermuz/inversify-generator add-preset-module env

# Add the "react" preset module
npx @undermuz/inversify-generator add-preset-module react

# Add nested utility preset
npx @undermuz/inversify-generator add-preset-module utils/cache

# Choose concrete logger implementation
npx @undermuz/inversify-generator add-preset-module logger/logtape

# Specify custom app path
npx @undermuz/inversify-generator add-preset-module env --project=apps/web-app/src

The command will:

  • Copy the entire preset directory from presets/<name> to the app's di/ directory
  • If the preset contains module.ts, automatically update the main container.ts to include the new module

📁 What gets generated

Initial structure

di/
  container.ts
  my-provider/
    types.ts
    module.ts
    provider.ts

Adding new modules

When you add a new module using add-module, the following files are created:

di/
  my-new-module/
    types.ts
    module.ts
    provider.ts
  container.tsx   # (automatically updated)

Adding preset modules

When you add a preset module using add-preset-module, files are copied according to preset manifests:

di/
  <PRESET_SELECTOR>/   # copied from presets/<PRESET_SELECTOR>
    <FILES_FROM_MANIFEST>
  <DEPENDENCY_SELECTOR>/
    <DEPENDENCY_FILES_FROM_MANIFEST>
  container.ts         # updated for presets with a declared module

Preset manifest dependencies

Each standalone preset has preset.json with:

  • files: what to copy
  • module (optional): what to import/load into container.ts
  • dependencies (optional): dependent preset selectors and optional file subsets

To auto-suggest dependencies from relative imports:

# preview dependencies
npm run preset:deps -- utils/cache

# write dependencies to presets/<selector>/preset.json
npm run preset:deps -- utils/cache --write

📚 Dependencies added automatically

  • reflect-metadata
  • inversify

💡 Examples

After running the generator and adding modules, you can use the container in your application code. Typical workflow:

// src/di/container.ts (generated)
import { Container } from "inversify";
import { someModule } from "./some-module/module";

export const container = new Container();
container.load(someModule);
// src/di/some-module/types.ts
export const TYPES = {
  SomeService: Symbol.for("SomeService"),
};
// src/di/some-module/provider.ts
import { injectable } from "inversify";
import { createSomeService } from "./service";

@injectable()
export class SomeService {
  constructor() {}
  sayHi() { console.log("hello from injected service"); }
}
// src/index.ts
import "reflect-metadata"; // required by inversify
import { container } from "./di/container";
import { TYPES } from "./di/some-module/types";
import { SomeService } from "./di/some-module/provider";

const service = container.get<SomeService>(TYPES.SomeService);
service.sayHi();

React example

If you generated the react preset (or manually set up the bindings), you can expose the container via a provider and consume it in components:

// src/App.tsx
import React from "react";
import { useDi } from "./di/ReactProvider";
import { TYPES } from "./di/some-module/types";
import { SomeService } from "./di/some-module/provider";

import { DiProvider } from "./di/ReactProvider";

function Page() {
  const container = useDi();
  const service = container.get<SomeService>(TYPES.SomeService);

  React.useEffect(() => {
    service.sayHi();
  }, [service]);

  return <div>Check the console for a greeting</div>;
}

function App() {
  return (
    <DiProvider>
      <Page />
    </DiProvider>
  );
}

export default App;

The examples above show basic binding and retrieval; for more advanced patterns check the Inversify docs.


🧩 Requirements

  • Node.js 18+
  • npm or yarn

🧪 Testing

Run the test suite:

npm test

Tests cover the core actions: copying files, updating package.json, generating modules, and configuring TypeScript. Uses Vitest for fast, ESM-compatible testing.


📦 Installation (local development)

Clone the repository and link it globally:

npm install
npm link

Now the CLI is available system-wide:

inversify-generator

📄 License

MIT