Skip to content

Commit

Permalink
feature #1032 feat: add ability to skip package.json synchronization …
Browse files Browse the repository at this point in the history
…(wuchen90)

This PR was submitted for the 2.x branch but it was merged into the 1.x branch instead.

Discussion
----------

feat: add ability to skip package.json synchronization

For those who doesn't want the package.json synchronization, this PR offers to opt-out this behavior by setting the config below in extra section of composer.json:

```json
{
  "extra": {
    "symfony/flex": {
      "synchronize_package_json": false
    }
  }
}

```

fix #1017

Commits
-------

791e814 feat: add ability to skip package.json synchronization
  • Loading branch information
fabpot committed Mar 3, 2025
2 parents 0491870 + 791e814 commit 5cc9859
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 5cc9859

Please sign in to comment.