Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@broofa
Copy link
Collaborator

@broofa broofa commented Jun 14, 2025

Fixes #325.

@SuperchupuDev: If you could do some testing for this, that would be helpful (see Vercel preview build link below). The logic I've added for detecting ESM and CJS support is almost certainly imperfect. It just walks the package.json#exports field looking for import or require fields, or paths with .mjs or .cjs. I expect it's good enough to ship, but there's no real standard for how dual-module packages should be setup. Thus, I'm sure there will be edge cases that aren't properly detected.

CleanShot 2025-06-13 at 23 15 57@2x

@vercel
Copy link

vercel bot commented Jun 14, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
npmgraph ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 18, 2025 1:28pm

@SuperchupuDev
Copy link

SuperchupuDev commented Jun 14, 2025

hi, thank you for implementing this so fast! i can't find any dual package that doesn't use the exports field but i think the logic from node-modules.dev or npm-esm-vs-cjs is accurate if you want a reference implementation. might be worth adding a faux label too but i don't really mind 👍

@broofa broofa mentioned this pull request Jun 16, 2025
broofa added a commit that referenced this pull request Jun 17, 2025
Found myself fiddling with colors in the colorizer legends while working
on #326, and ended up going all-in on the `oklch`. This is admittedly a
bit of an experiment, an excuse to learn about the `oklch` colorspace.
It's [kinda weird](https://lch.oklch.com/#0.576,78.78,216.36,100), but
has the advantage of providing colors with a consistent brightness when
you vary the H(ue) value.

Also fixing up a few odds and ends that I turned up along the way ...
* NPMSIO colorizer legend uses CSS gradient with `scoreColor()` computed
endpoints
* Use `color-mix` for color interpolation
* Tweaks to colors and styling in release timeline chart
* Wider color variation in treemap

@fregante: The tl;dr: is "a bit more color"...

Before:
![CleanShot 2025-06-16 at 10 29
17](https://github.com/user-attachments/assets/44b4c0f1-1d14-4369-b336-a02dab6cc74f)

After:
![CleanShot 2025-06-16 at 10 30
19](https://github.com/user-attachments/assets/ca11bf8a-99a6-4190-bbf4-f3b8d732fd9c)
Comment on lines 92 to 95
} else if (k === 'default') {
pkgType.esm = true;
pkgType.cjs = true;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't sound right, if a package were to have only the default export it would only have one of them, but it would show up as dual

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. I read through the node-modules.dev and npm-esm-vs-cjs code a bit more closely and have tried to follow their lead on this. (I'm not directly pulling in the code from those projects, however, as it doesn't quite do what I'm after.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW: https://npmgraph-git-dualmodules-broofas-projects.vercel.app/?q=webdriver#color=moduleType&zoom=w seems to have a pretty good selection of module types... if you wanted to click through some of the package.json files for some of the modules to verify the detection logic works correctly.

(And, yes, I know there should be unit tests for this, but that's time and energy I don't have at the moment. :-) )

@broofa broofa merged commit b46caa7 into main Jun 18, 2025
8 checks passed
@broofa broofa deleted the dual_modules branch June 18, 2025 13:28
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

Successfully merging this pull request may close these issues.

specify if package is dual

3 participants