unnecessary-file-police
v1.0.0
Published
A pre-publish hook that screams at you if you are about to publish unnecessary files
Maintainers
Readme
Unnecessary File Police 🚔
A pre-publish hook that screams at you if you are about to publish unnecessary files to npm.
The Problem
People accidentally publish massive files to npm (Photoshop files, local databases, test videos), creating "bloatware" packages that waste bandwidth and storage space.
How It Works
You run npx diet-police (or add it to prepublishOnly). It scans the folder and ignores standard code files. It alerts you:
⚠️ Warning: You are about to publish 'design-mockup.psd' (55MB). Add to .npmignore?Why It's Unique
Existing tools just tell you the size of the package. This one identifies suspicious file types that don't belong in a registry.
Installation
npm install unnecessary-file-police --save-devUsage
As a CLI Tool
# Scan current directory
npx diet-police
# Scan specific directory
npx diet-police --directory ./my-package
# Set custom threshold (default: 10MB)
npx diet-police --threshold 5242880
# Verbose output
npx diet-police --verbose
# Auto-fix: automatically add suggestions to .npmignore
npx diet-police --auto-fixAs a Pre-publish Hook
Add to your package.json:
{
"scripts": {
"prepublishOnly": "diet-police"
}
}Now it will automatically run before you publish to npm!
What It Detects
Suspicious File Extensions
- Design files:
.psd,.ai,.sketch,.fig,.xd - Videos:
.mp4,.mov,.avi,.mkv - Databases:
.db,.sqlite,.sqlite3 - Archives:
.zip,.tar,.gz,.rar,.7z - Executables:
.exe,.dmg,.pkg,.deb,.rpm,.iso - Documents:
.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx - Audio files:
.wav,.flac,.aac,.ogg,.wma
Large Files
Any file larger than 10MB (configurable) that doesn't have a standard code extension will be flagged.
Allowed Extensions (Ignored)
Standard code and configuration files are ignored:
- JavaScript/TypeScript:
.js,.ts,.jsx,.tsx - Styles:
.css,.scss,.sass,.less - Config:
.json,.yml,.yaml,.md,.txt - Build files:
.html,.vue,.svelte - Other languages:
.py,.java,.c,.cpp,.go,.rs, etc.
Examples
Example Output
🔍 Scanning for unnecessary files...
⚠️ Found 3 suspicious file(s):
1. design-mockup.psd (55.2MB)
Reason: suspicious extension
2. test-video.mp4 (12.8MB)
Reason: large file
3. local.db (2.1MB)
Reason: suspicious extension
Total size of suspicious files: 70.1MB
💡 Suggested .npmignore entries:
**/*.psd
**/*.mp4
**/*.db
💡 Run with --auto-fix to automatically add these to .npmignore
🚨 Please review these files before publishing!Auto-fix Mode
npx diet-police --auto-fixThis will automatically add the suggested patterns to your .npmignore file.
API Usage
const UnnecessaryFilePolice = require('unnecessary-file-police');
const police = new UnnecessaryFilePolice({
threshold: 10 * 1024 * 1024, // 10MB
suspiciousExtensions: ['.psd', '.mp4'],
allowedExtensions: ['.js', '.json']
});
const suspiciousFiles = await police.scanDirectory('./my-package');
const suggestions = police.generateNpmignoreSuggestions(suspiciousFiles);
console.log('Suspicious files:', suspiciousFiles);
console.log('Npmignore suggestions:', suggestions);Configuration Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| threshold | number | 10485760 (10MB) | File size threshold in bytes |
| suspiciousExtensions | array | See above | File extensions to flag |
| allowedExtensions | array | See above | File extensions to ignore |
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
MIT © [Your Name]
Related Tools
npm-pack-list- Shows what files will be included in your npm packagesize-limit- Limit the size of your npm package
Stop bloatware before it happens! 🚔📦
