madge icon indicating copy to clipboard operation
madge copied to clipboard

package.json name paths not included

Open cjhines opened this issue 5 years ago • 5 comments

Paths using the name of my root directory package.json aren't included in dependency calculations

package.json:

{
  "name": "myproject",
  "version": "0.0.1",
...
}

Upon calling madge --orphans --basedir ./ ./ or madge --orphans ./ it lists a file as an orphan: src/services/Logger.js

This file isn't an orphan, however its dependant is using the package name in the import: import Logger from 'myproject/src/services/Logger'

.madgerc:

{
  "detectiveOptions": {
    "es6.mixedImports": "true"
  },
  "includeNpm": "true",
}

cjhines avatar Nov 14 '18 08:11 cjhines

This still might be unsupported at the commonjs resolution layer, but your madgerc might have a bug (may or may not fix it): "es6.mixedImports": true should be es6: { mixedImports: true }. Let me know if that fixes the issue.

mrjoelkemp avatar Nov 14 '18 12:11 mrjoelkemp

Thanks for the correction. Unfortunately it seems to have the same output.

{
  "detectiveOptions": {
    "es6": { "mixedImports": true }
  },
  "includeNpm": true
}

cjhines avatar Nov 14 '18 12:11 cjhines

Thanks for confirming! Assuming that's a valid import (curious why you need to qualify that import with the package name), there must be support for that missing in the node-filing-cabinet package. That package's commonjs resolution algorithm relies on the 'resolve' package. Is there something that we're not supplying there to make this work?

You can hack filing-cabinet in your node_modules folder to see what a fix could be.

mrjoelkemp avatar Nov 27 '18 14:11 mrjoelkemp

Sorry to revive this thread, but I'm wondering if there's been any development regarding this issue? I'm facing the same problem.

Here's my masgerc file:

{
	"tsConfig": "./jsconfig.json",
    "detectiveOptions": {
		"es6": {
			"mixedImports": true
		}
	},
    "includeNpm": true
}

and here's my jsconfig file:

{
    "compilerOptions": {
        "target": "ES6",
        "module": "commonjs",
        "baseUrl": ".",
        "paths": {
            "reusables/*": ["#reusableComponents/*"],
            "screens/*": ["#screens/*"],
            "styling/*": ["#styling/*"],
            "utils/*": ["#constants/*"],
            "media/*": ["_media/*"]
        }
    },
    
    "exclude": [
        "node_modules",
    ]
}

andersonaddo avatar Mar 26 '20 15:03 andersonaddo

If this bug do exist, it's similar to https://github.com/pahen/madge/issues/158 . I reckon we should solve them in a same PR.

PabloLION avatar Jan 29 '23 06:01 PabloLION