Skip to content

Commit

Permalink
fix: link command with replace (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka authored Oct 4, 2024
1 parent 3e16514 commit f94a9cd
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/Command/LinkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
final class LinkCommand extends BaseCommand
{
public const REQUIRE_KEYS = ['require', 'require-dev'];
public const REQUIRE_KEYS = ['require', 'require-dev', 'replace'];
use ReadJsonFileTrait;

/**
Expand Down Expand Up @@ -86,7 +86,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$dependencies = [
'require' => $this->mapRequireDependencies($composer, $config->composerFiles, $output),
'require-dev' => $this->mapRequireDevDependencies($composer, $config->composerFiles, $output)
'require-dev' => $this->mapRequireDevDependencies($composer, $config->composerFiles, $output),
'replace' => $this->mapReplaceDependencies($composer, $config->composerFiles, $output)
];

foreach ($dependencies['require'] as $dependency) {
Expand All @@ -96,8 +97,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($dependencies['require-dev'] as $dependency) {
static::$fileContents[$composerFile]['require-dev'][$dependency] = '@dev';
}

foreach ($dependencies['replace'] as $dependency) {
static::$fileContents[$composerFile]['require-dev'][$dependency] = '@dev';
}


foreach (array_merge($dependencies['require'], $dependencies['require-dev']) as $dependency) {
foreach (array_merge($dependencies['require'], $dependencies['require-dev'], $dependencies['replace']) as $dependency) {
foreach ($config->composerFiles as $f) {
// mapDependencies reads the composer.json contents, if it's not there we don't need to map this dependency
if (!isset(static::$fileContents[$f])) {
Expand Down Expand Up @@ -166,6 +172,16 @@ private function mapRequireDevDependencies(array $composer, array $composerFiles
return array_unique(iterator_to_array($this->mapDependencies($composer, $composerFiles, 'require-dev', $output)));
}

/**
* @param ComposerJsonType $composer
* @param array<string, string> $composerFiles
*
* @return array<string>
*/
private function mapReplaceDependencies(array $composer, array $composerFiles, OutputInterface $output): array {
return array_unique(iterator_to_array($this->mapDependencies($composer, $composerFiles, 'replace', $output)));
}

/**
* @param value-of<self::REQUIRE_KEYS> $key
* @param ComposerJsonType $composer
Expand Down

0 comments on commit f94a9cd

Please sign in to comment.