updateShortestPaths = (
  graph,
  packageLocation,
  logicalPath,
  preferredPackageLogicalPathMap = new Map(),
) => {
  const node = graph[packageLocation];
  if (!node) {
    throw new ReferenceError(
      `Cannot find package at ${packageLocation} in graph`,
    );
  }

  const bestLogicalPath = currentBestLogicalPath(
    logicalPath,
    packageLocation,
    preferredPackageLogicalPathMap,
  );

  if (bestLogicalPath === logicalPath) {
    preferredPackageLogicalPathMap.set(packageLocation, bestLogicalPath);

    for (const name of keys(node.dependencyLocations).sort()) {
      const packageLocation = node.dependencyLocations[name];
      if (!packageLocation) {
        // "should never happen"
        throw new ReferenceError(
          `Expected graph node ${q(node.name)} to contain a dependency location for ${q(name)}`,
        );
      }
      updateShortestPaths(
        graph,
        packageLocation,
        [...logicalPath, name],
        preferredPackageLogicalPathMap,
      );
    }
  }

  // a path length of 0 means the node represents the eventual entry compartment.
  // we do not want to mess with that path.
  if (node.path.length && node.path !== bestLogicalPath) {
    node.path = bestLogicalPath;
  }

  return undefined;
}
Updates the shortest paths in a subgraph of `graph` starting with `packageLocation`.

This should be called upon the second (and each subsequent) visit to a graph node.

@param {Graph} graph Graph
@param {string} packageLocation Location of the package to start with
@param {string[]} logicalPath Current path parts of the same package
@param {Map<string, string[]>} [preferredPackageLogicalPathMap] Mapping of shortest known paths for each package location
@returns {void}