From 5b8dfa372882dc8d08766d4425e7909a43905a66 Mon Sep 17 00:00:00 2001 From: Soner Sayakci Date: Tue, 8 Nov 2022 13:37:49 +0100 Subject: [PATCH 1/5] Fix testMemoryLimit on PHP installed using Nix --- tests/ScriptExecutorTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/ScriptExecutorTest.php b/tests/ScriptExecutorTest.php index 211910ac4..1b6413122 100644 --- a/tests/ScriptExecutorTest.php +++ b/tests/ScriptExecutorTest.php @@ -39,7 +39,11 @@ public function testMemoryLimit(): void $arguments = $phpFinder->findArguments(); $ini = php_ini_loaded_file(); - $arguments[] = "--php-ini={$ini}"; + + if (false !== $ini) { + $arguments[] = "--php-ini={$ini}"; + } + $arguments[] = "-d memory_limit={$memoryLimit}"; $phpArgs = implode(' ', array_map([ProcessExecutor::class, 'escape'], $arguments)); From 5616f6119e83c753bf1e34f7d352208e12db7675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20H=C3=A9lias?= Date: Mon, 23 Jan 2023 11:43:16 +0100 Subject: [PATCH 2/5] Remove deprecation warnings --- src/Configurator/DockerComposeConfigurator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Configurator/DockerComposeConfigurator.php b/src/Configurator/DockerComposeConfigurator.php index 89ca30474..4bc2f2c75 100644 --- a/src/Configurator/DockerComposeConfigurator.php +++ b/src/Configurator/DockerComposeConfigurator.php @@ -315,9 +315,9 @@ private function getContentsAfterApplyingRecipe(string $rootDir, Recipe $recipe, return []; } - $files = array_map(function ($file) use ($rootDir) { + $files = array_filter(array_map(function ($file) use ($rootDir) { return $this->findDockerComposeFile($rootDir, $file); - }, array_keys($config)); + }, array_keys($config))); $originalContents = []; foreach ($files as $file) { From 2aa65bb976a45c89daf578cdcfa21dc4239da97b Mon Sep 17 00:00:00 2001 From: Jan Rosier Date: Mon, 23 Jan 2023 12:45:21 +0100 Subject: [PATCH 3/5] Fix recipe history url --- src/Command/RecipesCommand.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Command/RecipesCommand.php b/src/Command/RecipesCommand.php index 022fe52e5..b8aedbd55 100644 --- a/src/Command/RecipesCommand.php +++ b/src/Command/RecipesCommand.php @@ -165,6 +165,10 @@ private function displayPackageInformation(Recipe $recipe) $lockBranch = $recipeLock['recipe']['branch'] ?? null; $lockVersion = $recipeLock['recipe']['version'] ?? $recipeLock['version'] ?? null; + if ('master' === $lockBranch && \in_array($lockRepo, ['github.com/symfony/recipes', 'github.com/symfony/recipes-contrib'])) { + $lockBranch = 'main'; + } + $status = 'up to date'; if ($recipe->isAuto()) { $status = 'auto-generated recipe'; From dd579194e49f0cd461b4a762920abc64bfeddb1e Mon Sep 17 00:00:00 2001 From: Soner Sayakci Date: Tue, 8 Nov 2022 13:37:49 +0100 Subject: [PATCH 4/5] Fix testMemoryLimit on PHP installed using Nix --- tests/ScriptExecutorTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/ScriptExecutorTest.php b/tests/ScriptExecutorTest.php index 211910ac4..1b6413122 100644 --- a/tests/ScriptExecutorTest.php +++ b/tests/ScriptExecutorTest.php @@ -39,7 +39,11 @@ public function testMemoryLimit(): void $arguments = $phpFinder->findArguments(); $ini = php_ini_loaded_file(); - $arguments[] = "--php-ini={$ini}"; + + if (false !== $ini) { + $arguments[] = "--php-ini={$ini}"; + } + $arguments[] = "-d memory_limit={$memoryLimit}"; $phpArgs = implode(' ', array_map([ProcessExecutor::class, 'escape'], $arguments)); From ae95fe1b9d40607ee11af61bac53bdc380a1c64f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Andr=C3=A9?= Date: Thu, 19 Jan 2023 20:44:24 +0100 Subject: [PATCH 5/5] Keep existing constraints in package.json --- src/PackageJsonSynchronizer.php | 21 +++++++++++-- .../stricter_constraints_package.json | 11 +++++++ tests/PackageJsonSynchronizerTest.php | 30 +++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 tests/Fixtures/packageJson/stricter_constraints_package.json diff --git a/src/PackageJsonSynchronizer.php b/src/PackageJsonSynchronizer.php index 7c41b5f70..fb0255d3f 100644 --- a/src/PackageJsonSynchronizer.php +++ b/src/PackageJsonSynchronizer.php @@ -13,6 +13,7 @@ use Composer\Json\JsonFile; use Composer\Json\JsonManipulator; +use Composer\Semver\VersionParser; use Seld\JsonLint\ParsingException; /** @@ -23,11 +24,13 @@ class PackageJsonSynchronizer { private $rootDir; private $vendorDir; + private $versionParser; public function __construct(string $rootDir, string $vendorDir = 'vendor') { $this->rootDir = $rootDir; $this->vendorDir = $vendorDir; + $this->versionParser = new VersionParser(); } public function shouldSynchronize(): bool @@ -136,8 +139,10 @@ private function registerDependencies(array $flexDependencies): bool $content['devDependencies'][$dependency] = $constraint; $didChangePackageJson = true; } elseif ($constraint !== $content[$parentNode][$dependency]) { - $content[$parentNode][$dependency] = $constraint; - $didChangePackageJson = true; + if ($this->shouldUpdateConstraint($content[$parentNode][$dependency], $constraint)) { + $content[$parentNode][$dependency] = $constraint; + $didChangePackageJson = true; + } } } @@ -163,6 +168,18 @@ private function registerDependencies(array $flexDependencies): bool return $didChangePackageJson; } + private function shouldUpdateConstraint(string $existingConstraint, string $constraint) + { + try { + $existingConstraint = $this->versionParser->parseConstraints($existingConstraint); + $constraint = $this->versionParser->parseConstraints($constraint); + + return !$existingConstraint->matches($constraint); + } catch (\UnexpectedValueException $e) { + return true; + } + } + private function registerWebpackResources(array $phpPackages) { if (!file_exists($controllersJsonPath = $this->rootDir.'/assets/controllers.json')) { diff --git a/tests/Fixtures/packageJson/stricter_constraints_package.json b/tests/Fixtures/packageJson/stricter_constraints_package.json new file mode 100644 index 000000000..cf3654fda --- /dev/null +++ b/tests/Fixtures/packageJson/stricter_constraints_package.json @@ -0,0 +1,11 @@ +{ + "name": "symfony/fixture", + "devDependencies": { + "@hotcookies": "^2", + "@hotdogs": "^1.9", + "@symfony/existing-package": "file:vendor/symfony/existing-package/Resources/assets" + }, + "browserslist": [ + "defaults" + ] +} diff --git a/tests/PackageJsonSynchronizerTest.php b/tests/PackageJsonSynchronizerTest.php index 85349b77b..36472e25d 100644 --- a/tests/PackageJsonSynchronizerTest.php +++ b/tests/PackageJsonSynchronizerTest.php @@ -245,4 +245,34 @@ public function testExistingElevatedPackage() json_decode(file_get_contents($this->tempDir.'/package.json'), true) ); } + + public function testStricterConstraintsAreKeptNonMatchingAreReplaced() + { + (new Filesystem())->copy($this->tempDir.'/stricter_constraints_package.json', $this->tempDir.'/package.json', true); + + $this->synchronizer->synchronize([ + [ + 'name' => 'symfony/existing-package', + 'keywords' => ['symfony-ux'], + ], + ]); + + // Should keep existing constraints when stricter than packages ones + $this->assertSame( + [ + 'name' => 'symfony/fixture', + 'devDependencies' => [ + // this satisfies the constraint, so it's kept + '@hotcookies' => '^2', + // this was too low, so it's replaced + '@hotdogs' => '^2', + '@symfony/existing-package' => 'file:vendor/symfony/existing-package/Resources/assets', + ], + 'browserslist' => [ + 'defaults', + ], + ], + json_decode(file_get_contents($this->tempDir.'/package.json'), true) + ); + } }