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

Support package.json "imports" field ("#hash"-style imports) #406

Open
towerofnix opened this issue Mar 27, 2024 · 0 comments
Open

Support package.json "imports" field ("#hash"-style imports) #406

towerofnix opened this issue Mar 27, 2024 · 0 comments

Comments

@towerofnix
Copy link

Hey, first time using Madge so I admit I might have missed an important detail!

In my ESM Node project, I use the top-level package.json imports property to make certain import names accessible no matter what file I'm importing them from. For example:

"imports": {
    "#aggregate": "./src/util/aggregate.js",
    "#cacheable-object": "./src/data/cacheable-object.js",
    "#colors": "./src/util/colors.js",
    ...
}

This makes it so I can use this code...

import {openAggregate} from '#aggregate';
import {getColors} from '#colors';

...anywhere in my project at all! It makes keeping track of imports way easier, since I don't need to think how many levels deep the current JS file is nested, or where anything else is. (Plus I can move around the actual imported files and just update the corresponding record in package.json, instead of changing every single import, as long as the # name stays the same!)

But, I don't think Madge recognizes this syntax (and cross-references with package.json appropriately)? I created a graph using madge --image graph.svg src/upd8.js and it only contains nodes for the imports which use the normal from './write/build-modes/index.js' syntax (for example).

Unfortunately that means Madge really can't do anything for my project. Luckily my code doesn't really involve dynamic imports, so I could probably write a series of find-replaces that more or less swap out all the from '#aggregate'-style lines with the normal syntax, but that's a pretty inconvenient barrier for using Madge, obviously.

@towerofnix towerofnix changed the title Support package.json "imports" field Support package.json "imports" field ("#hash"-style imports) Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant