slowprog/composer-copy-file
Composer script handler that copies files and directories after install/update. Configure mappings in composer.json (supports dev vs prod rules), nested directories, and overwrite control (override or only if older). Useful for publishing vendor assets like fonts/JS/CSS.
slowprog/composer-copy-file is a lightweight solution for copying files during Composer installation, which aligns well with Laravel’s dependency management workflow. It addresses a common need: ensuring assets, configs, or vendor-specific files are copied to the correct locations post-installation without manual intervention.post-install-cmd or post-update-cmd scripts in composer.json. It avoids reinventing wheel by leveraging Composer’s native scripting capabilities.composer.json under scripts, making it trivial to adopt.php artisan vendor:publish --tag=config for Laravel-specific files) mitigates this.post-install-cmd: ["php", "bin/copy-files.php"] without an external package?.env overrides only in staging)?vendor:publish, package-specific publishers)?cweagans/composer-patches) should be considered.vendor:publish for package-specific files.composer install.composer.json under require:
"require": {
"slowprog/composer-copy-file": "^1.0"
}
scripts:
"scripts": {
"post-install-cmd": [
"Slowprog\\ComposerCopyFile\\CopyFileCommand"
],
"post-update-cmd": [
"Slowprog\\ComposerCopyFile\\CopyFileCommand"
]
}
composer.json:
"extra": {
"copy-file": {
"path/to/source/file": "path/to/destination/file"
}
}
"scripts": {
"post-install-cmd": [
"php -r \"copy('path/to/source', 'path/to/dest');\""
]
}
cweagans/composer-patches for more complex logic.composer install may cause flakiness in CI if files are not idempotent. Ensure scripts are designed for repeatability.composer install/update but before any Laravel-specific bootstrapping (e.g., bootstrap/cache clearing).composer validate or composer show.post-autoload-dump instead of post-install-cmd if files must exist before autoloading (e.g., for custom PSR-4 paths).composer.json must be manually updated if source/destination paths change.post-cmd scripts if critical.composer install --verbose
post-autoload-dump to parallelize.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Source file missing | Build fails during composer install |
Use post-cmd checks or CI validation. |
| Destination directory unwritable | Silent failure or permission errors | Ensure proper file permissions in deployment. |
| Path resolution errors (relative paths) | Copies fail in CI vs. local dev | Use absolute paths or environment variables. |
| Package compatibility issues (Composer 2.x) | Scripts fail to execute | Test early; fallback to native scripts. |
| Race conditions in CI/CD | Flaky builds due to concurrent scripts | Use post-autoload-dump or sequential scripts. |
README.md or CONTRIBUTING.md about file-copying behavior during composer install.composer.json.composer install --verbose output).composer.json file-copying sections.php artisan vendor:validate-copy-files
How can I help you explore Laravel packages today?