sverweij / dependency-cruiser

Validate and visualize dependencies. Your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.
https://npmjs.com/dependency-cruiser
MIT License
5.16k stars 249 forks source link

Question: How to configure for tsconfig path mapping in yarn monorepo? #862

Closed KevinSchiener closed 9 months ago

KevinSchiener commented 10 months ago

Summary

I get error not-to-unresolvable when running in a monorepo where the packages have individual path mappings in their tsconfig.json.

Can I configure dependency-cruiser to pick up the package tsconfig.json when running from the workspace root?

Context

I have a yarn workspaces monorepo with different packages in /packages/ and /apps/. Some packages define path maps in their respective tsconfig.json.

- /root
  - tsconfig.json
  - /apps
  - /packages
    - /A
      - tsconfig.json
    - /B
      - tsconfig.json

Example:

{
    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "@/*": [
                "src/*"
            ]
        },

These mappings are not picked up by dependency-cruiser when running from the repository root and will result in errors like:

error not-to-unresolvable: package/A/src/pages/Dashboard/Dashboard.tsx → @/hooks/use-pageTitle

It only works if I run dependency-cruiser from the /packages/A folder directly. My guess is that it only picks up the tsconfig.json from the current working directory.

I only have a .dependency-cruiser.js in the root.

Is there a way to have it pick up the configs of each subfolder respectively?

Environment

sverweij commented 10 months ago

Hi @KevinSchiener dependency-cruiser currently directly supports one tsconfig.json. Supporting multiple ones at the same time is a future feature. It'll likely need a meaty chunk of time to implement correctly (and make it work with reasonable speed).

There are workarounds, but they will require some manual work.

Related: https://github.com/sverweij/dependency-cruiser/issues/565

github-actions[bot] commented 10 months ago

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

KevinSchiener commented 9 months ago

@sverweij Thanks for the reply. Hadn't gotten around to the issue for a while.