Skip to content

fix: detect native binary packages as 'unknown' module type - #203

Open
clanzhang wants to merge 1 commit into
antfu:mainfrom
clanzhang:fix/native-binding-module-type
Open

fix: detect native binary packages as 'unknown' module type#203
clanzhang wants to merge 1 commit into
antfu:mainfrom
clanzhang:fix/native-binding-module-type

Conversation

@clanzhang

Copy link
Copy Markdown
Contributor

Native binding packages (e.g. @oxc-parser/binding-linux-x64-gnu) have a main field pointing to a .node file. These are native binaries, not CJS or ESM modules, but were incorrectly categorized as CJS. This PR detects .node files and labels them as 'unknown'.

Fixes #124

🔗 Linked issue

Resolves #124

🧭 Context

Native binding packages are becoming more common (e.g. SWC, OXC, esbuild). Their main field points to a .node binary file. The current detection logic falls through to the default 'cjs' return, which is misleading — these packages contain no JavaScript module at all.

📚 Description

  • Detect .node extension in main field and return 'unknown'
  • Handle .node in exports string analysis (skip without setting import/require flags)
  • Change default fallback from 'cjs' to 'unknown' for packages with no recognizable module entry
  • Add 'unknown' to PackageModuleTypes, MODULE_TYPES_FULL, and MODULE_TYPES_FULL_SELECT
  • Add test fixture for @oxc-parser/binding-linux-x64-gnu
  • Update max-depth fallback test expectation from 'cjs' to 'unknown'

Native binding packages (e.g. @oxc-parser/binding-linux-x64-gnu) have
a `main` field pointing to a `.node` file. These are not CJS or ESM
modules but native binaries. Previously they were incorrectly categorized
as CJS.

- Detect `.node` files in main/exports and return 'unknown'
- Add 'unknown' to PackageModuleTypes and UI display lists

Fixes antfu#124
@pkg-pr-new

pkg-pr-new Bot commented Aug 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/node-modules-inspector@203
npm i https://pkg.pr.new/node-modules-tools@203

commit: 862fc68

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.

"Other" modules as categorized as CJS by default

1 participant