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

safe-ts-commit

v1.0.1

Published

A Git hook utility that prevents committing TypeScript files with type errors

Readme

safe-ts-commit 🛡️

Stop bad commits before they happen. Automatically block Git commits if any TypeScript errors are detected in your staged files.


✨ What is safe-ts-commit?

safe-ts-commit is a production-ready CLI tool designed to protect your codebase by blocking Git commits if TypeScript type errors are present in your staged files.

Perfect for teams and solo devs who value code quality and type safety.


🚀 Why use this?

  • Type-Safe Commits – Prevent buggy or broken commits due to TS errors.
  • Fast & Lightweight – Only checks staged .ts / .tsx files.
  • 🎯 Zero Config – No extra setup required beyond install.
  • 🔌 Husky-Ready – Integrates seamlessly as a Git pre-commit hook.
  • 🎨 Readable Output – Colorful and actionable terminal messages.

🔧 Features

  • 🧠 Detects only staged TypeScript files
  • 🚫 Aborts commit if errors are found
  • ✅ Allows commit to proceed if everything passes
  • 🧼 Supports filenames with spaces/special characters
  • 🖍️ Clean and colorful CLI messages
  • 🧪 One-line setup: Auto-installs Husky and configures pre-commit hook.

📦 Prerequisites

  • Node.js v12+
  • TypeScript installed locally (npm install typescript --save-dev)
  • Git (with initialized repo)

📥 Installation

npm install --save-dev safe-ts-commit

⚡ One-Liner Setup (Auto-Install)

Don’t want to manually configure Husky? Run this:

npx safe-ts-commit --install

This will:

  • ✅ Install Husky (if not already installed)
  • ✅ Add prepare script to your package.json
  • ✅ Create a .husky/pre-commit hook that runs safe-ts-commit
  • ✅ Lock your commits behind type safety in seconds

Perfect for teams or quick setups. One command and you’re protected.


⚙️ Setup with Husky (Manual)

  1. Install Husky:
npm install husky --save-dev
npx husky install
  1. Add a prepare script in your package.json:
"scripts": {
  "prepare": "husky install"
}
  1. Add a pre-commit hook:
npx husky add .husky/pre-commit "npx safe-ts-commit"

🛠 How it Works

When a commit is attempted, safe-ts-commit:

  1. Collects staged files via git diff --cached --name-only
  2. Filters .ts and .tsx files
  3. Runs tsc --noEmit on those files
  4. If any type errors are found:
    • ❌ The commit is blocked with a detailed error report
  5. If all files pass:
    • ✅ The commit proceeds as normal

🧪 Manual Usage

You can run it manually without a Git hook:

npx safe-ts-commit

🔄 Optional CLI Flags

safe-ts-commit [options]

--install        Run auto-setup with Husky
--debug          Print detailed debug logs
--silent         Hide output unless there's an error
--tsconfig       Path to custom tsconfig.json

🧰 Troubleshooting

| Issue | Solution | |-----------------------------|--------------------------------------------------------------------------| | TypeScript not found | Ensure you installed TypeScript locally (npm install typescript) | | No files being checked | Make sure your TypeScript files are staged (git add path/to/file.ts) | | Hook not running | Ensure Husky is installed and the pre-commit hook is executable |


🗂 Project Structure

safe-ts-commit/
├── bin/
│   └── cli.js            # CLI entry (compiled from src/cli.ts)
├── src/
│   ├── getStagedFiles.ts
│   ├── checkTsErrors.ts
│   └── utils.ts
├── .husky/               # Husky hooks
├── tsconfig.json
├── package.json
└── README.md

📜 License

MIT — feel free to fork, improve, and contribute!