[AssetMapper] Allow to define entrypoint in importmap.php

by @Jibbarth

Some issues have been detected in this pull request

Issues that can be fixed by applying a patch

Review the proposed patch then download it to apply it manually or execute the following command from the repository root directory:

curl https://fabbot.io/patch/symfony/flex/1026/20f3f73cfd89f5778b216165932f5c6d3fa3ef5a/cs.diff | patch -p0
diff -ru src/PackageJsonSynchronizer.php src/PackageJsonSynchronizer.php
--- src/PackageJsonSynchronizer.php	2025-02-02 13:08:09.859406498 +0000
+++ src/PackageJsonSynchronizer.php	2025-02-02 13:08:11.094408792 +0000
@@ -104,7 +104,7 @@
 
         foreach (['dependencies' => $jsDependencies, 'devDependencies' => $jsDevDependencies] as $key => $packages) {
             foreach ($packages as $name => $version) {
-                if ('@' !== $name[0] || 0 !== strpos($version, 'file:'.$this->vendorDir.'/') || false === strpos($version, '/assets')) {
+                if ('@' !== $name[0] || !str_starts_with($version, 'file:'.$this->vendorDir.'/') || !str_contains($version, '/assets')) {
                     continue;
                 }
                 if (file_exists($this->rootDir.'/'.substr($version, 5).'/package.json')) {
@@ -163,12 +163,12 @@
             }
 
             // Case "@mybundle/script.js": "entrypoint:%PACKAGE%/script.js" | "@mybundle/script.js": {"version": "entrypoint:%PACKAGE%/script.js"}
-            if (0 === strpos($constraint, 'entrypoint:')) {
+            if (str_starts_with($constraint, 'entrypoint:')) {
                 $entrypoint = true;
                 $constraint = str_replace('entrypoint:', 'path:', $constraint);
             }
 
-            if (0 === strpos($constraint, 'path:')) {
+            if (str_starts_with($constraint, 'path:')) {
                 $path = substr($constraint, 5);
                 $path = str_replace('%PACKAGE%', \dirname($packageJson->getPath()), $path);
 
@@ -276,7 +276,7 @@
                     continue;
                 }
 
-                $this->io->writeError(sprintf('Updating package <comment>%s</> from <info>%s</> to <info>%s</>.', $name, $version, $versionConstraint));
+                $this->io->writeError(\sprintf('Updating package <comment>%s</> from <info>%s</> to <info>%s</>.', $name, $version, $versionConstraint));
             }
 
             if (isset($importMapEntry['path'])) {
@@ -309,7 +309,7 @@
                 continue;
             }
 
-            throw new \InvalidArgumentException(sprintf('Invalid importmap entry: "%s".', var_export($importMapEntry, true)));
+            throw new \InvalidArgumentException(\sprintf('Invalid importmap entry: "%s".', var_export($importMapEntry, true)));
         }
     }
 
diff -ru tests/PackageJsonSynchronizerTest.php tests/PackageJsonSynchronizerTest.php
--- tests/PackageJsonSynchronizerTest.php	2025-02-02 13:08:10.269407259 +0000
+++ tests/PackageJsonSynchronizerTest.php	2025-02-02 13:08:11.496409540 +0000
@@ -401,7 +401,7 @@
                 'version' => '1.8.0',
             ],
         ];
-        file_put_contents($this->tempDir.'/importmap.php', sprintf('<?php return %s;', var_export($importMap, true)));
+        file_put_contents($this->tempDir.'/importmap.php', \sprintf('<?php return %s;', var_export($importMap, true)));
 
         $fileModulePath = $this->tempDir.'/vendor/symfony/new-package/assets/dist/loader.js';
         $entrypointPath = $this->tempDir.'/vendor/symfony/new-package/assets/entry.js';
@@ -434,9 +434,9 @@
             '@symfony/new-package/entry2.js' => [
                 'path' => './vendor/symfony/new-package/assets/entry2.js',
                 'entrypoint' => true,
-            ]
+            ],
         ];
-        file_put_contents($this->tempDir.'/importmap.php', sprintf('<?php return %s;', var_export($importMap, true)));
+        file_put_contents($this->tempDir.'/importmap.php', \sprintf('<?php return %s;', var_export($importMap, true)));
 
         $fileModulePath = $this->tempDir.'/vendor/symfony/new-package/assets/dist/loader.js';
         $entrypointPath = $this->tempDir.'/vendor/symfony/new-package/assets/entry.js';

0
Common Typos

0
JSON Files Syntax

0
File Permissions

0
Merge Commits

0
Exception Messages Formatting

0
Usage of void in test files

0
Use ::class whenever possible

0
Deprecation Messages