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

@bemedev/codebase

v2.9.0

Published

The CLI for to generate codebase, and import partially a library. From @bemedev.

Readme

@bemedev/codebase

License Node.js TypeScript

A powerful CLI to generate and analyze your TypeScript/JavaScript codebase. This tool allows partial importing of libraries and generates comprehensive analyses of your source code.

🚀 Main Features

  • 📊 Codebase analysis: Full analysis of imports, exports and dependencies
  • 🔧 Automatic generation: Creates detailed JSON analysis files
  • ⚡ Intuitive CLI: Simple and effective command-line interface
  • 📦 Partial import: Selective import of library parts
  • 🎯 Flexible exclusion: Ability to exclude specific files
  • 📈 Statistics: Detailed reports about your codebase
  • 🧹 Code pruning: Automatic removal of unused declarations, empty files, and empty folders in target directories

📋 Prerequisites

  • Node.js ≥ 24.0.0
  • pnpm (recommended) or npm/yarn

🛠️ Installation

Global installation (recommended)

pnpm add -g @bemedev/codebase

Local installation

pnpm add @bemedev/codebase

Development installation

pnpm add -D @bemedev/codebase

🎯 Usage

CLI

Generate a codebase analysis

# Basic analysis - generates a codebase.json file
codebase

# Specify a custom output file
codebase --output my-analysis.json

# Exclude specific files
codebase --exclude node_modules dist lib build

# Use short options
codebase -o output.json node_modules dist

Available options

  • -o, --output <file> : Output file (default: codebase.json)
  • [excludes...] : List of files/folders to exclude

Programmatic API

Analyzing and generating the codebase JSON

import { generate, analyze } from '@bemedev/codebase';

// Analyze the codebase
const analysis = analyze({ src: 'src' });

// Generate an analysis file
await generate({
  output: 'my-codebase.json',
  excludes: ['node_modules', 'dist'],
});

Managing dependencies programmatically

You can also use the programmatic API to initialize workspace configurations and selectively add/remove files using their regular slash-separated paths (instead of dot-parsed notation).

import {
  init,
  softInit,
  add,
  remove,
  cleanup,
} from '@bemedev/codebase';
import analysis from './codebase.json';

// Initialize the project workspace
init(analysis.CODEBASE_ANALYSIS, {
  root: 'my-project-src',
  json: '.project-codebase.json',
});

// Rebuild types and imports structure if configuration already exists
softInit(analysis.CODEBASE_ANALYSIS, {
  root: 'my-project-src',
  json: '.project-codebase.json',
});

// Add files dynamically using regular slash-separated paths
add(
  analysis.CODEBASE_ANALYSIS,
  '.project-codebase.json',
  'nested/Tooltip',
);

// Remove files dynamically using regular slash-separated paths
remove(
  analysis.CODEBASE_ANALYSIS,
  '.project-codebase.json',
  'nested/Tooltip',
);

// Reset target folder files list configuration to an empty array
cleanup.files('.project-codebase.json');

// Delete the generated target directory
cleanup('my-project-src');

// Delete the target directory and remove the configuration JSON file
cleanup.all('my-project-src', '.project-codebase.json');

Pruning unused code programmatically

You can use the lift function to prune unused declarations (references, types, variables, classes, functions, or enums) and clean up imports within a target folder, automatically deleting files and folders that become empty.

import { lift, LiftOutput } from '@bemedev/codebase';
import { Project } from 'ts-morph';
import analysis from './codebase.json';

// Prune unused code and perform tree shaking using the codebase configuration path and optional exceptions
// It returns a detailed report of deleted elements
const result: LiftOutput = lift(
  analysis.CODEBASE_ANALYSIS,
  '.project-codebase.json',
  'exceptionVar1',
  'exceptionVar2',
);

/*
result is of type:
{
  tokens: string[];      // Names of deleted unused tokens
  imports: string[];     // Text of removed imports
  files: string[];       // Paths of deleted empty files
  directories: string[]; // Paths of deleted empty directories
}
*/

// Optionally pass an existing ts-morph Project instance to reuse
const project = new Project({ tsConfigFilePath: 'tsconfig.json' });
const result2 = lift(
  analysis.CODEBASE_ANALYSIS,
  '.project-codebase.json',
  'exceptionVar1',
  project,
);

Helper utilities

You can also use helper utilities exported from the library:

import { hasNoDeclarations } from '@bemedev/codebase';
import { Project } from 'ts-morph';

const project = new Project();
const sf = project.createSourceFile('test.ts', 'export const a = 1;');

// Check if a source file contains no declarations (types, variables, classes, functions, enums, interfaces, namespaces)
// Also considers files with live re-exports as non-empty
console.log(hasNoDeclarations(sf)); // false

📊 Output format

The generated JSON file contains:

{
  "STATS": {
    "files": 42,
    "imports": 156,
    "exports": 89
  },
  "CODEBASE_ANALYSIS": {
    "src/index.ts": {
      "imports": ["./functions", "./types"],
      "relativePath": "src/index.ts",
      "text": "export * from './functions';"
    }
  }
}

🏗️ Project structure

src/
├── cli/           # CLI interface
├── functions/     # Core functions
│   ├── add.ts     # Add dependencies
│   ├── generate.ts # Generate analysis
│   ├── init.ts    # Initialization
│   ├── lift.ts    # Code pruning/tree shaking
│   ├── remove.ts  # Removal
│   └── softInit.ts # Soft initialization helper
├── analyse.ts     # Analysis engine
├── types.ts       # TypeScript definitions
└── constants.ts   # Global constants

🧪 Development scripts

# Run tests
pnpm test

# Linting
pnpm lint

# Build
pnpm build

# Development mode with watch
pnpm dev

🎨 Examples

Analyze a React project

codebase -o react-analysis.json node_modules public build

Analyze a Node.js project

codebase -o backend-analysis.json node_modules dist coverage

Integrate into an NPM script

{
  "scripts": {
    "analyze": "codebase -o analysis/codebase.json",
    "analyze:clean": "codebase -o analysis/clean.json node_modules dist lib build"
  }
}

🤝 Contribution

Contributions are welcome! How to contribute:

  1. Fork the project
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Contribution guidelines

  • Follow commit conventions (Conventional Commits)
  • Add tests for new features
  • Update documentation when necessary
  • Respect existing code style

🐛 Report a bug

If you find a bug, please open an issue with:

  • A clear description of the problem
  • Steps to reproduce the bug
  • Your environment (OS, Node.js version, etc.)
  • Error logs if available

License (MIT)

CHANGELOG

Author

chlbri, my github

Links