fix(npm): peerDependency resolution leading to multiple versions being installed + hanging (#32358)
Essentially, this PR rewrites our dependency resolution code to use a
two-phase approach, which fixes duplicate peer dependencies or hanging
installation.
Peer deps were resolved inline during BFS traversal, making results
dependent on traversal order. If package lib (which peers with `react`)
was encountered before `react` was added to the graph by a sibling, it
would auto-resolve `react@18.2.0 (latest)`. When encountered again in a
subtree where `react@18.3.0` already existed, it got a different
resolution, which creates a duplicate lib entry. With patterns like
Expo/React Native (100+ plugins all peering with `react`,
`react-native`, and `expo`), this caused exponential blowup.