function Composer::vendorTestCodeCleanup

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Composer/Composer.php \Drupal\Core\Composer\Composer::vendorTestCodeCleanup()

Remove possibly problematic test files from vendored projects.

Parameters

\Composer\Installer\PackageEvent $event: A PackageEvent object to get the configured composer vendor directories from.

Deprecated

in drupal:9.5.0 and is removed from drupal:10.0.0. Any "scripts" section mentioning this in composer.json can be removed and replaced with the drupal/core-vendor-hardening Composer plugin, as needed.

See also

https://www.drupal.org/node/3260624

1 call to Composer::vendorTestCodeCleanup()
ComposerDeprecationTest::testVendorTestCodeCleanup in core/tests/Drupal/Tests/Core/Composer/ComposerDeprecationTest.php
@covers ::vendorTestCodeCleanup @group legacy

File

core/lib/Drupal/Core/Composer/Composer.php, line 192

Class

Composer
Provides static functions for composer script events.

Namespace

Drupal\Core\Composer

Code

public static function vendorTestCodeCleanup(PackageEvent $event) {
    trigger_error('Calling ' . __METHOD__ . ' from composer.json is deprecated in drupal:9.5.0 and is removed from drupal:10.0.0. Any "scripts" section mentioning this in composer.json can be removed and replaced with the drupal/core-vendor-hardening Composer plugin, as needed. See https://www.drupal.org/node/3260624', E_USER_DEPRECATED);
    $vendor_dir = $event->getComposer()
        ->getConfig()
        ->get('vendor-dir');
    $io = $event->getIO();
    $op = $event->getOperation();
    if ($op instanceof UpdateOperation) {
        $package = $op->getTargetPackage();
    }
    else {
        $package = $op->getPackage();
    }
    $package_key = static::findPackageKey($package->getName());
    $message = sprintf("    Processing <comment>%s</comment>", $package->getPrettyName());
    if ($io->isVeryVerbose()) {
        $io->write($message);
    }
    if ($package_key) {
        foreach (static::$packageToCleanup[$package_key] as $path) {
            $dir_to_remove = $vendor_dir . '/' . $package_key . '/' . $path;
            $print_message = $io->isVeryVerbose();
            if (is_dir($dir_to_remove)) {
                if (static::deleteRecursive($dir_to_remove)) {
                    $message = sprintf("      <info>Removing directory '%s'</info>", $path);
                }
                else {
                    // Always display a message if this fails as it means something has
                    // gone wrong. Therefore the message has to include the package name
                    // as the first informational message might not exist.
                    $print_message = TRUE;
                    $message = sprintf("      <error>Failure removing directory '%s'</error> in package <comment>%s</comment>.", $path, $package->getPrettyName());
                }
            }
            else {
                // If the package has changed or the --prefer-dist version does not
                // include the directory this is not an error.
                $message = sprintf("      Directory '%s' does not exist", $path);
            }
            if ($print_message) {
                $io->write($message);
            }
        }
        if ($io->isVeryVerbose()) {
            // Add a new line to separate this output from the next package.
            $io->write("");
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.