Skip to content

Remove importmap entries when uninstalling a package - #1098

Open
Amoifr wants to merge 1 commit into
symfony:2.xfrom
Amoifr:feature-1009-importmap-remove
Open

Remove importmap entries when uninstalling a package#1098
Amoifr wants to merge 1 commit into
symfony:2.xfrom
Amoifr:feature-1009-importmap-remove

Conversation

@Amoifr

@Amoifr Amoifr commented Jul 23, 2026

Copy link
Copy Markdown

Fix #1009

When AssetMapper is used, Flex runs importmap:require for the entries declared by a UX package on install, but nothing removed them on uninstall: the entries stayed in importmap.php forever.

The tricky part is that by the time PackageJsonSynchronizer runs (POST_UPDATE_CMD), the uninstalled package's files are gone, so its symfony.importmap config cannot be read anymore. And blindly diffing importmap.php against the entries declared by the remaining packages is not an option either: it would also remove the entries the user added manually with importmap:require.

So this PR captures the entry names on PRE_PACKAGE_UNINSTALL, while the package files still exist, and passes them to the synchronizer, which then runs a single importmap:remove for the captured names, except those that are:

  • still declared by an installed package (e.g. two bundles sharing a JS dependency), or
  • not present in importmap.php (e.g. already removed by hand).

The synchronize() signature change is backward compatible (new optional parameter), and the webpack/package.json path is untouched (obsolete file: links were already cleaned up by removeObsoletePackageJsonLinks()).

@Kocal

Kocal commented Jul 23, 2026

Copy link
Copy Markdown
Member

What if an other UX package require the same dependency from the package you are removing... does the dependency stay in importmap.php?

@Amoifr

Amoifr commented Jul 24, 2026

Copy link
Copy Markdown
Author

Good catch to check! Yes, it stays: the removal list is filtered against the entries still declared by the installed packages, so anything another package still needs is skipped. This exact scenario is covered by testSynchronizeAssetMapperRemovesObsoleteImportMapEntries (@hotcake/foo belongs to the removed package but is still declared by symfony/new-package, and it survives the uninstall). 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove importmap entries when uninstalling a package

2 participants