Skip to content

Commit

Permalink
feat: add ability to skip package.json synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
wuchen90 authored and fabpot committed Mar 3, 2025
1 parent 0491870 commit 791e814
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Flex.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,12 @@ public function finish(string $rootDir, ?string $originalComposerJsonHash = null

private function synchronizePackageJson(string $rootDir)
{
if (!($this->composer->getPackage()->getExtra()['symfony/flex']['synchronize_package_json'] ?? true)) {
$this->io->writeError('<info>Skip synchronizing package.json with PHP packages</>');

return;
}

if (!$this->downloader->isEnabled()) {
$this->io->writeError('<warning>Synchronizing package.json is disabled: "symfony/flex" not found in the root composer.json</>');

Expand Down
41 changes: 41 additions & 0 deletions tests/FlexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,47 @@ class_exists(LockArrayRepository::class) ? LockArrayRepository::class : Reposito
$this->assertSame('2.3', $recipes['doctrine/doctrine-bundle']->getVersion());
}

public function testInstallWithPackageJsonToSynchronizeSkipped()
{
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE);
$rootPackage = $this->mockRootPackage([
'symfony/flex' => ['synchronize_package_json' => false],
]);

$flex = $this->mockFlex($io, $rootPackage);
$flex->install($this->mockFlexEvent());

$this->assertStringContainsString(
'Skip synchronizing package.json with PHP packages',
$io->getOutput(),
);
}

/**
* @dataProvider getDataForTestInstallWithoutPackageJsonToSynchronizeSkipped
*/
public function testInstallWithoutPackageJsonToSynchronizeSkipped(array $extra)
{
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE);
$rootPackage = $this->mockRootPackage($extra);

$flex = $this->mockFlex($io, $rootPackage);
$flex->install($this->mockFlexEvent());

$this->assertStringNotContainsString(
'Skip synchronizing package.json with PHP packages',
$io->getOutput(),
);
}

public function getDataForTestInstallWithoutPackageJsonToSynchronizeSkipped(): array
{
return [
'default_behavior' => [[]],
'with_config_explicitly_set' => [['symfony/flex' => ['synchronize_package_json' => true]]],
];
}

public static function getTestPackages(): array
{
return [
Expand Down

0 comments on commit 791e814

Please sign in to comment.