Greatly simplify the implementation of brew-leaves
Make brew-leaves respect optional deps
Move brew-leaves into core

Closes #24371.