folivoro / composer-dropin-installer
Copies a single file from a package into a target directory defined by installer-paths.
Package info
github.com/folivoro/dropin-installer-plugin
Type:composer-plugin
pkg:composer/folivoro/composer-dropin-installer
Requires
- php: ^8.4
- composer-plugin-api: ^2.0
Requires (Dev)
- composer/composer: ^2.0
- pestphp/pest: ^3.0
README
Folivoro Composer-Dropin-Installer
A Composer plugin that copies a single file from any installed package into a target directory resolved from the root package's installer-paths configuration.
Why
Some packages need to place a single file at a specific location in the project — for example, a WordPress MU-plugin bootstrapper. The standard composer/installers approach installs an entire package directory. This plugin does one thing: copies a single declared file to the right place.
Installation
composer require folivoro/composer-dropin-installer
Usage
In any package that wants to install a dropin file, add to composer.json:
{
"extra": {
"dropin": {
"file": "my-plugin.php",
"target-type": "wordpress-muplugin",
"target-dir": "my-plugin"
}
}
}
The root project must have installer-paths configured for the target type:
{
"extra": {
"installer-paths": {
"public/extensions/components/{$name}/": [
"type:wordpress-muplugin"
]
}
}
}
Given the above, my-plugin.php will be copied to:
public/extensions/components/my-plugin/my-plugin.php
Configuration
| Key | Required | Description |
|---|---|---|
file |
✅ | Filename to copy from the package root |
target-type |
✅ | The installer-paths type to resolve the target directory |
target-dir |
❌ | Subdirectory name within the resolved path. Defaults to the package name. |
How it works
On pre-autoload-dump, the plugin iterates all installed packages and checks for extra.dropin configuration. For each match, it resolves the target directory from the root package's installer-paths and copies the file. On uninstall, the copied file is removed.
License
MIT