Skip to content

Commit 2ff8465

Browse files
committed
Merge branch '1.x' into 2.x
* 1.x: Keep existing constraints in package.json Fix testMemoryLimit on PHP installed using Nix Fix recipe history url Remove deprecation warnings Fix testMemoryLimit on PHP installed using Nix
2 parents 52baff1 + 51077ed commit 2ff8465

File tree

6 files changed

+71
-5
lines changed

6 files changed

+71
-5
lines changed

src/Command/RecipesCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ private function displayPackageInformation(Recipe $recipe)
165165
$lockBranch = $recipeLock['recipe']['branch'] ?? null;
166166
$lockVersion = $recipeLock['recipe']['version'] ?? $recipeLock['version'] ?? null;
167167

168+
if ('master' === $lockBranch && \in_array($lockRepo, ['github.com/symfony/recipes', 'github.com/symfony/recipes-contrib'])) {
169+
$lockBranch = 'main';
170+
}
171+
168172
$status = '<comment>up to date</comment>';
169173
if ($recipe->isAuto()) {
170174
$status = '<comment>auto-generated recipe</comment>';

src/Configurator/DockerComposeConfigurator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ private function getContentsAfterApplyingRecipe(string $rootDir, Recipe $recipe,
315315
return [];
316316
}
317317

318-
$files = array_map(function ($file) use ($rootDir) {
318+
$files = array_filter(array_map(function ($file) use ($rootDir) {
319319
return $this->findDockerComposeFile($rootDir, $file);
320-
}, array_keys($config));
320+
}, array_keys($config)));
321321

322322
$originalContents = [];
323323
foreach ($files as $file) {

src/PackageJsonSynchronizer.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Composer\Json\JsonFile;
1515
use Composer\Json\JsonManipulator;
16+
use Composer\Semver\VersionParser;
1617
use Seld\JsonLint\ParsingException;
1718

1819
/**
@@ -23,11 +24,13 @@ class PackageJsonSynchronizer
2324
{
2425
private $rootDir;
2526
private $vendorDir;
27+
private $versionParser;
2628

2729
public function __construct(string $rootDir, string $vendorDir = 'vendor')
2830
{
2931
$this->rootDir = $rootDir;
3032
$this->vendorDir = $vendorDir;
33+
$this->versionParser = new VersionParser();
3134
}
3235

3336
public function shouldSynchronize(): bool
@@ -136,8 +139,10 @@ private function registerDependencies(array $flexDependencies): bool
136139
$content['devDependencies'][$dependency] = $constraint;
137140
$didChangePackageJson = true;
138141
} elseif ($constraint !== $content[$parentNode][$dependency]) {
139-
$content[$parentNode][$dependency] = $constraint;
140-
$didChangePackageJson = true;
142+
if ($this->shouldUpdateConstraint($content[$parentNode][$dependency], $constraint)) {
143+
$content[$parentNode][$dependency] = $constraint;
144+
$didChangePackageJson = true;
145+
}
141146
}
142147
}
143148

@@ -163,6 +168,18 @@ private function registerDependencies(array $flexDependencies): bool
163168
return $didChangePackageJson;
164169
}
165170

171+
private function shouldUpdateConstraint(string $existingConstraint, string $constraint)
172+
{
173+
try {
174+
$existingConstraint = $this->versionParser->parseConstraints($existingConstraint);
175+
$constraint = $this->versionParser->parseConstraints($constraint);
176+
177+
return !$existingConstraint->matches($constraint);
178+
} catch (\UnexpectedValueException $e) {
179+
return true;
180+
}
181+
}
182+
166183
private function registerWebpackResources(array $phpPackages)
167184
{
168185
if (!file_exists($controllersJsonPath = $this->rootDir.'/assets/controllers.json')) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "symfony/fixture",
3+
"devDependencies": {
4+
"@hotcookies": "^2",
5+
"@hotdogs": "^1.9",
6+
"@symfony/existing-package": "file:vendor/symfony/existing-package/Resources/assets"
7+
},
8+
"browserslist": [
9+
"defaults"
10+
]
11+
}

tests/PackageJsonSynchronizerTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,34 @@ public function testExistingElevatedPackage()
245245
json_decode(file_get_contents($this->tempDir.'/package.json'), true)
246246
);
247247
}
248+
249+
public function testStricterConstraintsAreKeptNonMatchingAreReplaced()
250+
{
251+
(new Filesystem())->copy($this->tempDir.'/stricter_constraints_package.json', $this->tempDir.'/package.json', true);
252+
253+
$this->synchronizer->synchronize([
254+
[
255+
'name' => 'symfony/existing-package',
256+
'keywords' => ['symfony-ux'],
257+
],
258+
]);
259+
260+
// Should keep existing constraints when stricter than packages ones
261+
$this->assertSame(
262+
[
263+
'name' => 'symfony/fixture',
264+
'devDependencies' => [
265+
// this satisfies the constraint, so it's kept
266+
'@hotcookies' => '^2',
267+
// this was too low, so it's replaced
268+
'@hotdogs' => '^2',
269+
'@symfony/existing-package' => 'file:vendor/symfony/existing-package/Resources/assets',
270+
],
271+
'browserslist' => [
272+
'defaults',
273+
],
274+
],
275+
json_decode(file_get_contents($this->tempDir.'/package.json'), true)
276+
);
277+
}
248278
}

tests/ScriptExecutorTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ public function testMemoryLimit(): void
3939

4040
$arguments = $phpFinder->findArguments();
4141
$ini = php_ini_loaded_file();
42-
$arguments[] = "--php-ini={$ini}";
42+
43+
if (false !== $ini) {
44+
$arguments[] = "--php-ini={$ini}";
45+
}
46+
4347
$arguments[] = "-d memory_limit={$memoryLimit}";
4448

4549
$phpArgs = implode(' ', array_map([ProcessExecutor::class, 'escape'], $arguments));

0 commit comments

Comments
 (0)