Repository: barryvdh/composer-cleanup-plugin
Branch: master
Commit: d7bfbe026ac5
Files: 5
Total size: 14.2 KB
Directory structure:
gitextract_lijcdq0e/
├── .gitignore
├── README.md
├── composer.json
└── src/
├── CleanupPlugin.php
└── CleanupRules.php
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
/vendor
/.idea
composer.phar
composer.lock
.DS_Store
================================================
FILE: README.md
================================================
Composer Cleanup Plugin
=======================
Remove tests & documentation from the vendor dir. Based on [laravel-vendor-cleanup](https://github.com/barryvdh/laravel-vendor-cleanup) but implemented as a Composer Plugin instead of a Laravel command.
Usually disk size shouldn't be a problem, but when you have to use FTP to deploy or have very limited disk space,
you can use this package to cut down the vendor directory by deleting files that aren't used in production (tests/docs etc).
> **Note:** This package is abandoned. Packages should add files they want to exclude to .gitattributes
## Install
Require this package in your composer.json:
"barryvdh/composer-cleanup-plugin": "0.4.x"
## Usage
This plugin will work automatically on any packages installed as `dist`. Therefore, if you are using it to build a package archive, simply run `composer install` with the `--prefer-dist` option.
## What does it do?
For every installed or updated package in the default list, in general:
1. Remove documentation, such as README files, docs folders, etc.
2. Remove tests, PHPUnit configs, and other build/CI configuration.
Some packages don't obey the general rules, and remove more/less files. Packages that do not have
rules added are ignored.
## Adding rules
Please submit a PR to [src/CleanupRules.php] to add more rules for packages.
Make sure you test them first, sometimes tests dirs are classmapped and will error when deleted.
[src/CleanupRules.php]: ./src/CleanupRules.php
================================================
FILE: composer.json
================================================
{
"name": "barryvdh/composer-cleanup-plugin",
"type": "composer-plugin",
"description": "A composer cleanup plugin, to remove tests and documentation to save space",
"license": "MIT",
"authors": [
{
"name": "Barry vd. Heuvel",
"email": "barryvdh@gmail.com"
}
],
"require": {
"composer-plugin-api": "^2.0"
},
"require-dev": {
"composer/composer": "^2.0"
},
"autoload": {
"psr-4": {
"Barryvdh\\Composer\\": "src/"
}
},
"extra": {
"branch-alias": {
"dev-master": "0.3-dev"
},
"class": "Barryvdh\\Composer\\CleanupPlugin"
}
}
================================================
FILE: src/CleanupPlugin.php
================================================
<?php
namespace Barryvdh\Composer;
use Composer\Composer;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use Composer\Script\ScriptEvents;
use Composer\Installer\PackageEvent;
use Composer\Script\CommandEvent;
use Composer\Util\Filesystem;
use Composer\Package\BasePackage;
class CleanupPlugin implements PluginInterface, EventSubscriberInterface
{
/** @var \Composer\Composer $composer */
protected $composer;
/** @var \Composer\IO\IOInterface $io */
protected $io;
/** @var \Composer\Config $config */
protected $config;
/** @var \Composer\Util\Filesystem $filesystem */
protected $filesystem;
/** @var array $rules */
protected $rules;
/**
* {@inheritDoc}
*/
public function activate(Composer $composer, IOInterface $io)
{
$this->composer = $composer;
$this->io = $io;
$this->config = $composer->getConfig();
$this->filesystem = new Filesystem();
$this->rules = CleanupRules::getRules();
}
/**
* {@inheritDoc}
*/
public function deactivate(Composer $composer, IOInterface $io)
{
//
}
/**
* {@inheritDoc}
*/
public function uninstall(Composer $composer, IOInterface $io)
{
//
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return array(
'post-package-install' => 'onPostPackageInstall',
'post-package-update' => 'onPostPackageUpdate',
/*ScriptEvents::POST_INSTALL_CMD => array(
array('onPostInstallUpdateCmd', 0)
),
ScriptEvents::POST_UPDATE_CMD => array(
array('onPostInstallUpdateCmd', 0)
),*/
);
}
/**
* Function to run after a package has been installed
*/
public function onPostPackageInstall(PackageEvent $event)
{
/** @var \Composer\Package\CompletePackage $package */
$package = $event->getOperation()->getPackage();
$this->cleanPackage($package);
}
/**
* Function to run after a package has been updated
*/
public function onPostPackageUpdate(PackageEvent $event)
{
/** @var \Composer\Package\CompletePackage $package */
$package = $event->getOperation()->getTargetPackage();
$this->cleanPackage($package);
}
/**
* Function to run after a package has been updated
*
* @param CommandEvent $event
*/
public function onPostInstallUpdateCmd(CommandEvent $event)
{
/** @var \Composer\Repository\WritableRepositoryInterface $repository */
$repository = $this->composer->getRepositoryManager()->getLocalRepository();
/** @var \Composer\Package\CompletePackage $package */
foreach($repository->getPackages() as $package){
if ($package instanceof BasePackage) {
$this->cleanPackage($package);
}
}
}
/**
* Clean a package, based on its rules.
*
* @param BasePackage $package The package to clean
* @return bool True if cleaned
*/
protected function cleanPackage(BasePackage $package)
{
// Only clean 'dist' packages
if ($package->getInstallationSource() !== 'dist') {
return false;
}
$vendorDir = $this->config->get('vendor-dir');
$targetDir = $package->getTargetDir();
$packageName = $package->getPrettyName();
$packageDir = $targetDir ? $packageName . '/' . $targetDir : $packageName ;
$rules = isset($this->rules[$packageName]) ? $this->rules[$packageName] : null;
if(!$rules){
return;
}
$dir = $this->filesystem->normalizePath(realpath($vendorDir . '/' . $packageDir));
if (!is_dir($dir)) {
return false;
}
foreach((array) $rules as $part) {
// Split patterns for single globs (should be max 260 chars)
$patterns = explode(' ', trim($part));
foreach ($patterns as $pattern) {
try {
foreach (glob($dir.'/'.$pattern) as $file) {
$this->filesystem->remove($file);
}
} catch (\Exception $e) {
$this->io->write("Could not parse $packageDir ($pattern): ".$e->getMessage());
}
}
}
return true;
}
}
================================================
FILE: src/CleanupRules.php
================================================
<?php
namespace Barryvdh\Composer;
class CleanupRules
{
public static function getRules()
{
// Default patterns for common files
$docs = 'README* CHANGELOG* FAQ* CONTRIBUTING* HISTORY* UPGRADING* UPGRADE* package* demo example examples doc docs readme* changelog* composer*';
$tests = '.travis.yml .scrutinizer.yml phpcs.xml* phpcs.php phpunit.xml* phpunit.php test tests Tests travis patchwork.json';
return array(
'tecnickcom/tcpdf' => array($docs, $tests, 'fonts'),
'anahkiasen/former' => array($docs, $tests),
'anahkiasen/html-object' => array($docs, 'phpunit.xml* tests/*'),
'anahkiasen/rocketeer' => array($docs, $tests),
'anahkiasen/underscore-php' => array($docs, $tests),
'aws/aws-sdk-php' => array($docs, $tests),
'barryvdh/composer-cleanup-plugin' => array($docs, $tests),
'barryvdh/laravel-debugbar' => array($docs, $tests),
'barryvdh/laravel-ide-helper' => array($docs, $tests),
'bllim/datatables' => array($docs, $tests),
'cartalyst/sentry' => array($docs, $tests),
'classpreloader/classpreloader' => array($docs, $tests),
'd11wtq/boris' => array($docs, $tests),
'danielstjules/stringy' => array($docs, $tests),
'dflydev/markdown' => array($docs, $tests),
'dnoegel/php-xdg-base-dir' => array($docs, $tests),
'doctrine/annotations' => array($docs, $tests, 'bin'),
'doctrine/cache' => array($docs, $tests, 'bin'),
'doctrine/collections' => array($docs, $tests),
'doctrine/common' => array($docs, $tests, 'bin lib/vendor'),
'doctrine/dbal' => array($docs, $tests, 'bin build* docs2 lib/vendor'),
'doctrine/inflector' => array($docs, $tests),
'dompdf/dompdf' => array($docs, $tests, 'www'),
'filp/whoops' => array($docs, $tests),
'guzzle/guzzle' => array($docs, $tests),
'guzzlehttp/guzzle' => array($docs, $tests),
'guzzlehttp/oauth-subscriber' => array($docs, $tests),
'guzzlehttp/streams' => array($docs, $tests),
'imagine/imagine' => array($docs, $tests, 'lib/Imagine/Test'),
'intervention/image' => array($docs, $tests, 'public'),
'ircmaxell/password-compat' => array($docs, $tests),
'jakub-onderka/php-console-color' => array($docs, $tests, 'build.xml example.php'),
'jakub-onderka/php-console-highlighter' => array($docs, $tests, 'build.xml'),
'jasonlewis/basset' => array($docs, $tests),
'jeremeamia/SuperClosure' => array($docs, $tests, 'demo'),
'kriswallsmith/assetic' => array($docs, $tests),
'laravel/framework' => array($docs, $tests, 'build'),
'leafo/lessphp' => array($docs, $tests, 'Makefile package.sh'),
'league/flysystem' => array($docs, $tests),
'league/stack-robots' => array($docs, $tests),
'maximebf/debugbar' => array($docs, $tests, 'demo'),
'mccool/laravel-auto-presenter' => array($docs, $tests),
'mockery/mockery' => array($docs, $tests),
'monolog/monolog' => array($docs, $tests),
'mrclay/minify' => array($docs, $tests, 'MIN.txt min_extras min_unit_tests min/builder min/config* min/quick-test* min/utils.php min/groupsConfig.php min/index.php'),
'mtdowling/cron-expression' => array($docs, $tests),
'mustache/mustache' => array($docs, $tests, 'bin'),
'nesbot/carbon' => array($docs, $tests),
'nikic/php-parser' => array($docs, $tests, 'test_old'),
'oyejorge/less.php' => array($docs, $tests),
'patchwork/utf8' => array($docs, $tests),
'phenx/php-font-lib' => array($docs, $tests. 'www'),
'phpdocumentor/reflection-docblock' => array($docs, $tests),
'phpoffice/phpexcel' => array($docs, $tests, 'Examples unitTests changelog.txt'),
'phpoffice/phpspreadsheet' => array($docs, $tests, 'samples'),
'phpseclib/phpseclib' => array($docs, $tests, 'build'),
'predis/predis' => array($docs, $tests, 'bin'),
'psr/log' => array($docs, $tests),
'psy/psysh' => array($docs, $tests),
'quickbooks/v3-php-sdk' => array($docs, $tests, 'docs docs/* src/XSD2PHP/test src/XSD2PHP/test/*'),
'rcrowe/twigbridge' => array($docs, $tests),
'simplepie/simplepie' => array($docs, $tests, 'build compatibility_test ROADMAP.md'),
'stack/builder' => array($docs, $tests),
'swiftmailer/swiftmailer' => array($docs, $tests, 'build* notes test-suite create_pear_package.php'),
'symfony/browser-kit' => array($docs, $tests),
'symfony/class-loader' => array($docs, $tests),
'symfony/console' => array($docs, $tests),
'symfony/css-selector' => array($docs, $tests),
'symfony/debug' => array($docs, $tests),
'symfony/dom-crawler' => array($docs, $tests),
'symfony/event-dispatcher' => array($docs, $tests),
'symfony/filesystem' => array($docs, $tests),
'symfony/finder' => array($docs, $tests),
'symfony/http-foundation' => array($docs, $tests),
'symfony/http-kernel' => array($docs, $tests),
'symfony/process' => array($docs, $tests),
'symfony/routing' => array($docs, $tests),
'symfony/security' => array($docs, $tests),
'symfony/security-core' => array($docs, $tests),
'symfony/translation' => array($docs, $tests),
'symfony/var-dumper' => array($docs, $tests),
'tijsverkoyen/css-to-inline-styles' => array($docs, $tests),
'twig/twig' => array($docs, $tests),
'venturecraft/revisionable' => array($docs, $tests),
'vlucas/phpdotenv' => array($docs, $tests),
'willdurand/geocoder' => array($docs, $tests),
'willdurand/geocoder' => array($docs, $tests),
);
}
}
gitextract_lijcdq0e/
├── .gitignore
├── README.md
├── composer.json
└── src/
├── CleanupPlugin.php
└── CleanupRules.php
SYMBOL INDEX (11 symbols across 2 files)
FILE: src/CleanupPlugin.php
class CleanupPlugin (line 15) | class CleanupPlugin implements PluginInterface, EventSubscriberInterface
method activate (line 31) | public function activate(Composer $composer, IOInterface $io)
method deactivate (line 43) | public function deactivate(Composer $composer, IOInterface $io)
method uninstall (line 51) | public function uninstall(Composer $composer, IOInterface $io)
method getSubscribedEvents (line 59) | public static function getSubscribedEvents()
method onPostPackageInstall (line 76) | public function onPostPackageInstall(PackageEvent $event)
method onPostPackageUpdate (line 87) | public function onPostPackageUpdate(PackageEvent $event)
method onPostInstallUpdateCmd (line 100) | public function onPostInstallUpdateCmd(CommandEvent $event)
method cleanPackage (line 119) | protected function cleanPackage(BasePackage $package)
FILE: src/CleanupRules.php
class CleanupRules (line 5) | class CleanupRules
method getRules (line 7) | public static function getRules()
Condensed preview — 5 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (15K chars).
[
{
"path": ".gitignore",
"chars": 56,
"preview": "/vendor\r\n/.idea\r\ncomposer.phar\r\ncomposer.lock\r\n.DS_Store"
},
{
"path": "README.md",
"chars": 1541,
"preview": "Composer Cleanup Plugin\n=======================\n\nRemove tests & documentation from the vendor dir. Based on [laravel-ven"
},
{
"path": "composer.json",
"chars": 683,
"preview": "{\n \"name\": \"barryvdh/composer-cleanup-plugin\",\n \"type\": \"composer-plugin\",\n \"description\": \"A composer cleanup "
},
{
"path": "src/CleanupPlugin.php",
"chars": 4501,
"preview": "<?php\n\nnamespace Barryvdh\\Composer;\n\nuse Composer\\Composer;\nuse Composer\\EventDispatcher\\EventSubscriberInterface;\nuse C"
},
{
"path": "src/CleanupRules.php",
"chars": 7756,
"preview": "<?php\n\nnamespace Barryvdh\\Composer;\n\nclass CleanupRules\n{\n public static function getRules()\n {\n // Default"
}
]
About this extraction
This page contains the full source code of the barryvdh/composer-cleanup-plugin GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 5 files (14.2 KB), approximately 3.5k tokens, and a symbol index with 11 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.