MCPcopy Index your code
hub / github.com/npmx-dev/npmx.dev / getExtensionPriority

Function getExtensionPriority

server/utils/import-resolver.ts:59–102  ·  view source on GitHub ↗

* Get file extension priority order based on source file type.

(sourceFile: string)

Source from the content-addressed store, hash-verified

57 * Get file extension priority order based on source file type.
58 */
59function getExtensionPriority(sourceFile: string): string[][] {
60 const ext = sourceFile.split('.').slice(1).join('.')
61
62 // Declaration files prefer other declaration files
63 if (ext === 'd.ts' || ext === 'd.mts' || ext === 'd.cts') {
64 return [
65 [], // exact match first
66 ['.d.ts', '.d.mts', '.d.cts'],
67 ['.ts', '.mts', '.cts'],
68 ['.js', '.mjs', '.cjs'],
69 ['.tsx', '.jsx'],
70 ['.json'],
71 ]
72 }
73
74 // TypeScript files
75 if (ext === 'ts' || ext === 'tsx') {
76 return [[], ['.ts', '.tsx'], ['.d.ts'], ['.js', '.jsx'], ['.json']]
77 }
78
79 if (ext === 'mts') {
80 return [[], ['.mts'], ['.d.mts', '.d.ts'], ['.mjs', '.js'], ['.json']]
81 }
82
83 if (ext === 'cts') {
84 return [[], ['.cts'], ['.d.cts', '.d.ts'], ['.cjs', '.js'], ['.json']]
85 }
86
87 // JavaScript files
88 if (ext === 'js' || ext === 'jsx') {
89 return [[], ['.js', '.jsx'], ['.ts', '.tsx'], ['.json']]
90 }
91
92 if (ext === 'mjs') {
93 return [[], ['.mjs'], ['.js'], ['.mts', '.ts'], ['.json']]
94 }
95
96 if (ext === 'cjs') {
97 return [[], ['.cjs'], ['.js'], ['.cts', '.ts'], ['.json']]
98 }
99
100 // Default for other files (vue, svelte, etc.)
101 return [[], ['.ts', '.js'], ['.d.ts'], ['.json']]
102}
103
104/**
105 * Get index file extensions to try for directory imports.

Callers 1

resolveRelativeImportFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected