madge
madge copied to clipboard
Is it possible to customize module name resolver?
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!
No easy way to fix that. Do you have an example of the naming of those files?
@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",
}
}
]
]
}
+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'
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?
Yes, seems to me "pass the tsconfig" solves. Is this a dup of #158 ?
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