When an Unlocked Package is installed into a subscriber org, the metadata from the package is tagged as belonging to the package.
In that subscriber org, we can go to the package details through the Setup UI, view the list of components, and remove some of them from the ownership of the package.
One use-case is to transfer a metadata item from package to another.
But, is there a programmatic way to achieve the same thing?
I've seen this question before here: Remove component from Unlocked Package programmatically
But my question is not a duplicate. The accepted answer is just about transferring from one package to another. There are other use-cases where creating a package version excluding the metadata that we want to remove is not appropriate.
The other use-cases include:
- Releasing the metadata to be managed in the org, not by any package. Installing a version which excludes the metadata item there ends up marking it as deprecated forever
- Having two packages with overlapping metadata where only one of them will be installed at a time, and a subscriber org decides to migrate from one package to another
- Working around bugs in 2GP where it claims there are metadata clashes when the metadata is in-fact all from the same package
So: Is there a programmatic way to remove metadata from an Unlocked Package other than installing a new version of the same package?