graphology / graphology

A robust & multipurpose Graph object for JavaScript & TypeScript.
https://graphology.github.io
MIT License
1.31k stars 86 forks source link

metrics centrality algorithms use graphology-indices as an implicit dependency #520

Closed kradical closed 3 months ago

kradical commented 3 months ago

When attempting to use a couple of the centrality algorithms I hit an error from yarn about being unable to resolve dependencies. It looks like we are implicitly depending on graphology-indices in those files.

Error:

✘ [ERROR] Could not resolve "graphology-indices/neighborhood"

    ../.yarn/__virtual__/graphology-metrics-virtual-ff9ef19213/0/cache/graphology-metrics-npm-2.3.0-ede16f4f27-2e0ff08de4.zip/node_modules/graphology-metrics/centrality/pagerank.js:14:10:
      14 │   require('graphology-indices/neighborhood').WeightedNeighborhoodIndex;
         ╵           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  The Yarn Plug'n'Play manifest forbids importing "graphology-indices" here because it's not listed
  as a dependency of this package:

    ../.pnp.cjs:14014:31:
      14014 │         "packageDependencies": [\
            ╵                                ~~

  You can mark the path "graphology-indices/neighborhood" as external to exclude it from the bundle,
  which will remove this error and leave the unresolved path in the bundle. You can also surround
  this "require" call with a try/catch block to handle this failure at run-time instead of
  bundle-time.

~I'll put up a PR to add that dependency, which I think should fix things.~ https://github.com/graphology/graphology/pull/521

Yomguithereal commented 3 months ago

Hello @kradical,

yarn seems to have some radical opinions about this kind of dependencies contrary to all other dependency resolvers, sigh. It was actually convenient for me to maintain this without having to specify the graphology-indices version in graphology-metrics so as to keep it automatically aligned with graphology-shortest-path. But I see their point also.

In any case, let me merge your PR and publish a bugfix :)

kradical commented 3 months ago

ahh I see, not so great for mono repo lib maintainers :(. well I appreciate you making my life easier!