savinmikhail / dist-size-optimizer
Optimizes your package distribution size by automatically managing .gitattributes export-ignore rules
Installs: 162
Dependents: 3
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/savinmikhail/dist-size-optimizer
Requires
- php: ^8.2
- symfony/console: ^7.2
- symfony/finder: ^7.2
Requires (Dev)
- ergebnis/composer-normalize: ^2.47
- friendsofphp/php-cs-fixer: ^3.75
- icanhazstring/composer-unused: ^0.9.3
- maglnet/composer-require-checker: ^4.16
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.5
- phpyh/coding-standard: ^2.6
- rector/rector: ^2.0
- savinmikhail/add_named_arguments_rector: ^0.1.16
- symfony/var-dumper: ^7.2
- dev-main
- v0.2.6
- v0.2.5
- v0.2.4
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.7
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- dev-codex/fix-issue-with-dist-size-optimizer-6u6ehx
- dev-codex/design-badge-for-optimization-status
- dev-codex/fix-issue-with-dist-size-optimizer-ozcg5z
- dev-codex/fix-issue-with-dist-size-optimizer
This package is auto-updated.
Last update: 2025-10-14 15:01:51 UTC
README
A command-line tool that helps you optimize your package distribution size by automatically managing .gitattributes export-ignore rules.
Note: This package was previously known as
export-ignore-check. The functionality remains the same, but the name better reflects its purpose of optimizing distribution size.
Why?
When you publish a package to Packagist, Composer creates a distribution archive using git archive. Files and directories that are not needed in production (like tests, documentation, CI configs) should be excluded using .gitattributes export-ignore to:
- Reduce package size
- Speed up installation
- Improve CI/CD pipeline performance
- Keep production packages clean
This tool helps you identify what should be excluded and can automatically fix your .gitattributes file.
Installation
-
As composer dependency:
composer require --dev savinmikhail/dist-size-optimizer
-
Or as standalone phar package:
box.phar compile ./dist-size-optimizer.phar check
Dist Size Badge
Show the status of your distribution size with a badge. The badge is green when the package is optimized and red when it needs optimization:
Add badge to your project
-
Copy the dist-size workflow into your repository.
-
Add the following snippet to your
README.md, replacing<USER>and<REPO>with your repository details:
The workflow updates dist-size-status.json, and the badge reflects your repository's current status.
Usage
Check Current Project
To check your current project (recommended during development):
vendor/bin/dist-size-optimizer check
This will:
- Create a git archive of your project (simulating Packagist's distribution)
- Scan for files that should be excluded
- Show you what to add to your
.gitattributesfile - Automatically append the suggested patterns to your
.gitattributesfile
Note: When checking your current project, the tool uses
git archive HEAD, which means it only includes committed changes. Make sure to commit your changes before running the check to get accurate results.
Check Any Package
To check any package from Packagist:
vendor/bin/dist-size-optimizer check vendor/package
For example:
vendor/bin/dist-size-optimizer check symfony/console
Clean .gitattributes
If your .gitattributes file contains stale export-ignore entries copied from other projects, you can remove all non-existent paths with:
vendor/bin/dist-size-optimizer check --clean
This command will:
- Read your existing
.gitattributesfile - Remove all lines with
export-ignorepatterns that no longer match any file or directory in the project - Overwrite
.gitattributeswith the cleaned content
Output Options
Dry Run
By default, the tool will automatically append suggested patterns to your .gitattributes file. Use --dry-run to only see what would be added without making any changes:
vendor/bin/dist-size-optimizer check --dry-run
JSON Output
Add --json flag to get machine-readable output:
vendor/bin/dist-size-optimizer check --json
Custom Config
By default, the tool uses a predefined set of patterns to check. You can provide your own config file:
vendor/bin/dist-size-optimizer check --config=/path/to/config.php
# or using short option
vendor/bin/dist-size-optimizer check -c /path/to/config.php
The config file should be a PHP file that returns an array of patterns to check:
<?php return [ 'tests/', '.gitignore', // ... your patterns ];
Custom Working Directory
By default, the tool uses a system temporary directory for working directory. You can provide your own working directory path:
vendor/bin/dist-size-optimizer check --workdir=/path/to/workdir
# or using short option
vendor/bin/dist-size-optimizer check -w /path/to/workdir
Example Output
Directories that should be excluded using export-ignore:
• `/tests/`
• `/docs/`
• `/.github/`
Files that should be excluded using export-ignore:
• `/.gitignore`
• `/.editorconfig`
• `/phpunit.xml.dist`
• `/README.md`
To fix this, add the following lines to your `.gitattributes` file:
/tests/ export-ignore
/docs/ export-ignore
/.github/ export-ignore
/.gitignore export-ignore
/.editorconfig export-ignore
/phpunit.xml.dist export-ignore
/README.md export-ignore
🌿 Your package size could be reduced by approximately 2.5 MB!
🚀 This improves installation time, reduces archive size, and helps CI/CD pipelines.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.