Skip to content
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

add merge-replace config #233

Merged
merged 3 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Usage
"merge-dev": true,
"merge-extra": false,
"merge-extra-deep": false,
"merge-replace": true,
"merge-scripts": false
}
}
Expand Down Expand Up @@ -180,6 +181,11 @@ they are processed by Composer.
Note that `merge-plugin` sections are excluded from the merge process, but are
always processed by the plugin unless [recursion](#recurse) is disabled.

### merge-replace

By default, the `replace` section of included files are merged.
A `"merge-replace": false` setting will disable this behavior.

### merge-scripts

A `"merge-scripts": true` setting enables merging the contents of the
Expand Down
6 changes: 5 additions & 1 deletion src/ExtraPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ public function mergeInto(RootPackageInterface $root, PluginState $state)
$this->mergeRequires('require', $root, $state);

$this->mergePackageLinks('conflict', $root);
$this->mergePackageLinks('replace', $root);

if ($state->shouldMergeReplace()) {
$this->mergePackageLinks('replace', $root);
}

$this->mergePackageLinks('provide', $root);

$this->mergeSuggests($root);
Expand Down
21 changes: 21 additions & 0 deletions src/PluginState.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ class PluginState
*/
protected $mergeExtraDeep = false;

/**
* Whether to merge the replace section.
*
* @var bool $mergeReplace
*/
protected $mergeReplace = true;

/**
* Whether to merge the scripts section.
*
Expand Down Expand Up @@ -160,6 +167,7 @@ public function loadSettings()
'merge-dev' => true,
'merge-extra' => false,
'merge-extra-deep' => false,
'merge-replace' => true,
'merge-scripts' => false,
],
$extra['merge-plugin'] ?? []
Expand All @@ -175,6 +183,7 @@ public function loadSettings()
$this->mergeDev = (bool)$config['merge-dev'];
$this->mergeExtra = (bool)$config['merge-extra'];
$this->mergeExtraDeep = (bool)$config['merge-extra-deep'];
$this->mergeReplace = (bool)$config['merge-replace'];
$this->mergeScripts = (bool)$config['merge-scripts'];
}

Expand Down Expand Up @@ -386,6 +395,18 @@ public function shouldMergeExtraDeep()
return $this->mergeExtraDeep;
}

/**
* Should the replace section be merged?
*
* By default, the replace section is merged.
*
* @return bool
*/
public function shouldMergeReplace()
{
return $this->mergeReplace;
}

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