Package Exports
- auto-req-cleaner
- auto-req-cleaner/dist/index.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 (auto-req-cleaner) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
auto-req-cleaner
Automatically detect and remove unused require/import statements in Node.js projects. This tool helps keep your codebase clean by identifying and removing unused imports, supporting both CommonJS (require
) and ES6 import syntax.
Features
- ๐ Detects unused imports in JavaScript files
- โป๏ธ Supports both
require
andimport
statements - ๐ฏ Handles destructured imports (e.g.,
const { foo } = require('bar')
) - ๐ Supports default exports (e.g.,
const foo = require('bar').default
) - ๐ก๏ธ Safe mode with dry-run option
- โก Fast and efficient analysis
- ๐ Flexible file pattern matching
Installation
You can install the package globally:
npm install -g auto-req-cleaner
Or locally in your project:
npm install --save-dev auto-req-cleaner
Usage
Command Line Interface
If installed globally:
auto-req-cleaner --pattern "**/*.js"
If installed locally:
npx auto-req-cleaner --pattern "**/*.js"
Options
-p, --pattern <pattern>
: File pattern to analyze (default: "**/*.js")-i, --ignore <patterns>
: Patterns to ignore (default: "node_modules/**")--dry-run
: Show what would be removed without making changes
Examples
- Analyze all JavaScript files in your project:
auto-req-cleaner
- Analyze specific files or directories:
auto-req-cleaner --pattern "src/**/*.js"
- Ignore multiple directories:
auto-req-cleaner --ignore "node_modules/**,dist/**,build/**"
- Preview changes without removing anything:
auto-req-cleaner --dry-run
Supported Import Types
The tool can handle various import patterns:
// Regular require
const foo = require('foo');
// Destructured require
const { foo, bar } = require('foo');
// Default export require
const foo = require('foo').default;
// ES6 imports
import foo from 'foo';
import { foo, bar } from 'foo';
Output
The tool will show:
- Files being analyzed
- Unused imports found in each file
- Summary of cleaning actions
- Success message when no unused imports are found
Example output:
File: src/example.js
Unused imports:
- require: unused-package
- import: another-unused-package
๐งน Cleaned up 2 unused imports
Safe Mode
Using the --dry-run
option will show you what would be removed without actually making any changes:
auto-req-cleaner --dry-run
Known Limitations
- Only analyzes static imports (dynamic imports like
require(variable)
are not supported) - Does not analyze imports inside comments or strings
- Requires files to be valid JavaScript/Node.js syntax
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
Support
If you encounter any issues or have questions, please file an issue on the GitHub repository.