MCPcopy Create free account
hub / github.com/npmx-dev/npmx.dev / getIndexExtensions

Function getIndexExtensions

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

* Get index file extensions to try for directory imports.

(sourceFile: string)

Source from the content-addressed store, hash-verified

105 * Get index file extensions to try for directory imports.
106 */
107function getIndexExtensions(sourceFile: string): string[] {
108 const ext = sourceFile.split('.').slice(1).join('.')
109
110 if (ext === 'd.ts' || ext === 'd.mts' || ext === 'd.cts') {
111 return ['index.d.ts', 'index.d.mts', 'index.d.cts', 'index.ts', 'index.js']
112 }
113
114 if (ext === 'mts' || ext === 'mjs') {
115 return ['index.mts', 'index.mjs', 'index.ts', 'index.js']
116 }
117
118 if (ext === 'cts' || ext === 'cjs') {
119 return ['index.cts', 'index.cjs', 'index.ts', 'index.js']
120 }
121
122 if (ext === 'ts' || ext === 'tsx') {
123 return ['index.ts', 'index.tsx', 'index.js', 'index.jsx']
124 }
125
126 return ['index.js', 'index.ts', 'index.mjs', 'index.cjs']
127}
128
129export interface ResolvedImport {
130 /** The resolved file path (relative to package root) */

Callers 1

resolveRelativeImportFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected