From dcf711939f39c8ba87a6bd0811466c966931889d Mon Sep 17 00:00:00 2001 From: Younes ENNAJI Date: Thu, 20 Nov 2025 18:16:00 +0100 Subject: [PATCH] [AssetMapper] Fix entrypoint status lost during update --- .../ImportMap/ImportMapManager.php | 2 ++ .../Tests/ImportMap/ImportMapManagerTest.php | 36 ++++++++++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/AssetMapper/ImportMap/ImportMapManager.php b/src/Symfony/Component/AssetMapper/ImportMap/ImportMapManager.php index 4a12a6a083728..25262535487fc 100644 --- a/src/Symfony/Component/AssetMapper/ImportMap/ImportMapManager.php +++ b/src/Symfony/Component/AssetMapper/ImportMap/ImportMapManager.php @@ -112,6 +112,8 @@ private function updateImportMapConfig(bool $update, array $packagesToRequire, a $entry->packageModuleSpecifier, null, $importName, + null, + $entry->isEntrypoint, ); // remove it: then it will be re-added diff --git a/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapManagerTest.php b/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapManagerTest.php index 7762c2216df22..04eb6a5b36f8b 100644 --- a/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapManagerTest.php +++ b/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapManagerTest.php @@ -366,6 +366,34 @@ public static function getPackageNameTests(): iterable ]; } + public function testUpdatePreservesEntrypointStatus() + { + $manager = $this->createImportMapManager(); + + $this->mockImportMap([ + self::createRemoteEntry('my_entrypoint', version: '1.0.0', isEntrypoint: true), + self::createRemoteEntry('standard_lib', version: '2.0.0', isEntrypoint: false), + ]); + + $this->packageResolver->expects($this->once()) + ->method('resolvePackages') + ->willReturn([ + self::resolvedPackage('my_entrypoint', '1.0.1', isEntrypoint: true), + self::resolvedPackage('standard_lib', '2.1.0'), + ]); + + $this->configReader->expects($this->once()) + ->method('writeEntries') + ->with($this->callback(function (ImportMapEntries $entries) { + $this->assertTrue($entries->get('my_entrypoint')->isEntrypoint, 'Entrypoint status lost!'); + $this->assertFalse($entries->get('standard_lib')->isEntrypoint); + + return true; + })); + + $manager->update(); + } + private function createImportMapManager(): ImportMapManager { $this->assetMapper = $this->createMock(AssetMapperInterface::class); @@ -390,10 +418,10 @@ private function createImportMapManager(): ImportMapManager ); } - private static function resolvedPackage(string $packageName, string $version, ImportMapType $type = ImportMapType::JS) + private static function resolvedPackage(string $packageName, string $version, ImportMapType $type = ImportMapType::JS, bool $isEntrypoint = false) { return new ResolvedImportMapPackage( - new PackageRequireOptions($packageName), + new PackageRequireOptions($packageName, entrypoint: $isEntrypoint), $version, $type, ); @@ -421,11 +449,11 @@ private static function createLocalEntry(string $importName, string $path, Impor return ImportMapEntry::createLocal($importName, $type, path: $path, isEntrypoint: $isEntrypoint); } - private static function createRemoteEntry(string $importName, string $version, ?string $path = null, ImportMapType $type = ImportMapType::JS, ?string $packageSpecifier = null): ImportMapEntry + private static function createRemoteEntry(string $importName, string $version, ?string $path = null, ImportMapType $type = ImportMapType::JS, ?string $packageSpecifier = null, bool $isEntrypoint = false): ImportMapEntry { $packageSpecifier = $packageSpecifier ?? $importName; $path = $path ?? '/vendor/any-path.js'; - return ImportMapEntry::createRemote($importName, $type, path: $path, version: $version, packageModuleSpecifier: $packageSpecifier, isEntrypoint: false); + return ImportMapEntry::createRemote($importName, $type, path: $path, version: $version, packageModuleSpecifier: $packageSpecifier, isEntrypoint: $isEntrypoint); } }