Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/node-modules-inspector/src/app/utils/module-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { PackageModuleType, PackageNode } from 'node-modules-tools'
import { computed } from 'vue'
import { settings } from '../state/settings'

export const MODULE_TYPES_FULL = ['dual', 'esm', 'faux', 'cjs', 'dts'] as PackageModuleType[]
export const MODULE_TYPES_FULL_SELECT = ['dual', 'esm', 'faux', 'cjs'] as PackageModuleType[]
export const MODULE_TYPES_FULL = ['dual', 'esm', 'faux', 'cjs', 'dts', 'unknown'] as PackageModuleType[]
export const MODULE_TYPES_FULL_SELECT = ['dual', 'esm', 'faux', 'cjs', 'unknown'] as PackageModuleType[]

// @unocss-include
export const MODULE_TYPES_COLOR_BADGE = {
Expand Down
2 changes: 1 addition & 1 deletion packages/node-modules-tools/src/analyze-esm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ describe('analyzePackageModuleType', () => {
it('stops recursive export analysis after max depth', () => {
expect(analyze({
exports: nestExports(11, './index.mjs'),
})).toBe('cjs')
})).toBe('unknown')
})
})
8 changes: 7 additions & 1 deletion packages/node-modules-tools/src/analyze-esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ function analyzeExports(exports: unknown, depth = 0): ExportsAnalysis {
result.hasImport = true
else if (exports.endsWith('.cjs') || exports.endsWith('.cts'))
result.hasRequire = true
else if (exports.endsWith('.node'))
return { hasImport: false, hasRequire: false, hasModule: false }
return result
}

Expand Down Expand Up @@ -67,6 +69,10 @@ export function analyzePackageModuleType(pkgJson: PackageJson): PackageModuleTyp
if (pkgJson.name?.startsWith('@types/'))
return 'dts'

// // Native binary packages (e.g. @oxc-parser/binding-linux-x64-gnu)
if (pkgJson.main?.endsWith('.node'))
return 'unknown'

const hasExports = pkgJson.exports != null
const hasModule = !!pkgJson.module
const hasMain = !!pkgJson.main
Expand Down Expand Up @@ -115,5 +121,5 @@ export function analyzePackageModuleType(pkgJson: PackageJson): PackageModuleTyp
if (pkgJson.types || pkgJson.typings)
return 'dts'

return 'cjs'
return 'unknown'
}
2 changes: 1 addition & 1 deletion packages/node-modules-tools/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PackageModuleType } from './types'

export const PackageModuleTypes: readonly PackageModuleType[] = Object.freeze(['cjs', 'esm', 'dual', 'faux', 'dts'])
export const PackageModuleTypes: readonly PackageModuleType[] = Object.freeze(['cjs', 'esm', 'dual', 'faux', 'dts', 'unknown'])

export const CLUSTER_DEP_PROD = 'dep:prod'
export const CLUSTER_DEP_DEV = 'dep:dev'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ export const packageJsonSnapshots = {
},
},
},
'@oxc-parser/binding-linux-x64-gnu (#124)': {
expected: 'unknown',
packageJson: {
name: '@oxc-parser/binding-linux-x64-gnu',
version: '0.147.0',
main: 'parser.linux-x64-gnu.node',
},
},
'@octokit/rest@22.0.1 (#128)': {
expected: 'esm',
packageJson: {
Expand Down
Loading