JSPM

safe-ts-commit

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q35141F
  • License MIT

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

Package Exports

  • safe-ts-commit
  • safe-ts-commit/dist/bin/cli.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (safe-ts-commit) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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!