Skip to content
Merged
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
17 changes: 9 additions & 8 deletions src/FileSystem/ComposerJsonPackageVersionUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ public static function update(string $composerJsonContents, string $packageName,
sprintf('"%s": "%s"', $packageName, $newVersion)
);

$suggestContent = Strings::match($composerJsonContents, '#"suggest"\s*:\s*{[^}]*}#');

if ($suggestContent !== null) {
$allChanges = Strings::replace(
$allChanges,
'#"suggest"\s*:\s*{[^}]*}#',
$suggestContent[0]
);
$skippedKeys = ['suggest', 'replace', 'provide', 'conflict'];

foreach ($skippedKeys as $skippedKey) {
$regexKeyContent = sprintf('#"%s"\s*:\s*{[^}]*}#', $skippedKey);
$skippedContent = Strings::match($composerJsonContents, $regexKeyContent);

if ($skippedContent !== null) {
$allChanges = Strings::replace($allChanges, $regexKeyContent, $skippedContent[0]);
}
}

return $allChanges;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"require-dev": {
"illuminate/container": "^9.0"
},
"conflict": {
"illuminate/container": "<9.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,35 @@ public function testSkipSuggestChange(string $file, string $changedFileContent):
$this->assertSame($changedFileContent, $changedPackageVersionsResult->getComposerJsonContents());
}

public function testSkipConflictChange(): void
{
$composerJsonContents = FileSystem::read(__DIR__ . '/Fixture/skip-conflict.json');

$changedPackageVersionsResult = $this->raiseToInstalledComposerProcessor->process($composerJsonContents);

$changedPackageVersion = $changedPackageVersionsResult->getChangedPackageVersions()[0];

$this->assertSame('illuminate/container', $changedPackageVersion->getPackageName());
$this->assertSame('^9.0', $changedPackageVersion->getOldVersion());
$this->assertSame('^12.19', $changedPackageVersion->getNewVersion());

$this->assertSame(
<<<'JSON'
{
"require-dev": {
"illuminate/container": "^12.19"
},
"conflict": {
"illuminate/container": "<9.0"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be <12.19, but for now, skip is better than update both require-dev and conflict to ^12.19 which make unable to be installed as conflict using ^.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
}

JSON
,
$changedPackageVersionsResult->getComposerJsonContents()
);
}

public function testSinglePiped(): void
{
$composerJsonContents = FileSystem::read(__DIR__ . '/Fixture/single-piped.json');
Expand Down