antoine-coulon / skott

All-in-one devtool to automatically analyze, search and visualize project modules and dependencies from JavaScript, TypeScript (JSX/TSX) and Node.js (ES6, CommonJS)
MIT License
643 stars 25 forks source link

The `groupBy` feature #146

Closed AlexandrHoroshih closed 6 months ago

AlexandrHoroshih commented 6 months ago

Summary

This PR adds the first part for "grouped graph" feature, as discussed in #125 :

Example

const instance = await skott({
 groupBy: (path) => {
          if (path.includes("src/core")) return "core";
          if (path.includes("src/features/feature-a")) return "feature-a";

          return undefined;
      }
  }
});

const {groupedGraph} = instance.getStructure();

groupedGraph.core // { id: "core", adjacentTo, body: { size, files, ... } }
groupedGraph["feature-a"] // { id: "feature-a", adjacentTo, body: { size, files, ... } }

Implementation

As was discussed in the issue, there is a single groupBy function, which assigns module to a group based on its node.id (which is the path of the module location).

Under the hood it is the separate graph, which is built in the moment of getStructure call, using the original graph of project structure as a source of truth.

Testing

Integration tests in the integration/api.spec.ts

Impacted documentation

The changeset is generated and the JSDoc comment is added to the groupBy field, also documentation is added into skott/README.md

antoine-coulon commented 6 months ago

@all-contributors please add @AlexandrHoroshih for code

allcontributors[bot] commented 6 months ago

@antoine-coulon

I've put up a pull request to add @AlexandrHoroshih! :tada: