Summary:
Adds infrastructure for reporting *import stacks* as part of resolution errors in Metro. An import stack is the (inverse) chain of dependencies in the graph that led to a resolution error. This can help users understand and fix build errors that occur inside third-party packages (e.g. because of configuration errors).
See expo/expo#23551 for more motivation.
## Caveats
Ideally, we'd always be able to print the full chain of dependencies from an entry point to the module containing the error.¹ However, since we update the graph incrementally in response to filesystem changes, and produce import stacks while there are still pending changes to process, we can only safely print edges that we have *just* traversed². Otherwise, it's possible that a dependency's metadata (e.g. source location) will be stale, or indeed that an edge we print doesn't exist anymore.
¹ Also, for UX reasons, we'd want to print the *shortest path* between those two modules.
² Our main traversal is depth-first, so it's also not guaranteed to take the shortest possible path to each module.
As a result, **there is an observable difference between** (the import stacks printed by) **initial and incremental builds**.
* An error in an initial build (no existing Graph instance) will contain the full import stack, from the module containing the error down to the entry point.
* An error in an incremental build (e.g. full reload / Fast Refresh of a bundle that previously built successfully) will contain a *partial* import stack - from the module containing the error down to some ancestor module *M*, where M is in the set of modules added/changed/invalidated since the previous successful build.
* In this case we can still reliably tell the user that the dependency chain connects *somehow* to the bundle's entry point (since otherwise the module wouldn't be in the graph).
Changelog:
* **[Feature]** Include import stacks in resolution errors.
---
TODO:
* See how this renders in LogBox/RedBox and adjust accordingly.
* Decide whether to bake the import stack into the error message or fully rely on external error reporters for presentation.
* Probably print project-relative paths rather than absolute paths.
* Pretty-print the paths of context modules rather than expose the generated, virtual paths.
Differential Revision: D47548085
fbshipit-source-id: 781e3c4c4fc17a4e216e9adea1ab4c0cd708aff0