Skip to content

Ignore certain require'd packages #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ Usage
"recurse": true,
"replace": false,
"ignore-duplicates": false,
"ignore-require": [
"vendor/package",
"other-vendor/*"
],
"merge-dev": true,
"merge-extra": false,
"merge-extra-deep": false,
Expand Down Expand Up @@ -145,6 +149,14 @@ alphabetical order.
Note: `"replace": true` and `"ignore-duplicates": true` modes are mutually
exclusive. If both are set, `"ignore-duplicates": true` will be used.

### ignore-require

In some cases you might want to ignore requirements imposed by included
configuration files (e.g. those requirements are fulfilled by other included
configuration files). This option allows you to set a list of composer-style
package name specifications that will get ignored when assembling the
combined final require statements.

### merge-dev

By default, `autoload-dev` and `require-dev` sections of included files are
Expand Down
12 changes: 12 additions & 0 deletions src/Merge/ExtraPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,18 @@ protected function mergeRequires(
return;
}

$ignoreRequire = $state->getIgnoreRequire();
if (!empty($ignoreRequire)) {
$requires = array_filter($requires, function ($name) use ($ignoreRequire) {
foreach ($ignoreRequire as $ignorePattern) {
if (fnmatch($ignorePattern, $name)) {
return false;
}
}
return true;
}, ARRAY_FILTER_USE_KEY);
}

$this->mergeStabilityFlags($root, $requires);

$requires = $this->replaceSelfVersionDependencies(
Expand Down
18 changes: 18 additions & 0 deletions src/Merge/PluginState.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class PluginState
*/
protected $ignore = false;

/**
* @var array $ignoreRequire
*/
protected $ignoreRequire = array();

/**
* Whether to merge the -dev sections.
* @var bool $mergeDev
Expand Down Expand Up @@ -145,6 +150,7 @@ public function loadSettings()
'recurse' => true,
'replace' => false,
'ignore-duplicates' => false,
'ignore-require' => array(),
'merge-dev' => true,
'merge-extra' => false,
'merge-extra-deep' => false,
Expand All @@ -160,6 +166,8 @@ public function loadSettings()
$this->recurse = (bool)$config['recurse'];
$this->replace = (bool)$config['replace'];
$this->ignore = (bool)$config['ignore-duplicates'];
$this->ignoreRequire = (is_array($config['ignore-require'])) ?
$config['ignore-require'] : array($config['ignore-require']);
$this->mergeDev = (bool)$config['merge-dev'];
$this->mergeExtra = (bool)$config['merge-extra'];
$this->mergeExtraDeep = (bool)$config['merge-extra-deep'];
Expand Down Expand Up @@ -363,6 +371,16 @@ public function ignoreDuplicateLinks()
return $this->ignore;
}

/**
* Return an array of require package name specifications that should be ignored
*
* @return array
*/
public function getIgnoreRequire()
{
return $this->ignoreRequire;
}

/**
* Should the extra section be merged?
*
Expand Down