@@ -81,6 +81,14 @@ export interface HasInvalidatedFromResolutionCache {
8181 hasInvalidatedResolutions : HasInvalidatedResolutions ;
8282 hasInvalidatedLibResolutions : HasInvalidatedLibResolutions ;
8383}
84+ /** @internal */
85+ export type CallbackOnNewResolution < T extends ResolutionWithFailedLookupLocations > = (
86+ existing : T | undefined ,
87+ current : T ,
88+ path : Path ,
89+ name : string ,
90+ mode : ResolutionMode ,
91+ ) => void ;
8492/**
8593 * This is the cache of module/typedirectives resolution that can be retained across program
8694 *
@@ -100,8 +108,6 @@ export interface ResolutionCache {
100108 dirPathToSymlinkPackageRefCount : Map < Path , number > ;
101109 countResolutionsResolvedWithGlobalCache ( ) : number ;
102110 countResolutionsResolvedWithoutGlobalCache ( ) : number ;
103- startRecordingFilesWithChangedResolutions ( ) : void ;
104- finishRecordingFilesWithChangedResolutions ( ) : Path [ ] | undefined ;
105111
106112 watchFailedLookupLocationsOfExternalModuleResolutions < T extends ResolutionWithFailedLookupLocations , R extends ResolutionWithResolvedFileName > (
107113 name : string ,
@@ -118,6 +124,7 @@ export interface ResolutionCache {
118124 options : CompilerOptions ,
119125 containingSourceFile : SourceFile ,
120126 reusedNames : readonly StringLiteralLike [ ] | undefined ,
127+ onNewResolution ?: CallbackOnNewResolution < ResolvedModuleWithFailedLookupLocations > ,
121128 ) : readonly ResolvedModuleWithFailedLookupLocations [ ] ;
122129 resolveTypeReferenceDirectiveReferences < T extends FileReference | string > (
123130 typeDirectiveReferences : readonly T [ ] ,
@@ -533,7 +540,8 @@ export function needsResolutionFromGlobalCache(moduleName: string, resolution: R
533540 return ! isExternalModuleNameRelative ( moduleName ) && isUnresolvedOrResolvedToJs ( resolution ) ;
534541}
535542
536- function isUnresolvedOrResolvedToJs ( resolution : ResolvedModuleWithFailedLookupLocations ) {
543+ /** @internal */
544+ export function isUnresolvedOrResolvedToJs ( resolution : ResolvedModuleWithFailedLookupLocations ) : boolean {
537545 return ! resolution . resolvedModule || ! resolutionExtensionIsTSOrJson ( resolution . resolvedModule . extension ) ;
538546}
539547
@@ -592,7 +600,6 @@ export function createResolutionCache(
592600 resolutionHost : ResolutionCacheHost ,
593601 rootDirForResolution : string ,
594602) : ResolutionCache {
595- let filesWithChangedSetOfUnresolvedImports : Path [ ] | undefined ;
596603 let filesWithInvalidatedResolutions : Set < Path > | undefined ;
597604 const nonRelativeExternalModuleResolutions = new Set < ResolutionWithFailedLookupLocations > ( ) ;
598605
@@ -675,8 +682,6 @@ export function createResolutionCache(
675682 countResolutionsResolvedWithoutGlobalCache : ( ) => resolutionsResolvedWithoutGlobalCache ,
676683 watchFailedLookupLocationsOfExternalModuleResolutions,
677684 getModuleResolutionCache : ( ) => moduleResolutionCache ,
678- startRecordingFilesWithChangedResolutions,
679- finishRecordingFilesWithChangedResolutions,
680685 // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
681686 // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
682687 startCachingPerDirectoryResolution,
@@ -742,16 +747,6 @@ export function createResolutionCache(
742747 typeReferenceDirectiveResolutionCache . update ( resolutionHost . getCompilationSettings ( ) ) ;
743748 }
744749
745- function startRecordingFilesWithChangedResolutions ( ) {
746- filesWithChangedSetOfUnresolvedImports = [ ] ;
747- }
748-
749- function finishRecordingFilesWithChangedResolutions ( ) {
750- const collected = filesWithChangedSetOfUnresolvedImports ;
751- filesWithChangedSetOfUnresolvedImports = undefined ;
752- return collected ;
753- }
754-
755750 function createHasInvalidatedResolutions (
756751 customHasInvalidatedResolutions : HasInvalidatedResolutions ,
757752 customHasInvalidatedLibResolutions : HasInvalidatedLibResolutions ,
@@ -880,8 +875,8 @@ export function createResolutionCache(
880875 perFileCache : Map < Path , ModeAwareCache < T > > ;
881876 loader : ResolutionLoader < Entry , T , SourceFile > ;
882877 getResolutionWithResolvedFileName : GetResolutionWithResolvedFileName < T , R > ;
883- logChanges ?: boolean ;
884878 deferWatchingNonRelativeResolution : boolean ;
879+ onNewResolution ?: CallbackOnNewResolution < T > ;
885880 }
886881 function resolveNamesWithLocalCache < Entry , SourceFile , T extends ResolutionWithFailedLookupLocations , R extends ResolutionWithResolvedFileName > ( {
887882 entries,
@@ -894,7 +889,7 @@ export function createResolutionCache(
894889 loader,
895890 getResolutionWithResolvedFileName,
896891 deferWatchingNonRelativeResolution,
897- logChanges ,
892+ onNewResolution ,
898893 } : ResolveNamesWithLocalCacheInput < Entry , SourceFile , T , R > ) : readonly T [ ] {
899894 const path = resolutionHost . toPath ( containingFile ) ;
900895 const resolutionsInFile = perFileCache . get ( path ) || perFileCache . set ( path , createModeAwareCache ( ) ) . get ( path ) ! ;
@@ -935,12 +930,7 @@ export function createResolutionCache(
935930 stopWatchFailedLookupLocationOfResolution ( existingResolution , path , getResolutionWithResolvedFileName ) ;
936931 }
937932 }
938-
939- if ( logChanges && filesWithChangedSetOfUnresolvedImports && ! resolutionIsEqualTo ( existingResolution , resolution ) ) {
940- filesWithChangedSetOfUnresolvedImports . push ( path ) ;
941- // reset log changes to avoid recording the same file multiple times
942- logChanges = false ;
943- }
933+ onNewResolution ?.( existingResolution , resolution , path , name , mode ) ;
944934 }
945935 else {
946936 const host = getModuleResolutionHost ( resolutionHost ) ;
@@ -987,24 +977,6 @@ export function createResolutionCache(
987977 } ) ;
988978 }
989979 return resolvedModules ;
990-
991- function resolutionIsEqualTo ( oldResolution : T | undefined , newResolution : T | undefined ) : boolean {
992- if ( oldResolution === newResolution ) {
993- return true ;
994- }
995- if ( ! oldResolution || ! newResolution ) {
996- return false ;
997- }
998- const oldResult = getResolutionWithResolvedFileName ( oldResolution ) ;
999- const newResult = getResolutionWithResolvedFileName ( newResolution ) ;
1000- if ( oldResult === newResult ) {
1001- return true ;
1002- }
1003- if ( ! oldResult || ! newResult ) {
1004- return false ;
1005- }
1006- return oldResult . resolvedFileName === newResult . resolvedFileName ;
1007- }
1008980 }
1009981
1010982 function resolveTypeReferenceDirectiveReferences < T extends FileReference | string > (
@@ -1042,6 +1014,7 @@ export function createResolutionCache(
10421014 options : CompilerOptions ,
10431015 containingSourceFile : SourceFile ,
10441016 reusedNames : readonly StringLiteralLike [ ] | undefined ,
1017+ onNewResolution ?: CallbackOnNewResolution < ResolvedModuleWithFailedLookupLocations > ,
10451018 ) : readonly ResolvedModuleWithFailedLookupLocations [ ] {
10461019 return resolveNamesWithLocalCache ( {
10471020 entries : moduleLiterals ,
@@ -1059,8 +1032,8 @@ export function createResolutionCache(
10591032 moduleResolutionCache ,
10601033 ) ,
10611034 getResolutionWithResolvedFileName : getResolvedModuleFromResolution ,
1062- logChanges : ! ! resolutionHost . getGlobalTypingsCacheLocation ,
10631035 deferWatchingNonRelativeResolution : true , // Defer non relative resolution watch because we could be using ambient modules
1036+ onNewResolution,
10641037 } ) ;
10651038 }
10661039
0 commit comments