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

opti-mommy

v0.1.3

Published

Opti-Mommy — semantic JavaScript optimizer (MVP)

Readme

💗 Opti-Mommy

A semantic JavaScript optimizer that analyzes your code and generates an optimized version automatically.

Opti-Mommy is a JavaScript optimizer focused on AST-based transformations. It reads your source code, analyzes it, applies optimization passes, and writes the optimized result to dist/ without modifying your original source files.

The project is implemented entirely in plain modern JavaScript (ESM).


✨ Features

  • 🧠 AST-based JavaScript analysis
  • ⚡ Automatic code optimization
  • 🛡️ SAFE optimization mode
  • 🔥 AGGRESSIVE optimization mode
  • 👀 Automatic file watching during development
  • 💾 Content-based caching
  • 🗂️ Separate src/ and dist/ directories
  • 🧪 Automated tests with Vitest
  • 📦 npm-compatible CLI
  • 🚫 Never modifies your original source files

📦 Installation

Install dependencies

npm install

Install globally

To use the opti-mommy command globally:

npm install -g .

You can then run:

opti-mommy

You can also run the CLI directly:

node src/cli/index.js

🚀 Quick Start

Place your JavaScript files inside a src/ directory:

my-project/
├── src/
│   ├── app.js
│   └── utils.js
├── package.json
└── ...

Start the development optimizer:

opti-mommy dev

Opti-Mommy watches src/ for changes and automatically generates optimized files inside dist/.

src/app.js
     ↓
 Opti-Mommy
     ↓
dist/app.js

Your original source files remain untouched.


🛠️ Commands

opti-mommy dev

Starts development mode and watches src/ for changes.

opti-mommy dev

Changed JavaScript files are automatically optimized and written to dist/.


opti-mommy dev --aggressive

Starts development mode using the AGGRESSIVE optimization pipeline.

opti-mommy dev --aggressive

opti-mommy build

Builds the entire project using SAFE optimizations.

opti-mommy build

opti-mommy build --aggressive

Builds the entire project using both SAFE and AGGRESSIVE optimization passes.

opti-mommy build --aggressive

opti-mommy run

Runs the generated code from dist/ instead of executing the original source from src/.

opti-mommy run

🛡️ SAFE Mode

SAFE mode is the default optimization mode.

opti-mommy build

It focuses on transformations that are highly likely to preserve the original behavior of the program.

Current SAFE passes include:

  • Constant folding
  • Dead-code elimination

The optimization priority is:

Correctness
    ↓
Compatibility
    ↓
Performance

If an optimization cannot be considered sufficiently safe, it should not be applied in SAFE mode.


🔥 AGGRESSIVE Mode

AGGRESSIVE mode can be enabled explicitly:

opti-mommy build --aggressive

It runs all SAFE passes first and then enables additional optimization passes that require deeper analysis.

Current AGGRESSIVE optimization:

  • Conservative function inlining

AGGRESSIVE does not mean blindly rewriting code.

Every optimization must have defined rules and tests designed to prevent unnecessary behavioral changes.


🧠 How It Works

Opti-Mommy uses an AST-based optimization pipeline:

JavaScript source
       ↓
     Parser
       ↓
       AST
       ↓
    Analyzer
       ↓
Optimization Pipeline
       ↓
 Optimization Passes
       ↓
    Code Generator
       ↓
Optimized JavaScript
       ↓
      dist/

This architecture allows new optimization passes to be added without rewriting the entire optimizer.


💾 Cache

Opti-Mommy uses content hashing to avoid unnecessarily processing files that have not changed.

The cache also takes the optimization mode into account.

For example:

app.js + SAFE

and:

app.js + AGGRESSIVE

are treated as different optimization results.

This prevents an AGGRESSIVE build from accidentally reusing a SAFE build result.


📁 Project Structure

opti-mommy/
├── src/
│   ├── cli/
│   ├── parser/
│   ├── analyzer/
│   ├── optimizer/
│   │   └── passes/
│   │       ├── safe/
│   │       └── aggressive/
│   ├── generator/
│   ├── watcher/
│   └── cache/
│
├── tests/
│   ├── optimizer/
│   │   ├── safe/
│   │   └── aggressive/
│   ├── parser/
│   └── integration/
│
├── package.json
└── README.md

All implementation code is written in JavaScript.

There is no TypeScript in the project.


🧰 Technology

| Component | Technology | | -------------- | ------------------ | | Runtime | Node.js | | Language | JavaScript (ESM) | | Parser | @babel/parser | | Code generator | @babel/generator | | File watcher | chokidar | | Tests | Vitest | | Cache | Content hash |


🧪 Testing

Run the test suite with:

npm test

Tests cover optimization passes and core functionality of the optimizer.

When adding a new optimization, add its implementation to the appropriate safe/ or aggressive/ directory and create corresponding tests.


📊 Optimization Pipeline

SAFE

A simplified SAFE build looks like:

Parser
  ↓
Constant Folding
  ↓
Dead Code Elimination
  ↓
Generator

AGGRESSIVE

An AGGRESSIVE build looks like:

Parser
  ↓
Constant Folding
  ↓
Dead Code Elimination
  ↓
Conservative Function Inlining
  ↓
Generator

The pipeline is modular, allowing additional optimization passes to be added independently.


⚠️ Important

Opti-Mommy performs source-to-source transformations and should be tested before being used in production.

Extra caution is recommended when using:

opti-mommy build --aggressive

Always benchmark optimized code against the original when performance is important.


🎯 Philosophy

Opti-Mommy is not intended to be just a minifier.

The goal is to build a semantic JavaScript optimizer that understands the structure of JavaScript through its AST and applies transformations based on that structure.

The intended workflow is:

Write JavaScript
      ↓
Opti-Mommy analyzes it
      ↓
Opti-Mommy optimizes it
      ↓
Optimized JavaScript
      ↓
Run the optimized version

All while keeping the developer's original source code intact.


📄 License

See the project's license information for details.