Skip to content

Commit 7ed5bfa

Browse files
committed
fix package sorting
1 parent 5cbb480 commit 7ed5bfa

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/PackageJsonSynchronizer.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ private function removePackageJsonLinks(array $packageJson)
6363
}
6464
}
6565

66+
private static function sortPackages(JsonManipulator $manipulator, $subNode)
67+
{
68+
$content = json_decode($manipulator->getContents(), true);
69+
$subNodeContent = $content[$subNode];
70+
ksort($subNodeContent);
71+
72+
return json_encode([$subNode => $subNodeContent]);
73+
}
74+
6675
private function addPackageJsonLink(string $phpPackage)
6776
{
6877
if (!$assetsDir = $this->resolveAssetsDir($phpPackage)) {
@@ -71,7 +80,7 @@ private function addPackageJsonLink(string $phpPackage)
7180

7281
$manipulator = new JsonManipulator(file_get_contents($this->rootDir.'/package.json'));
7382
$manipulator->addSubNode('devDependencies', '@'.$phpPackage, 'file:vendor/'.$phpPackage.$assetsDir);
74-
file_put_contents($this->rootDir.'/package.json', $manipulator->getContents());
83+
file_put_contents($this->rootDir.'/package.json', self::sortPackages($manipulator, 'devDependencies'));
7584
}
7685

7786
private function registerWebpackResources(array $phpPackages)

tests/PackageJsonSynchronizerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ public function testSynchronizeExistingPackage()
6565
$this->assertSame(
6666
[
6767
'devDependencies' => [
68+
'@symfony/existing-package' => 'file:vendor/symfony/existing-package/Resources/assets',
6869
'@symfony/stimulus-bridge' => '^1.0.0',
6970
'stimulus' => '^1.1.1',
70-
'@symfony/existing-package' => 'file:vendor/symfony/existing-package/Resources/assets',
7171
],
7272
],
7373
json_decode(file_get_contents($this->tempDir.'/package.json'), true)
@@ -101,10 +101,10 @@ public function testSynchronizeNewPackage()
101101
$this->assertSame(
102102
[
103103
'devDependencies' => [
104-
'@symfony/stimulus-bridge' => '^1.0.0',
105-
'stimulus' => '^1.1.1',
106104
'@symfony/existing-package' => 'file:vendor/symfony/existing-package/Resources/assets',
107105
'@symfony/new-package' => 'file:vendor/symfony/new-package/assets',
106+
'@symfony/stimulus-bridge' => '^1.0.0',
107+
'stimulus' => '^1.1.1',
108108
],
109109
],
110110
json_decode(file_get_contents($this->tempDir.'/package.json'), true)

0 commit comments

Comments
 (0)