Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: customize grouping names and module names #692

Open
danielo515 opened this issue Nov 23, 2022 · 6 comments
Open

Feature request: customize grouping names and module names #692

danielo515 opened this issue Nov 23, 2022 · 6 comments
Labels
enhancement this will make dependency-cruiser sweeter

Comments

@danielo515
Copy link
Contributor

It will be lovely to be able to specify a function or a regex to customize the way groups are named. I read the docs and I didn't found a way to do this, please forgive me if I overlooked something.

Context

We have a code base where, instead of using folders, we group files by using a naming convention. Something like Kind__Module.bs.js
I will like to be a able to specify a way to both group them and rename the visualization. So in one arch visualization I may want to see relations between all the kinds, and I want groups to be named after the Kind, and in another visualization I may want to see relations between modules and want to group them based on module name and only show the module name.

Expected Behavior

Ideally I want a function for maximum flexibility, but separated regex for grouping or renaming will be also fine.

Current Behavior

I think the current collapsing options are not enough to achieve this.

Possible Solution

Considered alternatives

Writing a new reporter? Not sure

@sverweij
Copy link
Owner

Hi @danielo515 thanks for this interesting use case (and I'm interested what the reason has been to choose a naming convention over folders).

It is indeed not yet possible with dependency-cruiser('s reporters) to do group files not in a folder as if they were in a folder. Thinking out loud it could be done in an addition to a (or copy of/ a generalisation of the dot) reporter - the grouping done there is just a function (call over here).

With collapsePatterns it is currently already possible to do this high level. This is
an example of modules in dependency-cruiser grouped by their extensions:

image

Generated with this command

dependency-cruiser src test -c .dependency-cruiser.js -T dot | dot -T svg | browser
.dependency-cruiser.js
/** @type {import('dependency-cruiser').IConfiguration} */
module.exports = {
  options: {
    includeOnly: {
      path: ["^src/", "^test/"],
    },
    exclude: {
      path: ["mock", "fixture", "integration"],
    },
    doNotFollow: {
      path: "node_modules",
    },
    reporterOptions: {
      dot: {
        collapsePattern: [
          "\\.[^.]+\\.(c|m)?js$",
          "\\.js$",
          "\\.[^.]+\\.ts$",
        ],

        theme: {
          graph: {
            splines: "ortho",
          },
        },
      },
    },
  },
};

@danielo515
Copy link
Contributor Author

(and I'm interested what the reason has been to choose a naming convention over folders).

It is simpler than you think. We use a compile to js language (reasonML) where everything is in the same global namespace, and the only namespacing is at the file name (AKA module).
On top of that, you may want to group your source files also based on other conventions. If you name all your schema files similarly, but you want them collocated by feature, you still may want to see them in a graph with a different representation.

@github-actions
Copy link

github-actions bot commented Dec 9, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale label Dec 9, 2022
@danielo515
Copy link
Contributor Author

danielo515 commented Dec 9, 2022 via email

@sverweij
Copy link
Owner

sverweij commented Dec 9, 2022

Hi @danielo515 - this seems like a legit feature. I'll tame stale bot.

@sverweij sverweij added enhancement this will make dependency-cruiser sweeter and removed stale labels Dec 9, 2022
@connorjs
Copy link

Another use case, albeit maybe more specific (let me know if I should create a new issue).

I want to group all built-in Node.js module dependencies. Right now, they end up as independent modules.

When looking at the JSON output, I see they have "protocol": "node:" (I use "node:fs" for the import/require), so maybe we could include protocol in the (maybe/eventual) grouping configuration?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement this will make dependency-cruiser sweeter
Projects
None yet
Development

No branches or pull requests

3 participants