Automating Composer Install for TypeRocket in MU-Plugins
When managing WordPress projects, keeping dependencies updated efficiently is key. If you’re using TypeRocket as an MU plugin (must-use plugin), you might encounter some friction when handling Composer dependencies.
The Challenge
When TypeRocket is installed at wp-content/mu-plugins/typerocket
, and all its dependencies are managed via Composer inside that directory, you might find yourself needing to SSH into your host manually whenever running composer install
after adding or updating dependencies.
This process can become tedious, especially when working in a team where updates happen frequently.
The Solution: Composer Scripts
You will be happy to find out that Composer scripts allow execution of commands in subdirectories automatically. This means the host can handle composer install
for TypeRocket without requiring manual SSH access and cd
into the MU plugins folder.
composer.json
Updated By adding these scripts to the root composer.json
, Composer automatically installs or updates dependencies in the mu-plugins/typerocket
directory whenever the main composer install
or composer update
command is executed.
{
"scripts": {
"post-install-cmd": [
"composer install --working-dir=wp-content/mu-plugins/typerocket"
],
"post-update-cmd": [
"composer update --working-dir=wp-content/mu-plugins/typerocket"
]
}
}
Now, every time composer install
or composer update
is run at the project root, it also applies to TypeRocket’s dependencies automatically. This will require having a composer.json
file in your root folder and it will make a vendor
folder in the root directory. However, the tradeoff is worth it.
Running Composer from the WordPress Root
To ensure that dependencies for both WordPress and TypeRocket are installed, navigate to your WordPress root directory and run:
composer install
or, if dependencies have already been installed and need updating:
composer update
Composer will execute the necessary commands for both the root project and the TypeRocket subdirectory.
Additional Resources
If you're setting up TypeRocket via Composer in an MU-plugins directory, check out the official documentation for installation details:
This small tweak saves time and makes dependency management smoother. Hope this helps anyone dealing with similar setups! 🙂