stolt/lean-package-validator
CLI tool to validate a project or micro-package for “leanness” by ensuring common repo artifacts are excluded from release archives. Also creates, updates, and reformats .gitattributes export-ignore entries for lean distribution packages.
Installation:
composer require --dev stolt/lean-package-validator
or globally:
composer global require stolt/lean-package-validator
First Validation: Run in your project root:
vendor/bin/lean-package-validator validate
This checks if .gitattributes excludes common non-release files (e.g., .github/, vendor/).
Quick Fix:
Auto-generate a compliant .gitattributes:
vendor/bin/lean-package-validator create
--preset=PHP (default) or others (Python, Rust, etc.) for language-specific rules.vendor/bin/lean-package-validator validate --help for options.Pre-Release Validation:
Add to composer.json:
"scripts": {
"pre-release": [
"@validate-gitattributes",
"phpunit"
],
"validate-gitattributes": "lean-package-validator validate --validate-git-archive"
}
Ensures no unwanted files slip into releases.
CI/CD Integration:
Use the GitHub Action in .github/workflows/validate.yml:
- name: Validate Lean Package
uses: raphaelstolt/lean-package-validator-action@v1
with:
directory: '.'
Custom Patterns:
Create a .lpv file in your project root:
lean-package-validator init --preset=PHP
Edit to add custom glob patterns (e.g., *.env).
Artisan Command: Publish the CLI as an Artisan command:
php artisan vendor:publish --provider="Stolt\LeanPackageValidator\LeanPackageValidatorServiceProvider"
Then call via:
php artisan lean-package-validator:validate
Package Development: For Laravel packages, enforce lean releases by:
lean-package-validator validate --preset=PHP --keep-glob-pattern '{LICENSE,README.md}'
Testing: Validate in PHPUnit tests:
use Stolt\LeanPackageValidator\Validator;
public function testGitAttributes()
{
$validator = new Validator();
$this->assertTrue($validator->validate(__DIR__.'/../'));
}
post-update-cmd to auto-fix .gitattributes:
"scripts": {
"post-update-cmd": "lean-package-validator update"
}
find packages -name "composer.json" -exec dirname {} \; | xargs -I{} lean-package-validator validate {}
lean-package-validator validate --glob-pattern '{*.phar,build/}'
False Positives:
--validate-git-archive may fail if composer.lock is excluded but needed for testing.--keep-glob-pattern '{composer.lock}' or adjust presets.Order Sensitivity:
--enforce-strict-order fails if .gitattributes entries are reordered.--sort-from-directories-to-files to standardize order.PHAR Conflicts:
.lpv:
*.phar !export-ignore
Case Sensitivity:
*.php) for cross-platform compatibility.Nested Directories:
.gitattributes files may not be detected.lean-package-validator validate from the project root.Dry Runs:
Use --dry-run with update or reformat to preview changes:
lean-package-validator update --dry-run
Diff Output:
Compare current vs. expected .gitattributes:
lean-package-validator validate --diff
Tree Inspection: Debug what’s excluded:
lean-package-validator tree --src --dist-package
Custom Presets:
Extend Stolt\LeanPackageValidator\Presets\PresetInterface to add language support (e.g., LaravelPreset).
Agentic Mode:
Use --agentic-run for programmatic output (JSON):
lean-package-validator validate --agentic-run | jq '.valid'
Git Hooks:
Integrate with pre-push to block non-lean commits:
lean-package-validator validate || exit 1
Vendor Exclusions:
Laravel’s vendor/ is already excluded by default, but ensure:
vendor/ export-ignore
Configuration Caching:
If using config:cache, exclude:
bootstrap/cache/ export-ignore
Artisan Commands: For custom commands, exclude:
app/Console/Commands/ export-ignore
bootstrap/cache/lean-package-validator.json for repeated runs.parallel-lint or pest to validate multiple packages simultaneously.How can I help you explore Laravel packages today?