[ScanDependencies] Re-structure the dependency resolver
Rewrite part of the dependency scanner into a class so it is easier to
keep track of the global states and avoid redundent work. This allows
folding the pruning unused VFS job into the same loop and reduce a lot
of repeated dependency cache updates.