Skip to content

fix: detect esm only pkg w/ main and module fields#1494

Open
jonchurch wants to merge 1 commit intonpmx-dev:mainfrom
jonchurch:legacy-dual-detection
Open

fix: detect esm only pkg w/ main and module fields#1494
jonchurch wants to merge 1 commit intonpmx-dev:mainfrom
jonchurch:legacy-dual-detection

Conversation

@jonchurch
Copy link

@jonchurch jonchurch commented Feb 14, 2026

Problem

In the Compare feature, the heuristic for legacy fallback for dual vs esm only detection has a bug currently where it assumes main contains CJS when the package also has a module field.

That reports ESM only packages w/ both esm main and module fields like lodash-es as dual packages.

  "type": "module",
  "jsnext:main": "lodash.js",
  "main": "lodash.js",
  "module": "lodash.js",

Above is an ESM only package description, but currently that will be reported as "ESM + CJS"

Solution

Infer if the main field should be CJS or ESM. If main is .cjs extension then we for sure know it's CJS. If we have a .js file and no "type": "module" then we have a CJS file.

📸

Before:
image

After:
image

@vercel
Copy link

vercel bot commented Feb 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Feb 14, 2026 7:11am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Feb 14, 2026 7:11am
npmx-lunaria Ignored Ignored Feb 14, 2026 7:11am

Request Review

@codecov
Copy link

codecov bot commented Feb 14, 2026

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
shared/utils/package-analysis.ts 0.00% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 14, 2026

📝 Walkthrough

Walkthrough

The changes modify the module format detection logic in detectModuleFormat within the package analysis utility. Previously, when both module and main fields were present, the function always returned 'dual'. The new implementation conditionally returns 'dual' or 'esm' based on whether the main field ends with .cjs or .js (when package type is not module). Test cases have been added to verify both dual and ESModule detection scenarios with type, module, and main fields present.

Suggested reviewers

  • danielroe
  • ghostdevv
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main
Description check ✅ Passed The pull request description clearly explains the bug in module format detection and provides a specific solution aligned with the code changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant