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 committed Nov 29, 2024
1 parent 92f4fba commit 9b8e4cb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Flex.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,14 @@ public function finish(string $rootDir, ?string $originalComposerJsonHash = null

private function synchronizePackageJson(string $rootDir)
{
$synchronizePackageJson = $this->composer->getPackage()->getExtra()['symfony/flex']['synchronize_package_json'] ?? true;

if (!$synchronizePackageJson) {
$this->io->writeError('<info>Skip synchronizing package.json with PHP packages</>');

return;
}

$rootDir = realpath($rootDir);
$vendorDir = trim((new Filesystem())->makePathRelative($this->config->get('vendor-dir'), $rootDir), '/');

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',
str_replace("\r\n", "\n", $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',
str_replace("\r\n", "\n", $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 9b8e4cb

Please sign in to comment.