
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
file-usage-analyzer
Advanced tools
Analyze file usage in JavaScript/TypeScript projects to identify unused files
A powerful utility to analyze file usage in JavaScript/TypeScript projects, identifying which files are unused and potentially removable.
npm install -g file-usage-analyzer
npm install --save-dev file-usage-analyzer
# 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
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}`);
});
Option | Description | Default |
---|---|---|
src | Source directory to analyze | 'src' |
patterns | File patterns to include | ['src/**/*.{js,vue,ts}'] |
fileTypeMapping | Mapping of path patterns to file types | See default mapping |
providePattern | RegExp for detecting special provide patterns | /app\.provide\(['"]([$][^'"]+)['"], ([^)]+)\)/g |
mainJsPattern | Pattern to identify main app file | 'main.js' |
importPatterns | Custom regex patterns for import detection | See default patterns |
outputDir | Directory for output files | './' |
generateFiles | Whether to generate output files | true |
{
'/services/': 'service',
'/components/': 'component',
'/views/': 'view',
'/store/': 'store',
'/utils/': 'utility',
'/router/': 'router',
'/assets/': 'asset',
'/constants/': 'constant'
}
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.
file-analysis.json
- Complete analysis datafile-analysis-table.json
- Simplified format for UI displayfile-analysis-summary.json
- Summary statisticsfile-analysis.md
- Markdown report with summary and unused filesMIT
FAQs
Analyze file usage in JavaScript/TypeScript projects to identify unused files
We found that file-usage-analyzer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.