Skip to content

Commit

Permalink
Merge pull request #17 from uWaterloo/additional-packageTypes
Browse files Browse the repository at this point in the history
Allow defining additional package types
  • Loading branch information
jhedstrom authored Mar 20, 2019
2 parents 9fd1846 + f9e13ee commit b17a052
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ This is only required when downloading projects that aren't full releases (for i
## Installation

`composer require drupal-composer/info-rewrite:~1.0`

## Configuration

By default, this plugin only acts on packages of type `drupal-core`, `drupal-module`, `drupal-profile`, and `drupal-theme` (see DrupalInfo::$packageTypes). You can add additional package types in your `composer.json` file. Add to the `config` array an entry with key `drupal-info-rewrite--additional-packageTypes` and make its value be an array of strings which are the additional types you would like to add.
12 changes: 10 additions & 2 deletions src/DrupalInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DrupalInfo implements PluginInterface, EventSubscriberInterface
/**
* Package types to process.
*/
protected static $packageTypes = [
protected $packageTypes = [
'drupal-core',
'drupal-module',
'drupal-profile',
Expand All @@ -51,6 +51,14 @@ public function activate(Composer $composer, IOInterface $io)
{
$this->composer = $composer;
$this->io = $io;

$config = $this->composer->getConfig();
if ($config) {
$additionalPackageTypes = $config->get('drupal-info-rewrite--additional-packageTypes');
if (is_array($additionalPackageTypes)) {
$this->packageTypes = array_merge($this->packageTypes, $additionalPackageTypes);
}
}
}

/**
Expand Down Expand Up @@ -248,7 +256,7 @@ protected function findPackage(PackageInterface $package)
*/
protected function processPackage(PackageInterface $package)
{
return in_array($package->getType(), static::$packageTypes);
return in_array($package->getType(), $this->packageTypes);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/DrupalInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public function testInstallOperationWriteInfoFiles()
$manager->getInstaller('drupal-module')->willReturn($installer->reveal());
$this->composer = $this->prophesize(Composer::class);
$this->composer->getInstallationManager()->willReturn($manager->reveal());
$this->composer->getConfig()->willReturn(null);

$this->fixture->activate(
$this->composer->reveal(),
Expand Down Expand Up @@ -169,6 +170,7 @@ public function testNoInfoFile()
$manager->getInstaller('drupal-module')->willReturn($installer->reveal());
$this->composer = $this->prophesize(Composer::class);
$this->composer->getInstallationManager()->willReturn($manager->reveal());
$this->composer->getConfig()->willReturn(null);
$this->io->write('<info>No info files found for foo</info>')->shouldBeCalled();
$this->io->isVerbose()->willReturn(true);
$this->fixture->activate(
Expand Down Expand Up @@ -242,6 +244,7 @@ public function testRollbackRewrite()
$this->composer = $this->prophesize(Composer::class);
$this->composer->getRepositoryManager()->willReturn($manager->reveal());
$this->composer->getInstallationManager()->willReturn($location_manager->reveal());
$this->composer->getConfig()->willReturn(null);

$this->fixture->activate(
$this->composer->reveal(),
Expand Down

0 comments on commit b17a052

Please sign in to comment.