@@ -3,7 +3,7 @@ import { getEntrypointResolutionProblems } from "./checks/entrypointResolutionPr
3
3
import { getFileProblems } from "./checks/fileProblems.js" ;
4
4
import { getResolutionBasedFileProblems } from "./checks/resolutionBasedFileProblems.js" ;
5
5
import type { Package } from "./createPackage.js" ;
6
- import { createMultiCompilerHost , type MultiCompilerHost } from "./multiCompilerHost.js" ;
6
+ import { createCompilerHosts , type CompilerHosts , CompilerHostWrapper } from "./multiCompilerHost.js" ;
7
7
import type { CheckResult , EntrypointInfo , EntrypointResolutionAnalysis , Resolution , ResolutionKind } from "./types.js" ;
8
8
9
9
export async function checkPackage ( pkg : Package ) : Promise < CheckResult > {
@@ -20,11 +20,11 @@ export async function checkPackage(pkg: Package): Promise<CheckResult> {
20
20
return { packageName, packageVersion, types } ;
21
21
}
22
22
23
- const host = createMultiCompilerHost ( pkg ) ;
24
- const entrypointResolutions = getEntrypointInfo ( packageName , pkg , host ) ;
25
- const entrypointResolutionProblems = getEntrypointResolutionProblems ( entrypointResolutions , host ) ;
26
- const resolutionBasedFileProblems = getResolutionBasedFileProblems ( packageName , entrypointResolutions , host ) ;
27
- const fileProblems = getFileProblems ( entrypointResolutions , host ) ;
23
+ const hosts = createCompilerHosts ( pkg ) ;
24
+ const entrypointResolutions = getEntrypointInfo ( packageName , pkg , hosts ) ;
25
+ const entrypointResolutionProblems = getEntrypointResolutionProblems ( entrypointResolutions , hosts ) ;
26
+ const resolutionBasedFileProblems = getResolutionBasedFileProblems ( packageName , entrypointResolutions , hosts ) ;
27
+ const fileProblems = getFileProblems ( entrypointResolutions , hosts ) ;
28
28
29
29
return {
30
30
packageName,
@@ -62,7 +62,7 @@ function getProxyDirectories(rootDir: string, fs: Package) {
62
62
. filter ( ( f ) => f !== "./" ) ;
63
63
}
64
64
65
- function getEntrypointInfo ( packageName : string , fs : Package , host : MultiCompilerHost ) : Record < string , EntrypointInfo > {
65
+ function getEntrypointInfo ( packageName : string , fs : Package , hosts : CompilerHosts ) : Record < string , EntrypointInfo > {
66
66
const packageJson = JSON . parse ( fs . readFile ( `/node_modules/${ packageName } /package.json` ) ) ;
67
67
const subpaths = getSubpaths ( packageJson . exports ) ;
68
68
const entrypoints = subpaths . length ? subpaths : [ "." ] ;
@@ -72,10 +72,10 @@ function getEntrypointInfo(packageName: string, fs: Package, host: MultiCompiler
72
72
const result : Record < string , EntrypointInfo > = { } ;
73
73
for ( const entrypoint of entrypoints ) {
74
74
const resolutions : Record < ResolutionKind , EntrypointResolutionAnalysis > = {
75
- node10 : getEntrypointResolution ( packageName , "node10" , entrypoint , host ) ,
76
- "node16-cjs" : getEntrypointResolution ( packageName , "node16-cjs" , entrypoint , host ) ,
77
- "node16-esm" : getEntrypointResolution ( packageName , "node16-esm" , entrypoint , host ) ,
78
- bundler : getEntrypointResolution ( packageName , "bundler" , entrypoint , host ) ,
75
+ node10 : getEntrypointResolution ( packageName , hosts . node10 , "node10" , entrypoint ) ,
76
+ "node16-cjs" : getEntrypointResolution ( packageName , hosts . node16 , "node16-cjs" , entrypoint ) ,
77
+ "node16-esm" : getEntrypointResolution ( packageName , hosts . node16 , "node16-esm" , entrypoint ) ,
78
+ bundler : getEntrypointResolution ( packageName , hosts . bundler , "bundler" , entrypoint ) ,
79
79
} ;
80
80
result [ entrypoint ] = {
81
81
subpath : entrypoint ,
@@ -89,16 +89,15 @@ function getEntrypointInfo(packageName: string, fs: Package, host: MultiCompiler
89
89
90
90
function getEntrypointResolution (
91
91
packageName : string ,
92
+ host : CompilerHostWrapper ,
92
93
resolutionKind : ResolutionKind ,
93
- entrypoint : string ,
94
- host : MultiCompilerHost
94
+ entrypoint : string
95
95
) : EntrypointResolutionAnalysis {
96
96
if ( entrypoint . includes ( "*" ) ) {
97
97
return { name : entrypoint , resolutionKind, isWildcard : true } ;
98
98
}
99
99
const moduleSpecifier = packageName + entrypoint . substring ( 1 ) ; // remove leading . before slash
100
100
const importingFileName = resolutionKind === "node16-esm" ? "/index.mts" : "/index.ts" ;
101
- const moduleResolution = resolutionKind === "node10" ? "node10" : resolutionKind === "bundler" ? "bundler" : "node16" ;
102
101
const resolutionMode = resolutionKind === "node16-esm" ? ts . ModuleKind . ESNext : ts . ModuleKind . CommonJS ;
103
102
104
103
const resolution = tryResolve ( ) ;
@@ -107,7 +106,7 @@ function getEntrypointResolution(
107
106
108
107
const files = resolution
109
108
? host
110
- . createProgram ( moduleResolution , [ resolution . fileName ] )
109
+ . createProgram ( [ resolution . fileName ] )
111
110
. getSourceFiles ( )
112
111
. map ( ( f ) => f . fileName )
113
112
: undefined ;
@@ -124,7 +123,6 @@ function getEntrypointResolution(
124
123
const { resolution, trace } = host . resolveModuleName (
125
124
moduleSpecifier ,
126
125
importingFileName ,
127
- moduleResolution ,
128
126
resolutionMode ,
129
127
noDtsResolution
130
128
) ;
@@ -135,7 +133,7 @@ function getEntrypointResolution(
135
133
136
134
return {
137
135
fileName,
138
- moduleKind : host . getModuleKindForFile ( fileName , moduleResolution ) ,
136
+ moduleKind : host . getModuleKindForFile ( fileName ) ,
139
137
isJson : resolution . resolvedModule . extension === ts . Extension . Json ,
140
138
isTypeScript : ts . hasTSFileExtension ( resolution . resolvedModule . resolvedFileName ) ,
141
139
trace,
0 commit comments