Composer: Why can I remove dependend packages via ‘replace’?


There is this question already, but it does not explain that it is possible to remove a dependency via replace.

I’ve found some posts in the web (like here or here, which is Magento related) that recommends to use composer’s replace in order to remove dependencies. They specify it like this:

"replace": {
    "magento/module-fedex": "*"

Actually, it is a removal and not a replacement. I’d think if a package is required it is supposed to be an essential part and therefore cannot just be dropped since that may break the app.

In the provided examples, these replace statements are within composer.json of a projects, not libraries. As far as I understand that declaration should be used in library packages, that get required in project packages. So if they are part of project, is it a hack to remove dependencies that way?

How does this work?

Source: Composer php