madge icon indicating copy to clipboard operation
madge copied to clipboard

Is it possible to customize module name resolver?

Open d6u opened this issue 4 years ago • 6 comments

As far as I understand, madge uses file path to detect dependencies. However, my org's setup make files name the module name, i.e. every file name is unique in any folders, so when requiring, we don't have to specify the path, just the file name.

I'm wondering if it's possible for madge to properly recognize the dependencies?

Thanks!

d6u avatar Nov 21 '19 06:11 d6u

No easy way to fix that. Do you have an example of the naming of those files?

pahen avatar Nov 21 '19 06:11 pahen

@pahen Same here. This is a pretty drastic showstopper for a lot of developers, I think. Our imports look like this, for example.

import { tracker } from 'skoove/src/global/tracking/services/tracker';

While our babel.config.json looks like this

{
  ...
  "plugins": [
    [
      "module-resolver",
      {
        "alias": {
          "skoove/src": "./src",
        }
      }
    ]
  ]
}

mlostekk avatar Feb 08 '22 08:02 mlostekk

+1 - this is a common workflow (for better or worse) in a lot of codebases. Our tsconfig uses a tilde to always point to the root:

tsconfig.json

        "paths": {
            "~/*": [
                "*"
            ]
        },

so our imports look like:

import foo from '~/src/foo'

adam-clio avatar Dec 14 '22 13:12 adam-clio

Wow, that was fast, I'm wrong. I just need to pass the tsconfig option and it works!

@mlostekk I see there's no support for babel.config, but maybe you could try and leverage the require config or webpack config options for the purposes of resolving your imports when using madge?

adam-clio avatar Dec 14 '22 14:12 adam-clio

Yes, seems to me "pass the tsconfig" solves. Is this a dup of #158 ?

PabloLION avatar Jan 29 '23 08:01 PabloLION

Wow, that was fast, I'm wrong. I just need to pass the tsconfig option and it works!

@mlostekk I see there's no support for babel.config, but maybe you could try and leverage the require config or webpack config options for the purposes of resolving your imports when using madge?

Can you send your tsconfig file. I am working on a React project (plain JavaScript) that has the following jsconfig.json file:

{
  "compilerOptions": {
    "baseUrl": "src"
  },
  "include": ["src"]
}

Also there is no webpack file (atleast visible at the root).

Example imports (actual --> in project path):

  • src/components/core --> components/core
  • src/pages/xyz --> pages/xyz

sanjarcode avatar Aug 05 '23 08:08 sanjarcode