npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

autoremover-import

v1.4.0

Published

remove and auto import package json for javascript

Downloads

534

Readme

🧹 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]