Skip to content

Commit 9b8e4cb

Browse files
committed
feat: add ability to skip package.json synchronization
1 parent 92f4fba commit 9b8e4cb

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/Flex.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,14 @@ public function finish(string $rootDir, ?string $originalComposerJsonHash = null
502502

503503
private function synchronizePackageJson(string $rootDir)
504504
{
505+
$synchronizePackageJson = $this->composer->getPackage()->getExtra()['symfony/flex']['synchronize_package_json'] ?? true;
506+
507+
if (!$synchronizePackageJson) {
508+
$this->io->writeError('<info>Skip synchronizing package.json with PHP packages</>');
509+
510+
return;
511+
}
512+
505513
$rootDir = realpath($rootDir);
506514
$vendorDir = trim((new Filesystem())->makePathRelative($this->config->get('vendor-dir'), $rootDir), '/');
507515

tests/FlexTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,47 @@ class_exists(LockArrayRepository::class) ? LockArrayRepository::class : Reposito
310310
$this->assertSame('2.3', $recipes['doctrine/doctrine-bundle']->getVersion());
311311
}
312312

313+
public function testInstallWithPackageJsonToSynchronizeSkipped()
314+
{
315+
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE);
316+
$rootPackage = $this->mockRootPackage([
317+
'symfony/flex' => ['synchronize_package_json' => false],
318+
]);
319+
320+
$flex = $this->mockFlex($io, $rootPackage);
321+
$flex->install($this->mockFlexEvent());
322+
323+
$this->assertStringContainsString(
324+
'Skip synchronizing package.json with PHP packages',
325+
str_replace("\r\n", "\n", $io->getOutput()),
326+
);
327+
}
328+
329+
/**
330+
* @dataProvider getDataForTestInstallWithoutPackageJsonToSynchronizeSkipped
331+
*/
332+
public function testInstallWithoutPackageJsonToSynchronizeSkipped(array $extra)
333+
{
334+
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE);
335+
$rootPackage = $this->mockRootPackage($extra);
336+
337+
$flex = $this->mockFlex($io, $rootPackage);
338+
$flex->install($this->mockFlexEvent());
339+
340+
$this->assertStringNotContainsString(
341+
'Skip synchronizing package.json with PHP packages',
342+
str_replace("\r\n", "\n", $io->getOutput()),
343+
);
344+
}
345+
346+
public function getDataForTestInstallWithoutPackageJsonToSynchronizeSkipped(): array
347+
{
348+
return [
349+
'default_behavior' => [[]],
350+
'with_config_explicitly_set' => [['symfony/flex' => ['synchronize_package_json' => true]]],
351+
];
352+
}
353+
313354
public static function getTestPackages(): array
314355
{
315356
return [

0 commit comments

Comments
 (0)