Socket
Book a DemoInstallSign in
Socket

file-usage-analyzer

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-usage-analyzer

Analyze file usage in JavaScript/TypeScript projects to identify unused files

latest
Source
npmnpm
Version
1.1.6
Version published
Maintainers
1
Created
Source

File Usage Analyzer

A powerful utility to analyze file usage in JavaScript/TypeScript projects, identifying which files are unused and potentially removable.

Features

  • Detects which files are imported by other files
  • Handles various import patterns (static, dynamic, named, etc.)
  • Special handling for Vue, React, and service patterns
  • Configurable file type categorization
  • Customizable import detection patterns
  • Detailed reports in JSON and Markdown formats
  • Summary statistics by file type

Installation

Global Installation

npm install -g file-usage-analyzer

Local Installation

npm install --save-dev file-usage-analyzer

Usage

Command Line

# Basic usage (analyzes src folder)
file-usage-analyzer

# Analyze a specific folder
file-usage-analyzer --src app

# Use custom patterns
file-usage-analyzer --patterns "app/**/*.js,app/**/*.vue"

# Specify main file (for special pattern detection)
file-usage-analyzer --main app.js

# Custom output directory
file-usage-analyzer --output reports

# Don't generate output files (just display summary)
file-usage-analyzer --no-files

Programmatic Usage

const { analyzeProject } = require('file-usage-analyzer');

// Basic usage
analyzeProject()
  .then(result => {
    console.log(result.summary);
  })
  .catch(err => {
    console.error('Analysis failed:', err);
  });

// With options
analyzeProject({
  src: 'app',
  patterns: ['app/**/*.js', 'app/**/*.vue'],
  mainJsPattern: 'app.js',
  providePattern: /app\.provide\(['"]([$][^'"]+)['"], ([^)]+)\)/g,
  fileTypeMapping: {
    '/components/': 'component',
    '/services/': 'service',
    '/pages/': 'page'
  },
  // Custom import patterns
  importPatterns: {
    staticImport: /import .+ from ['"](.+)['"]/g,
    namedImport: /import ['"](.+)['"]/g,
    // Override only what you need
  },
  outputDir: 'reports',
  generateFiles: true
})
  .then(result => {
    // result.analysis - detailed file analysis
    // result.summary - summary statistics
    // result.markdown - markdown report content
    console.log(`Total files: ${result.summary.total}`);
    console.log(`Unused files: ${result.summary.unused}`);
  });

Configuration Options

OptionDescriptionDefault
srcSource directory to analyze'src'
patternsFile patterns to include['src/**/*.{js,vue,ts}']
fileTypeMappingMapping of path patterns to file typesSee default mapping
providePatternRegExp for detecting special provide patterns/app\.provide\(['"]([$][^'"]+)['"], ([^)]+)\)/g
mainJsPatternPattern to identify main app file'main.js'
importPatternsCustom regex patterns for import detectionSee default patterns
outputDirDirectory for output files'./'
generateFilesWhether to generate output filestrue

Default File Type Mapping

{
  '/services/': 'service',
  '/components/': 'component',
  '/views/': 'view',
  '/store/': 'store',
  '/utils/': 'utility',
  '/router/': 'router',
  '/assets/': 'asset',
  '/constants/': 'constant'
}

Default Import Patterns

These are the default regular expressions used to detect different types of imports:

{
  staticImport: /import .+ from ['"](.+)['"]/g,
  namedImport: /import ['"](.+)['"]/g,
  lazyImport: /import\(['"](.+)['"]\)/g,
  routerImport: /component: \(\) => import\(['"](.+)['"]\)/g,
  provideImport: /provide\(['"][^'"]+['"], [^)]*?['"]([@/][^'"]+)['"]/g,
  appProvideImport: /app\.provide\(['"][^'"]+['"], [^)]*?['"]([@/][^'"]+)['"]/g,
  vueComponentImport: /components: {[^}]*['"]([^'"]+)['"]/g,
  serviceImport: /from ['"](@\/services\/[^'"]+)['"]/g
}

You can override any pattern by providing your own in the importPatterns option.

Output Files

  • file-analysis.json - Complete analysis data
  • file-analysis-table.json - Simplified format for UI display
  • file-analysis-summary.json - Summary statistics
  • file-analysis.md - Markdown report with summary and unused files

License

MIT

Keywords

file

FAQs

Package last updated on 28 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.