mcaskill/composer-exclude-files

Exclude files from autoload_files.php

Installs: 702 204

Dependents: 7

Suggesters: 0

Security: 0

Stars: 35

Watchers: 4

Forks: 5

Open Issues: 0

Type:composer-plugin

v3.0.1 2023-05-24 17:29 UTC

This package is auto-updated.

Last update: 2024-04-08 17:01:29 UTC


README

Build Status Latest Release License

A Composer plugin for excluding files required by packages using the files autoloading mechanism.

This is useful for ignoring files required for bootstrapping a package or that provide PHP functions, for example.

Resolves composer/composer#5029

Installation

The plugin can be installed locally or globally.

composer require mcaskill/composer-exclude-files

As of Composer 2.2.0, for additional security, you should declare the allow-plugins config to allow Composer to run the plugin.

composer config allow-plugins.mcaskill/composer-exclude-files true

Usage

You can only ignore files from the root composer.json. File exclusions of dependencies' composer.json are ignored.

From the root composer.json, add the exclude-from-files property to the extra section. The list of paths must be relative to this composer manifest's vendor directory.

This plugin is invoked before the autoloader is dumped, such as with the commands install, update, and dump-autoload.

Example 1: Using illuminate/support
{
    "require": {
        "illuminate/support": "^9.6"
    },
    "extra": {
        "exclude-from-files": [
            "illuminate/support/helpers.php"
        ]
    },
    "config": {
        "allow-plugins": {
            "mcaskill/composer-exclude-files": true
        }
    }
}
Example 2: Using laravel/framework
{
    "require": {
        "laravel/framework": "^9.6"
    },
    "extra": {
        "exclude-from-files": [
            "laravel/framework/src/Illuminate/Foundation/helpers.php"
        ]
    },
    "config": {
        "allow-plugins": {
            "mcaskill/composer-exclude-files": true
        }
    }
}

The plugin will traverse each package and remove all files in the paths configured above from the prepared autoload map. The vendor files themselves are not removed. The root package is ignored.

The resulting effect is the specified files are never included in vendor/composer/autoload_files.php.

License

This is licensed under MIT.