Commit 2ffb26b0 authored by catch's avatar catch
Browse files

Issue #3534278 by phenaproxima, longwave, xjm, catch: The vendor hardening...

Issue #3534278 by phenaproxima, longwave, xjm, catch: The vendor hardening plugin should provide a way to skip cleaning certain packages

(cherry picked from commit be8698ac)
parent 6528a0f3
Loading
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -126,6 +126,11 @@ public function getAllCleanupPaths() {
      $this->configData = array_change_key_case($package_config['drupal-core-vendor-hardening'], CASE_LOWER);
    }

    // Find the packages which should not be cleaned up.
    $do_not_clean = array_filter($this->configData, function ($paths) {
      return $paths === FALSE;
    });

    // Ensure the values are arrays.
    $this->configData = array_map(function ($paths) {
      return (array) $paths;
@@ -137,6 +142,10 @@ public function getAllCleanupPaths() {
        $this->configData[$package] ?? [],
        $paths);
    }

    // Remove packages that should not be cleaned up.
    $this->configData = array_diff_key($this->configData, $do_not_clean);

    return $this->configData;
  }

+11 −0
Original line number Diff line number Diff line
@@ -80,3 +80,14 @@ paths specified for this package might look like this:
This would then cause the plugin to try and remove
web/modules/contrib/module_name/tests and
web/modules/contrib/module_name/src/Tests.

The plugin can be configured to NOT clean certain packages. This is not
recommended, but it may be useful for advanced use cases, such as allowing
Drupal to use a copy of Composer installed locally in the project. For
example, to prevent the plugin from cleaning `composer/composer`:

    "extra": {
      "drupal-core-vendor-hardening": {
        "composer/composer": false
      }
    }
+6 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@
use Symfony\Component\Validator\Constraints\Blank;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\Validator\Constraints\IdenticalTo;
use Symfony\Component\Validator\Constraints\Image;
use Symfony\Component\Validator\Constraints\NotBlank;
@@ -118,6 +119,11 @@ public function registerDefinitions() {
      'class' => Choice::class,
      'type' => FALSE,
    ]);
    $this->getDiscovery()->setDefinition('File', [
      'label' => new TranslatableMarkup('File'),
      'class' => File::class,
      'type' => ['string'],
    ]);
    $this->getDiscovery()->setDefinition('Image', [
      'label' => new TranslatableMarkup('Image'),
      'class' => Image::class,
+17 −0
Original line number Diff line number Diff line
@@ -110,4 +110,21 @@ public function testMixedCaseConfigCleanupPackages(): void {
    }
  }

  /**
   * @covers ::getAllCleanupPaths
   */
  public function testSkipClean(): void {
    $root = $this->createMock(RootPackageInterface::class);
    $root->expects($this->once())
      ->method('getExtra')
      ->willReturn([
        'drupal-core-vendor-hardening' => [
          'composer/composer' => FALSE,
        ],
      ]);

    $plugin_config = (new Config($root))->getAllCleanupPaths();
    $this->assertArrayNotHasKey('composer/composer', $plugin_config);
  }

}