1.4.0 โ€ข Published 7 months ago

autoremover-import v1.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

๐Ÿงน Autoremover Import

Automatically manage your JavaScript/React project dependencies by analyzing imports in real-time. Never worry about unused dependencies or missing packages again!

โœจ Features

  • ๐Ÿ” Real-time Analysis: Monitors your code for import changes
  • ๐Ÿš€ Auto-Installation: Automatically installs missing dependencies
  • ๐Ÿ—‘๏ธ Auto-Removal: Safely removes unused dependencies
  • ๐Ÿ›ก๏ธ Safe Mode: Optional confirmation before any package changes
  • ๐Ÿ“ฆ Multiple Package Managers: Supports both npm and yarn
  • ๐ŸŒŸ Smart Detection: Supports both ES6 imports and require syntax
  • ๐Ÿ”’ Protected Packages: Prevent accidental removal of essential packages
  • ๐Ÿ“ Deep Scanning: Recursively analyzes all project files

๐Ÿ“ฅ Installation

npm install autoremover-import
# or
yarn add autoremover-import

๐Ÿš€ Quick Start

  1. After installation, initialize the configuration:
npx autoremover-import init
  1. Start watching your imports:
npm run watch-imports
# or
yarn watch-imports

๐Ÿ’ป Usage Examples

Basic Usage

const ImportManager = require('autoremover-import');

// Initialize with your project path
const manager = new ImportManager(__dirname);

// Start watching for changes
manager.start().catch(error => {
    console.error('Error:', error);
    process.exit(1);
});

With Safe Mode

const ImportManager = require('autoremover-import');
const path = require('path');

const manager = new ImportManager(__dirname);

async function run() {
    try {
        await manager.start();
        console.log('โœจ Import manager is now watching for changes');
        
        // Keep the process running
        process.stdin.resume();
        
        // Handle graceful shutdown
        process.on('SIGINT', () => {
            console.log('Stopping import manager...');
            manager.stop();
            process.exit(0);
        });
    } catch (error) {
        console.error('Error:', error);
        process.exit(1);
    }
}

run();

โš™๏ธ Configuration

Create an import-manager.config.js file in your project root:

module.exports = {
  // Packages that will never be removed automatically
  ignoredPackages: [
    'react',
    'typescript'
  ],

  // Watcher configuration
  watcherConfig: {
    watchOnSave: true,          // Watch for file changes
    watchInterval: 1000,        // Check interval in milliseconds
    ignoredPaths: [             // Paths to ignore
      'node_modules',
      'dist',
      'build',
      '.next',
      '*.test.*',
      'package.json',
      'package-lock.json'
    ],
    fileExtensions: [           // File types to watch
      '.js',
      '.jsx',
      '.ts',
      '.tsx'
    ]
  },

  // Package.json configuration
  packageJsonConfig: {
    checkDevDependencies: false,  // Whether to manage devDependencies
    defaultVersion: 'latest',     // Default version when installing new packages
    safeMode: false,             // Ask for confirmation before changes
    packageManager: 'npm'        // 'npm' or 'yarn'
  },

  // Enable debug logs
  debug: true
};

Configuration Options Explained

๐Ÿ›ก๏ธ ignoredPackages

  • Purpose: Protect packages from being removed
  • Example: ['react', 'typescript']
  • Use Case: Essential packages that should never be removed

โšก watcherConfig

  • watchOnSave: Enable/disable file watching
    • true: Real-time monitoring
    • false: Manual analysis only
  • watchInterval: Delay between checks
    • Lower value = More frequent checks
    • Higher value = Better performance
  • ignoredPaths: Paths to exclude from analysis
  • fileExtensions: File types to analyze

๐Ÿ“ฆ packageJsonConfig

  • checkDevDependencies: Include devDependencies in analysis
    • true: Manage both dependencies and devDependencies
    • false: Only manage dependencies
  • safeMode: Confirmation prompts
    • true: Ask before any package changes
    • false: Automatic changes without confirmation
  • packageManager: Choose your package manager
    • 'npm': Use npm commands
    • 'yarn': Use yarn commands

๐Ÿ” Import Detection

Supports various import syntaxes:

// ES6 imports
import axios from 'axios';
import { get, post } from 'axios';
import * as React from 'react';

// CommonJS requires
const axios = require('axios');
const { get, post } = require('axios');

๐Ÿ› ๏ธ Advanced Features

Protected Packages

Some packages are protected by default and won't be removed:

  • The package itself (autoremover-import)
  • Packages listed in ignoredPackages

Deep Analysis

  • Analyzes all files in your project recursively
  • Ensures packages used in any file are not removed
  • Handles complex import patterns and dependencies

Safe Mode Operations

When safeMode is enabled:

๐Ÿค” Do you want to install axios? (y/n): y
๐Ÿ“ฅ Installing axios...
โœ… axios installed successfully

๐Ÿค” Do you want to remove moment? (y/n): n
โญ๏ธ Skipping removal of moment

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ“„ License

MIT ยฉ rs12

1.2.0

8 months ago

1.4.0

7 months ago

1.3.0

7 months ago

1.0.8

8 months ago

1.0.6

8 months ago

1.0.4

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago