JSPM

auto-req-cleaner

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

    Automatically removes unused require/import statements in Node.js projects

    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 and import 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

    1. Analyze all JavaScript files in your project:
    auto-req-cleaner
    1. Analyze specific files or directories:
    auto-req-cleaner --pattern "src/**/*.js"
    1. Ignore multiple directories:
    auto-req-cleaner --ignore "node_modules/**,dist/**,build/**"
    1. 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.