stolt/lean-package-validator
CLI tool to validate a PHP project/micro-package for “leanness” by ensuring common repo artifacts aren’t shipped in release archives. Also creates and updates .gitattributes export-ignore entries to enforce lean release assets.
.github/, .idea/, vendor/) from release artifacts. Reduces bloated distributions and improves maintainability..gitattributes (native Git feature) for exclusion rules, avoiding custom build steps or post-processing. Complements Laravel’s existing Git workflows.storage/logs/, bootstrap/cache/).composer.json scripts (e.g., post-release hooks) or CI/CD pipelines. Example:
"scripts": {
"post-release": "lean-package-validator validate --validate-git-archive"
}
lpv in a custom Artisan command for devs (e.g., php artisan validate:gitattributes)..gitattributes before deploying to production to prevent accidental inclusion of sensitive files (e.g., storage/).config/ which may contain critical runtime files). Mitigate via --keep-glob-pattern or custom .lpv files.--validate-git-archive creates temporary archives, which may slow down CI pipelines for large repos. Test performance with Laravel’s monorepo-like structures (e.g., vendor/).--preset=PHP to align with Laravel’s conventions.storage/, bootstrap/cache/) be pre-configured in the PHP preset? If so, propose a PR to the package.--validate-git-archive perform in CI for Laravel projects with large vendor/ or node_modules/? Benchmark with a sample repo.--agentic-run JSON output be parsed by Laravel’s Horizon or Nova for automated remediation (e.g., auto-fixing .gitattributes)?git-archive-all or Laravel’s composer.json "extra": "exclude-from-classmap" for overlap.laravel/framework, custom packages). Reduces distribution size and improves Composer install times..gitattributes in monorepos (e.g., laravel/valet, laravel/sail) to exclude dev-specific files.composer.json scripts or composer validate-gitattributes command.GitAttributesValidator) to surface lpv functionality to Laravel devs.composer require --dev stolt/lean-package-validator
composer.json:
"scripts": {
"validate-gitattributes": "lean-package-validator validate --preset=PHP"
}
composer validate-gitattributes
- name: Validate Git Attributes
run: composer validate-gitattributes -- --validate-git-archive
--validate-git-archive catches leaks).--keep-glob-pattern '{storage/logs/,bootstrap/cache/}' to whitelist Laravel-specific files..gitattributes, which is independent of Laravel’s build tools.post-autoload-dump)..lpv file or --glob-pattern:
lean-package-validator validate --glob-pattern '{*.php,config/,storage/logs/,vendor/}'
composer validate-gitattributes --validate-git-archive to catch leaks before tagging..gitattributes or add excluded files.pre-commit hooks (via husky or Laravel Forge) to catch issues early.composer update stolt/lean-package-validator)..gitattributes diverging from expected patterns. Mitigate with:
lean-package-validator update in CI to reconcile drift..lpv files to composer.json or README.md for reproducibility.--create/--overwrite flags deprecated in v5.0. Migrate to create/update commands in Laravel projects.storage/framework/). Solution: Use --keep-glob-pattern..gitattributes or use --dry-run for debugging.--diff and --report-stale-export-ignores for diagnosing mismatches.--agentic-run for programmatic error handling.--validate-git-archive may slow down CI. Optimize by:
vendor/ from validation (it’s already ignored by default).--glob-pattern-file to define per-package rules in a monorepo (e.g., packages/package-a/.lpv).| Failure Scenario | Impact | Mitigation |
|---|---|---|
.gitattributes missing |
CI fails or releases include dev files. | Use --create or init in CI setup. |
Stale export-ignore entries |
Non-existent files still ignored. | Use --report-stale-export-ignores in CI. |
--validate-git-archive timeout |
CI job fails due to large repo. | Exclude vendor/ or run in a subdirectory. |
Custom .lpv file conflicts |
Manual changes override presets. | Use refresh command to merge updates. |
| PHP version mismatch | Tool fails on Laravel 9.x. | Pin to PHP 8.1 or use a fork. |
composer.json and run composer validate-gitattributes locally.How can I help you explore Laravel packages today?