File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,6 +13,13 @@ export function isSyntheticDefaultImportsAllow(config?: Tsconfig) {
1313
1414const NODE_NEXT_MODULES = new Set ( [ 'nodenext' , 'node16' ] ) ;
1515
16+ const NODE_NEXT_EXTENSION_MAP : ReadonlyArray < readonly [ string , string ] > = [
17+ [ '.tsx' , '.jsx' ] ,
18+ [ '.mts' , '.mjs' ] ,
19+ [ '.cts' , '.cjs' ] ,
20+ [ '.ts' , '.js' ] ,
21+ ] ;
22+
1623export function getImportExtension (
1724 fileExtension : string ,
1825 tsconfig ?: Tsconfig ,
@@ -29,9 +36,12 @@ export function getImportExtension(
2936 ( module && NODE_NEXT_MODULES . has ( module ) ) ||
3037 ( moduleResolution && NODE_NEXT_MODULES . has ( moduleResolution ) )
3138 ) {
32- return fileExtension . endsWith ( '.ts' )
33- ? `${ fileExtension . slice ( 0 , - 3 ) } .js`
34- : fileExtension ;
39+ for ( const [ from , to ] of NODE_NEXT_EXTENSION_MAP ) {
40+ if ( fileExtension . endsWith ( from ) ) {
41+ return `${ fileExtension . slice ( 0 , - from . length ) } ${ to } ` ;
42+ }
43+ }
44+ return fileExtension ;
3545 }
3646
3747 return fileExtension . replace ( / \. t s $ / , '' ) || '' ;
Original file line number Diff line number Diff line change @@ -222,6 +222,10 @@ function normalizeCanonicalImportPaths(
222222 schemaPath ,
223223 canonical . importPath . replaceAll ( '\\' , '/' ) ,
224224 ) ;
225+ // `relative` derives from canonical.importPath (built via getPath) so it
226+ // normally ends with `fileExtension`; the `.ts$` branch is a defensive
227+ // fallback for legacy/hardcoded `.ts` paths that don't match the
228+ // configured fileExtension (e.g. `.gen.ts`).
225229 const withoutFileExtension = relative . endsWith ( fileExtension )
226230 ? relative . slice ( 0 , - fileExtension . length )
227231 : relative . replace ( / \. t s $ / , '' ) ;
You can’t perform that action at this time.
0 commit comments