remove-comments-cli
v1.0.0
Published
A fast and flexible CLI tool to remove comments from JavaScript/TypeScript files while preserving important ones
Maintainers
Readme
remove-comments-cli
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-devUsage
Basic Usage
Remove all comments from a file:
npx remove-comments input.ts > output.tsProcess multiple files using glob patterns:
npx remove-comments "src/**/*.{js,ts,jsx,tsx}" --outDir distPreserving 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.tsCLI 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 informationExamples
Process TypeScript files and preserve comments starting with ! or #:
npx remove-comments "src/**/*.ts" -k "!#" --outDir distProcess JSX/TSX files and preserve comments starting with *:
npx remove-comments "src/**/*.{jsx,tsx}" -k "*" --outDir distProcess a single file and output to stdout:
npx remove-comments input.js > output.jsPerformance
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 Version | Support 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
--verbosefor more details
"Error: Cannot find module"
- Run
npm install remove-comments-cliagain - Check Node.js version compatibility
- Verify package.json dependencies
- Run
Debug Mode
Run with debug logging enabled:
DEBUG=remove-comments* npx remove-comments input.tsSecurity
- 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
