@@ -859,7 +859,7 @@ namespace ts {
859
859
* @returns `undefined` if the path has no relevant implied format, `ModuleKind.ESNext` for esm format, and `ModuleKind.CommonJS` for cjs format
860
860
*/
861
861
export function getImpliedNodeFormatForFile ( fileName : Path , packageJsonInfoCache : PackageJsonInfoCache | undefined , host : ModuleResolutionHost , options : CompilerOptions ) : ResolutionMode {
862
- const result = getImpliedNodeFormatForFileWorker ( fileName , packageJsonInfoCache , host , options ) ;
862
+ const result = getImpliedNodeFormatForFileWorker ( fileName , packageJsonInfoCache , host , options , /*oldBuildInfoProgram*/ undefined ) ;
863
863
return typeof result === "object" ? result . impliedNodeFormat : result ;
864
864
}
865
865
@@ -869,6 +869,7 @@ namespace ts {
869
869
packageJsonInfoCache : PackageJsonInfoCache | undefined ,
870
870
host : ModuleResolutionHost ,
871
871
options : CompilerOptions ,
872
+ oldBuildInfoProgram : OldBuildInfoProgram | undefined ,
872
873
) {
873
874
switch ( getEmitModuleResolutionKind ( options ) ) {
874
875
case ModuleResolutionKind . Node16 :
@@ -885,9 +886,16 @@ namespace ts {
885
886
const packageJsonLocations : string [ ] = [ ] ;
886
887
state . failedLookupLocations = packageJsonLocations ;
887
888
state . affectingLocations = packageJsonLocations ;
888
- const packageJsonScope = getPackageScopeForPath ( fileName , state ) ;
889
+ const fromOld = oldBuildInfoProgram ?. getPackageJsonPath ( getDirectoryPath ( fileName ) ) ;
890
+ const packageJsonScope = fromOld ?
891
+ getPackageJsonInfo ( getDirectoryPath ( fromOld ) , /*onlyRecordFailures*/ false , state ) :
892
+ getPackageScopeForPath ( fileName , state ) ;
889
893
const impliedNodeFormat = packageJsonScope ?. packageJsonContent . type === "module" ? ModuleKind . ESNext : ModuleKind . CommonJS ;
890
- return { impliedNodeFormat, packageJsonLocations, packageJsonScope } ;
894
+ return {
895
+ impliedNodeFormat,
896
+ packageJsonLocations : packageJsonLocations . length ? packageJsonLocations : undefined ,
897
+ packageJsonScope
898
+ } ;
891
899
}
892
900
}
893
901
@@ -1977,7 +1985,7 @@ namespace ts {
1977
1985
if ( ! newSourceFile ) {
1978
1986
return StructureIsReused . Not ;
1979
1987
}
1980
- newSourceFile . packageJsonLocations = sourceFileOptions . packageJsonLocations ?. length ? sourceFileOptions . packageJsonLocations : undefined ;
1988
+ newSourceFile . packageJsonLocations = sourceFileOptions . packageJsonLocations ;
1981
1989
newSourceFile . packageJsonScope = sourceFileOptions . packageJsonScope ;
1982
1990
1983
1991
Debug . assert ( ! newSourceFile . redirectInfo , "Host should not return a redirect source file from `getSourceFile`" ) ;
@@ -3048,7 +3056,7 @@ namespace ts {
3048
3056
redirect . resolvedPath = resolvedPath ;
3049
3057
redirect . originalFileName = originalFileName ;
3050
3058
redirect . redirectInfo = { redirectTarget, unredirected } ;
3051
- redirect . packageJsonLocations = sourceFileOptions . packageJsonLocations ?. length ? sourceFileOptions . packageJsonLocations : undefined ;
3059
+ redirect . packageJsonLocations = sourceFileOptions . packageJsonLocations ;
3052
3060
redirect . packageJsonScope = sourceFileOptions . packageJsonScope ;
3053
3061
sourceFilesFoundSearchingNodeModules . set ( path , currentNodeModulesDepth > 0 ) ;
3054
3062
Object . defineProperties ( redirect , {
@@ -3080,7 +3088,7 @@ namespace ts {
3080
3088
// It's a _little odd_ that we can't set `impliedNodeFormat` until the program step - but it's the first and only time we have a resolution cache
3081
3089
// and a freshly made source file node on hand at the same time, and we need both to set the field. Persisting the resolution cache all the way
3082
3090
// to the check and emit steps would be bad - so we much prefer detecting and storing the format information on the source file node upfront.
3083
- const result = getImpliedNodeFormatForFileWorker ( toPath ( fileName ) , moduleResolutionCache ?. getPackageJsonInfoCache ( ) , host , options ) ;
3091
+ const result = getImpliedNodeFormatForFileWorker ( toPath ( fileName ) , moduleResolutionCache ?. getPackageJsonInfoCache ( ) , host , options , oldBuildInfoProgram ) ;
3084
3092
const languageVersion = getEmitScriptTarget ( options ) ;
3085
3093
const setExternalModuleIndicator = getSetExternalModuleIndicator ( options ) ;
3086
3094
return typeof result === "object" ?
@@ -3214,7 +3222,7 @@ namespace ts {
3214
3222
file . path = path ;
3215
3223
file . resolvedPath = toPath ( fileName ) ;
3216
3224
file . originalFileName = originalFileName ;
3217
- file . packageJsonLocations = sourceFileOptions . packageJsonLocations ?. length ? sourceFileOptions . packageJsonLocations : undefined ;
3225
+ file . packageJsonLocations = sourceFileOptions . packageJsonLocations ;
3218
3226
file . packageJsonScope = sourceFileOptions . packageJsonScope ;
3219
3227
addFileIncludeReason ( file , reason ) ;
3220
3228
0 commit comments