Issue
I want to use a package with composer require but I don't want it to load all the folders. I know that I should fork this package on github and make my changes, but I want to easily update the package when need, and copy/pasting folders isn't the best option.
So, I was thinking, is it possible to somehow on my forked repository on composer.json
file, tell that I don't want to load Eloquent
and Console
folders from the illuminate/database
package?
reference: https://github.com/illuminate/database
Solution
First of all there is no way to exclude these folders from Composer.
And I will never understand why some people are still hunting for the last 2 bytes of disk space. Disk space is really cheap nowadays. And for example you would never go and delete some single functions that you don't use from a package or do you?
In almost any package/framework I use, there are some things I don't use but it would never come into my mind to remove them unless I'm a NASA guy sending my code to Pluto or something.
My advice: Keep these files unless there is a really big need to have them removed.
If you need to remove them you could write a script and run it at a post-package-update
event.
Here is how you define a script event in your composer.json
:
{
"scripts": {
"post-update-cmd": "MyVendor\\MyClass::postUpdate",
"post-package-install": [
"MyVendor\\MyClass::postPackageInstall"
],
"post-install-cmd": [
"MyVendor\\MyClass::warmCache",
"phpunit -c app/"
],
"post-create-project-cmd" : [
"php -r \"copy('config/local-example.php', 'config/local.php');\""
]
}
}
And an example for the MyVendor\MyClass
class:
<?php
namespace MyVendor;
use Composer\Script\Event;
use Composer\Installer\PackageEvent;
class MyClass
{
public static function postUpdate(Event $event)
{
$composer = $event->getComposer();
// do stuff
}
public static function postPackageInstall(PackageEvent $event)
{
$installedPackage = $event->getOperation()->getPackage();
// do stuff
}
public static function warmCache(Event $event)
{
// make cache toasty
}
}
For more on how to use scripts see the official composer documentation - scripts.
Answered By - Pᴇʜ
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.