New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

remove-comments-cli

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remove-comments-cli

A fast and flexible CLI tool to remove comments from JavaScript/TypeScript files while preserving important ones

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

remove-comments-cli

npm version CI codecov License: MIT PRs Welcome

A fast and flexible CLI tool to remove comments from JavaScript/TypeScript files while preserving important ones.

Features

  • 🚀 Fast and memory-efficient comment removal
  • 💡 Preserve important comments using markers
  • 🌟 Support for JavaScript, TypeScript, and JSX
  • 🔍 Smart handling of strings, regex, and JSX syntax
  • 📁 Process multiple files using glob patterns
  • 🎯 Configurable output directory

Installation

npm install remove-comments-cli --save-dev

Usage

Basic Usage

Remove all comments from a file:

npx remove-comments input.ts > output.ts

Process multiple files using glob patterns:

npx remove-comments "src/**/*.{js,ts,jsx,tsx}" --outDir dist

Preserving Comments

By default, comments starting with ! are preserved:

// This comment will be removed
//! This important comment will be preserved
/* This block comment will be removed */
/*! This important block comment will be preserved */

You can specify custom markers:

# Preserve comments starting with # or *
npx remove-comments input.ts -k "#*" > output.ts

CLI Options

npx remove-comments --help

Options:
  -k, --keep-markers <chars>  Characters that mark comments to preserve (default: "!")
  -o, --outDir <dir>         Output directory for processed files
  -v, --verbose             Print detailed processing information
  -h, --help                Display help information

Examples

Process TypeScript files and preserve comments starting with ! or #:

npx remove-comments "src/**/*.ts" -k "!#" --outDir dist

Process JSX/TSX files and preserve comments starting with *:

npx remove-comments "src/**/*.{jsx,tsx}" -k "*" --outDir dist

Process a single file and output to stdout:

npx remove-comments input.js > output.js

Performance

The tool is optimized for performance and memory efficiency:

  • ⚡ Processes ~1000 files/second on modern hardware
  • 📉 Low memory footprint (~10MB for 1000 files)
  • 🔄 Streaming file processing for large files
  • 💻 Multi-threaded processing for large directories

Compatibility

Node.js VersionSupport Status
20.x✅ Full
18.x (LTS)✅ Full
16.x❌ Not supported

Tested on:

  • Windows 10/11
  • macOS 10.15+
  • Ubuntu 20.04+

Troubleshooting

Common Issues

  • "Error: ENOENT: no such file or directory"

    • Check if the file paths are correct
    • Ensure glob patterns are quoted in the shell
    • Use forward slashes (/) even on Windows
  • "SyntaxError: Unexpected token"

    • Verify the input file is valid JavaScript/TypeScript
    • Check for malformed comments or JSX syntax
    • Try running with --verbose for more details
  • "Error: Cannot find module"

    • Run npm install remove-comments-cli again
    • Check Node.js version compatibility
    • Verify package.json dependencies

Debug Mode

Run with debug logging enabled:

DEBUG=remove-comments* npx remove-comments input.ts

Security

  • No eval or dynamic code execution
  • No external network calls
  • Input validation for all file paths
  • Safe handling of symbolic links

Contributing

We welcome contributions! Please see our Contributing Guide for details.

License

MIT

Keywords

cli

FAQs

Package last updated on 10 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts