Debugging vendors on a virtual machine or container

Learn how to modify, debug or fix vendors in your projects when they are hosted on your containers or your virtual machine.

The problem

People who develop using virtual machines or containers often avoid mounting their vendors due to performance reasons. It's much faster to only have vendors on your container or VM.

This is all fine and it works great, that is, until you find a bug in one of the vendors and you have to debug it or you just want to add a feature to it. No matter the reason, when you need to edit the vendors - you end up mounting them anyways. As a result, if you use a lot of vendors, it could drastically decrease performance.

The solution

The solution is actually really simple by using a handy composer plugin created by Mina Nabil Sami.

This plugin allows you to define a custom path for a vendor, this way you can mount a single (or multiple) vendors while keeping all the others on the VM/container. This way, you only have a marginal performance loss and don't have to deal with slow loading speeds while you're messing around in the vendors.

Just tell me how!

The plugin readme should already get you going, it's very simple. But I'll explain in a few simple steps, so let's get started.

We'll start by installing the composer plugin, note that I'm saving in require-dev because I'll be moving the vendor back to where it belongs when I'm done with it.

composer require mnsami/composer-custom-directory-installer
Next up, we need to add a custom path for a vendor in your composer.json. Let's say you have monolog installed, the custom folder could look like the following:

Next step is to update the autoloader:
composer install

And that's about it, the monolog vendor is now installed in ./customdir/!

The git directories are all there, so you could even create a pull request! (you just have to fork and change the remote url)

That's it!

Thats it, you're done. If you have any questions or comments, please post them in the comment section!

PS: We're looking for awesome people to join our team!