11import ts from "typescript" ;
22import type { EntrypointInfo , EntrypointResolutionProblem } from "../types.js" ;
33import type { CompilerHosts } from "../multiCompilerHost.js" ;
4- import { resolvedThroughFallback , visitResolutions } from "../utils.js" ;
4+ import { getResolutionOption , resolvedThroughFallback , visitResolutions } from "../utils.js" ;
55
66export function getEntrypointResolutionProblems (
77 entrypointResolutions : Record < string , EntrypointInfo > ,
@@ -11,6 +11,7 @@ export function getEntrypointResolutionProblems(
1111 visitResolutions ( entrypointResolutions , ( result , entrypoint ) => {
1212 const { subpath } = entrypoint ;
1313 const { resolutionKind } = result ;
14+ const resolutionOption = getResolutionOption ( resolutionKind ) ;
1415 if ( result . isWildcard ) {
1516 problems . push ( {
1617 kind : "Wildcard" ,
@@ -70,13 +71,14 @@ export function getEntrypointResolutionProblems(
7071 } ) ;
7172 }
7273
73- if ( resolutionKind === "node16-esm" && resolution && implementationResolution ) {
74- const typesSourceFile = hosts . node16 . getSourceFile ( resolution . fileName ) ;
74+ if ( resolution && implementationResolution ) {
75+ const host = hosts [ resolutionOption ] ;
76+ const typesSourceFile = host . getSourceFile ( resolution . fileName ) ;
7577 if ( typesSourceFile ) {
7678 ts . bindSourceFile ( typesSourceFile , { target : ts . ScriptTarget . Latest , allowJs : true , checkJs : true } ) ;
7779 }
7880 const typesExports = typesSourceFile ?. symbol ?. exports ;
79- const jsSourceFile = typesExports && hosts . node16 . getSourceFile ( implementationResolution . fileName ) ;
81+ const jsSourceFile = typesExports && host . getSourceFile ( implementationResolution . fileName ) ;
8082 if ( jsSourceFile ) {
8183 ts . bindSourceFile ( jsSourceFile , { target : ts . ScriptTarget . Latest , allowJs : true , checkJs : true } ) ;
8284 }
@@ -88,12 +90,26 @@ export function getEntrypointResolutionProblems(
8890 jsExports . has ( ts . InternalSymbolName . ExportEquals ) &&
8991 ! jsExports . has ( ts . InternalSymbolName . Default )
9092 ) {
91- // Also need to check for `default` property on `jsModule["export="]`?
92- problems . push ( {
93- kind : "FalseExportDefault" ,
94- entrypoint : subpath ,
95- resolutionKind,
96- } ) ;
93+ const jsChecker = host
94+ . createProgram ( [ implementationResolution . fileName ] , {
95+ allowJs : true ,
96+ checkJs : true ,
97+ noResolve : true ,
98+ target : ts . ScriptTarget . Latest ,
99+ } )
100+ . getTypeChecker ( ) ;
101+ // Check for `default` property on `jsModule["export="]`
102+ if (
103+ ! jsChecker
104+ . getExportsAndPropertiesOfModule ( jsChecker . resolveExternalModuleSymbol ( jsSourceFile . symbol ) )
105+ . some ( ( s ) => s . name === "default" )
106+ ) {
107+ problems . push ( {
108+ kind : "FalseExportDefault" ,
109+ entrypoint : subpath ,
110+ resolutionKind,
111+ } ) ;
112+ }
97113 }
98114 }
99115 }
0 commit comments