@typescript-deploys/pr-build 5.9.0-pr-54183-44 → 5.9.0-pr-61732-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/_tsc.js CHANGED
@@ -39622,19 +39622,40 @@ function createResolvedModuleWithFailedLookupLocationsHandlingSymlink(moduleName
39622
39622
  alternateResult
39623
39623
  );
39624
39624
  }
39625
+ function updateResultFromCache(resultFromCache, failedLookupLocations, affectingLocations, diagnostics) {
39626
+ resultFromCache.failedLookupLocations = updateResolutionField(resultFromCache.failedLookupLocations, failedLookupLocations);
39627
+ resultFromCache.affectingLocations = updateResolutionField(resultFromCache.affectingLocations, affectingLocations);
39628
+ resultFromCache.resolutionDiagnostics = updateResolutionField(resultFromCache.resolutionDiagnostics, diagnostics);
39629
+ }
39630
+ function updatePrimaryAndGlobalCacheResolution(primaryWithGlobalCacheResult, failedLookupLocations, affectingLocations, diagnostics) {
39631
+ updateResultFromCache(primaryWithGlobalCacheResult, failedLookupLocations, affectingLocations, diagnostics);
39632
+ if (primaryWithGlobalCacheResult.globalCacheResolution.globalResult.resolvedModule) {
39633
+ updateResultFromCache(primaryWithGlobalCacheResult.globalCacheResolution.globalResult, failedLookupLocations, affectingLocations, diagnostics);
39634
+ } else {
39635
+ primaryWithGlobalCacheResult.globalCacheResolution.globalResult.failedLookupLocations = primaryWithGlobalCacheResult.failedLookupLocations;
39636
+ primaryWithGlobalCacheResult.globalCacheResolution.globalResult.affectingLocations = primaryWithGlobalCacheResult.affectingLocations;
39637
+ primaryWithGlobalCacheResult.globalCacheResolution.globalResult.resolutionDiagnostics = primaryWithGlobalCacheResult.resolutionDiagnostics;
39638
+ }
39639
+ }
39625
39640
  function createResolvedModuleWithFailedLookupLocations(resolved, isExternalLibraryImport, failedLookupLocations, affectingLocations, diagnostics, resultFromCache, cache, alternateResult) {
39641
+ var _a;
39626
39642
  if (resultFromCache) {
39627
39643
  if (!(cache == null ? void 0 : cache.isReadonly)) {
39628
- resultFromCache.failedLookupLocations = updateResolutionField(resultFromCache.failedLookupLocations, failedLookupLocations);
39629
- resultFromCache.affectingLocations = updateResolutionField(resultFromCache.affectingLocations, affectingLocations);
39630
- resultFromCache.resolutionDiagnostics = updateResolutionField(resultFromCache.resolutionDiagnostics, diagnostics);
39644
+ if (isResolvedWithGlobalCachePass(resultFromCache)) {
39645
+ updatePrimaryAndGlobalCacheResolution(resultFromCache.globalCacheResolution.primary, failedLookupLocations, affectingLocations, diagnostics);
39646
+ } else if ((_a = resultFromCache.globalCacheResolution) == null ? void 0 : _a.globalResult) {
39647
+ updatePrimaryAndGlobalCacheResolution(resultFromCache, failedLookupLocations, affectingLocations, diagnostics);
39648
+ } else {
39649
+ updateResultFromCache(resultFromCache, failedLookupLocations, affectingLocations, diagnostics);
39650
+ }
39631
39651
  return resultFromCache;
39632
39652
  } else {
39633
39653
  return {
39634
- ...resultFromCache,
39654
+ resolvedModule: resultFromCache.resolvedModule,
39635
39655
  failedLookupLocations: initializeResolutionFieldForReadonlyCache(resultFromCache.failedLookupLocations, failedLookupLocations),
39636
39656
  affectingLocations: initializeResolutionFieldForReadonlyCache(resultFromCache.affectingLocations, affectingLocations),
39637
- resolutionDiagnostics: initializeResolutionFieldForReadonlyCache(resultFromCache.resolutionDiagnostics, diagnostics)
39657
+ resolutionDiagnostics: initializeResolutionFieldForReadonlyCache(resultFromCache.resolutionDiagnostics, diagnostics),
39658
+ alternateResult: resultFromCache.alternateResult
39638
39659
  };
39639
39660
  }
39640
39661
  }
@@ -39888,16 +39909,14 @@ function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFil
39888
39909
  affectingLocations: initializeResolutionField(affectingLocations),
39889
39910
  resolutionDiagnostics: initializeResolutionField(diagnostics)
39890
39911
  };
39891
- if (containingDirectory && cache && !cache.isReadonly) {
39892
- cache.getOrCreateCacheForDirectory(containingDirectory, redirectedReference).set(
39912
+ if (containingDirectory) {
39913
+ cache == null ? void 0 : cache.setPerDirectoryAndNonRelativeNameCacheResult(
39893
39914
  typeReferenceDirectiveName,
39894
- /*mode*/
39895
39915
  resolutionMode,
39916
+ containingDirectory,
39917
+ redirectedReference,
39896
39918
  result
39897
39919
  );
39898
- if (!isExternalModuleNameRelative(typeReferenceDirectiveName)) {
39899
- cache.getOrCreateCacheForNonRelativeName(typeReferenceDirectiveName, resolutionMode, redirectedReference).set(containingDirectory, result);
39900
- }
39901
39920
  }
39902
39921
  if (traceEnabled) traceResult(result);
39903
39922
  return result;
@@ -40083,6 +40102,9 @@ function compilerOptionValueToString(value) {
40083
40102
  function getKeyForCompilerOptions(options, affectingOptionDeclarations) {
40084
40103
  return affectingOptionDeclarations.map((option) => compilerOptionValueToString(getCompilerOptionValue(options, option))).join("|") + `|${options.pathsBasePath}`;
40085
40104
  }
40105
+ function computeRedirectsCacheKey(options) {
40106
+ return getKeyForCompilerOptions(options, moduleResolutionOptionDeclarations);
40107
+ }
40086
40108
  function createCacheWithRedirects(ownOptions, optionsToRedirectsKey) {
40087
40109
  const redirectsMap = /* @__PURE__ */ new Map();
40088
40110
  const redirectsKeyToMap = /* @__PURE__ */ new Map();
@@ -40093,7 +40115,11 @@ function createCacheWithRedirects(ownOptions, optionsToRedirectsKey) {
40093
40115
  getOrCreateMapOfCacheRedirects,
40094
40116
  update,
40095
40117
  clear: clear2,
40096
- getOwnMap: () => ownMap
40118
+ forEach: forEach2,
40119
+ compact: compact2,
40120
+ getOwnMap: () => ownMap,
40121
+ getOwnOptions: () => ownOptions,
40122
+ redirectsKeyToMap
40097
40123
  };
40098
40124
  function getMapOfCacheRedirects(redirectedReference) {
40099
40125
  return redirectedReference ? getOrCreateMap(
@@ -40151,10 +40177,33 @@ function createCacheWithRedirects(ownOptions, optionsToRedirectsKey) {
40151
40177
  function getRedirectsCacheKey(options) {
40152
40178
  let result = optionsToRedirectsKey.get(options);
40153
40179
  if (!result) {
40154
- optionsToRedirectsKey.set(options, result = getKeyForCompilerOptions(options, moduleResolutionOptionDeclarations));
40180
+ optionsToRedirectsKey.set(options, result = computeRedirectsCacheKey(options));
40155
40181
  }
40156
40182
  return result;
40157
40183
  }
40184
+ function forEach2(cb) {
40185
+ ownMap.forEach((value, key) => cb(
40186
+ value,
40187
+ key,
40188
+ /*redirectsCacheKey*/
40189
+ void 0,
40190
+ ownMap
40191
+ ));
40192
+ redirectsKeyToMap.forEach((map2, redirectsCacheKey) => {
40193
+ if (map2 !== ownMap) map2.forEach((value, key) => cb(value, key, redirectsCacheKey, map2));
40194
+ });
40195
+ }
40196
+ function compact2(availableOptions) {
40197
+ const toDeleteRedirectsCacheKeys = new Set(redirectsKeyToMap.keys());
40198
+ optionsToRedirectsKey.forEach((key, options) => {
40199
+ if (options === ownOptions || availableOptions.has(options)) {
40200
+ toDeleteRedirectsCacheKeys.delete(key);
40201
+ } else {
40202
+ redirectsMap.delete(options);
40203
+ }
40204
+ });
40205
+ toDeleteRedirectsCacheKeys.forEach((key) => redirectsKeyToMap.delete(key));
40206
+ }
40158
40207
  }
40159
40208
  function createPackageJsonInfoCache(currentDirectory, getCanonicalFileName) {
40160
40209
  let cache;
@@ -40181,7 +40230,7 @@ function getOrCreateCache(cacheWithRedirects, redirectedReference, key, create)
40181
40230
  }
40182
40231
  return result;
40183
40232
  }
40184
- function createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, options, optionsToRedirectsKey) {
40233
+ function createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, options, optionsToRedirectsKey, getValidResolution) {
40185
40234
  const directoryToModuleNameMap = createCacheWithRedirects(options, optionsToRedirectsKey);
40186
40235
  return {
40187
40236
  getFromDirectoryCache,
@@ -40203,7 +40252,7 @@ function createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileNam
40203
40252
  function getFromDirectoryCache(name, mode, directoryName, redirectedReference) {
40204
40253
  var _a, _b;
40205
40254
  const path = toPath(directoryName, currentDirectory, getCanonicalFileName);
40206
- return (_b = (_a = directoryToModuleNameMap.getMapOfCacheRedirects(redirectedReference)) == null ? void 0 : _a.get(path)) == null ? void 0 : _b.get(name, mode);
40255
+ return getValidResolution((_b = (_a = directoryToModuleNameMap.getMapOfCacheRedirects(redirectedReference)) == null ? void 0 : _a.get(path)) == null ? void 0 : _b.get(name, mode));
40207
40256
  }
40208
40257
  }
40209
40258
  function createModeAwareCacheKey(specifier, mode) {
@@ -40230,7 +40279,7 @@ function createModeAwareCache() {
40230
40279
  forEach(cb) {
40231
40280
  return underlying.forEach((elem, key) => {
40232
40281
  const [specifier, mode] = memoizedReverseKeys.get(key);
40233
- return cb(elem, specifier, mode);
40282
+ return cb(elem, specifier, mode, key);
40234
40283
  });
40235
40284
  },
40236
40285
  size() {
@@ -40245,18 +40294,20 @@ function createModeAwareCache() {
40245
40294
  }
40246
40295
  }
40247
40296
  function getOriginalOrResolvedModuleFileName(result) {
40248
- return result.resolvedModule && (result.resolvedModule.originalPath || result.resolvedModule.resolvedFileName);
40297
+ const resolvedModule = !result.globalCacheResolution ? result.resolvedModule : result.globalCacheResolution.primary.resolvedModule;
40298
+ return resolvedModule && (resolvedModule.originalPath || resolvedModule.resolvedFileName);
40249
40299
  }
40250
40300
  function getOriginalOrResolvedTypeReferenceFileName(result) {
40251
40301
  return result.resolvedTypeReferenceDirective && (result.resolvedTypeReferenceDirective.originalPath || result.resolvedTypeReferenceDirective.resolvedFileName);
40252
40302
  }
40253
- function createNonRelativeNameResolutionCache(currentDirectory, getCanonicalFileName, options, getResolvedFileName, optionsToRedirectsKey) {
40303
+ function createNonRelativeNameResolutionCache(currentDirectory, getCanonicalFileName, options, getResolvedFileName, optionsToRedirectsKey, getValidResolution) {
40254
40304
  const moduleNameToDirectoryMap = createCacheWithRedirects(options, optionsToRedirectsKey);
40255
40305
  return {
40256
40306
  getFromNonRelativeNameCache,
40257
40307
  getOrCreateCacheForNonRelativeName,
40258
40308
  clear: clear2,
40259
- update
40309
+ update,
40310
+ moduleNameToDirectoryMap
40260
40311
  };
40261
40312
  function clear2() {
40262
40313
  moduleNameToDirectoryMap.clear();
@@ -40267,38 +40318,79 @@ function createNonRelativeNameResolutionCache(currentDirectory, getCanonicalFile
40267
40318
  function getFromNonRelativeNameCache(nonRelativeModuleName, mode, directoryName, redirectedReference) {
40268
40319
  var _a, _b;
40269
40320
  Debug.assert(!isExternalModuleNameRelative(nonRelativeModuleName));
40270
- return (_b = (_a = moduleNameToDirectoryMap.getMapOfCacheRedirects(redirectedReference)) == null ? void 0 : _a.get(createModeAwareCacheKey(nonRelativeModuleName, mode))) == null ? void 0 : _b.get(directoryName);
40321
+ return (_b = (_a = moduleNameToDirectoryMap.getMapOfCacheRedirects(redirectedReference)) == null ? void 0 : _a.get(
40322
+ createModeAwareCacheKey(nonRelativeModuleName, mode)
40323
+ )) == null ? void 0 : _b.get(directoryName);
40271
40324
  }
40272
40325
  function getOrCreateCacheForNonRelativeName(nonRelativeModuleName, mode, redirectedReference) {
40273
40326
  Debug.assert(!isExternalModuleNameRelative(nonRelativeModuleName));
40274
- return getOrCreateCache(moduleNameToDirectoryMap, redirectedReference, createModeAwareCacheKey(nonRelativeModuleName, mode), createPerModuleNameCache);
40327
+ return getOrCreateCache(
40328
+ moduleNameToDirectoryMap,
40329
+ redirectedReference,
40330
+ createModeAwareCacheKey(nonRelativeModuleName, mode),
40331
+ createPerModuleNameCache
40332
+ );
40275
40333
  }
40276
40334
  function createPerModuleNameCache() {
40277
40335
  const directoryPathMap = /* @__PURE__ */ new Map();
40278
- return { get, set };
40336
+ return { get, set, deleteByPath, directoryPathMap };
40279
40337
  function get(directory) {
40280
- return directoryPathMap.get(toPath(directory, currentDirectory, getCanonicalFileName));
40338
+ return getByPath(toPath(directory, currentDirectory, getCanonicalFileName));
40339
+ }
40340
+ function getByPath(directoryPath, primary, forSet) {
40341
+ const result = getValidResolution(directoryPathMap.get(directoryPath), forSet);
40342
+ return !result || result === primary ? void 0 : result;
40343
+ }
40344
+ function deleteByPath(directory) {
40345
+ const existing = directoryPathMap.get(directory);
40346
+ if (existing) {
40347
+ directoryPathMap.delete(directory);
40348
+ withCommonPrefix(
40349
+ directory,
40350
+ getCommonPrefix(directory, existing),
40351
+ (parent) => directoryPathMap.delete(parent)
40352
+ );
40353
+ }
40281
40354
  }
40282
- function set(directory, result) {
40355
+ function set(directory, result, primary) {
40283
40356
  const path = toPath(directory, currentDirectory, getCanonicalFileName);
40284
- if (directoryPathMap.has(path)) {
40357
+ if (getByPath(
40358
+ path,
40359
+ primary,
40360
+ /*forSet*/
40361
+ true
40362
+ )) {
40285
40363
  return;
40286
40364
  }
40365
+ if (!primary) deleteByPath(path);
40287
40366
  directoryPathMap.set(path, result);
40288
- const resolvedFileName = getResolvedFileName(result);
40289
- const commonPrefix = resolvedFileName && getCommonPrefix(path, resolvedFileName);
40367
+ withCommonPrefix(
40368
+ path,
40369
+ getCommonPrefix(path, result),
40370
+ (parent) => directoryPathMap.set(parent, result),
40371
+ primary
40372
+ );
40373
+ }
40374
+ function withCommonPrefix(path, commonPrefix, action, primary) {
40290
40375
  let current = path;
40291
40376
  while (current !== commonPrefix) {
40292
40377
  const parent = getDirectoryPath(current);
40293
- if (parent === current || directoryPathMap.has(parent)) {
40378
+ if (parent === current || getByPath(
40379
+ parent,
40380
+ primary,
40381
+ /*forSet*/
40382
+ true
40383
+ )) {
40294
40384
  break;
40295
40385
  }
40296
- directoryPathMap.set(parent, result);
40386
+ action(parent);
40297
40387
  current = parent;
40298
40388
  }
40299
40389
  }
40300
40390
  function getCommonPrefix(directory, resolution) {
40301
- const resolutionDirectory = toPath(getDirectoryPath(resolution), currentDirectory, getCanonicalFileName);
40391
+ const resolvedFileName = getResolvedFileName(resolution);
40392
+ if (!resolvedFileName) return void 0;
40393
+ const resolutionDirectory = toPath(getDirectoryPath(resolvedFileName), currentDirectory, getCanonicalFileName);
40302
40394
  let i = 0;
40303
40395
  const limit = Math.min(directory.length, resolutionDirectory.length);
40304
40396
  while (i < limit && directory.charCodeAt(i) === resolutionDirectory.charCodeAt(i)) {
@@ -40319,69 +40411,130 @@ function createNonRelativeNameResolutionCache(currentDirectory, getCanonicalFile
40319
40411
  }
40320
40412
  }
40321
40413
  }
40322
- function createModuleOrTypeReferenceResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache, getResolvedFileName, optionsToRedirectsKey) {
40414
+ function createModuleOrTypeReferenceResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache, getResolvedFileName, optionsToRedirectsKey, getValidResolution) {
40323
40415
  optionsToRedirectsKey ?? (optionsToRedirectsKey = /* @__PURE__ */ new Map());
40416
+ getValidResolution ?? (getValidResolution = identity);
40324
40417
  const perDirectoryResolutionCache = createPerDirectoryResolutionCache(
40325
40418
  currentDirectory,
40326
40419
  getCanonicalFileName,
40327
40420
  options,
40328
- optionsToRedirectsKey
40421
+ optionsToRedirectsKey,
40422
+ getValidResolution
40329
40423
  );
40330
40424
  const nonRelativeNameResolutionCache = createNonRelativeNameResolutionCache(
40331
40425
  currentDirectory,
40332
40426
  getCanonicalFileName,
40333
40427
  options,
40334
40428
  getResolvedFileName,
40335
- optionsToRedirectsKey
40429
+ optionsToRedirectsKey,
40430
+ getValidResolution
40336
40431
  );
40337
40432
  packageJsonInfoCache ?? (packageJsonInfoCache = createPackageJsonInfoCache(currentDirectory, getCanonicalFileName));
40338
- return {
40433
+ const cache = {
40339
40434
  ...packageJsonInfoCache,
40340
40435
  ...perDirectoryResolutionCache,
40341
40436
  ...nonRelativeNameResolutionCache,
40342
40437
  clear: clear2,
40343
40438
  update,
40439
+ gc,
40440
+ compact: compact2,
40441
+ setPerDirectoryAndNonRelativeNameCacheResult,
40442
+ options: () => options,
40344
40443
  getPackageJsonInfoCache: () => packageJsonInfoCache,
40345
- clearAllExceptPackageJsonInfoCache,
40346
- optionsToRedirectsKey
40444
+ optionsToRedirectsKey,
40445
+ print
40347
40446
  };
40447
+ return cache;
40348
40448
  function clear2() {
40349
- clearAllExceptPackageJsonInfoCache();
40350
- packageJsonInfoCache.clear();
40351
- }
40352
- function clearAllExceptPackageJsonInfoCache() {
40353
40449
  perDirectoryResolutionCache.clear();
40354
40450
  nonRelativeNameResolutionCache.clear();
40451
+ packageJsonInfoCache.clear();
40355
40452
  }
40356
- function update(options2) {
40357
- perDirectoryResolutionCache.update(options2);
40358
- nonRelativeNameResolutionCache.update(options2);
40453
+ function update(updatedOptions) {
40454
+ options = updatedOptions;
40455
+ perDirectoryResolutionCache.update(updatedOptions);
40456
+ nonRelativeNameResolutionCache.update(updatedOptions);
40457
+ }
40458
+ function gc(setOrMapToCheckPresence) {
40459
+ perDirectoryResolutionCache.directoryToModuleNameMap.forEach((resolutions, dir, redirectsCacheKey, directoryToModuleNameMap) => {
40460
+ resolutions.forEach((resolution, name, mode, key) => {
40461
+ if (setOrMapToCheckPresence.has(resolution)) return;
40462
+ resolutions.delete(name, mode);
40463
+ if (!isExternalModuleNameRelative(name)) {
40464
+ const moduleNameToDirectoryMap = !redirectsCacheKey ? nonRelativeNameResolutionCache.moduleNameToDirectoryMap.getOwnMap() : nonRelativeNameResolutionCache.moduleNameToDirectoryMap.redirectsKeyToMap.get(redirectsCacheKey);
40465
+ const directoryMap = moduleNameToDirectoryMap == null ? void 0 : moduleNameToDirectoryMap.get(key);
40466
+ directoryMap == null ? void 0 : directoryMap.deleteByPath(dir);
40467
+ if (!(directoryMap == null ? void 0 : directoryMap.directoryPathMap.size)) moduleNameToDirectoryMap.delete(key);
40468
+ }
40469
+ });
40470
+ if (!resolutions.size()) directoryToModuleNameMap.delete(dir);
40471
+ });
40472
+ }
40473
+ function compact2(availableOptions = new Set(optionsToRedirectsKey.keys()), skipOptionsToRedirectsKeyCleanup) {
40474
+ perDirectoryResolutionCache.directoryToModuleNameMap.compact(availableOptions);
40475
+ nonRelativeNameResolutionCache.moduleNameToDirectoryMap.compact(availableOptions);
40476
+ if (!skipOptionsToRedirectsKeyCleanup) {
40477
+ optionsToRedirectsKey.forEach(
40478
+ (_redirectsKey, options2) => {
40479
+ if (!availableOptions.has(options2)) optionsToRedirectsKey.delete(options2);
40480
+ }
40481
+ );
40482
+ }
40483
+ }
40484
+ function setPerDirectoryAndNonRelativeNameCacheResult(name, mode, directoryName, redirectedReference, result, primary) {
40485
+ if (cache.isReadonly) return;
40486
+ cache.getOrCreateCacheForDirectory(directoryName, redirectedReference).set(name, mode, result);
40487
+ if (!isExternalModuleNameRelative(name)) {
40488
+ cache.getOrCreateCacheForNonRelativeName(name, mode, redirectedReference).set(directoryName, result, primary);
40489
+ }
40490
+ }
40491
+ function print() {
40492
+ console.log(`directoryToModuleNameMap::`);
40493
+ perDirectoryResolutionCache.directoryToModuleNameMap.forEach((moduleNameMap, directoryPath, redirectsCacheKey) => {
40494
+ if (!redirectsCacheKey) console.log(" OwnMap");
40495
+ else console.log(` redirectsCacheKey:: ${redirectsCacheKey}`);
40496
+ console.log(` directoryPath:: ${directoryPath}`);
40497
+ moduleNameMap.forEach((value, key, mode) => {
40498
+ console.log(` ${key} ${mode} ${JSON.stringify(value, void 0, " ")}`);
40499
+ });
40500
+ });
40501
+ console.log(`moduleNameToDirectoryMap::`);
40502
+ nonRelativeNameResolutionCache.moduleNameToDirectoryMap.forEach((perNonRelativeNameCache, key, redirectsCacheKey) => {
40503
+ if (!redirectsCacheKey) console.log(" OwnMap");
40504
+ else console.log(` redirectsCacheKey:: ${redirectsCacheKey}`);
40505
+ console.log(` modeAwareCacheKey:: ${key}`);
40506
+ perNonRelativeNameCache.directoryPathMap.forEach((value, key2) => {
40507
+ console.log(` ${key2} ${JSON.stringify(value, void 0, " ")}`);
40508
+ });
40509
+ });
40359
40510
  }
40360
40511
  }
40361
- function createModuleResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache, optionsToRedirectsKey) {
40512
+ function createModuleResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache, optionsToRedirectsKey, getValidResolution) {
40362
40513
  const result = createModuleOrTypeReferenceResolutionCache(
40363
40514
  currentDirectory,
40364
40515
  getCanonicalFileName,
40365
40516
  options,
40366
40517
  packageJsonInfoCache,
40367
40518
  getOriginalOrResolvedModuleFileName,
40368
- optionsToRedirectsKey
40519
+ optionsToRedirectsKey,
40520
+ getValidResolution
40369
40521
  );
40370
40522
  result.getOrCreateCacheForModuleName = (nonRelativeName, mode, redirectedReference) => result.getOrCreateCacheForNonRelativeName(nonRelativeName, mode, redirectedReference);
40371
40523
  return result;
40372
40524
  }
40373
- function createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache, optionsToRedirectsKey) {
40525
+ function createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache, optionsToRedirectsKey, getValidResolution) {
40374
40526
  return createModuleOrTypeReferenceResolutionCache(
40375
40527
  currentDirectory,
40376
40528
  getCanonicalFileName,
40377
40529
  options,
40378
40530
  packageJsonInfoCache,
40379
40531
  getOriginalOrResolvedTypeReferenceFileName,
40380
- optionsToRedirectsKey
40532
+ optionsToRedirectsKey,
40533
+ getValidResolution
40381
40534
  );
40382
40535
  }
40383
40536
  function getOptionsForLibraryResolution(options) {
40384
- return { moduleResolution: 2 /* Node10 */, traceResolution: options.traceResolution };
40537
+ return { moduleResolution: 2 /* Node10 */, traceResolution: options == null ? void 0 : options.traceResolution };
40385
40538
  }
40386
40539
  function resolveLibrary(libraryName, resolveFrom, compilerOptions, host, cache) {
40387
40540
  return resolveModuleName(libraryName, resolveFrom, getOptionsForLibraryResolution(compilerOptions), host, cache);
@@ -40434,12 +40587,13 @@ function resolveModuleName(moduleName, containingFile, compilerOptions, host, ca
40434
40587
  default:
40435
40588
  return Debug.fail(`Unexpected moduleResolution: ${moduleResolution}`);
40436
40589
  }
40437
- if (cache && !cache.isReadonly) {
40438
- cache.getOrCreateCacheForDirectory(containingDirectory, redirectedReference).set(moduleName, resolutionMode, result);
40439
- if (!isExternalModuleNameRelative(moduleName)) {
40440
- cache.getOrCreateCacheForNonRelativeName(moduleName, resolutionMode, redirectedReference).set(containingDirectory, result);
40441
- }
40442
- }
40590
+ cache == null ? void 0 : cache.setPerDirectoryAndNonRelativeNameCacheResult(
40591
+ moduleName,
40592
+ resolutionMode,
40593
+ containingDirectory,
40594
+ redirectedReference,
40595
+ result
40596
+ );
40443
40597
  }
40444
40598
  if (traceEnabled) {
40445
40599
  if (result.resolvedModule) {
@@ -40718,7 +40872,7 @@ function nodeModuleNameResolverWorker(features, moduleName, containingDirectory,
40718
40872
  result = tryResolve(extensions, state);
40719
40873
  }
40720
40874
  let alternateResult;
40721
- if (state.resolvedPackageDirectory && !isConfigLookup && !isExternalModuleNameRelative(moduleName)) {
40875
+ if (!state.resultFromCache && state.resolvedPackageDirectory && !isConfigLookup && !isExternalModuleNameRelative(moduleName)) {
40722
40876
  const wantedTypesButGotJs = (result == null ? void 0 : result.value) && extensions & (1 /* TypeScript */ | 4 /* Declaration */) && !extensionIsOk(1 /* TypeScript */ | 4 /* Declaration */, result.value.resolved.extension);
40723
40877
  if (((_a = result == null ? void 0 : result.value) == null ? void 0 : _a.isExternalLibraryImport) && wantedTypesButGotJs && features & 8 /* Exports */ && (conditions == null ? void 0 : conditions.includes("import"))) {
40724
40878
  traceIfEnabled(state, Diagnostics.Resolution_of_non_relative_name_failed_trying_with_modern_Node_resolution_features_disabled_to_see_if_npm_library_needs_configuration_update);
@@ -46497,7 +46651,7 @@ function createTypeChecker(host) {
46497
46651
  void 0
46498
46652
  );
46499
46653
  },
46500
- containsContextSensitive,
46654
+ isContextSensitive,
46501
46655
  getTypeOfPropertyOfContextualType,
46502
46656
  getFullyQualifiedName,
46503
46657
  getResolvedSignature: (node, candidatesOutArray, argumentCount) => getResolvedSignatureWorker(node, candidatesOutArray, argumentCount, 0 /* Normal */),
@@ -50464,7 +50618,7 @@ function createTypeChecker(host) {
50464
50618
  );
50465
50619
  }
50466
50620
  function symbolValueDeclarationIsContextSensitive(symbol) {
50467
- return symbol && !!symbol.valueDeclaration && isExpression(symbol.valueDeclaration) && !containsContextSensitive(symbol.valueDeclaration);
50621
+ return symbol && !!symbol.valueDeclaration && isExpression(symbol.valueDeclaration) && !isContextSensitive(symbol.valueDeclaration);
50468
50622
  }
50469
50623
  function toNodeBuilderFlags(flags = 0 /* None */) {
50470
50624
  return flags & 848330095 /* NodeBuilderFlagsMask */;
@@ -56691,7 +56845,7 @@ function createTypeChecker(host) {
56691
56845
  case 200 /* MappedType */:
56692
56846
  case 194 /* ConditionalType */: {
56693
56847
  const outerTypeParameters = getOuterTypeParameters(node, includeThisTypes);
56694
- if ((kind === 218 /* FunctionExpression */ || kind === 219 /* ArrowFunction */ || isObjectLiteralMethod(node)) && containsContextSensitive(node)) {
56848
+ if ((kind === 218 /* FunctionExpression */ || kind === 219 /* ArrowFunction */ || isObjectLiteralMethod(node)) && isContextSensitive(node)) {
56695
56849
  const signature = firstOrUndefined(getSignaturesOfType(getTypeOfSymbol(getSymbolOfDeclaration(node)), 0 /* Call */));
56696
56850
  if (signature && signature.typeParameters) {
56697
56851
  return [...outerTypeParameters || emptyArray, ...signature.typeParameters];
@@ -63458,47 +63612,39 @@ function createTypeChecker(host) {
63458
63612
  function instantiateIndexInfo(info, mapper) {
63459
63613
  return createIndexInfo(info.keyType, instantiateType(info.type, mapper), info.isReadonly, info.declaration, info.components);
63460
63614
  }
63461
- function containsContextRelatedNode(node, predicate) {
63615
+ function isContextSensitive(node) {
63462
63616
  Debug.assert(node.kind !== 174 /* MethodDeclaration */ || isObjectLiteralMethod(node));
63463
63617
  switch (node.kind) {
63464
63618
  case 218 /* FunctionExpression */:
63465
63619
  case 219 /* ArrowFunction */:
63466
63620
  case 174 /* MethodDeclaration */:
63467
63621
  case 262 /* FunctionDeclaration */:
63468
- case 213 /* CallExpression */:
63469
- case 214 /* NewExpression */:
63470
- return predicate(node);
63622
+ return isContextSensitiveFunctionLikeDeclaration(node);
63471
63623
  case 210 /* ObjectLiteralExpression */:
63472
- return some(node.properties, (p) => containsContextRelatedNode(p, predicate));
63624
+ return some(node.properties, isContextSensitive);
63473
63625
  case 209 /* ArrayLiteralExpression */:
63474
- return some(node.elements, (e) => containsContextRelatedNode(e, predicate));
63626
+ return some(node.elements, isContextSensitive);
63475
63627
  case 227 /* ConditionalExpression */:
63476
- return containsContextRelatedNode(node.whenTrue, predicate) || containsContextRelatedNode(node.whenFalse, predicate);
63628
+ return isContextSensitive(node.whenTrue) || isContextSensitive(node.whenFalse);
63477
63629
  case 226 /* BinaryExpression */:
63478
- return (node.operatorToken.kind === 57 /* BarBarToken */ || node.operatorToken.kind === 61 /* QuestionQuestionToken */) && (containsContextRelatedNode(node.left, predicate) || containsContextRelatedNode(node.right, predicate));
63630
+ return (node.operatorToken.kind === 57 /* BarBarToken */ || node.operatorToken.kind === 61 /* QuestionQuestionToken */) && (isContextSensitive(node.left) || isContextSensitive(node.right));
63479
63631
  case 303 /* PropertyAssignment */:
63480
- return containsContextRelatedNode(node.initializer, predicate);
63632
+ return isContextSensitive(node.initializer);
63481
63633
  case 217 /* ParenthesizedExpression */:
63482
- return containsContextRelatedNode(node.expression, predicate);
63634
+ return isContextSensitive(node.expression);
63483
63635
  case 292 /* JsxAttributes */:
63484
- return some(node.properties, (p) => containsContextRelatedNode(p, predicate)) || isJsxOpeningElement(node.parent) && some(node.parent.parent.children, (c) => containsContextRelatedNode(c, predicate));
63636
+ return some(node.properties, isContextSensitive) || isJsxOpeningElement(node.parent) && some(node.parent.parent.children, isContextSensitive);
63485
63637
  case 291 /* JsxAttribute */: {
63486
63638
  const { initializer } = node;
63487
- return !!initializer && containsContextRelatedNode(initializer, predicate);
63639
+ return !!initializer && isContextSensitive(initializer);
63488
63640
  }
63489
63641
  case 294 /* JsxExpression */: {
63490
63642
  const { expression } = node;
63491
- return !!expression && containsContextRelatedNode(expression, predicate);
63643
+ return !!expression && isContextSensitive(expression);
63492
63644
  }
63493
63645
  }
63494
63646
  return false;
63495
63647
  }
63496
- function containsContextSensitive(node) {
63497
- return containsContextRelatedNode(node, isContextSensitiveFunctionOrObjectLiteralMethod);
63498
- }
63499
- function containsContextSensitiveOrCallOrNewExpression(node) {
63500
- return containsContextRelatedNode(node, (n) => isContextSensitiveFunctionOrObjectLiteralMethod(n) || isCallOrNewExpression(n));
63501
- }
63502
63648
  function isContextSensitiveFunctionLikeDeclaration(node) {
63503
63649
  return hasContextSensitiveParameters(node) || hasContextSensitiveReturnExpression(node);
63504
63650
  }
@@ -63507,9 +63653,9 @@ function createTypeChecker(host) {
63507
63653
  return false;
63508
63654
  }
63509
63655
  if (node.body.kind !== 241 /* Block */) {
63510
- return containsContextSensitive(node.body);
63656
+ return isContextSensitive(node.body);
63511
63657
  }
63512
- return !!forEachReturnStatement(node.body, (statement) => !!statement.expression && containsContextSensitive(statement.expression));
63658
+ return !!forEachReturnStatement(node.body, (statement) => !!statement.expression && isContextSensitive(statement.expression));
63513
63659
  }
63514
63660
  function isContextSensitiveFunctionOrObjectLiteralMethod(func) {
63515
63661
  return (isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) && isContextSensitiveFunctionLikeDeclaration(func);
@@ -73570,7 +73716,7 @@ function createTypeChecker(host) {
73570
73716
  hasOmittedExpression
73571
73717
  ));
73572
73718
  elementFlags.push(hasOmittedExpression ? 2 /* Optional */ : 1 /* Required */);
73573
- if (inTupleContext && checkMode && checkMode & 2 /* Inferential */ && !(checkMode & 4 /* SkipContextSensitive */) && containsContextSensitiveOrCallOrNewExpression(e)) {
73719
+ if (inTupleContext && checkMode && checkMode & 2 /* Inferential */ && !(checkMode & 4 /* SkipContextSensitive */) && isContextSensitive(e)) {
73574
73720
  const inferenceContext = getInferenceContext(node);
73575
73721
  Debug.assert(inferenceContext);
73576
73722
  addIntraExpressionInferenceSite(inferenceContext, e, type);
@@ -73769,7 +73915,7 @@ function createTypeChecker(host) {
73769
73915
  prop.links.target = member;
73770
73916
  member = prop;
73771
73917
  allPropertiesTable == null ? void 0 : allPropertiesTable.set(prop.escapedName, prop);
73772
- if (contextualType && checkMode & 2 /* Inferential */ && !(checkMode & 4 /* SkipContextSensitive */) && (memberDecl.kind === 303 /* PropertyAssignment */ || memberDecl.kind === 174 /* MethodDeclaration */) && containsContextSensitiveOrCallOrNewExpression(memberDecl)) {
73918
+ if (contextualType && checkMode & 2 /* Inferential */ && !(checkMode & 4 /* SkipContextSensitive */) && (memberDecl.kind === 303 /* PropertyAssignment */ || memberDecl.kind === 174 /* MethodDeclaration */) && isContextSensitive(memberDecl)) {
73773
73919
  const inferenceContext = getInferenceContext(node);
73774
73920
  Debug.assert(inferenceContext);
73775
73921
  const inferenceNode = memberDecl.kind === 303 /* PropertyAssignment */ ? memberDecl.initializer : memberDecl;
@@ -73947,7 +74093,7 @@ function createTypeChecker(host) {
73947
74093
  addDeprecatedSuggestion(attributeDecl.name, prop.declarations, attributeDecl.name.escapedText);
73948
74094
  }
73949
74095
  }
73950
- if (contextualType && checkMode & 2 /* Inferential */ && !(checkMode & 4 /* SkipContextSensitive */) && containsContextSensitiveOrCallOrNewExpression(attributeDecl)) {
74096
+ if (contextualType && checkMode & 2 /* Inferential */ && !(checkMode & 4 /* SkipContextSensitive */) && isContextSensitive(attributeDecl)) {
73951
74097
  const inferenceContext = getInferenceContext(attributes);
73952
74098
  Debug.assert(inferenceContext);
73953
74099
  const inferenceNode = attributeDecl.initializer.expression;
@@ -76181,7 +76327,7 @@ function createTypeChecker(host) {
76181
76327
  }
76182
76328
  const args = getEffectiveCallArguments(node);
76183
76329
  const isSingleNonGenericCandidate = candidates.length === 1 && !candidates[0].typeParameters;
76184
- if (!isDecorator2 && !isSingleNonGenericCandidate && some(args, containsContextSensitive)) {
76330
+ if (!isDecorator2 && !isSingleNonGenericCandidate && some(args, isContextSensitive)) {
76185
76331
  argCheckMode = 4 /* SkipContextSensitive */;
76186
76332
  }
76187
76333
  const signatureHelpTrailingComma = !!(checkMode & 16 /* IsForSignatureHelp */) && node.kind === 213 /* CallExpression */ && node.arguments.hasTrailingComma;
@@ -78681,7 +78827,7 @@ function createTypeChecker(host) {
78681
78827
  if (isFunctionExpression(node)) {
78682
78828
  checkCollisionsForDeclarationName(node, node.name);
78683
78829
  }
78684
- if (checkMode && checkMode & 4 /* SkipContextSensitive */ && containsContextSensitive(node)) {
78830
+ if (checkMode && checkMode & 4 /* SkipContextSensitive */ && isContextSensitive(node)) {
78685
78831
  if (!getEffectiveReturnTypeNode(node) && !hasContextSensitiveParameters(node)) {
78686
78832
  const contextualSignature = getContextualSignature(node);
78687
78833
  if (contextualSignature && couldContainTypeVariables(getReturnTypeOfSignature(contextualSignature))) {
@@ -78728,7 +78874,7 @@ function createTypeChecker(host) {
78728
78874
  if (!signature) {
78729
78875
  return;
78730
78876
  }
78731
- if (containsContextSensitive(node)) {
78877
+ if (isContextSensitive(node)) {
78732
78878
  if (contextualSignature) {
78733
78879
  const inferenceContext = getInferenceContext(node);
78734
78880
  let instantiatedContextualSignature;
@@ -121501,6 +121647,10 @@ function loadWithModeAwareCache(entries, containingFile, redirectedReference, op
121501
121647
  return resolutions;
121502
121648
  }
121503
121649
  var inferredTypesContainingFile = "__inferred type names__.ts";
121650
+ function getAutomaticTypeDirectiveContainingFile(options, currentDirectory) {
121651
+ const containingDirectory = options.configFilePath ? getDirectoryPath(options.configFilePath) : currentDirectory;
121652
+ return combinePaths(containingDirectory, inferredTypesContainingFile);
121653
+ }
121504
121654
  function getInferredLibraryNameResolveFrom(options, currentDirectory, libFileName) {
121505
121655
  const containingDirectory = options.configFilePath ? getDirectoryPath(options.configFilePath) : currentDirectory;
121506
121656
  return combinePaths(containingDirectory, `__lib_node_modules_lookup_${libFileName}__.ts`);
@@ -121729,7 +121879,7 @@ function createCreateProgramOptions(rootNames, options, host, oldProgram, config
121729
121879
  };
121730
121880
  }
121731
121881
  function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _configFileParsingDiagnostics) {
121732
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
121882
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
121733
121883
  let _createProgramOptions = isArray(_rootNamesOrOptions) ? createCreateProgramOptions(_rootNamesOrOptions, _options, _host, _oldProgram, _configFileParsingDiagnostics) : _rootNamesOrOptions;
121734
121884
  const { rootNames, options, configFileParsingDiagnostics, projectReferences, typeScriptVersion: typeScriptVersion2, host: createProgramOptionsHost } = _createProgramOptions;
121735
121885
  let { oldProgram } = _createProgramOptions;
@@ -121934,9 +122084,10 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
121934
122084
  automaticTypeDirectiveResolutions = createModeAwareCache();
121935
122085
  if (automaticTypeDirectiveNames.length) {
121936
122086
  (_k = tracing) == null ? void 0 : _k.push(tracing.Phase.Program, "processTypeReferences", { count: automaticTypeDirectiveNames.length });
121937
- const containingDirectory = options.configFilePath ? getDirectoryPath(options.configFilePath) : currentDirectory;
121938
- const containingFilename = combinePaths(containingDirectory, inferredTypesContainingFile);
121939
- const resolutions = resolveTypeReferenceDirectiveNamesReusingOldState(automaticTypeDirectiveNames, containingFilename);
122087
+ const resolutions = resolveTypeReferenceDirectiveNamesReusingOldState(
122088
+ automaticTypeDirectiveNames,
122089
+ getAutomaticTypeDirectiveContainingFile(options, currentDirectory)
122090
+ );
121940
122091
  for (let i = 0; i < automaticTypeDirectiveNames.length; i++) {
121941
122092
  automaticTypeDirectiveResolutions.set(
121942
122093
  automaticTypeDirectiveNames[i],
@@ -121957,6 +122108,17 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
121957
122108
  );
121958
122109
  }
121959
122110
  (_n = tracing) == null ? void 0 : _n.pop();
122111
+ } else {
122112
+ (_o = host.onReusedTypeReferenceDirectiveResolutions) == null ? void 0 : _o.call(
122113
+ host,
122114
+ /*reusedNames*/
122115
+ void 0,
122116
+ /*containingSourceFile*/
122117
+ void 0,
122118
+ /*redirectedReference*/
122119
+ void 0,
122120
+ options
122121
+ );
121960
122122
  }
121961
122123
  if (rootNames.length && !skipDefaultLib) {
121962
122124
  const defaultLibraryFileName = getDefaultLibraryFileName();
@@ -122092,6 +122254,7 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
122092
122254
  getResolvedProjectReferenceByPath,
122093
122255
  forEachResolvedProjectReference: forEachResolvedProjectReference2,
122094
122256
  isSourceOfProjectReferenceRedirect,
122257
+ getRedirectReferenceForResolution,
122095
122258
  getRedirectReferenceForResolutionFromSourceOfProject,
122096
122259
  getCompilerOptionsForFile,
122097
122260
  getDefaultResolutionModeForFile: getDefaultResolutionModeForFile2,
@@ -122103,7 +122266,7 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
122103
122266
  readFile,
122104
122267
  directoryExists,
122105
122268
  getSymlinkCache,
122106
- realpath: (_o = host.realpath) == null ? void 0 : _o.bind(host),
122269
+ realpath: (_p = host.realpath) == null ? void 0 : _p.bind(host),
122107
122270
  useCaseSensitiveFileNames: () => host.useCaseSensitiveFileNames(),
122108
122271
  getCanonicalFileName,
122109
122272
  getFileIncludeReasons: () => programDiagnostics.getFileReasons(),
@@ -122117,7 +122280,7 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
122117
122280
  }
122118
122281
  mark("afterProgram");
122119
122282
  measure("Program", "beforeProgram", "afterProgram");
122120
- (_p = tracing) == null ? void 0 : _p.pop();
122283
+ (_q = tracing) == null ? void 0 : _q.pop();
122121
122284
  return program;
122122
122285
  function getResolvedModule(file, moduleName, mode) {
122123
122286
  var _a2;
@@ -122295,6 +122458,7 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
122295
122458
  redirectedReference: getRedirectReferenceForResolution(containingFile),
122296
122459
  nameAndModeGetter: moduleResolutionNameAndModeGetter,
122297
122460
  resolutionWorker: resolveModuleNamesWorker,
122461
+ onReusedResolutions: maybeBind(host, host.onReusedModuleResolutions),
122298
122462
  getResolutionFromOldProgram: (name, mode) => oldProgram == null ? void 0 : oldProgram.getResolvedModule(containingFile, name, mode),
122299
122463
  getResolved: getResolvedModuleFromResolution,
122300
122464
  canReuseResolutionsInFile: () => containingFile === (oldProgram == null ? void 0 : oldProgram.getSourceFile(containingFile.fileName)) && !hasInvalidatedResolutions(containingFile.path),
@@ -122310,6 +122474,7 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
122310
122474
  redirectedReference: containingSourceFile && getRedirectReferenceForResolution(containingSourceFile),
122311
122475
  nameAndModeGetter: typeReferenceResolutionNameAndModeGetter,
122312
122476
  resolutionWorker: resolveTypeReferenceDirectiveNamesWorker,
122477
+ onReusedResolutions: maybeBind(host, host.onReusedTypeReferenceDirectiveResolutions),
122313
122478
  getResolutionFromOldProgram: (name, mode) => {
122314
122479
  var _a2;
122315
122480
  return containingSourceFile ? oldProgram == null ? void 0 : oldProgram.getResolvedTypeReferenceDirective(containingSourceFile, name, mode) : (_a2 = oldProgram == null ? void 0 : oldProgram.getAutomaticTypeDirectiveResolutions()) == null ? void 0 : _a2.get(name, mode);
@@ -122325,12 +122490,21 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
122325
122490
  redirectedReference,
122326
122491
  nameAndModeGetter,
122327
122492
  resolutionWorker,
122493
+ onReusedResolutions,
122328
122494
  getResolutionFromOldProgram,
122329
122495
  getResolved,
122330
122496
  canReuseResolutionsInFile,
122331
122497
  resolveToOwnAmbientModule
122332
122498
  }) {
122333
- if (!entries.length) return emptyArray;
122499
+ if (!entries.length) {
122500
+ onReusedResolutions == null ? void 0 : onReusedResolutions(
122501
+ entries,
122502
+ containingSourceFile,
122503
+ redirectedReference,
122504
+ options
122505
+ );
122506
+ return emptyArray;
122507
+ }
122334
122508
  if (structureIsReused === 0 /* Not */ && (!resolveToOwnAmbientModule || !containingSourceFile.ambientModuleNames.length)) {
122335
122509
  return resolutionWorker(
122336
122510
  entries,
@@ -122385,8 +122559,20 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
122385
122559
  (unknownEntries ?? (unknownEntries = [])).push(entry);
122386
122560
  (unknownEntryIndices ?? (unknownEntryIndices = [])).push(i);
122387
122561
  }
122388
- if (!unknownEntries) return result;
122389
- const resolutions = resolutionWorker(unknownEntries, containingFile, reusedNames);
122562
+ if (!unknownEntries) {
122563
+ onReusedResolutions == null ? void 0 : onReusedResolutions(
122564
+ reusedNames,
122565
+ containingSourceFile,
122566
+ redirectedReference,
122567
+ options
122568
+ );
122569
+ return result;
122570
+ }
122571
+ const resolutions = resolutionWorker(
122572
+ unknownEntries,
122573
+ containingFile,
122574
+ reusedNames
122575
+ );
122390
122576
  if (!result) return resolutions;
122391
122577
  resolutions.forEach((resolution, index) => result[unknownEntryIndices[index]] = resolution);
122392
122578
  return result;
@@ -123413,7 +123599,7 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
123413
123599
  return typeof result === "object" ? { ...result, languageVersion, setExternalModuleIndicator: setExternalModuleIndicator2, jsDocParsingMode: host2.jsDocParsingMode } : { languageVersion, impliedNodeFormat: result, setExternalModuleIndicator: setExternalModuleIndicator2, jsDocParsingMode: host2.jsDocParsingMode };
123414
123600
  }
123415
123601
  function findSourceFileWorker(fileName, isDefaultLib, ignoreNoDefaultLib, reason, packageId) {
123416
- var _a2;
123602
+ var _a2, _b2;
123417
123603
  const path = toPath3(fileName);
123418
123604
  if (useSourceOfProjectReferenceRedirect) {
123419
123605
  let source = getSourceOfProjectReferenceRedirect(path);
@@ -123558,6 +123744,8 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
123558
123744
  processingOtherFiles.push(file);
123559
123745
  }
123560
123746
  (filesWithReferencesProcessed ?? (filesWithReferencesProcessed = /* @__PURE__ */ new Set())).add(file.path);
123747
+ } else {
123748
+ (_b2 = host.onSourceFileNotCreated) == null ? void 0 : _b2.call(host, sourceFileOptions);
123561
123749
  }
123562
123750
  return file;
123563
123751
  }
@@ -123655,8 +123843,19 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
123655
123843
  });
123656
123844
  }
123657
123845
  function processTypeReferenceDirectives(file) {
123846
+ var _a2;
123658
123847
  const typeDirectives = file.typeReferenceDirectives;
123659
- if (!typeDirectives.length) return;
123848
+ if (!typeDirectives.length) {
123849
+ (_a2 = host.onReusedTypeReferenceDirectiveResolutions) == null ? void 0 : _a2.call(
123850
+ host,
123851
+ /*reusedNames*/
123852
+ void 0,
123853
+ file,
123854
+ getRedirectReferenceForResolution(file),
123855
+ options
123856
+ );
123857
+ return;
123858
+ }
123660
123859
  const resolutions = (resolvedTypeReferenceDirectiveNamesProcessing == null ? void 0 : resolvedTypeReferenceDirectiveNamesProcessing.get(file.path)) || resolveTypeReferenceDirectiveNamesReusingOldState(typeDirectives, file);
123661
123860
  const resolutionsInFile = createModeAwareCache();
123662
123861
  (resolvedTypeReferenceDirectiveNames ?? (resolvedTypeReferenceDirectiveNames = /* @__PURE__ */ new Map())).set(file.path, resolutionsInFile);
@@ -123783,6 +123982,7 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
123783
123982
  return host.getCanonicalFileName(fileName);
123784
123983
  }
123785
123984
  function processImportedModules(file) {
123985
+ var _a2;
123786
123986
  collectExternalModuleReferences(file);
123787
123987
  if (file.imports.length || file.moduleAugmentations.length) {
123788
123988
  const moduleNames = getModuleNames(file);
@@ -123826,6 +124026,15 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
123826
124026
  currentNodeModulesDepth--;
123827
124027
  }
123828
124028
  }
124029
+ } else {
124030
+ (_a2 = host.onReusedModuleResolutions) == null ? void 0 : _a2.call(
124031
+ host,
124032
+ /*reusedNames*/
124033
+ void 0,
124034
+ file,
124035
+ getRedirectReferenceForResolution(file),
124036
+ options
124037
+ );
123829
124038
  }
123830
124039
  }
123831
124040
  function checkSourceFilesBelongToPath(sourceFiles, rootDirectory) {
@@ -126992,7 +127201,7 @@ function createEmitAndSemanticDiagnosticsBuilderProgram(newProgramOrRootNames, h
126992
127201
  );
126993
127202
  }
126994
127203
 
126995
- // src/compiler/resolutionCache.ts
127204
+ // src/compiler/sharedResolutionCache.ts
126996
127205
  function removeIgnoredPath(path) {
126997
127206
  if (endsWith(path, "/node_modules/.staging")) {
126998
127207
  return removeSuffix(path, "/.staging");
@@ -127123,24 +127332,930 @@ function getDirectoryOfFailedLookupWatch(dirComponents, dirPathComponents, lengt
127123
127332
  packageDirPath: packageDirLength !== void 0 ? getPathFromPathComponents(dirPathComponents, packageDirLength) : void 0
127124
127333
  };
127125
127334
  }
127126
- function getDirectoryToWatchFailedLookupLocationFromTypeRoot(typeRoot, typeRootPath, rootPath, rootPathComponents, isRootWatchable, getCurrentDirectory, preferNonRecursiveWatch, filterCustomPath) {
127127
- const typeRootPathComponents = getPathComponents(typeRootPath);
127128
- if (isRootWatchable && isInDirectoryPath(rootPathComponents, typeRootPathComponents)) {
127129
- return rootPath;
127130
- }
127131
- typeRoot = isRootedDiskPath(typeRoot) ? normalizePath(typeRoot) : getNormalizedAbsolutePath(typeRoot, getCurrentDirectory());
127132
- const toWatch = getDirectoryToWatchFromFailedLookupLocationDirectory(
127133
- getPathComponents(typeRoot),
127134
- typeRootPathComponents,
127135
- typeRootPathComponents.length,
127136
- perceivedOsRootLengthForWatching(typeRootPathComponents, typeRootPathComponents.length),
127137
- typeRootPathComponents.indexOf("node_modules"),
127138
- rootPathComponents,
127139
- typeRootPathComponents.lastIndexOf("node_modules"),
127140
- preferNonRecursiveWatch
127335
+ function getModuleOrTypeRefResolved(resolution) {
127336
+ return resolution.resolvedModule ?? resolution.resolvedTypeReferenceDirective;
127337
+ }
127338
+ function createSharedResolutionCache(sharedCacheHost) {
127339
+ const resolutionsWithFailedLookups = /* @__PURE__ */ new Set();
127340
+ const resolutionsWithOnlyAffectingLocations = /* @__PURE__ */ new Set();
127341
+ const resolvedFileToResolution = /* @__PURE__ */ new Map();
127342
+ const impliedFormatPackageJsons = /* @__PURE__ */ new Map();
127343
+ const watchedResolutionInfoMap = /* @__PURE__ */ new Map();
127344
+ const typeRootsWatches = /* @__PURE__ */ new Map();
127345
+ const inUseResolutionCaches = /* @__PURE__ */ new Map();
127346
+ const cacheToOptions = /* @__PURE__ */ new Map();
127347
+ let affectingPathChecks;
127348
+ let failedLookupChecks;
127349
+ let startsWithPathChecks;
127350
+ let isInDirectoryChecks;
127351
+ let cachesNeedingGc;
127352
+ let potentiallyUnreferencedDirWatchers;
127353
+ let considerNonWatchedResolutionAsInvalidated = false;
127354
+ const getCurrentDirectory = memoize(() => sharedCacheHost.getCurrentDirectory());
127355
+ const moduleResolutionCache = createModuleResolutionCache(
127356
+ getCurrentDirectory(),
127357
+ sharedCacheHost.getCanonicalFileName,
127358
+ /*options*/
127359
+ void 0,
127360
+ /*packageJsonInfoCache*/
127361
+ void 0,
127362
+ /*optionsToRedirectsKey*/
127363
+ void 0,
127364
+ getValidModuleResolution
127365
+ );
127366
+ const typeReferenceDirectiveResolutionCache = createTypeReferenceDirectiveResolutionCache(
127367
+ getCurrentDirectory(),
127368
+ sharedCacheHost.getCanonicalFileName,
127369
+ /*options*/
127370
+ void 0,
127371
+ moduleResolutionCache.getPackageJsonInfoCache(),
127372
+ moduleResolutionCache.optionsToRedirectsKey,
127373
+ getValidResolution
127374
+ );
127375
+ const libraryResolutionCache = createModuleResolutionCache(
127376
+ getCurrentDirectory(),
127377
+ sharedCacheHost.getCanonicalFileName,
127378
+ getOptionsForLibraryResolution(
127379
+ /*options*/
127380
+ void 0
127381
+ ),
127382
+ moduleResolutionCache.getPackageJsonInfoCache(),
127383
+ /*optionsToRedirectsKey*/
127384
+ void 0,
127385
+ getValidResolution
127386
+ );
127387
+ const packageJsonRefCount = /* @__PURE__ */ new Map();
127388
+ let potentiallyUnwatchedPackageJsons;
127389
+ const directoryWatchesOfFailedLookups = /* @__PURE__ */ new Map();
127390
+ const nonRecursiveDirectoryWatchesOfFailedLookups = /* @__PURE__ */ new Map();
127391
+ const fileWatchesOfAffectingLocations = /* @__PURE__ */ new Map();
127392
+ const isSymlinkCache = /* @__PURE__ */ new Map();
127393
+ const packageDirWatchers = /* @__PURE__ */ new Map();
127394
+ const dirPathToSymlinkPackageRefCount = /* @__PURE__ */ new Map();
127395
+ let currentCache;
127396
+ return {
127397
+ sharedCacheHost,
127398
+ moduleResolutionCache,
127399
+ typeReferenceDirectiveResolutionCache,
127400
+ libraryResolutionCache,
127401
+ resolvedFileToResolution,
127402
+ resolutionsWithFailedLookups,
127403
+ resolutionsWithOnlyAffectingLocations,
127404
+ packageJsonRefCount,
127405
+ watchedResolutionInfoMap,
127406
+ typeRootsWatches,
127407
+ inUseResolutionCaches,
127408
+ cacheToOptions,
127409
+ directoryWatchesOfFailedLookups,
127410
+ nonRecursiveDirectoryWatchesOfFailedLookups,
127411
+ fileWatchesOfAffectingLocations,
127412
+ packageDirWatchers,
127413
+ dirPathToSymlinkPackageRefCount,
127414
+ clear: clear2,
127415
+ startCachingPerDirectoryResolution,
127416
+ finishCachingPerDirectoryResolution,
127417
+ compactCaches,
127418
+ watchResolution,
127419
+ releaseResolution,
127420
+ createFileWatcherOfAffectingLocation,
127421
+ releaseFileWatcherOfAffectingLocation,
127422
+ closeFileWatcherOfAffectingLocation,
127423
+ addToPotentiallyUnwatchedPackageJsons,
127424
+ invalidateResolutionsOfFailedLookupLocations,
127425
+ invalidateResolutionOfFile,
127426
+ invalidateResolution,
127427
+ createTypeRootsWatch,
127428
+ currentCache: () => currentCache
127429
+ };
127430
+ function clearForCache(cache) {
127431
+ let gcCaches = false;
127432
+ currentCache = cache;
127433
+ watchedResolutionInfoMap.forEach((watchedResolutionInfo, resolution) => {
127434
+ if (watchedResolutionInfo.caches.has(cache)) {
127435
+ gcCaches = releaseResolution(
127436
+ resolution,
127437
+ /*moduleOrTypeRefCache*/
127438
+ void 0
127439
+ ) || gcCaches;
127440
+ }
127441
+ });
127442
+ fileWatchesOfAffectingLocations.forEach((watcher, location) => {
127443
+ var _a;
127444
+ if ((_a = watcher.files) == null ? void 0 : _a.delete(cache)) closeFileWatcherOfAffectingLocation(location, watcher);
127445
+ });
127446
+ inUseResolutionCaches.delete(cache);
127447
+ if (gcCaches) {
127448
+ gcModuleOrTypeRefCache(moduleResolutionCache);
127449
+ gcModuleOrTypeRefCache(typeReferenceDirectiveResolutionCache);
127450
+ gcModuleOrTypeRefCache(libraryResolutionCache);
127451
+ }
127452
+ currentCache = void 0;
127453
+ if (cacheToOptions.delete(cache)) compactCachesWoker();
127454
+ }
127455
+ function clear2(cache) {
127456
+ if (!inUseResolutionCaches.has(cache)) return;
127457
+ if (inUseResolutionCaches.size !== 1) return clearForCache(cache);
127458
+ currentCache = void 0;
127459
+ inUseResolutionCaches.clear();
127460
+ cacheToOptions.clear();
127461
+ cachesNeedingGc = void 0;
127462
+ potentiallyUnwatchedPackageJsons = void 0;
127463
+ clearMap(directoryWatchesOfFailedLookups, closeFileWatcherOf);
127464
+ clearMap(nonRecursiveDirectoryWatchesOfFailedLookups, closeFileWatcherOf);
127465
+ clearMap(fileWatchesOfAffectingLocations, closeFileWatcherOf);
127466
+ clearMap(typeRootsWatches, closeFileWatcherOf);
127467
+ packageJsonRefCount.clear();
127468
+ isSymlinkCache.clear();
127469
+ packageDirWatchers.clear();
127470
+ dirPathToSymlinkPackageRefCount.clear();
127471
+ resolvedFileToResolution.clear();
127472
+ resolutionsWithFailedLookups.clear();
127473
+ resolutionsWithOnlyAffectingLocations.clear();
127474
+ watchedResolutionInfoMap.clear();
127475
+ failedLookupChecks = void 0;
127476
+ startsWithPathChecks = void 0;
127477
+ isInDirectoryChecks = void 0;
127478
+ affectingPathChecks = void 0;
127479
+ moduleResolutionCache.clear();
127480
+ typeReferenceDirectiveResolutionCache.clear();
127481
+ libraryResolutionCache.clear();
127482
+ impliedFormatPackageJsons.clear();
127483
+ }
127484
+ function startCachingPerDirectoryResolution(cache) {
127485
+ currentCache = cache;
127486
+ moduleResolutionCache.isReadonly = void 0;
127487
+ typeReferenceDirectiveResolutionCache.isReadonly = void 0;
127488
+ libraryResolutionCache.isReadonly = void 0;
127489
+ moduleResolutionCache.getPackageJsonInfoCache().isReadonly = void 0;
127490
+ isSymlinkCache.clear();
127491
+ }
127492
+ function finishCachingPerDirectoryResolution() {
127493
+ potentiallyUnreferencedDirWatchers == null ? void 0 : potentiallyUnreferencedDirWatchers.forEach(
127494
+ (path) => closeDirectoryWatchesOfFailedLookup(
127495
+ getDirectoryWatchesOfFailedLookup(
127496
+ path,
127497
+ /*nonRecursive*/
127498
+ false
127499
+ ),
127500
+ path,
127501
+ /*nonRecursive*/
127502
+ false
127503
+ )
127504
+ );
127505
+ potentiallyUnreferencedDirWatchers = void 0;
127506
+ cachesNeedingGc == null ? void 0 : cachesNeedingGc.forEach(gcModuleOrTypeRefCache);
127507
+ cachesNeedingGc = void 0;
127508
+ potentiallyUnwatchedPackageJsons == null ? void 0 : potentiallyUnwatchedPackageJsons.forEach(releasePotentiallyUnwatchedPackageJson);
127509
+ potentiallyUnwatchedPackageJsons = void 0;
127510
+ moduleResolutionCache.isReadonly = true;
127511
+ typeReferenceDirectiveResolutionCache.isReadonly = true;
127512
+ libraryResolutionCache.isReadonly = true;
127513
+ moduleResolutionCache.getPackageJsonInfoCache().isReadonly = true;
127514
+ isSymlinkCache.clear();
127515
+ currentCache = void 0;
127516
+ }
127517
+ function compactCaches(availableOptions, cache) {
127518
+ if (availableOptions.size) cacheToOptions.set(cache, availableOptions);
127519
+ else cacheToOptions.delete(cache);
127520
+ compactCachesWoker();
127521
+ }
127522
+ function compactCachesWoker() {
127523
+ let availableOptions;
127524
+ if (cacheToOptions.size === 1) availableOptions = firstDefinedIterator(cacheToOptions.values(), identity);
127525
+ else {
127526
+ availableOptions = /* @__PURE__ */ new Set();
127527
+ cacheToOptions.forEach((setOfOptions) => setOfOptions.forEach((options) => availableOptions.add(options)));
127528
+ }
127529
+ moduleResolutionCache.compact(
127530
+ availableOptions,
127531
+ /*skipOptionsToRedirectsKeyCleanup*/
127532
+ true
127533
+ );
127534
+ typeReferenceDirectiveResolutionCache.compact(availableOptions);
127535
+ libraryResolutionCache.compact();
127536
+ }
127537
+ function gcModuleOrTypeRefCache(cache) {
127538
+ considerNonWatchedResolutionAsInvalidated = true;
127539
+ cache.gc(watchedResolutionInfoMap);
127540
+ considerNonWatchedResolutionAsInvalidated = false;
127541
+ }
127542
+ function getValidResolution(resolution) {
127543
+ return isInvalidatedResolution(resolution) ? void 0 : resolution;
127544
+ }
127545
+ function getValidModuleResolution(resolution, forSet) {
127546
+ var _a, _b, _c;
127547
+ resolution = getValidResolution(resolution);
127548
+ return resolution && (forSet ? resolution.globalCacheResolution && isInvalidatedResolution(resolution.globalCacheResolution.globalResult) ? void 0 : resolution : ((_b = currentCache == null ? void 0 : (_a = currentCache.resolutionHost).getGlobalTypingsCacheLocation) == null ? void 0 : _b.call(_a)) && ((_c = resolution == null ? void 0 : resolution.globalCacheResolution) == null ? void 0 : _c.globalResult) ? currentCache.getValidResolution(resolution.globalCacheResolution.globalResult) : resolution);
127549
+ }
127550
+ function isInvalidatedResolution(resolution) {
127551
+ var _a;
127552
+ return !resolution || considerNonWatchedResolutionAsInvalidated && !watchedResolutionInfoMap.has(resolution) || ((_a = watchedResolutionInfoMap.get(resolution)) == null ? void 0 : _a.isInvalidated);
127553
+ }
127554
+ function isNodeModulesAtTypesDirectory(dirPath) {
127555
+ return endsWith(dirPath, "/node_modules/@types");
127556
+ }
127557
+ function watchResolution(resolution, getResolutionWithResolvedFileName, redirectedReference) {
127558
+ var _a, _b, _c;
127559
+ let watchedResolutionInfo = watchedResolutionInfoMap.get(resolution);
127560
+ if (!(watchedResolutionInfo == null ? void 0 : watchedResolutionInfo.caches.has(currentCache))) addRefCountToCacheMap(inUseResolutionCaches, currentCache);
127561
+ if (!(watchedResolutionInfo == null ? void 0 : watchedResolutionInfo.caches.size)) {
127562
+ if (!watchedResolutionInfo) {
127563
+ watchedResolutionInfoMap.set(resolution, watchedResolutionInfo = { caches: /* @__PURE__ */ new Set() });
127564
+ if (isResolvedWithGlobalCachePass(resolution) && !watchedResolutionInfoMap.has(resolution.globalCacheResolution.primary)) {
127565
+ watchedResolutionInfoMap.set(resolution.globalCacheResolution.primary, { caches: /* @__PURE__ */ new Set() });
127566
+ }
127567
+ }
127568
+ if (isResolvedWithGlobalCachePassButStillUnresolved(resolution)) {
127569
+ (_a = resolution.globalCacheResolution.globalResolution.failedLookupLocations) == null ? void 0 : _a.forEach(
127570
+ addToPotentiallyUnwatchedPackageJsonsIfPackageJson
127571
+ );
127572
+ if (resolution.globalCacheResolution.globalResolution.alternateResult) addToPotentiallyUnwatchedPackageJsonsIfPackageJson(resolution.globalCacheResolution.globalResolution.alternateResult);
127573
+ (_b = resolution.globalCacheResolution.globalResolution.affectingLocations) == null ? void 0 : _b.forEach(addToPotentiallyUnwatchedPackageJsons);
127574
+ }
127575
+ const resolved = getResolutionWithResolvedFileName(resolution);
127576
+ if (resolved && resolved.resolvedFileName) {
127577
+ const key = sharedCacheHost.toPath(resolved.resolvedFileName);
127578
+ let resolutions = resolvedFileToResolution.get(key);
127579
+ if (!resolutions) resolvedFileToResolution.set(key, resolutions = /* @__PURE__ */ new Set());
127580
+ resolutions.add(resolution);
127581
+ }
127582
+ }
127583
+ watchFailedLookupLocationOfResolution(resolution, redirectedReference, watchedResolutionInfo);
127584
+ watchAffectingLocationsOfResolution(resolution, watchedResolutionInfo);
127585
+ watchedResolutionInfo.caches.add(currentCache);
127586
+ if (isResolvedWithGlobalCachePass(resolution)) {
127587
+ watchPrimaryOrGlobalResultFailedAndAffectedLookups(resolution.globalCacheResolution.primary);
127588
+ } else if ((_c = resolution.globalCacheResolution) == null ? void 0 : _c.globalResult) {
127589
+ watchPrimaryOrGlobalResultFailedAndAffectedLookups(resolution.globalCacheResolution.globalResult);
127590
+ }
127591
+ }
127592
+ function watchPrimaryOrGlobalResultFailedAndAffectedLookups(primaryOrGlobalResult) {
127593
+ const watchInfo = watchedResolutionInfoMap.get(primaryOrGlobalResult);
127594
+ if (!(watchInfo == null ? void 0 : watchInfo.caches.size)) return;
127595
+ const first2 = firstDefinedIterator(watchInfo.caches, identity);
127596
+ const savedCurrentCache = currentCache;
127597
+ currentCache = first2;
127598
+ watchFailedLookupLocationOfResolution(
127599
+ primaryOrGlobalResult,
127600
+ /*redirectedReference*/
127601
+ void 0,
127602
+ watchInfo
127603
+ );
127604
+ watchAffectingLocationsOfResolution(primaryOrGlobalResult, watchInfo);
127605
+ currentCache = savedCurrentCache;
127606
+ }
127607
+ function watchFailedLookupLocation(failedLookupLocation, resolution, redirectedReference, watchedResolutionInfo) {
127608
+ var _a, _b;
127609
+ watchedResolutionInfo.rootDirInfo ?? (watchedResolutionInfo.rootDirInfo = currentCache.getRootDirInfoForResolution(redirectedReference, resolution));
127610
+ const failedLookupLocationPath = sharedCacheHost.toPath(failedLookupLocation);
127611
+ if (endsWith(failedLookupLocationPath, "/package.json")) addRefToPackageJson(failedLookupLocationPath);
127612
+ const toWatch = getDirectoryToWatchFailedLookupLocation(
127613
+ failedLookupLocation,
127614
+ failedLookupLocationPath,
127615
+ watchedResolutionInfo.rootDirInfo.rootDir,
127616
+ watchedResolutionInfo.rootDirInfo.rootPath,
127617
+ watchedResolutionInfo.rootDirInfo.rootPathComponents,
127618
+ watchedResolutionInfo.rootDirInfo.canWatch,
127619
+ getCurrentDirectory,
127620
+ sharedCacheHost.preferNonRecursiveWatch
127621
+ );
127622
+ if (!toWatch) return;
127623
+ const { dir, dirPath, nonRecursive, packageDir, packageDirPath } = toWatch;
127624
+ if (!packageDirPath || !currentCache.resolutionHost.realpath) {
127625
+ if (!((_a = !nonRecursive ? watchedResolutionInfo.dirWatches : watchedResolutionInfo.nonRecursiveDirWatches) == null ? void 0 : _a.has(dirPath))) {
127626
+ const dirWatcher = createOrAddRefToDirectoryWatchOfFailedLookups(dir, dirPath, nonRecursive, currentCache);
127627
+ (!nonRecursive ? watchedResolutionInfo.dirWatches ?? (watchedResolutionInfo.dirWatches = /* @__PURE__ */ new Set()) : watchedResolutionInfo.nonRecursiveDirWatches ?? (watchedResolutionInfo.nonRecursiveDirWatches = /* @__PURE__ */ new Set())).add(dirPath);
127628
+ addRefCountToMapForCaches(dirWatcher.refCount, watchedResolutionInfo.caches, currentCache);
127629
+ }
127630
+ } else {
127631
+ Debug.assert(!nonRecursive);
127632
+ const forDirPath = (_b = watchedResolutionInfo.packageDirWatchers) == null ? void 0 : _b.get(packageDirPath);
127633
+ if (!(forDirPath == null ? void 0 : forDirPath.has(dirPath))) {
127634
+ const packageDirWatcher = createDirectoryWatcherForPackageDir(dir, dirPath, packageDir, packageDirPath);
127635
+ if (forDirPath) forDirPath.add(dirPath);
127636
+ else (watchedResolutionInfo.packageDirWatchers ?? (watchedResolutionInfo.packageDirWatchers = /* @__PURE__ */ new Map())).set(packageDirPath, /* @__PURE__ */ new Set([dirPath]));
127637
+ forRefCountCaches(watchedResolutionInfo.caches, (cache) => addRefToDirPathWatcherOfPackageDir(packageDirWatcher, dirPath, cache), currentCache);
127638
+ }
127639
+ }
127640
+ }
127641
+ function addRefToPackageJson(path) {
127642
+ addRefCountToCacheMap(packageJsonRefCount, path);
127643
+ }
127644
+ function releasePackageJsonCachePath(path) {
127645
+ var _a;
127646
+ (_a = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap()) == null ? void 0 : _a.delete(path);
127647
+ packageJsonRefCount.delete(path);
127648
+ }
127649
+ function addToPotentiallyUnwatchedPackageJsons(location) {
127650
+ (potentiallyUnwatchedPackageJsons ?? (potentiallyUnwatchedPackageJsons = /* @__PURE__ */ new Set())).add(sharedCacheHost.toPath(location));
127651
+ }
127652
+ function addToPotentiallyUnwatchedPackageJsonsIfPackageJson(location) {
127653
+ if (endsWith(location, "/package.json")) addToPotentiallyUnwatchedPackageJsons(location);
127654
+ }
127655
+ function releasePotentiallyUnwatchedPackageJson(path) {
127656
+ var _a;
127657
+ if (!packageJsonRefCount.has(path)) (_a = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap()) == null ? void 0 : _a.delete(path);
127658
+ }
127659
+ function releasePackageJson(path) {
127660
+ const existing = packageJsonRefCount.get(path);
127661
+ if (existing !== 1) packageJsonRefCount.set(path, existing - 1);
127662
+ else releasePackageJsonCachePath(path);
127663
+ }
127664
+ function releaseIfPackageJson(failedLookupLocation) {
127665
+ if (endsWith(failedLookupLocation, "/package.json")) releasePackageJson(sharedCacheHost.toPath(failedLookupLocation));
127666
+ }
127667
+ function watchFailedLookupLocationOfResolution(resolution, redirectedReference, watchedResolutionInfo) {
127668
+ var _a, _b, _c, _d, _e;
127669
+ if (!watchedResolutionInfo.caches.has(currentCache)) {
127670
+ (_a = watchedResolutionInfo.dirWatches) == null ? void 0 : _a.forEach((dirPath) => addRefCountToCacheMap(getDirectoryWatchesOfFailedLookup(
127671
+ dirPath,
127672
+ /*nonRecursive*/
127673
+ false
127674
+ ).refCount, currentCache));
127675
+ (_b = watchedResolutionInfo.nonRecursiveDirWatches) == null ? void 0 : _b.forEach((dirPath) => addRefCountToCacheMap(getDirectoryWatchesOfFailedLookup(
127676
+ dirPath,
127677
+ /*nonRecursive*/
127678
+ true
127679
+ ).refCount, currentCache));
127680
+ (_c = watchedResolutionInfo.packageDirWatchers) == null ? void 0 : _c.forEach((dirPaths, packageDirPath) => {
127681
+ const packageDirWatcher = packageDirWatchers.get(packageDirPath);
127682
+ dirPaths.forEach((dirPath) => addRefToDirPathWatcherOfPackageDir(packageDirWatcher, dirPath, currentCache));
127683
+ });
127684
+ }
127685
+ if (watchedResolutionInfo.watchedFailed === ((_d = resolution.failedLookupLocations) == null ? void 0 : _d.length)) return;
127686
+ if (!watchedResolutionInfo.watchedFailed) {
127687
+ resolutionsWithFailedLookups.add(resolution);
127688
+ if (watchedResolutionInfo.watchedAffected) resolutionsWithOnlyAffectingLocations.delete(resolution);
127689
+ }
127690
+ for (let i = watchedResolutionInfo.watchedFailed || 0; i < resolution.failedLookupLocations.length; i++) {
127691
+ watchFailedLookupLocation(
127692
+ resolution.failedLookupLocations[i],
127693
+ resolution,
127694
+ redirectedReference,
127695
+ watchedResolutionInfo
127696
+ );
127697
+ }
127698
+ if (!watchedResolutionInfo.watchedFailed && resolution.alternateResult) {
127699
+ watchFailedLookupLocation(
127700
+ resolution.alternateResult,
127701
+ resolution,
127702
+ redirectedReference,
127703
+ watchedResolutionInfo
127704
+ );
127705
+ }
127706
+ watchedResolutionInfo.watchedFailed = (_e = resolution.failedLookupLocations) == null ? void 0 : _e.length;
127707
+ }
127708
+ function createDirectoryWatcherForPackageDir(dir, dirPath, packageDir, packageDirPath) {
127709
+ let isSymlink = isSymlinkCache.get(packageDirPath);
127710
+ let packageDirWatcher = packageDirWatchers.get(packageDirPath);
127711
+ if (isSymlink === void 0) {
127712
+ const realPath2 = currentCache.resolutionHost.realpath(packageDir);
127713
+ isSymlink = realPath2 !== packageDir && sharedCacheHost.toPath(realPath2) !== packageDirPath;
127714
+ isSymlinkCache.set(packageDirPath, isSymlink);
127715
+ if (!packageDirWatcher) {
127716
+ packageDirWatchers.set(
127717
+ packageDirPath,
127718
+ packageDirWatcher = {
127719
+ dirPathToWatcher: /* @__PURE__ */ new Map(),
127720
+ isSymlink
127721
+ }
127722
+ );
127723
+ } else if (packageDirWatcher.isSymlink !== isSymlink) {
127724
+ packageDirWatcher.dirPathToWatcher.forEach((watcher, dirPath2, map2) => {
127725
+ releaseRefCountFromMapForCaches(watcher.watcher.refCount, watcher.refCount);
127726
+ (potentiallyUnreferencedDirWatchers ?? (potentiallyUnreferencedDirWatchers = /* @__PURE__ */ new Set())).add(packageDirWatcher.isSymlink ? packageDirPath : dirPath2);
127727
+ const firstCache = firstDefinedIterator(watcher.refCount.keys(), identity);
127728
+ if (firstCache) {
127729
+ watcher.watcher = createDirPathToWatcher(firstCache);
127730
+ addRefCountToMapForCaches(watcher.watcher.refCount, watcher.refCount, firstCache);
127731
+ } else {
127732
+ map2.delete(dirPath2);
127733
+ }
127734
+ });
127735
+ packageDirWatcher.isSymlink = isSymlink;
127736
+ }
127737
+ } else {
127738
+ Debug.assertIsDefined(packageDirWatcher);
127739
+ Debug.assert(isSymlink === packageDirWatcher.isSymlink);
127740
+ }
127741
+ if (packageDirWatcher.dirPathToWatcher.has(dirPath)) {
127742
+ addRefToDirPathWatcherOfPackageDir(packageDirWatcher, dirPath, currentCache);
127743
+ } else {
127744
+ packageDirWatcher.dirPathToWatcher.set(dirPath, {
127745
+ watcher: createDirPathToWatcher(currentCache),
127746
+ refCount: /* @__PURE__ */ new Map([[currentCache, 1]])
127747
+ });
127748
+ if (isSymlink) addRefCountToCacheMap(dirPathToSymlinkPackageRefCount, dirPath);
127749
+ }
127750
+ return packageDirWatcher;
127751
+ function createDirPathToWatcher(cache) {
127752
+ return isSymlink ? createOrAddRefToDirectoryWatchOfFailedLookups(
127753
+ packageDir,
127754
+ packageDirPath,
127755
+ /*nonRecursive*/
127756
+ false,
127757
+ cache
127758
+ ) : createOrAddRefToDirectoryWatchOfFailedLookups(
127759
+ dir,
127760
+ dirPath,
127761
+ /*nonRecursive*/
127762
+ false,
127763
+ cache
127764
+ );
127765
+ }
127766
+ }
127767
+ function addRefToDirPathWatcherOfPackageDir(packageDirWatcher, dirPath, cache) {
127768
+ const forDirPath = packageDirWatcher.dirPathToWatcher.get(dirPath);
127769
+ if (!forDirPath.refCount.has(cache)) addRefCountToCacheMap(forDirPath.watcher.refCount, cache);
127770
+ addRefCountToCacheMap(forDirPath.refCount, cache);
127771
+ }
127772
+ function removeRefToDirPathWatcherOfPackageDir(packageDirPath, dirPath) {
127773
+ const packageDirWatcher = packageDirWatchers.get(packageDirPath);
127774
+ if (!packageDirWatcher) return;
127775
+ const forDirPath = packageDirWatcher.dirPathToWatcher.get(dirPath);
127776
+ if (!forDirPath) return;
127777
+ releaseRefCountFromMap(forDirPath.refCount, currentCache);
127778
+ if (forDirPath.refCount.has(currentCache)) return;
127779
+ releaseRefCountFromMap(forDirPath.watcher.refCount, currentCache);
127780
+ if (forDirPath.refCount.size !== 0) return;
127781
+ closeDirectoryWatchesOfFailedLookup(
127782
+ forDirPath.watcher,
127783
+ packageDirWatcher.isSymlink ? packageDirPath : dirPath,
127784
+ /*nonRecursive*/
127785
+ false
127786
+ );
127787
+ packageDirWatcher.dirPathToWatcher.delete(dirPath);
127788
+ if (packageDirWatcher.isSymlink) releaseRefCountFromMap(dirPathToSymlinkPackageRefCount, dirPath);
127789
+ if (packageDirWatcher.dirPathToWatcher.size === 0) {
127790
+ packageDirWatchers.delete(packageDirPath);
127791
+ }
127792
+ }
127793
+ function getDirectoryWatchesOfFailedLookup(dirPath, nonRecursive) {
127794
+ const watchMap = !nonRecursive ? directoryWatchesOfFailedLookups : nonRecursiveDirectoryWatchesOfFailedLookups;
127795
+ return watchMap.get(dirPath);
127796
+ }
127797
+ function createOrAddRefToDirectoryWatchOfFailedLookups(dir, dirPath, nonRecursive, cache) {
127798
+ const watchMap = !nonRecursive ? directoryWatchesOfFailedLookups : nonRecursiveDirectoryWatchesOfFailedLookups;
127799
+ let dirWatcher = watchMap.get(dirPath);
127800
+ if (dirWatcher) {
127801
+ addRefCountToCacheMap(dirWatcher.refCount, cache);
127802
+ } else {
127803
+ watchMap.set(
127804
+ dirPath,
127805
+ dirWatcher = {
127806
+ watcher: cache.resolutionHost.watchDirectoryOfFailedLookupLocation(
127807
+ dir,
127808
+ (fileOrDirectory) => onDirectoryWatcher(dirPath, nonRecursive, fileOrDirectory),
127809
+ nonRecursive ? 0 /* None */ : 1 /* Recursive */
127810
+ ),
127811
+ refCount: /* @__PURE__ */ new Map([[cache, 1]])
127812
+ }
127813
+ );
127814
+ }
127815
+ return dirWatcher;
127816
+ }
127817
+ function removeDirectoryWatcher(dirPath, nonRecursive, forCaches) {
127818
+ const dirWatcher = getDirectoryWatchesOfFailedLookup(dirPath, nonRecursive);
127819
+ if (dirWatcher) releaseRefCountFromMapForCaches(dirWatcher.refCount, forCaches);
127820
+ closeDirectoryWatchesOfFailedLookup(dirWatcher, dirPath, nonRecursive);
127821
+ }
127822
+ function closeDirectoryWatchesOfFailedLookup(watcher, path, nonRecursive) {
127823
+ if (watcher && watcher.refCount.size === 0) {
127824
+ if (!nonRecursive) directoryWatchesOfFailedLookups.delete(path);
127825
+ else nonRecursiveDirectoryWatchesOfFailedLookups.delete(path);
127826
+ watcher.watcher.close();
127827
+ }
127828
+ }
127829
+ function onDirectoryWatcher(dirPath, nonRecursive, fileOrDirectory, fileOrDirectoryPath) {
127830
+ var _a;
127831
+ const refCountCache = (_a = getDirectoryWatchesOfFailedLookup(dirPath, nonRecursive)) == null ? void 0 : _a.refCount;
127832
+ if (!refCountCache) return;
127833
+ fileOrDirectoryPath ?? (fileOrDirectoryPath = sharedCacheHost.toPath(fileOrDirectory));
127834
+ refCountCache.forEach((_refCount, cache) => {
127835
+ var _a2;
127836
+ (_a2 = cache.resolutionHost.getCachedDirectoryStructureHost()) == null ? void 0 : _a2.addOrDeleteFileOrDirectory(fileOrDirectory, fileOrDirectoryPath);
127837
+ });
127838
+ scheduleInvalidateResolutionOfFailedLookupLocation(fileOrDirectoryPath, dirPath === fileOrDirectoryPath, refCountCache);
127839
+ }
127840
+ function watchAffectingLocationsOfResolution(resolution, watchedResolutionInfo) {
127841
+ var _a, _b, _c;
127842
+ if (((_a = resolution.affectingLocations) == null ? void 0 : _a.length) === watchedResolutionInfo.watchedAffected) {
127843
+ if (!watchedResolutionInfo.caches.has(currentCache)) {
127844
+ (_b = resolution.affectingLocations) == null ? void 0 : _b.forEach(
127845
+ (affectingLocation) => addRefCountToCacheMap(
127846
+ fileWatchesOfAffectingLocations.get(affectingLocation).resolutions,
127847
+ currentCache
127848
+ )
127849
+ );
127850
+ }
127851
+ return;
127852
+ }
127853
+ if (!watchedResolutionInfo.watchedAffected && !watchedResolutionInfo.watchedFailed) resolutionsWithOnlyAffectingLocations.add(resolution);
127854
+ for (let i = watchedResolutionInfo.watchedAffected || 0; i < resolution.affectingLocations.length; i++) {
127855
+ createFileWatcherOfAffectingLocation(
127856
+ resolution.affectingLocations[i],
127857
+ /*forResolution*/
127858
+ true
127859
+ );
127860
+ addRefCountToMapForCaches(
127861
+ fileWatchesOfAffectingLocations.get(resolution.affectingLocations[i]).resolutions,
127862
+ watchedResolutionInfo.caches,
127863
+ currentCache
127864
+ );
127865
+ }
127866
+ watchedResolutionInfo.watchedAffected = (_c = resolution.affectingLocations) == null ? void 0 : _c.length;
127867
+ }
127868
+ function createFileWatcherOfAffectingLocation(affectingLocation, forResolution) {
127869
+ if (!forResolution) addRefCountToCacheMap(inUseResolutionCaches, currentCache);
127870
+ const fileWatcher = fileWatchesOfAffectingLocations.get(affectingLocation);
127871
+ if (fileWatcher) {
127872
+ addRefCountToCacheMap(forResolution ? fileWatcher.resolutions ?? (fileWatcher.resolutions = /* @__PURE__ */ new Map()) : fileWatcher.files ?? (fileWatcher.files = /* @__PURE__ */ new Map()), currentCache);
127873
+ return;
127874
+ }
127875
+ let locationToWatch = affectingLocation;
127876
+ let isSymlink = false;
127877
+ let symlinkWatcher;
127878
+ if (currentCache.resolutionHost.realpath) {
127879
+ locationToWatch = currentCache.resolutionHost.realpath(affectingLocation);
127880
+ if (affectingLocation !== locationToWatch) {
127881
+ isSymlink = true;
127882
+ symlinkWatcher = fileWatchesOfAffectingLocations.get(locationToWatch);
127883
+ }
127884
+ }
127885
+ const resolutions = forResolution ? /* @__PURE__ */ new Map([[currentCache, 1]]) : void 0;
127886
+ const files = forResolution ? void 0 : /* @__PURE__ */ new Map([[currentCache, 1]]);
127887
+ if (!isSymlink || !symlinkWatcher) {
127888
+ const watcher = {
127889
+ watcher: canWatchAffectingLocation(sharedCacheHost.toPath(locationToWatch)) ? currentCache.resolutionHost.watchAffectingFileLocation(locationToWatch, (fileName, eventKind) => {
127890
+ const refCountCaches = /* @__PURE__ */ new Set();
127891
+ onFileWatcherOfAffectingLocation(locationToWatch, refCountCaches);
127892
+ const seenCaches = /* @__PURE__ */ new Set();
127893
+ refCountCaches.forEach(
127894
+ (caches) => forRefCountCaches(
127895
+ caches,
127896
+ (cache) => {
127897
+ var _a;
127898
+ if (!tryAddToSet(seenCaches, cache)) return;
127899
+ (_a = cache.resolutionHost.getCachedDirectoryStructureHost()) == null ? void 0 : _a.addOrDeleteFile(fileName, sharedCacheHost.toPath(locationToWatch), eventKind);
127900
+ cache.resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
127901
+ },
127902
+ /*skipCache*/
127903
+ void 0
127904
+ )
127905
+ );
127906
+ }) : noopFileWatcher,
127907
+ resolutions: isSymlink ? void 0 : resolutions,
127908
+ files: isSymlink ? void 0 : files,
127909
+ symlinks: void 0
127910
+ };
127911
+ fileWatchesOfAffectingLocations.set(locationToWatch, watcher);
127912
+ addRefToPackageJson(sharedCacheHost.toPath(locationToWatch));
127913
+ if (isSymlink) symlinkWatcher = watcher;
127914
+ }
127915
+ if (isSymlink) {
127916
+ Debug.assert(!!symlinkWatcher);
127917
+ const watcher = {
127918
+ watcher: {
127919
+ close: () => {
127920
+ var _a, _b, _c;
127921
+ const symlinkWatcher2 = fileWatchesOfAffectingLocations.get(locationToWatch);
127922
+ if (((_a = symlinkWatcher2 == null ? void 0 : symlinkWatcher2.symlinks) == null ? void 0 : _a.delete(affectingLocation)) && !symlinkWatcher2.symlinks.size && !((_b = symlinkWatcher2.resolutions) == null ? void 0 : _b.size) && !((_c = symlinkWatcher2.files) == null ? void 0 : _c.size)) {
127923
+ fileWatchesOfAffectingLocations.delete(locationToWatch);
127924
+ releasePackageJson(sharedCacheHost.toPath(locationToWatch));
127925
+ symlinkWatcher2.watcher.close();
127926
+ }
127927
+ }
127928
+ },
127929
+ resolutions,
127930
+ files,
127931
+ symlinks: void 0
127932
+ };
127933
+ fileWatchesOfAffectingLocations.set(affectingLocation, watcher);
127934
+ addRefToPackageJson(sharedCacheHost.toPath(affectingLocation));
127935
+ (symlinkWatcher.symlinks ?? (symlinkWatcher.symlinks = /* @__PURE__ */ new Set())).add(affectingLocation);
127936
+ }
127937
+ }
127938
+ function releaseFileWatcherOfAffectingLocation(location) {
127939
+ releaseRefCountFromMap(inUseResolutionCaches, currentCache);
127940
+ const watcher = fileWatchesOfAffectingLocations.get(location);
127941
+ releaseRefCountFromMap(watcher.files, currentCache);
127942
+ }
127943
+ function closeFileWatcherOfAffectingLocation(path, watcher) {
127944
+ var _a, _b, _c;
127945
+ watcher ?? (watcher = fileWatchesOfAffectingLocations.get(path));
127946
+ if (watcher && !((_a = watcher.files) == null ? void 0 : _a.size) && !((_b = watcher.resolutions) == null ? void 0 : _b.size) && !((_c = watcher.symlinks) == null ? void 0 : _c.size)) {
127947
+ fileWatchesOfAffectingLocations.delete(path);
127948
+ releasePackageJson(sharedCacheHost.toPath(path));
127949
+ watcher.watcher.close();
127950
+ }
127951
+ }
127952
+ function onFileWatcherOfAffectingLocation(path, seenCaches) {
127953
+ var _a, _b, _c, _d;
127954
+ const watcher = fileWatchesOfAffectingLocations.get(path);
127955
+ if ((_a = watcher == null ? void 0 : watcher.resolutions) == null ? void 0 : _a.size) {
127956
+ (affectingPathChecks ?? (affectingPathChecks = /* @__PURE__ */ new Set())).add(path);
127957
+ seenCaches.add(watcher.resolutions);
127958
+ }
127959
+ if ((_b = watcher == null ? void 0 : watcher.files) == null ? void 0 : _b.size) {
127960
+ watcher.files.forEach((_refCount, cache) => cache.invalidateAffectingFileWatcher(path));
127961
+ seenCaches.add(watcher.files);
127962
+ }
127963
+ (_c = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap()) == null ? void 0 : _c.delete(sharedCacheHost.toPath(path));
127964
+ (_d = watcher == null ? void 0 : watcher.symlinks) == null ? void 0 : _d.forEach((path2) => onFileWatcherOfAffectingLocation(path2, seenCaches));
127965
+ }
127966
+ function releaseResolution(resolution, moduleOrTypeRefCache) {
127967
+ var _a, _b, _c, _d, _e, _f;
127968
+ releaseRefCountFromMap(inUseResolutionCaches, currentCache);
127969
+ const watchedResolutionInfo = watchedResolutionInfoMap.get(resolution);
127970
+ watchedResolutionInfo.caches.delete(currentCache);
127971
+ const forCaches = /* @__PURE__ */ new Set([currentCache]);
127972
+ (_a = watchedResolutionInfo.dirWatches) == null ? void 0 : _a.forEach((dirPath) => removeDirectoryWatcher(
127973
+ dirPath,
127974
+ /*nonRecursive*/
127975
+ false,
127976
+ forCaches
127977
+ ));
127978
+ (_b = watchedResolutionInfo.nonRecursiveDirWatches) == null ? void 0 : _b.forEach((dirPath) => removeDirectoryWatcher(
127979
+ dirPath,
127980
+ /*nonRecursive*/
127981
+ true,
127982
+ forCaches
127983
+ ));
127984
+ (_c = watchedResolutionInfo.packageDirWatchers) == null ? void 0 : _c.forEach(
127985
+ (dirPaths, packageDirPath) => dirPaths.forEach(
127986
+ (dirPath) => removeRefToDirPathWatcherOfPackageDir(packageDirPath, dirPath)
127987
+ )
127988
+ );
127989
+ (_d = resolution.affectingLocations) == null ? void 0 : _d.forEach((affectingLocation) => {
127990
+ const watcher = fileWatchesOfAffectingLocations.get(affectingLocation);
127991
+ if (watcher == null ? void 0 : watcher.resolutions) releaseRefCountFromMap(watcher.resolutions, currentCache);
127992
+ closeFileWatcherOfAffectingLocation(affectingLocation, watcher);
127993
+ });
127994
+ if (watchedResolutionInfo.caches.size) return false;
127995
+ watchedResolutionInfoMap.delete(resolution);
127996
+ if (resolutionsWithFailedLookups.delete(resolution)) {
127997
+ (_e = resolution.failedLookupLocations) == null ? void 0 : _e.forEach(releaseIfPackageJson);
127998
+ if (resolution.alternateResult) releaseIfPackageJson(resolution.alternateResult);
127999
+ }
128000
+ resolutionsWithOnlyAffectingLocations.delete(resolution);
128001
+ const resolved = getModuleOrTypeRefResolved(resolution);
128002
+ if (resolved && resolved.resolvedFileName) {
128003
+ const key = sharedCacheHost.toPath(resolved.resolvedFileName);
128004
+ const resolutions = resolvedFileToResolution.get(key);
128005
+ if ((resolutions == null ? void 0 : resolutions.delete(resolution)) && !resolutions.size) resolvedFileToResolution.delete(key);
128006
+ }
128007
+ if (isResolvedWithGlobalCachePass(resolution)) {
128008
+ const primary = resolution.globalCacheResolution.primary;
128009
+ const primaryWatchedInfo = watchedResolutionInfoMap.get(primary);
128010
+ if (primaryWatchedInfo.caches.size) {
128011
+ primary.globalCacheResolution = { primary };
128012
+ } else {
128013
+ watchedResolutionInfoMap.delete(primary);
128014
+ }
128015
+ } else if ((_f = resolution.globalCacheResolution) == null ? void 0 : _f.globalResult) {
128016
+ watchedResolutionInfoMap.set(resolution, watchedResolutionInfo);
128017
+ watchedResolutionInfo.dirWatches = void 0;
128018
+ watchedResolutionInfo.nonRecursiveDirWatches = void 0;
128019
+ watchedResolutionInfo.packageDirWatchers = void 0;
128020
+ watchedResolutionInfo.watchedFailed = void 0;
128021
+ watchedResolutionInfo.watchedAffected = void 0;
128022
+ watchedResolutionInfo.isInvalidated = void 0;
128023
+ watchedResolutionInfo.rootDirInfo = void 0;
128024
+ }
128025
+ if (moduleOrTypeRefCache) (cachesNeedingGc ?? (cachesNeedingGc = /* @__PURE__ */ new Set())).add(moduleOrTypeRefCache.sharedCache);
128026
+ return true;
128027
+ }
128028
+ function invalidateResolutions(resolutions, canInvalidate) {
128029
+ if (!resolutions) return false;
128030
+ let invalidated = false;
128031
+ resolutions.forEach((resolution) => invalidated = invalidateResolution(resolution, canInvalidate) || invalidated);
128032
+ return invalidated;
128033
+ }
128034
+ function invalidateResolution(resolution, canInvalidate) {
128035
+ const watchedResolutionInfo = watchedResolutionInfoMap.get(resolution);
128036
+ if (watchedResolutionInfo.isInvalidated || !canInvalidate(resolution)) return false;
128037
+ watchedResolutionInfo.isInvalidated = true;
128038
+ watchedResolutionInfo.caches.forEach(
128039
+ (cache) => cache !== currentCache ? cache.invalidateResolution(resolution) : void 0
128040
+ );
128041
+ return true;
128042
+ }
128043
+ function invalidateResolutionOfFile(filePath) {
128044
+ return invalidateResolutions(resolvedFileToResolution.get(filePath), returnTrue);
128045
+ }
128046
+ function scheduleInvalidateResolutionOfFailedLookupLocation(fileOrDirectoryPath, isCreatingWatchedDirectory, refCountCache) {
128047
+ if (isCreatingWatchedDirectory) {
128048
+ (isInDirectoryChecks || (isInDirectoryChecks = /* @__PURE__ */ new Set())).add(fileOrDirectoryPath);
128049
+ } else {
128050
+ const updatedPath = removeIgnoredPath(fileOrDirectoryPath);
128051
+ if (!updatedPath) return false;
128052
+ fileOrDirectoryPath = updatedPath;
128053
+ if (sharedCacheHost.fileIsOpen(fileOrDirectoryPath)) {
128054
+ return false;
128055
+ }
128056
+ const dirOfFileOrDirectory = getDirectoryPath(fileOrDirectoryPath);
128057
+ if (isNodeModulesAtTypesDirectory(fileOrDirectoryPath) || isNodeModulesDirectory(fileOrDirectoryPath) || isNodeModulesAtTypesDirectory(dirOfFileOrDirectory) || isNodeModulesDirectory(dirOfFileOrDirectory)) {
128058
+ (failedLookupChecks || (failedLookupChecks = /* @__PURE__ */ new Set())).add(fileOrDirectoryPath);
128059
+ (startsWithPathChecks || (startsWithPathChecks = /* @__PURE__ */ new Set())).add(fileOrDirectoryPath);
128060
+ } else {
128061
+ if (fileExtensionIs(fileOrDirectoryPath, ".map")) {
128062
+ return false;
128063
+ }
128064
+ if (!forEachKey(
128065
+ refCountCache,
128066
+ (cache) => !isEmittedFileOfProgram(
128067
+ cache.resolutionHost.getCurrentProgram(),
128068
+ fileOrDirectoryPath
128069
+ )
128070
+ )) return false;
128071
+ (failedLookupChecks || (failedLookupChecks = /* @__PURE__ */ new Set())).add(fileOrDirectoryPath);
128072
+ (startsWithPathChecks || (startsWithPathChecks = /* @__PURE__ */ new Set())).add(fileOrDirectoryPath);
128073
+ const packagePath = parseNodeModuleFromPath(
128074
+ fileOrDirectoryPath,
128075
+ /*isFolder*/
128076
+ true
128077
+ );
128078
+ if (packagePath) (startsWithPathChecks || (startsWithPathChecks = /* @__PURE__ */ new Set())).add(packagePath);
128079
+ }
128080
+ }
128081
+ refCountCache.forEach((_refCount, cache) => cache.resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations());
128082
+ }
128083
+ function invalidatePackageJsonMap() {
128084
+ const packageJsonMap = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap();
128085
+ if (packageJsonMap && (failedLookupChecks || startsWithPathChecks || isInDirectoryChecks)) {
128086
+ packageJsonMap.forEach((_value, path) => isInvalidatedFailedLookup(path) ? packageJsonMap.delete(path) : void 0);
128087
+ }
128088
+ }
128089
+ function invalidateResolutionsOfFailedLookupLocations() {
128090
+ if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks && !affectingPathChecks) {
128091
+ return false;
128092
+ }
128093
+ let invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution);
128094
+ invalidatePackageJsonMap();
128095
+ failedLookupChecks = void 0;
128096
+ startsWithPathChecks = void 0;
128097
+ isInDirectoryChecks = void 0;
128098
+ invalidated = invalidateResolutions(resolutionsWithOnlyAffectingLocations, canInvalidatedFailedLookupResolutionWithAffectingLocation) || invalidated;
128099
+ affectingPathChecks = void 0;
128100
+ return invalidated;
128101
+ }
128102
+ function canInvalidateFailedLookupResolution(resolution) {
128103
+ var _a;
128104
+ if (canInvalidatedFailedLookupResolutionWithAffectingLocation(resolution)) return true;
128105
+ if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks) return false;
128106
+ return ((_a = resolution.failedLookupLocations) == null ? void 0 : _a.some((location) => isInvalidatedFailedLookup(sharedCacheHost.toPath(location)))) || !!resolution.alternateResult && isInvalidatedFailedLookup(sharedCacheHost.toPath(resolution.alternateResult));
128107
+ }
128108
+ function isInvalidatedFailedLookup(locationPath) {
128109
+ return (failedLookupChecks == null ? void 0 : failedLookupChecks.has(locationPath)) || firstDefinedIterator((startsWithPathChecks == null ? void 0 : startsWithPathChecks.keys()) || [], (fileOrDirectoryPath) => startsWith(locationPath, fileOrDirectoryPath) ? true : void 0) || firstDefinedIterator((isInDirectoryChecks == null ? void 0 : isInDirectoryChecks.keys()) || [], (dirPath) => locationPath.length > dirPath.length && startsWith(locationPath, dirPath) && (isDiskPathRoot(dirPath) || locationPath[dirPath.length] === directorySeparator) ? true : void 0);
128110
+ }
128111
+ function canInvalidatedFailedLookupResolutionWithAffectingLocation(resolution) {
128112
+ var _a;
128113
+ return !!affectingPathChecks && ((_a = resolution.affectingLocations) == null ? void 0 : _a.some((location) => affectingPathChecks.has(location)));
128114
+ }
128115
+ function createTypeRootsWatch(typeRoot, cache) {
128116
+ let watcher = typeRootsWatches.get(typeRoot);
128117
+ if (watcher) {
128118
+ watcher.refCount.add(cache);
128119
+ } else {
128120
+ typeRootsWatches.set(
128121
+ typeRoot,
128122
+ watcher = {
128123
+ watcher: canWatchAtTypes(sharedCacheHost.toPath(typeRoot)) ? cache.resolutionHost.watchTypeRootsDirectory(typeRoot, (fileOrDirectory) => {
128124
+ var _a;
128125
+ const fileOrDirectoryPath = sharedCacheHost.toPath(fileOrDirectory);
128126
+ (_a = typeRootsWatches.get(typeRoot)) == null ? void 0 : _a.refCount.forEach((cache2) => {
128127
+ var _a2;
128128
+ (_a2 = cache2.resolutionHost.getCachedDirectoryStructureHost()) == null ? void 0 : _a2.addOrDeleteFileOrDirectory(
128129
+ fileOrDirectory,
128130
+ fileOrDirectoryPath
128131
+ );
128132
+ cache2.invalidateTypeRoot();
128133
+ });
128134
+ const fileOrDirectoryPathComponents = getPathComponents(fileOrDirectoryPath);
128135
+ directoryWatchesOfFailedLookups.forEach((_watcher, dirPath) => {
128136
+ if (isInDirectoryPath(getPathComponents(dirPath), fileOrDirectoryPathComponents)) {
128137
+ onDirectoryWatcher(
128138
+ dirPath,
128139
+ /*nonRecursive*/
128140
+ false,
128141
+ fileOrDirectory,
128142
+ fileOrDirectoryPath
128143
+ );
128144
+ }
128145
+ });
128146
+ nonRecursiveDirectoryWatchesOfFailedLookups.forEach((_watcher, dirPath) => {
128147
+ const dirPathComponents = getPathComponents(dirPath);
128148
+ if (isInDirectoryPath(dirPathComponents, fileOrDirectoryPathComponents) && (dirPathComponents.length === fileOrDirectoryPathComponents.length || dirPathComponents.length + 1 === fileOrDirectoryPathComponents.length)) {
128149
+ onDirectoryWatcher(
128150
+ dirPath,
128151
+ /*nonRecursive*/
128152
+ true,
128153
+ fileOrDirectory,
128154
+ fileOrDirectoryPath
128155
+ );
128156
+ }
128157
+ });
128158
+ }, 1 /* Recursive */) : noopFileWatcher,
128159
+ refCount: /* @__PURE__ */ new Set([cache])
128160
+ }
128161
+ );
128162
+ }
128163
+ const result = {
128164
+ close: () => {
128165
+ const existing = typeRootsWatches.get(typeRoot);
128166
+ if (existing == null ? void 0 : existing.refCount.delete(cache)) {
128167
+ releaseRefCountFromMap(inUseResolutionCaches, cache);
128168
+ closeTypeRootsWatch(typeRoot, existing);
128169
+ }
128170
+ }
128171
+ };
128172
+ addRefCountToCacheMap(inUseResolutionCaches, cache);
128173
+ return result;
128174
+ }
128175
+ function closeTypeRootsWatch(typeRoot, watcher) {
128176
+ if (!watcher.refCount.size) {
128177
+ typeRootsWatches.delete(typeRoot);
128178
+ watcher.watcher.close();
128179
+ }
128180
+ }
128181
+ }
128182
+ function enableSharingModuleOrTypeReferenceResolutionCache(moduleOrTypeRefCache, sharedCache) {
128183
+ const getFromDirectoryCache = moduleOrTypeRefCache.getFromDirectoryCache;
128184
+ moduleOrTypeRefCache.getFromDirectoryCache = (name, mode, directoryName, redirectedReference) => {
128185
+ let result = getFromDirectoryCache.call(moduleOrTypeRefCache, name, mode, directoryName, redirectedReference);
128186
+ if (result) return result;
128187
+ result = withSharingModuleOrTypeReferenceResolutionCache(
128188
+ moduleOrTypeRefCache,
128189
+ (sharedCache2) => sharedCache2.getFromDirectoryCache(name, mode, directoryName, redirectedReference)
128190
+ );
128191
+ if (result) {
128192
+ moduleOrTypeRefCache.setPerDirectoryAndNonRelativeNameCacheResult(
128193
+ name,
128194
+ mode,
128195
+ directoryName,
128196
+ redirectedReference,
128197
+ result
128198
+ );
128199
+ }
128200
+ return result;
128201
+ };
128202
+ const getFromNonRelativeNameCache = moduleOrTypeRefCache.getFromNonRelativeNameCache;
128203
+ moduleOrTypeRefCache.getFromNonRelativeNameCache = (nonRelativeModuleName, mode, directoryName, redirectedReference) => getFromNonRelativeNameCache.call(moduleOrTypeRefCache, nonRelativeModuleName, mode, directoryName, redirectedReference) || withSharingModuleOrTypeReferenceResolutionCache(
128204
+ moduleOrTypeRefCache,
128205
+ (sharedCache2) => sharedCache2 == null ? void 0 : sharedCache2.getFromNonRelativeNameCache(nonRelativeModuleName, mode, directoryName, redirectedReference)
128206
+ );
128207
+ const setPerDirectoryAndNonRelativeNameCacheResult = moduleOrTypeRefCache.setPerDirectoryAndNonRelativeNameCacheResult;
128208
+ moduleOrTypeRefCache.setPerDirectoryAndNonRelativeNameCacheResult = (name, mode, directoryName, redirectedReference, result, primary) => {
128209
+ var _a;
128210
+ setPerDirectoryAndNonRelativeNameCacheResult.call(moduleOrTypeRefCache, name, mode, directoryName, redirectedReference, result, primary);
128211
+ if (primary) return;
128212
+ result = ((_a = result.globalCacheResolution) == null ? void 0 : _a.primary) || result;
128213
+ withSharingModuleOrTypeReferenceResolutionCache(
128214
+ moduleOrTypeRefCache,
128215
+ (sharedCache2) => sharedCache2.setPerDirectoryAndNonRelativeNameCacheResult(name, mode, directoryName, redirectedReference, result)
128216
+ );
128217
+ };
128218
+ const update = moduleOrTypeRefCache.update;
128219
+ moduleOrTypeRefCache.update = (options) => {
128220
+ var _a;
128221
+ update.call(moduleOrTypeRefCache, options);
128222
+ (_a = moduleOrTypeRefCache.sharedCache) == null ? void 0 : _a.update(options);
128223
+ };
128224
+ moduleOrTypeRefCache.sharedCache = sharedCache;
128225
+ return moduleOrTypeRefCache;
128226
+ }
128227
+ function withSharingModuleOrTypeReferenceResolutionCache(moduleOrTypeRefCache, cb) {
128228
+ if (!moduleOrTypeRefCache.sharedCache) return;
128229
+ moduleOrTypeRefCache.sharedCache.update(moduleOrTypeRefCache.options());
128230
+ return cb(moduleOrTypeRefCache.sharedCache);
128231
+ }
128232
+ function addRefCountToCacheMap(refCountCache, key) {
128233
+ refCountCache.set(key, (refCountCache.get(key) ?? 0) + 1);
128234
+ }
128235
+ function releaseRefCountFromMap(refCountCache, key) {
128236
+ const existing = refCountCache.get(key);
128237
+ if (existing !== 1) refCountCache.set(key, existing - 1);
128238
+ else refCountCache.delete(key);
128239
+ }
128240
+ function addRefCountToMapForCaches(refCountCache, forCaches, alreadyAddedCache) {
128241
+ forRefCountCaches(forCaches, (cache) => addRefCountToCacheMap(refCountCache, cache), alreadyAddedCache);
128242
+ }
128243
+ function releaseRefCountFromMapForCaches(refCountCache, forCaches) {
128244
+ forRefCountCaches(
128245
+ forCaches,
128246
+ (cache) => releaseRefCountFromMap(refCountCache, cache),
128247
+ /*skipCache*/
128248
+ void 0
127141
128249
  );
127142
- return toWatch && filterCustomPath(toWatch.dirPath) ? toWatch.dirPath : void 0;
127143
128250
  }
128251
+ function forRefCountCaches(forCaches, cb, skipCache) {
128252
+ forCaches.forEach((_refCount, cache) => {
128253
+ if (cache === skipCache) return;
128254
+ cb(cache);
128255
+ });
128256
+ }
128257
+
128258
+ // src/compiler/resolutionCache.ts
127144
128259
  function getRootDirectoryOfResolutionCache(rootDirForResolution, getCurrentDirectory) {
127145
128260
  const normalized = getNormalizedAbsolutePath(rootDirForResolution, getCurrentDirectory());
127146
128261
  return !isDiskPathRoot(normalized) ? removeTrailingDirectorySeparator(normalized) : normalized;
@@ -127163,103 +128278,157 @@ function createModuleResolutionLoaderUsingGlobalCache(containingFile, redirected
127163
128278
  )
127164
128279
  };
127165
128280
  }
128281
+ function needsResolutionFromGlobalCache(moduleName, resolution) {
128282
+ return !isExternalModuleNameRelative(moduleName) && isUnresolvedOrResolvedToJs(resolution);
128283
+ }
128284
+ function isUnresolvedOrResolvedToJs(resolution) {
128285
+ return !resolution.resolvedModule || !resolutionExtensionIsTSOrJson(resolution.resolvedModule.extension);
128286
+ }
128287
+ function isResolvedWithGlobalCachePass(resolution) {
128288
+ var _a;
128289
+ return ((_a = resolution.globalCacheResolution) == null ? void 0 : _a.globalResult) === resolution;
128290
+ }
128291
+ function isResolvedWithoutGlobalCachePass(resolution) {
128292
+ var _a;
128293
+ return ((_a = resolution.globalCacheResolution) == null ? void 0 : _a.primary) === resolution;
128294
+ }
128295
+ function isResolvedWithGlobalCachePassButStillUnresolved(resolution) {
128296
+ return isResolvedWithGlobalCachePass(resolution) && !resolution.globalCacheResolution.globalResolution.resolvedModule;
128297
+ }
128298
+ function createGlobalResolutionResultField(primary, global2) {
128299
+ if (!primary) return global2 == null ? void 0 : global2.slice();
128300
+ if (!global2) return primary.slice();
128301
+ return primary.concat(global2);
128302
+ }
127166
128303
  function resolveModuleNameUsingGlobalCache(resolutionHost, moduleResolutionCache, moduleName, containingFile, compilerOptions, redirectedReference, mode) {
128304
+ var _a;
127167
128305
  const host = getModuleResolutionHost(resolutionHost);
127168
- const primaryResult = resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference, mode);
127169
- if (!resolutionHost.getGlobalTypingsCacheLocation) {
127170
- return primaryResult;
127171
- }
127172
- const globalCache = resolutionHost.getGlobalTypingsCacheLocation();
127173
- if (globalCache !== void 0 && !isExternalModuleNameRelative(moduleName) && !(primaryResult.resolvedModule && extensionIsTS(primaryResult.resolvedModule.extension))) {
127174
- const { resolvedModule, failedLookupLocations, affectingLocations, resolutionDiagnostics } = loadModuleFromGlobalCache(
127175
- Debug.checkDefined(resolutionHost.globalCacheResolutionModuleName)(moduleName),
127176
- resolutionHost.projectName,
127177
- compilerOptions,
127178
- host,
127179
- globalCache,
127180
- moduleResolutionCache
127181
- );
127182
- if (resolvedModule) {
127183
- primaryResult.resolvedModule = resolvedModule;
127184
- primaryResult.failedLookupLocations = updateResolutionField(primaryResult.failedLookupLocations, failedLookupLocations);
127185
- primaryResult.affectingLocations = updateResolutionField(primaryResult.affectingLocations, affectingLocations);
127186
- primaryResult.resolutionDiagnostics = updateResolutionField(primaryResult.resolutionDiagnostics, resolutionDiagnostics);
127187
- return primaryResult;
127188
- }
128306
+ const primary = resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference, mode);
128307
+ if (!resolutionHost.getGlobalTypingsCacheLocation) return primary;
128308
+ const globalCache = (_a = resolutionHost.getGlobalTypingsCacheLocation) == null ? void 0 : _a.call(resolutionHost);
128309
+ if ((globalCache === void 0 ? isResolvedWithoutGlobalCachePass(primary) : isResolvedWithGlobalCachePass(primary)) || !needsResolutionFromGlobalCache(moduleName, primary)) return primary;
128310
+ if (globalCache === void 0) {
128311
+ primary.globalCacheResolution = { primary };
128312
+ return primary;
128313
+ }
128314
+ const globalResolution = loadModuleFromGlobalCache(
128315
+ Debug.checkDefined(resolutionHost.globalCacheResolutionModuleName)(moduleName),
128316
+ resolutionHost.projectName,
128317
+ compilerOptions,
128318
+ host,
128319
+ globalCache,
128320
+ moduleResolutionCache
128321
+ );
128322
+ if (globalResolution.resolvedModule) {
128323
+ primary.globalCacheResolution = { primary, globalResolution, globalResult: globalResolution };
128324
+ globalResolution.failedLookupLocations = createGlobalResolutionResultField(primary.failedLookupLocations, globalResolution.failedLookupLocations);
128325
+ globalResolution.affectingLocations = createGlobalResolutionResultField(primary.affectingLocations, globalResolution.affectingLocations);
128326
+ globalResolution.resolutionDiagnostics = createGlobalResolutionResultField(globalResolution.resolutionDiagnostics, primary.resolutionDiagnostics);
128327
+ globalResolution.alternateResult = primary.alternateResult;
128328
+ } else {
128329
+ primary.globalCacheResolution = {
128330
+ primary,
128331
+ globalResolution,
128332
+ globalResult: { ...primary }
128333
+ };
127189
128334
  }
127190
- return primaryResult;
128335
+ Debug.assertIsDefined(primary.globalCacheResolution.globalResult);
128336
+ primary.globalCacheResolution.globalResult.globalCacheResolution = primary.globalCacheResolution;
128337
+ moduleResolutionCache.setPerDirectoryAndNonRelativeNameCacheResult(
128338
+ moduleName,
128339
+ mode,
128340
+ getDirectoryPath(containingFile),
128341
+ redirectedReference,
128342
+ primary.globalCacheResolution.globalResult,
128343
+ primary
128344
+ );
128345
+ return primary.globalCacheResolution.globalResult;
127191
128346
  }
127192
- function createResolutionCache(resolutionHost, rootDirForResolution, logChangesWhenResolvingModule) {
127193
- let filesWithChangedSetOfUnresolvedImports;
128347
+ function createResolutionCache(resolutionHost, rootDirForResolution, sharedCache = createSharedResolutionCache(resolutionHost)) {
127194
128348
  let filesWithInvalidatedResolutions;
127195
- let filesWithInvalidatedNonRelativeUnresolvedImports;
127196
- const nonRelativeExternalModuleResolutions = /* @__PURE__ */ new Set();
127197
- const resolutionsWithFailedLookups = /* @__PURE__ */ new Set();
127198
- const resolutionsWithOnlyAffectingLocations = /* @__PURE__ */ new Set();
127199
- const resolvedFileToResolution = /* @__PURE__ */ new Map();
127200
128349
  const impliedFormatPackageJsons = /* @__PURE__ */ new Map();
128350
+ const filesReferencingResolution = /* @__PURE__ */ new Map();
127201
128351
  let hasChangedAutomaticTypeDirectiveNames = false;
127202
128352
  let affectingPathChecksForFile;
127203
- let affectingPathChecks;
127204
- let failedLookupChecks;
127205
- let startsWithPathChecks;
127206
- let isInDirectoryChecks;
127207
128353
  let allModuleAndTypeResolutionsAreInvalidated = false;
128354
+ let resolutionsWithGlobalCachePassAreInvalidated = false;
128355
+ let resolutionsWithoutGlobalCachePassAreInvalidated = false;
128356
+ let unresolvedResolutionsWithGlobalCachePassAreInvalidated = false;
128357
+ let pendingRemoveResolutionsOfFile;
128358
+ let potentiallyUnreferencedResolutions;
128359
+ let newUnresolvedResolutionCachePassResolutions;
128360
+ let considerNonWatchedResolutionAsInvalidated = false;
127208
128361
  const getCurrentDirectory = memoize(() => resolutionHost.getCurrentDirectory());
127209
- const cachedDirectoryStructureHost = resolutionHost.getCachedDirectoryStructureHost();
127210
128362
  const resolvedModuleNames = /* @__PURE__ */ new Map();
127211
- const moduleResolutionCache = createModuleResolutionCache(
127212
- getCurrentDirectory(),
127213
- resolutionHost.getCanonicalFileName,
127214
- resolutionHost.getCompilationSettings()
128363
+ const moduleResolutionCache = enableSharingModuleOrTypeReferenceResolutionCache(
128364
+ createModuleResolutionCache(
128365
+ getCurrentDirectory(),
128366
+ resolutionHost.getCanonicalFileName,
128367
+ /*options*/
128368
+ void 0,
128369
+ sharedCache.moduleResolutionCache.getPackageJsonInfoCache(),
128370
+ /*optionsToRedirectsKey*/
128371
+ void 0,
128372
+ getValidResolution
128373
+ ),
128374
+ sharedCache.moduleResolutionCache
127215
128375
  );
127216
128376
  const resolvedTypeReferenceDirectives = /* @__PURE__ */ new Map();
127217
- const typeReferenceDirectiveResolutionCache = createTypeReferenceDirectiveResolutionCache(
127218
- getCurrentDirectory(),
127219
- resolutionHost.getCanonicalFileName,
127220
- resolutionHost.getCompilationSettings(),
127221
- moduleResolutionCache.getPackageJsonInfoCache(),
127222
- moduleResolutionCache.optionsToRedirectsKey
128377
+ const typeReferenceDirectiveResolutionCache = enableSharingModuleOrTypeReferenceResolutionCache(
128378
+ createTypeReferenceDirectiveResolutionCache(
128379
+ getCurrentDirectory(),
128380
+ resolutionHost.getCanonicalFileName,
128381
+ /*options*/
128382
+ void 0,
128383
+ moduleResolutionCache.getPackageJsonInfoCache(),
128384
+ moduleResolutionCache.optionsToRedirectsKey,
128385
+ getValidResolution
128386
+ ),
128387
+ sharedCache.typeReferenceDirectiveResolutionCache
127223
128388
  );
127224
128389
  const resolvedLibraries = /* @__PURE__ */ new Map();
127225
- const libraryResolutionCache = createModuleResolutionCache(
127226
- getCurrentDirectory(),
127227
- resolutionHost.getCanonicalFileName,
127228
- getOptionsForLibraryResolution(resolutionHost.getCompilationSettings()),
127229
- moduleResolutionCache.getPackageJsonInfoCache()
128390
+ const libraryResolutionCache = enableSharingModuleOrTypeReferenceResolutionCache(
128391
+ createModuleResolutionCache(
128392
+ getCurrentDirectory(),
128393
+ resolutionHost.getCanonicalFileName,
128394
+ sharedCache.libraryResolutionCache.options(),
128395
+ moduleResolutionCache.getPackageJsonInfoCache(),
128396
+ /*optionsToRedirectsKey*/
128397
+ void 0,
128398
+ getValidResolution
128399
+ ),
128400
+ sharedCache.libraryResolutionCache
127230
128401
  );
127231
- const directoryWatchesOfFailedLookups = /* @__PURE__ */ new Map();
127232
- const fileWatchesOfAffectingLocations = /* @__PURE__ */ new Map();
127233
- const rootDir = getRootDirectoryOfResolutionCache(rootDirForResolution, getCurrentDirectory);
127234
- const rootPath = resolutionHost.toPath(rootDir);
127235
- const rootPathComponents = getPathComponents(rootPath);
127236
- const isRootWatchable = canWatchDirectoryOrFile(rootPathComponents);
127237
- const isSymlinkCache = /* @__PURE__ */ new Map();
127238
- const packageDirWatchers = /* @__PURE__ */ new Map();
127239
- const dirPathToSymlinkPackageRefCount = /* @__PURE__ */ new Map();
128402
+ let resolutionsResolvedWithGlobalCache = 0;
128403
+ let resolutionsResolvedWithoutGlobalCache = 0;
128404
+ const rootDirInfo = getRootDirInfo(rootDirForResolution);
128405
+ const redirectsToRootDirInfo = /* @__PURE__ */ new Map();
127240
128406
  const typeRootsWatches = /* @__PURE__ */ new Map();
127241
- return {
128407
+ const cache = {
128408
+ resolutionHost,
128409
+ sharedCache,
127242
128410
  rootDirForResolution,
127243
128411
  resolvedModuleNames,
127244
128412
  resolvedTypeReferenceDirectives,
127245
128413
  resolvedLibraries,
127246
- resolvedFileToResolution,
127247
- resolutionsWithFailedLookups,
127248
- resolutionsWithOnlyAffectingLocations,
127249
- directoryWatchesOfFailedLookups,
127250
- fileWatchesOfAffectingLocations,
127251
- packageDirWatchers,
127252
- dirPathToSymlinkPackageRefCount,
127253
- watchFailedLookupLocationsOfExternalModuleResolutions,
127254
- getModuleResolutionCache: () => moduleResolutionCache,
127255
- startRecordingFilesWithChangedResolutions,
127256
- finishRecordingFilesWithChangedResolutions,
128414
+ moduleResolutionCache,
128415
+ typeReferenceDirectiveResolutionCache,
128416
+ libraryResolutionCache,
128417
+ filesReferencingResolution,
128418
+ typeRootsWatches,
128419
+ countResolutionsResolvedWithGlobalCache: () => resolutionsResolvedWithGlobalCache,
128420
+ countResolutionsResolvedWithoutGlobalCache: () => resolutionsResolvedWithoutGlobalCache,
128421
+ watchResolution,
127257
128422
  // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
127258
128423
  // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
127259
128424
  startCachingPerDirectoryResolution,
127260
128425
  finishCachingPerDirectoryResolution,
128426
+ compactCaches,
127261
128427
  resolveModuleNameLiterals,
127262
128428
  resolveTypeReferenceDirectiveReferences,
128429
+ onReusedModuleResolutions,
128430
+ onReusedTypeReferenceDirectiveResolutions,
128431
+ onSourceFileNotCreated,
127263
128432
  resolveLibrary: resolveLibrary2,
127264
128433
  resolveSingleModuleNameWithoutWatching,
127265
128434
  removeResolutionsFromProjectReferenceRedirects,
@@ -127267,37 +128436,72 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
127267
128436
  hasChangedAutomaticTypeDirectiveNames: () => hasChangedAutomaticTypeDirectiveNames,
127268
128437
  invalidateResolutionOfFile,
127269
128438
  invalidateResolutionsOfFailedLookupLocations,
127270
- setFilesWithInvalidatedNonRelativeUnresolvedImports,
128439
+ invalidateResolutionsWithGlobalCachePass,
128440
+ invalidateResolutionsWithoutGlobalCachePass,
128441
+ invalidateUnresolvedResolutionsWithGlobalCachePass,
127271
128442
  createHasInvalidatedResolutions,
127272
- isFileWithInvalidatedNonRelativeUnresolvedImports,
127273
128443
  updateTypeRootsWatch,
127274
128444
  closeTypeRootsWatch,
127275
128445
  clear: clear2,
127276
- onChangesAffectModuleResolution
128446
+ onChangesAffectModuleResolution,
128447
+ // Used by shared cache
128448
+ getRootDirInfoForResolution: maybeBind(resolutionHost, resolutionHost.getRootDirInfoForResolution) ?? getRootDirInfoOfRedirectedReference,
128449
+ invalidateAffectingFileWatcher,
128450
+ invalidateResolution,
128451
+ invalidateTypeRoot,
128452
+ getValidResolution
127277
128453
  };
128454
+ return cache;
128455
+ function getRootDirInfo(rootDirForResolution2) {
128456
+ const rootDir = getRootDirectoryOfResolutionCache(rootDirForResolution2, getCurrentDirectory);
128457
+ const rootPath = resolutionHost.toPath(rootDir);
128458
+ const rootPathComponents = getPathComponents(rootPath);
128459
+ return {
128460
+ rootDir,
128461
+ rootPath,
128462
+ rootPathComponents,
128463
+ canWatch: canWatchDirectoryOrFile(rootPathComponents)
128464
+ };
128465
+ }
128466
+ function getRootDirInfoOfRedirectedReference(redirectedReference) {
128467
+ if (!redirectedReference) return rootDirInfo;
128468
+ let result = redirectsToRootDirInfo.get(redirectedReference);
128469
+ if (!result) {
128470
+ redirectsToRootDirInfo.set(
128471
+ redirectedReference,
128472
+ result = getRootDirInfo(
128473
+ getDirectoryPath(redirectedReference.sourceFile.fileName)
128474
+ )
128475
+ );
128476
+ }
128477
+ return result;
128478
+ }
128479
+ function cleanupRedirectRootDirInfo(newProgram) {
128480
+ const toDeleteRedirectToRootDirInfo = new Set(redirectsToRootDirInfo.keys());
128481
+ newProgram == null ? void 0 : newProgram.forEachResolvedProjectReference((redirect) => {
128482
+ toDeleteRedirectToRootDirInfo.delete(redirect);
128483
+ });
128484
+ toDeleteRedirectToRootDirInfo.forEach((redirect) => redirectsToRootDirInfo.delete(redirect));
128485
+ }
127278
128486
  function clear2() {
127279
- clearMap(directoryWatchesOfFailedLookups, closeFileWatcherOf);
127280
- clearMap(fileWatchesOfAffectingLocations, closeFileWatcherOf);
127281
- isSymlinkCache.clear();
127282
- packageDirWatchers.clear();
127283
- dirPathToSymlinkPackageRefCount.clear();
127284
- nonRelativeExternalModuleResolutions.clear();
128487
+ pendingRemoveResolutionsOfFile = void 0;
128488
+ potentiallyUnreferencedResolutions = void 0;
128489
+ newUnresolvedResolutionCachePassResolutions = void 0;
128490
+ redirectsToRootDirInfo.clear();
127285
128491
  closeTypeRootsWatch();
128492
+ sharedCache.clear(cache);
127286
128493
  resolvedModuleNames.clear();
127287
128494
  resolvedTypeReferenceDirectives.clear();
127288
- resolvedFileToResolution.clear();
127289
- resolutionsWithFailedLookups.clear();
127290
- resolutionsWithOnlyAffectingLocations.clear();
127291
- failedLookupChecks = void 0;
127292
- startsWithPathChecks = void 0;
127293
- isInDirectoryChecks = void 0;
127294
- affectingPathChecks = void 0;
128495
+ filesReferencingResolution.clear();
128496
+ resolutionsResolvedWithGlobalCache = 0;
128497
+ resolutionsResolvedWithoutGlobalCache = 0;
127295
128498
  affectingPathChecksForFile = void 0;
127296
128499
  allModuleAndTypeResolutionsAreInvalidated = false;
128500
+ resolutionsWithGlobalCachePassAreInvalidated = false;
128501
+ resolutionsWithoutGlobalCachePassAreInvalidated = false;
128502
+ unresolvedResolutionsWithGlobalCachePassAreInvalidated = false;
127297
128503
  moduleResolutionCache.clear();
127298
128504
  typeReferenceDirectiveResolutionCache.clear();
127299
- moduleResolutionCache.update(resolutionHost.getCompilationSettings());
127300
- typeReferenceDirectiveResolutionCache.update(resolutionHost.getCompilationSettings());
127301
128505
  libraryResolutionCache.clear();
127302
128506
  impliedFormatPackageJsons.clear();
127303
128507
  resolvedLibraries.clear();
@@ -127305,48 +128509,28 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
127305
128509
  }
127306
128510
  function onChangesAffectModuleResolution() {
127307
128511
  allModuleAndTypeResolutionsAreInvalidated = true;
127308
- moduleResolutionCache.clearAllExceptPackageJsonInfoCache();
127309
- typeReferenceDirectiveResolutionCache.clearAllExceptPackageJsonInfoCache();
127310
- moduleResolutionCache.update(resolutionHost.getCompilationSettings());
127311
- typeReferenceDirectiveResolutionCache.update(resolutionHost.getCompilationSettings());
127312
- }
127313
- function startRecordingFilesWithChangedResolutions() {
127314
- filesWithChangedSetOfUnresolvedImports = [];
127315
- }
127316
- function finishRecordingFilesWithChangedResolutions() {
127317
- const collected = filesWithChangedSetOfUnresolvedImports;
127318
- filesWithChangedSetOfUnresolvedImports = void 0;
127319
- return collected;
127320
- }
127321
- function isFileWithInvalidatedNonRelativeUnresolvedImports(path) {
127322
- if (!filesWithInvalidatedNonRelativeUnresolvedImports) {
127323
- return false;
127324
- }
127325
- const value = filesWithInvalidatedNonRelativeUnresolvedImports.get(path);
127326
- return !!value && !!value.length;
127327
128512
  }
127328
128513
  function createHasInvalidatedResolutions(customHasInvalidatedResolutions, customHasInvalidatedLibResolutions) {
127329
128514
  invalidateResolutionsOfFailedLookupLocations();
127330
128515
  const collected = filesWithInvalidatedResolutions;
127331
128516
  filesWithInvalidatedResolutions = void 0;
127332
128517
  return {
127333
- hasInvalidatedResolutions: (path) => customHasInvalidatedResolutions(path) || allModuleAndTypeResolutionsAreInvalidated || !!(collected == null ? void 0 : collected.has(path)) || isFileWithInvalidatedNonRelativeUnresolvedImports(path),
128518
+ hasInvalidatedResolutions: (path) => customHasInvalidatedResolutions(path) || allModuleAndTypeResolutionsAreInvalidated || resolutionsWithGlobalCachePassAreInvalidated || resolutionsWithoutGlobalCachePassAreInvalidated || unresolvedResolutionsWithGlobalCachePassAreInvalidated || !!(collected == null ? void 0 : collected.has(path)),
127334
128519
  hasInvalidatedLibResolutions: (libFileName) => {
127335
128520
  var _a;
127336
- return customHasInvalidatedLibResolutions(libFileName) || !!((_a = resolvedLibraries == null ? void 0 : resolvedLibraries.get(libFileName)) == null ? void 0 : _a.isInvalidated);
128521
+ return customHasInvalidatedLibResolutions(libFileName) || !!((_a = sharedCache.watchedResolutionInfoMap.get(resolvedLibraries == null ? void 0 : resolvedLibraries.get(libFileName))) == null ? void 0 : _a.isInvalidated);
127337
128522
  }
127338
128523
  };
127339
128524
  }
127340
- function startCachingPerDirectoryResolution() {
128525
+ function startCachingPerDirectoryResolution(options) {
127341
128526
  moduleResolutionCache.isReadonly = void 0;
127342
128527
  typeReferenceDirectiveResolutionCache.isReadonly = void 0;
127343
128528
  libraryResolutionCache.isReadonly = void 0;
127344
- moduleResolutionCache.getPackageJsonInfoCache().isReadonly = void 0;
127345
- moduleResolutionCache.clearAllExceptPackageJsonInfoCache();
127346
- typeReferenceDirectiveResolutionCache.clearAllExceptPackageJsonInfoCache();
127347
- libraryResolutionCache.clearAllExceptPackageJsonInfoCache();
127348
- watchFailedLookupLocationOfNonRelativeModuleResolutions();
127349
- isSymlinkCache.clear();
128529
+ moduleResolutionCache.update(options ?? resolutionHost.getCompilationSettings());
128530
+ typeReferenceDirectiveResolutionCache.update(options ?? resolutionHost.getCompilationSettings());
128531
+ sharedCache.startCachingPerDirectoryResolution(cache);
128532
+ pendingRemoveResolutionsOfFile == null ? void 0 : pendingRemoveResolutionsOfFile.forEach((path) => removeResolutionsOfFile(path));
128533
+ pendingRemoveResolutionsOfFile = void 0;
127350
128534
  }
127351
128535
  function cleanupLibResolutionWatching(newProgram) {
127352
128536
  resolvedLibraries.forEach((resolution, libFileName) => {
@@ -127355,32 +128539,35 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
127355
128539
  stopWatchFailedLookupLocationOfResolution(
127356
128540
  resolution,
127357
128541
  resolutionHost.toPath(getInferredLibraryNameResolveFrom(resolutionHost.getCompilationSettings(), getCurrentDirectory(), libFileName)),
127358
- getResolvedModuleFromResolution
128542
+ libraryResolutionCache
127359
128543
  );
127360
128544
  resolvedLibraries.delete(libFileName);
127361
128545
  }
127362
128546
  });
127363
128547
  }
127364
- function finishCachingPerDirectoryResolution(newProgram, oldProgram) {
127365
- filesWithInvalidatedNonRelativeUnresolvedImports = void 0;
128548
+ function finishCachingPerDirectoryResolution(newProgram, oldProgram, skipCacheCompact) {
127366
128549
  allModuleAndTypeResolutionsAreInvalidated = false;
127367
- watchFailedLookupLocationOfNonRelativeModuleResolutions();
128550
+ resolutionsWithGlobalCachePassAreInvalidated = false;
128551
+ resolutionsWithoutGlobalCachePassAreInvalidated = false;
128552
+ unresolvedResolutionsWithGlobalCachePassAreInvalidated = false;
128553
+ newUnresolvedResolutionCachePassResolutions = void 0;
128554
+ let potentiallyUnReferencedFileWatcherOfAffectingLocation;
127368
128555
  if (newProgram !== oldProgram) {
128556
+ const releaseFileWatcherOfAffectingLocation = (location) => {
128557
+ sharedCache.releaseFileWatcherOfAffectingLocation(location);
128558
+ (potentiallyUnReferencedFileWatcherOfAffectingLocation ?? (potentiallyUnReferencedFileWatcherOfAffectingLocation = /* @__PURE__ */ new Set())).add(location);
128559
+ };
127369
128560
  cleanupLibResolutionWatching(newProgram);
127370
128561
  newProgram == null ? void 0 : newProgram.getSourceFiles().forEach((newFile) => {
127371
128562
  var _a;
127372
128563
  const expected = ((_a = newFile.packageJsonLocations) == null ? void 0 : _a.length) ?? 0;
127373
128564
  const existing = impliedFormatPackageJsons.get(newFile.resolvedPath) ?? emptyArray;
127374
128565
  for (let i = existing.length; i < expected; i++) {
127375
- createFileWatcherOfAffectingLocation(
127376
- newFile.packageJsonLocations[i],
127377
- /*forResolution*/
127378
- false
127379
- );
128566
+ sharedCache.createFileWatcherOfAffectingLocation(newFile.packageJsonLocations[i]);
127380
128567
  }
127381
128568
  if (existing.length > expected) {
127382
128569
  for (let i = expected; i < existing.length; i++) {
127383
- fileWatchesOfAffectingLocations.get(existing[i]).files--;
128570
+ releaseFileWatcherOfAffectingLocation(existing[i]);
127384
128571
  }
127385
128572
  }
127386
128573
  if (expected) impliedFormatPackageJsons.set(newFile.resolvedPath, newFile.packageJsonLocations);
@@ -127389,38 +128576,68 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
127389
128576
  impliedFormatPackageJsons.forEach((existing, path) => {
127390
128577
  const newFile = newProgram == null ? void 0 : newProgram.getSourceFileByPath(path);
127391
128578
  if (!newFile || newFile.resolvedPath !== path) {
127392
- existing.forEach((location) => fileWatchesOfAffectingLocations.get(location).files--);
128579
+ existing.forEach(releaseFileWatcherOfAffectingLocation);
127393
128580
  impliedFormatPackageJsons.delete(path);
127394
128581
  }
127395
128582
  });
128583
+ cleanupRedirectRootDirInfo(newProgram);
127396
128584
  }
127397
- directoryWatchesOfFailedLookups.forEach(closeDirectoryWatchesOfFailedLookup);
127398
- fileWatchesOfAffectingLocations.forEach(closeFileWatcherOfAffectingLocation);
127399
- packageDirWatchers.forEach(closePackageDirWatcher);
128585
+ potentiallyUnReferencedFileWatcherOfAffectingLocation == null ? void 0 : potentiallyUnReferencedFileWatcherOfAffectingLocation.forEach((location) => sharedCache.closeFileWatcherOfAffectingLocation(location));
128586
+ potentiallyUnReferencedFileWatcherOfAffectingLocation = void 0;
128587
+ if (potentiallyUnreferencedResolutions) {
128588
+ potentiallyUnreferencedResolutions.forEach(gcModuleOrTypeRefCache);
128589
+ potentiallyUnreferencedResolutions = void 0;
128590
+ }
128591
+ sharedCache.finishCachingPerDirectoryResolution();
127400
128592
  hasChangedAutomaticTypeDirectiveNames = false;
128593
+ if (!skipCacheCompact) compactCaches(newProgram);
127401
128594
  moduleResolutionCache.isReadonly = true;
127402
128595
  typeReferenceDirectiveResolutionCache.isReadonly = true;
127403
128596
  libraryResolutionCache.isReadonly = true;
127404
128597
  moduleResolutionCache.getPackageJsonInfoCache().isReadonly = true;
127405
- isSymlinkCache.clear();
127406
128598
  }
127407
- function closePackageDirWatcher(watcher, packageDirPath) {
127408
- if (watcher.dirPathToWatcher.size === 0) {
127409
- packageDirWatchers.delete(packageDirPath);
128599
+ function compactCaches(newProgram) {
128600
+ const availableOptions = /* @__PURE__ */ new Set();
128601
+ if (newProgram) {
128602
+ availableOptions.add(newProgram.getCompilerOptions());
128603
+ newProgram.forEachResolvedProjectReference((ref) => {
128604
+ availableOptions.add(ref.commandLine.options);
128605
+ });
127410
128606
  }
128607
+ moduleResolutionCache.compact(
128608
+ availableOptions,
128609
+ /*skipOptionsToRedirectsKeyCleanup*/
128610
+ true
128611
+ );
128612
+ typeReferenceDirectiveResolutionCache.compact(availableOptions);
128613
+ libraryResolutionCache.compact();
128614
+ sharedCache.compactCaches(availableOptions, cache);
127411
128615
  }
127412
- function closeDirectoryWatchesOfFailedLookup(watcher, path) {
127413
- if (watcher.refCount === 0) {
127414
- directoryWatchesOfFailedLookups.delete(path);
127415
- watcher.watcher.close();
128616
+ function gcModuleOrTypeRefCache(setOfResolutions, cache2) {
128617
+ let needsGc = false;
128618
+ setOfResolutions.forEach((resolution) => needsGc = releaseResolution(resolution, cache2) || needsGc);
128619
+ if (needsGc) {
128620
+ considerNonWatchedResolutionAsInvalidated = true;
128621
+ cache2.gc(filesReferencingResolution);
128622
+ considerNonWatchedResolutionAsInvalidated = false;
127416
128623
  }
127417
128624
  }
127418
- function closeFileWatcherOfAffectingLocation(watcher, path) {
128625
+ function onSourceFileNotCreated(sourceFileOptions) {
127419
128626
  var _a;
127420
- if (watcher.files === 0 && watcher.resolutions === 0 && !((_a = watcher.symlinks) == null ? void 0 : _a.size)) {
127421
- fileWatchesOfAffectingLocations.delete(path);
127422
- watcher.watcher.close();
127423
- }
128627
+ (_a = sourceFileOptions.packageJsonLocations) == null ? void 0 : _a.forEach((location) => sharedCache.addToPotentiallyUnwatchedPackageJsons(location));
128628
+ }
128629
+ function getValidResolution(resolution) {
128630
+ return isInvalidatedResolution(resolution) ? void 0 : resolution;
128631
+ }
128632
+ function isInvalidatedResolution(resolution) {
128633
+ var _a;
128634
+ if (!resolution || considerNonWatchedResolutionAsInvalidated && !filesReferencingResolution.has(resolution) || ((_a = sharedCache.watchedResolutionInfoMap.get(resolution)) == null ? void 0 : _a.isInvalidated) || resolutionsWithGlobalCachePassAreInvalidated && isResolvedWithGlobalCachePass(resolution) || resolutionsWithoutGlobalCachePassAreInvalidated && isResolvedWithoutGlobalCachePass(resolution)) return true;
128635
+ if ((newUnresolvedResolutionCachePassResolutions == null ? void 0 : newUnresolvedResolutionCachePassResolutions.has(resolution)) || !isInvalidatedUnResolvedGlobalCachePassResolution(resolution)) return false;
128636
+ sharedCache.invalidateResolution(resolution, returnTrue);
128637
+ return true;
128638
+ }
128639
+ function isInvalidatedUnResolvedGlobalCachePassResolution(resolution) {
128640
+ return unresolvedResolutionsWithGlobalCachePassAreInvalidated && isResolvedWithGlobalCachePassButStillUnresolved(resolution);
127424
128641
  }
127425
128642
  function resolveNamesWithLocalCache({
127426
128643
  entries,
@@ -127429,17 +128646,15 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
127429
128646
  redirectedReference,
127430
128647
  options,
127431
128648
  perFileCache,
128649
+ moduleOrTypeRefCache,
127432
128650
  reusedNames,
127433
128651
  loader,
127434
128652
  getResolutionWithResolvedFileName,
127435
- deferWatchingNonRelativeResolution,
127436
- shouldRetryResolution,
127437
- logChanges
128653
+ onNewResolution
127438
128654
  }) {
127439
128655
  const path = resolutionHost.toPath(containingFile);
127440
128656
  const resolutionsInFile = perFileCache.get(path) || perFileCache.set(path, createModeAwareCache()).get(path);
127441
128657
  const resolvedModules = [];
127442
- const hasInvalidatedNonRelativeUnresolvedImport = logChanges && isFileWithInvalidatedNonRelativeUnresolvedImports(path);
127443
128658
  const program = resolutionHost.getCurrentProgram();
127444
128659
  const oldRedirect = program && program.getResolvedProjectReferenceToRedirect(containingFile);
127445
128660
  const unmatchedRedirects = oldRedirect ? !redirectedReference || redirectedReference.sourceFile.path !== oldRedirect.sourceFile.path : !!redirectedReference;
@@ -127448,8 +128663,7 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
127448
128663
  const name = loader.nameAndMode.getName(entry);
127449
128664
  const mode = loader.nameAndMode.getMode(entry, containingSourceFile, (redirectedReference == null ? void 0 : redirectedReference.commandLine.options) || options);
127450
128665
  let resolution = resolutionsInFile.get(name, mode);
127451
- if (!seenNamesInFile.has(name, mode) && (allModuleAndTypeResolutionsAreInvalidated || unmatchedRedirects || !resolution || resolution.isInvalidated || // If the name is unresolved import that was invalidated, recalculate
127452
- hasInvalidatedNonRelativeUnresolvedImport && !isExternalModuleNameRelative(name) && shouldRetryResolution(resolution))) {
128666
+ if (!seenNamesInFile.has(name, mode) && (allModuleAndTypeResolutionsAreInvalidated || unmatchedRedirects || isInvalidatedResolution(resolution))) {
127453
128667
  const existingResolution = resolution;
127454
128668
  resolution = loader.resolve(name, mode);
127455
128669
  if (resolutionHost.onDiscoveredSymlink && resolutionIsSymlink(resolution)) {
@@ -127457,15 +128671,15 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
127457
128671
  }
127458
128672
  resolutionsInFile.set(name, mode, resolution);
127459
128673
  if (resolution !== existingResolution) {
127460
- watchFailedLookupLocationsOfExternalModuleResolutions(name, resolution, path, getResolutionWithResolvedFileName, deferWatchingNonRelativeResolution);
128674
+ watchResolution(resolution, path, getResolutionWithResolvedFileName, redirectedReference);
127461
128675
  if (existingResolution) {
127462
- stopWatchFailedLookupLocationOfResolution(existingResolution, path, getResolutionWithResolvedFileName);
128676
+ stopWatchFailedLookupLocationOfResolution(existingResolution, path, moduleOrTypeRefCache);
127463
128677
  }
127464
128678
  }
127465
- if (logChanges && filesWithChangedSetOfUnresolvedImports && !resolutionIsEqualTo(existingResolution, resolution)) {
127466
- filesWithChangedSetOfUnresolvedImports.push(path);
127467
- logChanges = false;
128679
+ if (isInvalidatedUnResolvedGlobalCachePassResolution(resolution)) {
128680
+ (newUnresolvedResolutionCachePassResolutions ?? (newUnresolvedResolutionCachePassResolutions = /* @__PURE__ */ new Set())).add(resolution);
127468
128681
  }
128682
+ onNewResolution == null ? void 0 : onNewResolution(existingResolution, resolution, path, name, mode);
127469
128683
  } else {
127470
128684
  const host = getModuleResolutionHost(resolutionHost);
127471
128685
  if (isTraceEnabled(options, host) && !seenNamesInFile.has(name, mode)) {
@@ -127480,43 +128694,76 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
127480
128694
  );
127481
128695
  }
127482
128696
  }
127483
- Debug.assert(resolution !== void 0 && !resolution.isInvalidated);
128697
+ Debug.assert(resolution !== void 0 && !sharedCache.watchedResolutionInfoMap.get(resolution).isInvalidated);
127484
128698
  seenNamesInFile.set(name, mode, true);
127485
128699
  resolvedModules.push(resolution);
127486
128700
  }
128701
+ onReusedResolutions({
128702
+ reusedNames,
128703
+ containingSourceFile,
128704
+ redirectedReference,
128705
+ options,
128706
+ path,
128707
+ resolutionsInFile,
128708
+ seenNamesInFile,
128709
+ nameAndModeGetter: loader.nameAndMode,
128710
+ moduleOrTypeRefCache
128711
+ });
128712
+ return resolvedModules;
128713
+ }
128714
+ function onReusedResolutions({
128715
+ reusedNames,
128716
+ containingSourceFile,
128717
+ redirectedReference,
128718
+ options,
128719
+ path,
128720
+ resolutionsInFile,
128721
+ seenNamesInFile,
128722
+ nameAndModeGetter,
128723
+ moduleOrTypeRefCache
128724
+ }) {
128725
+ if (!resolutionsInFile) return;
128726
+ if (!seenNamesInFile) seenNamesInFile = createModeAwareCache();
127487
128727
  reusedNames == null ? void 0 : reusedNames.forEach(
127488
128728
  (entry) => seenNamesInFile.set(
127489
- loader.nameAndMode.getName(entry),
127490
- loader.nameAndMode.getMode(entry, containingSourceFile, (redirectedReference == null ? void 0 : redirectedReference.commandLine.options) || options),
128729
+ nameAndModeGetter.getName(entry),
128730
+ nameAndModeGetter.getMode(entry, containingSourceFile, (redirectedReference == null ? void 0 : redirectedReference.commandLine.options) || options),
127491
128731
  true
127492
128732
  )
127493
128733
  );
127494
128734
  if (resolutionsInFile.size() !== seenNamesInFile.size()) {
127495
128735
  resolutionsInFile.forEach((resolution, name, mode) => {
127496
128736
  if (!seenNamesInFile.has(name, mode)) {
127497
- stopWatchFailedLookupLocationOfResolution(resolution, path, getResolutionWithResolvedFileName);
128737
+ stopWatchFailedLookupLocationOfResolution(resolution, path, moduleOrTypeRefCache);
127498
128738
  resolutionsInFile.delete(name, mode);
127499
128739
  }
127500
128740
  });
127501
128741
  }
127502
- return resolvedModules;
127503
- function resolutionIsEqualTo(oldResolution, newResolution) {
127504
- if (oldResolution === newResolution) {
127505
- return true;
127506
- }
127507
- if (!oldResolution || !newResolution) {
127508
- return false;
127509
- }
127510
- const oldResult = getResolutionWithResolvedFileName(oldResolution);
127511
- const newResult = getResolutionWithResolvedFileName(newResolution);
127512
- if (oldResult === newResult) {
127513
- return true;
127514
- }
127515
- if (!oldResult || !newResult) {
127516
- return false;
127517
- }
127518
- return oldResult.resolvedFileName === newResult.resolvedFileName;
127519
- }
128742
+ }
128743
+ function onReusedModuleResolutions(reusedNames, containingSourceFile, redirectedReference, options) {
128744
+ onReusedResolutions({
128745
+ reusedNames,
128746
+ containingSourceFile,
128747
+ redirectedReference,
128748
+ options,
128749
+ path: containingSourceFile.path,
128750
+ resolutionsInFile: resolvedModuleNames.get(containingSourceFile.path),
128751
+ nameAndModeGetter: moduleResolutionNameAndModeGetter,
128752
+ moduleOrTypeRefCache: moduleResolutionCache
128753
+ });
128754
+ }
128755
+ function onReusedTypeReferenceDirectiveResolutions(reusedNames, containingSourceFile, redirectedReference, options) {
128756
+ const path = containingSourceFile ? containingSourceFile.path : resolutionHost.toPath(getAutomaticTypeDirectiveContainingFile(resolutionHost.getCompilationSettings(), getCurrentDirectory()));
128757
+ onReusedResolutions({
128758
+ reusedNames,
128759
+ containingSourceFile,
128760
+ redirectedReference,
128761
+ options,
128762
+ path,
128763
+ resolutionsInFile: resolvedTypeReferenceDirectives.get(path),
128764
+ nameAndModeGetter: typeReferenceResolutionNameAndModeGetter,
128765
+ moduleOrTypeRefCache: typeReferenceDirectiveResolutionCache
128766
+ });
127520
128767
  }
127521
128768
  function resolveTypeReferenceDirectiveReferences(typeDirectiveReferences, containingFile, redirectedReference, options, containingSourceFile, reusedNames) {
127522
128769
  return resolveNamesWithLocalCache({
@@ -127527,6 +128774,7 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
127527
128774
  options,
127528
128775
  reusedNames,
127529
128776
  perFileCache: resolvedTypeReferenceDirectives,
128777
+ moduleOrTypeRefCache: typeReferenceDirectiveResolutionCache,
127530
128778
  loader: createTypeReferenceResolutionLoader(
127531
128779
  containingFile,
127532
128780
  redirectedReference,
@@ -127534,12 +128782,10 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
127534
128782
  getModuleResolutionHost(resolutionHost),
127535
128783
  typeReferenceDirectiveResolutionCache
127536
128784
  ),
127537
- getResolutionWithResolvedFileName: getResolvedTypeReferenceDirectiveFromResolution,
127538
- shouldRetryResolution: (resolution) => resolution.resolvedTypeReferenceDirective === void 0,
127539
- deferWatchingNonRelativeResolution: false
128785
+ getResolutionWithResolvedFileName: getResolvedTypeReferenceDirectiveFromResolution
127540
128786
  });
127541
128787
  }
127542
- function resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, reusedNames) {
128788
+ function resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, reusedNames, onNewResolution) {
127543
128789
  return resolveNamesWithLocalCache({
127544
128790
  entries: moduleLiterals,
127545
128791
  containingFile,
@@ -127548,6 +128794,7 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
127548
128794
  options,
127549
128795
  reusedNames,
127550
128796
  perFileCache: resolvedModuleNames,
128797
+ moduleOrTypeRefCache: moduleResolutionCache,
127551
128798
  loader: createModuleResolutionLoaderUsingGlobalCache(
127552
128799
  containingFile,
127553
128800
  redirectedReference,
@@ -127556,30 +128803,26 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
127556
128803
  moduleResolutionCache
127557
128804
  ),
127558
128805
  getResolutionWithResolvedFileName: getResolvedModuleFromResolution,
127559
- shouldRetryResolution: (resolution) => !resolution.resolvedModule || !resolutionExtensionIsTSOrJson(resolution.resolvedModule.extension),
127560
- logChanges: logChangesWhenResolvingModule,
127561
- deferWatchingNonRelativeResolution: true
127562
- // Defer non relative resolution watch because we could be using ambient modules
128806
+ onNewResolution
127563
128807
  });
127564
128808
  }
127565
128809
  function resolveLibrary2(libraryName, resolveFrom, options, libFileName) {
127566
128810
  const host = getModuleResolutionHost(resolutionHost);
127567
128811
  let resolution = resolvedLibraries == null ? void 0 : resolvedLibraries.get(libFileName);
127568
- if (!resolution || resolution.isInvalidated) {
128812
+ if (isInvalidatedResolution(resolution)) {
127569
128813
  const existingResolution = resolution;
127570
128814
  resolution = resolveLibrary(libraryName, resolveFrom, options, host, libraryResolutionCache);
127571
128815
  const path = resolutionHost.toPath(resolveFrom);
127572
- watchFailedLookupLocationsOfExternalModuleResolutions(
127573
- libraryName,
128816
+ watchResolution(
127574
128817
  resolution,
127575
128818
  path,
127576
128819
  getResolvedModuleFromResolution,
127577
- /*deferWatchingNonRelativeResolution*/
127578
- false
128820
+ /*redirectedReference*/
128821
+ void 0
127579
128822
  );
127580
128823
  resolvedLibraries.set(libFileName, resolution);
127581
128824
  if (existingResolution) {
127582
- stopWatchFailedLookupLocationOfResolution(existingResolution, path, getResolvedModuleFromResolution);
128825
+ stopWatchFailedLookupLocationOfResolution(existingResolution, path, libraryResolutionCache);
127583
128826
  }
127584
128827
  } else {
127585
128828
  if (isTraceEnabled(options, host)) {
@@ -127605,7 +128848,7 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
127605
128848
  /*mode*/
127606
128849
  void 0
127607
128850
  );
127608
- if (resolution && !resolution.isInvalidated) return resolution;
128851
+ if (resolution && !sharedCache.watchedResolutionInfoMap.get(resolution).isInvalidated) return resolution;
127609
128852
  const data = (_a = resolutionHost.beforeResolveSingleModuleNameWithoutWatching) == null ? void 0 : _a.call(resolutionHost, moduleResolutionCache);
127610
128853
  const host = getModuleResolutionHost(resolutionHost);
127611
128854
  const result = resolveModuleName(
@@ -127618,306 +128861,48 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
127618
128861
  (_b = resolutionHost.afterResolveSingleModuleNameWithoutWatching) == null ? void 0 : _b.call(resolutionHost, moduleResolutionCache, moduleName, containingFile, result, data);
127619
128862
  return result;
127620
128863
  }
127621
- function isNodeModulesAtTypesDirectory(dirPath) {
127622
- return endsWith(dirPath, "/node_modules/@types");
127623
- }
127624
- function watchFailedLookupLocationsOfExternalModuleResolutions(name, resolution, filePath, getResolutionWithResolvedFileName, deferWatchingNonRelativeResolution) {
127625
- (resolution.files ?? (resolution.files = /* @__PURE__ */ new Set())).add(filePath);
127626
- if (resolution.files.size !== 1) return;
127627
- if (!deferWatchingNonRelativeResolution || isExternalModuleNameRelative(name)) {
127628
- watchFailedLookupLocationOfResolution(resolution);
127629
- } else {
127630
- nonRelativeExternalModuleResolutions.add(resolution);
127631
- }
127632
- const resolved = getResolutionWithResolvedFileName(resolution);
127633
- if (resolved && resolved.resolvedFileName) {
127634
- const key = resolutionHost.toPath(resolved.resolvedFileName);
127635
- let resolutions = resolvedFileToResolution.get(key);
127636
- if (!resolutions) resolvedFileToResolution.set(key, resolutions = /* @__PURE__ */ new Set());
127637
- resolutions.add(resolution);
127638
- }
127639
- }
127640
- function watchFailedLookupLocation(failedLookupLocation, setAtRoot) {
127641
- const failedLookupLocationPath = resolutionHost.toPath(failedLookupLocation);
127642
- const toWatch = getDirectoryToWatchFailedLookupLocation(
127643
- failedLookupLocation,
127644
- failedLookupLocationPath,
127645
- rootDir,
127646
- rootPath,
127647
- rootPathComponents,
127648
- isRootWatchable,
127649
- getCurrentDirectory,
127650
- resolutionHost.preferNonRecursiveWatch
127651
- );
127652
- if (toWatch) {
127653
- const { dir, dirPath, nonRecursive, packageDir, packageDirPath } = toWatch;
127654
- if (dirPath === rootPath) {
127655
- Debug.assert(nonRecursive);
127656
- Debug.assert(!packageDir);
127657
- setAtRoot = true;
127658
- } else {
127659
- setDirectoryWatcher(dir, dirPath, packageDir, packageDirPath, nonRecursive);
127660
- }
127661
- }
127662
- return setAtRoot;
127663
- }
127664
- function watchFailedLookupLocationOfResolution(resolution) {
127665
- var _a;
127666
- Debug.assert(!!((_a = resolution.files) == null ? void 0 : _a.size));
127667
- const { failedLookupLocations, affectingLocations, alternateResult } = resolution;
127668
- if (!(failedLookupLocations == null ? void 0 : failedLookupLocations.length) && !(affectingLocations == null ? void 0 : affectingLocations.length) && !alternateResult) return;
127669
- if ((failedLookupLocations == null ? void 0 : failedLookupLocations.length) || alternateResult) resolutionsWithFailedLookups.add(resolution);
127670
- let setAtRoot = false;
127671
- if (failedLookupLocations) {
127672
- for (const failedLookupLocation of failedLookupLocations) {
127673
- setAtRoot = watchFailedLookupLocation(failedLookupLocation, setAtRoot);
127674
- }
127675
- }
127676
- if (alternateResult) setAtRoot = watchFailedLookupLocation(alternateResult, setAtRoot);
127677
- if (setAtRoot) {
127678
- setDirectoryWatcher(
127679
- rootDir,
127680
- rootPath,
127681
- /*packageDir*/
127682
- void 0,
127683
- /*packageDirPath*/
127684
- void 0,
127685
- /*nonRecursive*/
127686
- true
127687
- );
127688
- }
127689
- watchAffectingLocationsOfResolution(resolution, !(failedLookupLocations == null ? void 0 : failedLookupLocations.length) && !alternateResult);
127690
- }
127691
- function watchAffectingLocationsOfResolution(resolution, addToResolutionsWithOnlyAffectingLocations) {
127692
- var _a;
127693
- Debug.assert(!!((_a = resolution.files) == null ? void 0 : _a.size));
127694
- const { affectingLocations } = resolution;
127695
- if (!(affectingLocations == null ? void 0 : affectingLocations.length)) return;
127696
- if (addToResolutionsWithOnlyAffectingLocations) resolutionsWithOnlyAffectingLocations.add(resolution);
127697
- for (const affectingLocation of affectingLocations) {
127698
- createFileWatcherOfAffectingLocation(
127699
- affectingLocation,
127700
- /*forResolution*/
127701
- true
127702
- );
127703
- }
127704
- }
127705
- function createFileWatcherOfAffectingLocation(affectingLocation, forResolution) {
127706
- const fileWatcher = fileWatchesOfAffectingLocations.get(affectingLocation);
127707
- if (fileWatcher) {
127708
- if (forResolution) fileWatcher.resolutions++;
127709
- else fileWatcher.files++;
127710
- return;
127711
- }
127712
- let locationToWatch = affectingLocation;
127713
- let isSymlink = false;
127714
- let symlinkWatcher;
127715
- if (resolutionHost.realpath) {
127716
- locationToWatch = resolutionHost.realpath(affectingLocation);
127717
- if (affectingLocation !== locationToWatch) {
127718
- isSymlink = true;
127719
- symlinkWatcher = fileWatchesOfAffectingLocations.get(locationToWatch);
127720
- }
127721
- }
127722
- const resolutions = forResolution ? 1 : 0;
127723
- const files = forResolution ? 0 : 1;
127724
- if (!isSymlink || !symlinkWatcher) {
127725
- const watcher = {
127726
- watcher: canWatchAffectingLocation(resolutionHost.toPath(locationToWatch)) ? resolutionHost.watchAffectingFileLocation(locationToWatch, (fileName, eventKind) => {
127727
- cachedDirectoryStructureHost == null ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
127728
- invalidateAffectingFileWatcher(locationToWatch, moduleResolutionCache.getPackageJsonInfoCache().getInternalMap());
127729
- resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
127730
- }) : noopFileWatcher,
127731
- resolutions: isSymlink ? 0 : resolutions,
127732
- files: isSymlink ? 0 : files,
127733
- symlinks: void 0
127734
- };
127735
- fileWatchesOfAffectingLocations.set(locationToWatch, watcher);
127736
- if (isSymlink) symlinkWatcher = watcher;
127737
- }
127738
- if (isSymlink) {
127739
- Debug.assert(!!symlinkWatcher);
127740
- const watcher = {
127741
- watcher: {
127742
- close: () => {
127743
- var _a;
127744
- const symlinkWatcher2 = fileWatchesOfAffectingLocations.get(locationToWatch);
127745
- if (((_a = symlinkWatcher2 == null ? void 0 : symlinkWatcher2.symlinks) == null ? void 0 : _a.delete(affectingLocation)) && !symlinkWatcher2.symlinks.size && !symlinkWatcher2.resolutions && !symlinkWatcher2.files) {
127746
- fileWatchesOfAffectingLocations.delete(locationToWatch);
127747
- symlinkWatcher2.watcher.close();
127748
- }
127749
- }
127750
- },
127751
- resolutions,
127752
- files,
127753
- symlinks: void 0
127754
- };
127755
- fileWatchesOfAffectingLocations.set(affectingLocation, watcher);
127756
- (symlinkWatcher.symlinks ?? (symlinkWatcher.symlinks = /* @__PURE__ */ new Set())).add(affectingLocation);
127757
- }
127758
- }
127759
- function invalidateAffectingFileWatcher(path, packageJsonMap) {
127760
- var _a;
127761
- const watcher = fileWatchesOfAffectingLocations.get(path);
127762
- if (watcher == null ? void 0 : watcher.resolutions) (affectingPathChecks ?? (affectingPathChecks = /* @__PURE__ */ new Set())).add(path);
127763
- if (watcher == null ? void 0 : watcher.files) (affectingPathChecksForFile ?? (affectingPathChecksForFile = /* @__PURE__ */ new Set())).add(path);
127764
- (_a = watcher == null ? void 0 : watcher.symlinks) == null ? void 0 : _a.forEach((path2) => invalidateAffectingFileWatcher(path2, packageJsonMap));
127765
- packageJsonMap == null ? void 0 : packageJsonMap.delete(resolutionHost.toPath(path));
127766
- }
127767
- function watchFailedLookupLocationOfNonRelativeModuleResolutions() {
127768
- nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfResolution);
127769
- nonRelativeExternalModuleResolutions.clear();
127770
- }
127771
- function createDirectoryWatcherForPackageDir(dir, dirPath, packageDir, packageDirPath, nonRecursive) {
127772
- Debug.assert(!nonRecursive);
127773
- let isSymlink = isSymlinkCache.get(packageDirPath);
127774
- let packageDirWatcher = packageDirWatchers.get(packageDirPath);
127775
- if (isSymlink === void 0) {
127776
- const realPath2 = resolutionHost.realpath(packageDir);
127777
- isSymlink = realPath2 !== packageDir && resolutionHost.toPath(realPath2) !== packageDirPath;
127778
- isSymlinkCache.set(packageDirPath, isSymlink);
127779
- if (!packageDirWatcher) {
127780
- packageDirWatchers.set(
127781
- packageDirPath,
127782
- packageDirWatcher = {
127783
- dirPathToWatcher: /* @__PURE__ */ new Map(),
127784
- isSymlink
127785
- }
127786
- );
127787
- } else if (packageDirWatcher.isSymlink !== isSymlink) {
127788
- packageDirWatcher.dirPathToWatcher.forEach((watcher) => {
127789
- removeDirectoryWatcher(packageDirWatcher.isSymlink ? packageDirPath : dirPath);
127790
- watcher.watcher = createDirPathToWatcher();
127791
- });
127792
- packageDirWatcher.isSymlink = isSymlink;
127793
- }
127794
- } else {
127795
- Debug.assertIsDefined(packageDirWatcher);
127796
- Debug.assert(isSymlink === packageDirWatcher.isSymlink);
127797
- }
127798
- const forDirPath = packageDirWatcher.dirPathToWatcher.get(dirPath);
127799
- if (forDirPath) {
127800
- forDirPath.refCount++;
127801
- } else {
127802
- packageDirWatcher.dirPathToWatcher.set(dirPath, {
127803
- watcher: createDirPathToWatcher(),
127804
- refCount: 1
127805
- });
127806
- if (isSymlink) dirPathToSymlinkPackageRefCount.set(dirPath, (dirPathToSymlinkPackageRefCount.get(dirPath) ?? 0) + 1);
127807
- }
127808
- function createDirPathToWatcher() {
127809
- return isSymlink ? createOrAddRefToDirectoryWatchOfFailedLookups(packageDir, packageDirPath, nonRecursive) : createOrAddRefToDirectoryWatchOfFailedLookups(dir, dirPath, nonRecursive);
127810
- }
127811
- }
127812
- function setDirectoryWatcher(dir, dirPath, packageDir, packageDirPath, nonRecursive) {
127813
- if (!packageDirPath || !resolutionHost.realpath) {
127814
- createOrAddRefToDirectoryWatchOfFailedLookups(dir, dirPath, nonRecursive);
128864
+ function watchResolution(resolution, filePath, getResolutionWithResolvedFileName, redirectedReference) {
128865
+ let files = filesReferencingResolution.get(resolution);
128866
+ if (!files) {
128867
+ filesReferencingResolution.set(resolution, files = /* @__PURE__ */ new Set([filePath]));
128868
+ if (isResolvedWithGlobalCachePass(resolution)) resolutionsResolvedWithGlobalCache++;
128869
+ else if (isResolvedWithoutGlobalCachePass(resolution)) resolutionsResolvedWithoutGlobalCache++;
127815
128870
  } else {
127816
- createDirectoryWatcherForPackageDir(dir, dirPath, packageDir, packageDirPath, nonRecursive);
127817
- }
127818
- }
127819
- function createOrAddRefToDirectoryWatchOfFailedLookups(dir, dirPath, nonRecursive) {
127820
- let dirWatcher = directoryWatchesOfFailedLookups.get(dirPath);
127821
- if (dirWatcher) {
127822
- Debug.assert(!!nonRecursive === !!dirWatcher.nonRecursive);
127823
- dirWatcher.refCount++;
127824
- } else {
127825
- directoryWatchesOfFailedLookups.set(dirPath, dirWatcher = { watcher: createDirectoryWatcher(dir, dirPath, nonRecursive), refCount: 1, nonRecursive });
127826
- }
127827
- return dirWatcher;
127828
- }
127829
- function stopWatchFailedLookupLocation(failedLookupLocation, removeAtRoot) {
127830
- const failedLookupLocationPath = resolutionHost.toPath(failedLookupLocation);
127831
- const toWatch = getDirectoryToWatchFailedLookupLocation(
127832
- failedLookupLocation,
127833
- failedLookupLocationPath,
127834
- rootDir,
127835
- rootPath,
127836
- rootPathComponents,
127837
- isRootWatchable,
127838
- getCurrentDirectory,
127839
- resolutionHost.preferNonRecursiveWatch
127840
- );
127841
- if (toWatch) {
127842
- const { dirPath, packageDirPath } = toWatch;
127843
- if (dirPath === rootPath) {
127844
- removeAtRoot = true;
127845
- } else if (packageDirPath && resolutionHost.realpath) {
127846
- const packageDirWatcher = packageDirWatchers.get(packageDirPath);
127847
- const forDirPath = packageDirWatcher.dirPathToWatcher.get(dirPath);
127848
- forDirPath.refCount--;
127849
- if (forDirPath.refCount === 0) {
127850
- removeDirectoryWatcher(packageDirWatcher.isSymlink ? packageDirPath : dirPath);
127851
- packageDirWatcher.dirPathToWatcher.delete(dirPath);
127852
- if (packageDirWatcher.isSymlink) {
127853
- const refCount = dirPathToSymlinkPackageRefCount.get(dirPath) - 1;
127854
- if (refCount === 0) {
127855
- dirPathToSymlinkPackageRefCount.delete(dirPath);
127856
- } else {
127857
- dirPathToSymlinkPackageRefCount.set(dirPath, refCount);
127858
- }
127859
- }
127860
- }
127861
- } else {
127862
- removeDirectoryWatcher(dirPath);
127863
- }
127864
- }
127865
- return removeAtRoot;
127866
- }
127867
- function stopWatchFailedLookupLocationOfResolution(resolution, filePath, getResolutionWithResolvedFileName) {
127868
- Debug.checkDefined(resolution.files).delete(filePath);
127869
- if (resolution.files.size) return;
127870
- resolution.files = void 0;
127871
- const resolved = getResolutionWithResolvedFileName(resolution);
127872
- if (resolved && resolved.resolvedFileName) {
127873
- const key = resolutionHost.toPath(resolved.resolvedFileName);
127874
- const resolutions = resolvedFileToResolution.get(key);
127875
- if ((resolutions == null ? void 0 : resolutions.delete(resolution)) && !resolutions.size) resolvedFileToResolution.delete(key);
127876
- }
127877
- const { failedLookupLocations, affectingLocations, alternateResult } = resolution;
127878
- if (resolutionsWithFailedLookups.delete(resolution)) {
127879
- let removeAtRoot = false;
127880
- if (failedLookupLocations) {
127881
- for (const failedLookupLocation of failedLookupLocations) {
127882
- removeAtRoot = stopWatchFailedLookupLocation(failedLookupLocation, removeAtRoot);
127883
- }
127884
- }
127885
- if (alternateResult) removeAtRoot = stopWatchFailedLookupLocation(alternateResult, removeAtRoot);
127886
- if (removeAtRoot) removeDirectoryWatcher(rootPath);
127887
- } else if (affectingLocations == null ? void 0 : affectingLocations.length) {
127888
- resolutionsWithOnlyAffectingLocations.delete(resolution);
127889
- }
127890
- if (affectingLocations) {
127891
- for (const affectingLocation of affectingLocations) {
127892
- const watcher = fileWatchesOfAffectingLocations.get(affectingLocation);
127893
- watcher.resolutions--;
127894
- }
127895
- }
127896
- }
127897
- function removeDirectoryWatcher(dirPath) {
127898
- const dirWatcher = directoryWatchesOfFailedLookups.get(dirPath);
127899
- dirWatcher.refCount--;
127900
- }
127901
- function createDirectoryWatcher(directory, dirPath, nonRecursive) {
127902
- return resolutionHost.watchDirectoryOfFailedLookupLocation(directory, (fileOrDirectory) => {
127903
- const fileOrDirectoryPath = resolutionHost.toPath(fileOrDirectory);
127904
- if (cachedDirectoryStructureHost) {
127905
- cachedDirectoryStructureHost.addOrDeleteFileOrDirectory(fileOrDirectory, fileOrDirectoryPath);
127906
- }
127907
- scheduleInvalidateResolutionOfFailedLookupLocation(fileOrDirectoryPath, dirPath === fileOrDirectoryPath);
127908
- }, nonRecursive ? 0 /* None */ : 1 /* Recursive */);
128871
+ files.add(filePath);
128872
+ }
128873
+ sharedCache.watchResolution(resolution, getResolutionWithResolvedFileName, redirectedReference);
128874
+ }
128875
+ function invalidateAffectingFileWatcher(path) {
128876
+ (affectingPathChecksForFile ?? (affectingPathChecksForFile = /* @__PURE__ */ new Set())).add(path);
128877
+ }
128878
+ function stopWatchFailedLookupLocationOfResolution(resolution, filePath, cache2) {
128879
+ const files = filesReferencingResolution.get(resolution);
128880
+ files.delete(filePath);
128881
+ if (files.size) return;
128882
+ let setOfResolutions = potentiallyUnreferencedResolutions == null ? void 0 : potentiallyUnreferencedResolutions.get(cache2);
128883
+ if (!setOfResolutions) (potentiallyUnreferencedResolutions ?? (potentiallyUnreferencedResolutions = /* @__PURE__ */ new Map())).set(cache2, setOfResolutions = /* @__PURE__ */ new Set());
128884
+ setOfResolutions.add(resolution);
128885
+ }
128886
+ function releaseResolution(resolution, moduleOrTypeRefCache) {
128887
+ const files = filesReferencingResolution.get(resolution);
128888
+ if (files.size) return false;
128889
+ filesReferencingResolution.delete(resolution);
128890
+ if (isResolvedWithGlobalCachePass(resolution)) resolutionsResolvedWithGlobalCache--;
128891
+ else if (isResolvedWithoutGlobalCachePass(resolution)) resolutionsResolvedWithoutGlobalCache--;
128892
+ sharedCache.releaseResolution(resolution, moduleOrTypeRefCache);
128893
+ return true;
127909
128894
  }
127910
- function removeResolutionsOfFileFromCache(cache, filePath, getResolutionWithResolvedFileName) {
127911
- const resolutions = cache.get(filePath);
128895
+ function removeResolutionsOfFileFromCache(cache2, filePath, moduleOrTypeRefCache) {
128896
+ const resolutions = cache2.get(filePath);
127912
128897
  if (resolutions) {
127913
128898
  resolutions.forEach(
127914
128899
  (resolution) => stopWatchFailedLookupLocationOfResolution(
127915
128900
  resolution,
127916
128901
  filePath,
127917
- getResolutionWithResolvedFileName
128902
+ moduleOrTypeRefCache
127918
128903
  )
127919
128904
  );
127920
- cache.delete(filePath);
128905
+ cache2.delete(filePath);
127921
128906
  }
127922
128907
  }
127923
128908
  function removeResolutionsFromProjectReferenceRedirects(filePath) {
@@ -127929,149 +128914,62 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
127929
128914
  resolvedProjectReference.commandLine.fileNames.forEach((f) => removeResolutionsOfFile(resolutionHost.toPath(f)));
127930
128915
  }
127931
128916
  function removeResolutionsOfFile(filePath) {
127932
- removeResolutionsOfFileFromCache(resolvedModuleNames, filePath, getResolvedModuleFromResolution);
127933
- removeResolutionsOfFileFromCache(resolvedTypeReferenceDirectives, filePath, getResolvedTypeReferenceDirectiveFromResolution);
128917
+ if (sharedCache.currentCache() === cache) {
128918
+ removeResolutionsOfFileFromCache(resolvedModuleNames, filePath, moduleResolutionCache);
128919
+ removeResolutionsOfFileFromCache(resolvedTypeReferenceDirectives, filePath, typeReferenceDirectiveResolutionCache);
128920
+ } else {
128921
+ (pendingRemoveResolutionsOfFile ?? (pendingRemoveResolutionsOfFile = /* @__PURE__ */ new Set())).add(filePath);
128922
+ }
127934
128923
  }
127935
- function invalidateResolutions(resolutions, canInvalidate) {
127936
- if (!resolutions) return false;
127937
- let invalidated = false;
127938
- resolutions.forEach((resolution) => {
127939
- if (resolution.isInvalidated || !canInvalidate(resolution)) return;
127940
- resolution.isInvalidated = invalidated = true;
127941
- for (const containingFilePath of Debug.checkDefined(resolution.files)) {
127942
- (filesWithInvalidatedResolutions ?? (filesWithInvalidatedResolutions = /* @__PURE__ */ new Set())).add(containingFilePath);
127943
- hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames || endsWith(containingFilePath, inferredTypesContainingFile);
127944
- }
127945
- });
127946
- return invalidated;
128924
+ function invalidateResolution(resolution) {
128925
+ const files = filesReferencingResolution.get(resolution);
128926
+ for (const containingFilePath of files) {
128927
+ (filesWithInvalidatedResolutions ?? (filesWithInvalidatedResolutions = /* @__PURE__ */ new Set())).add(containingFilePath);
128928
+ hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames || endsWith(containingFilePath, inferredTypesContainingFile);
128929
+ }
127947
128930
  }
127948
128931
  function invalidateResolutionOfFile(filePath) {
127949
128932
  removeResolutionsOfFile(filePath);
127950
128933
  const prevHasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames;
127951
- if (invalidateResolutions(resolvedFileToResolution.get(filePath), returnTrue) && hasChangedAutomaticTypeDirectiveNames && !prevHasChangedAutomaticTypeDirectiveNames) {
128934
+ if (sharedCache.invalidateResolutionOfFile(filePath) && hasChangedAutomaticTypeDirectiveNames && !prevHasChangedAutomaticTypeDirectiveNames) {
127952
128935
  resolutionHost.onChangedAutomaticTypeDirectiveNames();
127953
128936
  }
127954
128937
  }
127955
- function setFilesWithInvalidatedNonRelativeUnresolvedImports(filesMap) {
127956
- Debug.assert(filesWithInvalidatedNonRelativeUnresolvedImports === filesMap || filesWithInvalidatedNonRelativeUnresolvedImports === void 0);
127957
- filesWithInvalidatedNonRelativeUnresolvedImports = filesMap;
128938
+ function invalidateResolutionsWithGlobalCachePass() {
128939
+ if (resolutionsResolvedWithGlobalCache) resolutionsWithGlobalCachePassAreInvalidated = true;
127958
128940
  }
127959
- function scheduleInvalidateResolutionOfFailedLookupLocation(fileOrDirectoryPath, isCreatingWatchedDirectory) {
127960
- if (isCreatingWatchedDirectory) {
127961
- (isInDirectoryChecks || (isInDirectoryChecks = /* @__PURE__ */ new Set())).add(fileOrDirectoryPath);
127962
- } else {
127963
- const updatedPath = removeIgnoredPath(fileOrDirectoryPath);
127964
- if (!updatedPath) return false;
127965
- fileOrDirectoryPath = updatedPath;
127966
- if (resolutionHost.fileIsOpen(fileOrDirectoryPath)) {
127967
- return false;
127968
- }
127969
- const dirOfFileOrDirectory = getDirectoryPath(fileOrDirectoryPath);
127970
- if (isNodeModulesAtTypesDirectory(fileOrDirectoryPath) || isNodeModulesDirectory(fileOrDirectoryPath) || isNodeModulesAtTypesDirectory(dirOfFileOrDirectory) || isNodeModulesDirectory(dirOfFileOrDirectory)) {
127971
- (failedLookupChecks || (failedLookupChecks = /* @__PURE__ */ new Set())).add(fileOrDirectoryPath);
127972
- (startsWithPathChecks || (startsWithPathChecks = /* @__PURE__ */ new Set())).add(fileOrDirectoryPath);
127973
- } else {
127974
- if (isEmittedFileOfProgram(resolutionHost.getCurrentProgram(), fileOrDirectoryPath)) {
127975
- return false;
127976
- }
127977
- if (fileExtensionIs(fileOrDirectoryPath, ".map")) {
127978
- return false;
127979
- }
127980
- (failedLookupChecks || (failedLookupChecks = /* @__PURE__ */ new Set())).add(fileOrDirectoryPath);
127981
- (startsWithPathChecks || (startsWithPathChecks = /* @__PURE__ */ new Set())).add(fileOrDirectoryPath);
127982
- const packagePath = parseNodeModuleFromPath(
127983
- fileOrDirectoryPath,
127984
- /*isFolder*/
127985
- true
127986
- );
127987
- if (packagePath) (startsWithPathChecks || (startsWithPathChecks = /* @__PURE__ */ new Set())).add(packagePath);
127988
- }
127989
- }
127990
- resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
128941
+ function invalidateResolutionsWithoutGlobalCachePass() {
128942
+ if (resolutionsResolvedWithoutGlobalCache) resolutionsWithoutGlobalCachePassAreInvalidated = true;
127991
128943
  }
127992
- function invalidatePackageJsonMap() {
127993
- const packageJsonMap = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap();
127994
- if (packageJsonMap && (failedLookupChecks || startsWithPathChecks || isInDirectoryChecks)) {
127995
- packageJsonMap.forEach((_value, path) => isInvalidatedFailedLookup(path) ? packageJsonMap.delete(path) : void 0);
127996
- }
128944
+ function invalidateUnresolvedResolutionsWithGlobalCachePass() {
128945
+ if (resolutionsResolvedWithGlobalCache) unresolvedResolutionsWithGlobalCachePassAreInvalidated = true;
127997
128946
  }
127998
128947
  function invalidateResolutionsOfFailedLookupLocations() {
127999
128948
  var _a;
128000
- if (allModuleAndTypeResolutionsAreInvalidated) {
128001
- affectingPathChecksForFile = void 0;
128002
- invalidatePackageJsonMap();
128003
- if (failedLookupChecks || startsWithPathChecks || isInDirectoryChecks || affectingPathChecks) {
128004
- invalidateResolutions(resolvedLibraries, canInvalidateFailedLookupResolution);
128005
- }
128006
- failedLookupChecks = void 0;
128007
- startsWithPathChecks = void 0;
128008
- isInDirectoryChecks = void 0;
128009
- affectingPathChecks = void 0;
128010
- return true;
128011
- }
128012
- let invalidated = false;
128013
- if (affectingPathChecksForFile) {
128949
+ let invalidated = allModuleAndTypeResolutionsAreInvalidated;
128950
+ if (!allModuleAndTypeResolutionsAreInvalidated && affectingPathChecksForFile) {
128014
128951
  (_a = resolutionHost.getCurrentProgram()) == null ? void 0 : _a.getSourceFiles().forEach((f) => {
128015
128952
  if (some(f.packageJsonLocations, (location) => affectingPathChecksForFile.has(location))) {
128016
128953
  (filesWithInvalidatedResolutions ?? (filesWithInvalidatedResolutions = /* @__PURE__ */ new Set())).add(f.path);
128017
128954
  invalidated = true;
128018
128955
  }
128019
128956
  });
128020
- affectingPathChecksForFile = void 0;
128021
- }
128022
- if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks && !affectingPathChecks) {
128023
- return invalidated;
128024
128957
  }
128025
- invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution) || invalidated;
128026
- invalidatePackageJsonMap();
128027
- failedLookupChecks = void 0;
128028
- startsWithPathChecks = void 0;
128029
- isInDirectoryChecks = void 0;
128030
- invalidated = invalidateResolutions(resolutionsWithOnlyAffectingLocations, canInvalidatedFailedLookupResolutionWithAffectingLocation) || invalidated;
128031
- affectingPathChecks = void 0;
128032
- return invalidated;
128033
- }
128034
- function canInvalidateFailedLookupResolution(resolution) {
128035
- var _a;
128036
- if (canInvalidatedFailedLookupResolutionWithAffectingLocation(resolution)) return true;
128037
- if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks) return false;
128038
- return ((_a = resolution.failedLookupLocations) == null ? void 0 : _a.some((location) => isInvalidatedFailedLookup(resolutionHost.toPath(location)))) || !!resolution.alternateResult && isInvalidatedFailedLookup(resolutionHost.toPath(resolution.alternateResult));
128039
- }
128040
- function isInvalidatedFailedLookup(locationPath) {
128041
- return (failedLookupChecks == null ? void 0 : failedLookupChecks.has(locationPath)) || firstDefinedIterator((startsWithPathChecks == null ? void 0 : startsWithPathChecks.keys()) || [], (fileOrDirectoryPath) => startsWith(locationPath, fileOrDirectoryPath) ? true : void 0) || firstDefinedIterator((isInDirectoryChecks == null ? void 0 : isInDirectoryChecks.keys()) || [], (dirPath) => locationPath.length > dirPath.length && startsWith(locationPath, dirPath) && (isDiskPathRoot(dirPath) || locationPath[dirPath.length] === directorySeparator) ? true : void 0);
128042
- }
128043
- function canInvalidatedFailedLookupResolutionWithAffectingLocation(resolution) {
128044
- var _a;
128045
- return !!affectingPathChecks && ((_a = resolution.affectingLocations) == null ? void 0 : _a.some((location) => affectingPathChecks.has(location)));
128958
+ affectingPathChecksForFile = void 0;
128959
+ return sharedCache.invalidateResolutionsOfFailedLookupLocations() || invalidated;
128046
128960
  }
128047
128961
  function closeTypeRootsWatch() {
128048
128962
  clearMap(typeRootsWatches, closeFileWatcher);
128049
128963
  }
128050
128964
  function createTypeRootsWatch(typeRoot) {
128051
- return canWatchTypeRootPath(typeRoot) ? resolutionHost.watchTypeRootsDirectory(typeRoot, (fileOrDirectory) => {
128052
- const fileOrDirectoryPath = resolutionHost.toPath(fileOrDirectory);
128053
- if (cachedDirectoryStructureHost) {
128054
- cachedDirectoryStructureHost.addOrDeleteFileOrDirectory(fileOrDirectory, fileOrDirectoryPath);
128055
- }
128056
- hasChangedAutomaticTypeDirectiveNames = true;
128057
- resolutionHost.onChangedAutomaticTypeDirectiveNames();
128058
- const dirPath = getDirectoryToWatchFailedLookupLocationFromTypeRoot(
128059
- typeRoot,
128060
- resolutionHost.toPath(typeRoot),
128061
- rootPath,
128062
- rootPathComponents,
128063
- isRootWatchable,
128064
- getCurrentDirectory,
128065
- resolutionHost.preferNonRecursiveWatch,
128066
- (dirPath2) => directoryWatchesOfFailedLookups.has(dirPath2) || dirPathToSymlinkPackageRefCount.has(dirPath2)
128067
- );
128068
- if (dirPath) {
128069
- scheduleInvalidateResolutionOfFailedLookupLocation(fileOrDirectoryPath, dirPath === fileOrDirectoryPath);
128070
- }
128071
- }, 1 /* Recursive */) : noopFileWatcher;
128965
+ return sharedCache.createTypeRootsWatch(typeRoot, cache);
128966
+ }
128967
+ function invalidateTypeRoot() {
128968
+ hasChangedAutomaticTypeDirectiveNames = true;
128969
+ resolutionHost.onChangedAutomaticTypeDirectiveNames();
128072
128970
  }
128073
- function updateTypeRootsWatch() {
128074
- const options = resolutionHost.getCompilationSettings();
128971
+ function updateTypeRootsWatch(options) {
128972
+ options ?? (options = resolutionHost.getCompilationSettings());
128075
128973
  if (options.types) {
128076
128974
  closeTypeRootsWatch();
128077
128975
  return;
@@ -128090,10 +128988,6 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
128090
128988
  closeTypeRootsWatch();
128091
128989
  }
128092
128990
  }
128093
- function canWatchTypeRootPath(typeRoot) {
128094
- if (resolutionHost.getCompilationSettings().typeRoots) return true;
128095
- return canWatchAtTypes(resolutionHost.toPath(typeRoot));
128096
- }
128097
128991
  }
128098
128992
  function resolutionIsSymlink(resolution) {
128099
128993
  var _a, _b;
@@ -128861,22 +129755,23 @@ function createWatchProgram(host) {
128861
129755
  compilerHost.getParsedCommandLine = getParsedCommandLine;
128862
129756
  const resolutionCache = createResolutionCache(
128863
129757
  compilerHost,
128864
- configFileName ? getDirectoryPath(getNormalizedAbsolutePath(configFileName, currentDirectory)) : currentDirectory,
128865
- /*logChangesWhenResolvingModule*/
128866
- false
129758
+ configFileName ? getDirectoryPath(getNormalizedAbsolutePath(configFileName, currentDirectory)) : currentDirectory
128867
129759
  );
129760
+ compilerHost.onSourceFileNotCreated = resolutionCache.onSourceFileNotCreated.bind(resolutionCache);
128868
129761
  compilerHost.resolveModuleNameLiterals = maybeBind(host, host.resolveModuleNameLiterals);
128869
129762
  compilerHost.resolveModuleNames = maybeBind(host, host.resolveModuleNames);
128870
129763
  if (!compilerHost.resolveModuleNameLiterals && !compilerHost.resolveModuleNames) {
128871
129764
  compilerHost.resolveModuleNameLiterals = resolutionCache.resolveModuleNameLiterals.bind(resolutionCache);
129765
+ compilerHost.onReusedModuleResolutions = resolutionCache.onReusedModuleResolutions.bind(resolutionCache);
128872
129766
  }
128873
129767
  compilerHost.resolveTypeReferenceDirectiveReferences = maybeBind(host, host.resolveTypeReferenceDirectiveReferences);
128874
129768
  compilerHost.resolveTypeReferenceDirectives = maybeBind(host, host.resolveTypeReferenceDirectives);
128875
129769
  if (!compilerHost.resolveTypeReferenceDirectiveReferences && !compilerHost.resolveTypeReferenceDirectives) {
128876
129770
  compilerHost.resolveTypeReferenceDirectiveReferences = resolutionCache.resolveTypeReferenceDirectiveReferences.bind(resolutionCache);
129771
+ compilerHost.onReusedTypeReferenceDirectiveResolutions = resolutionCache.onReusedTypeReferenceDirectiveResolutions.bind(resolutionCache);
128877
129772
  }
128878
129773
  compilerHost.resolveLibrary = !host.resolveLibrary ? resolutionCache.resolveLibrary.bind(resolutionCache) : host.resolveLibrary.bind(host);
128879
- compilerHost.getModuleResolutionCache = host.resolveModuleNameLiterals || host.resolveModuleNames ? maybeBind(host, host.getModuleResolutionCache) : () => resolutionCache.getModuleResolutionCache();
129774
+ compilerHost.getModuleResolutionCache = host.resolveModuleNameLiterals || host.resolveModuleNames ? maybeBind(host, host.getModuleResolutionCache) : () => resolutionCache.moduleResolutionCache;
128880
129775
  const userProvidedResolution = !!host.resolveModuleNameLiterals || !!host.resolveTypeReferenceDirectiveReferences || !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
128881
129776
  const customHasInvalidatedResolutions = userProvidedResolution ? maybeBind(host, host.hasInvalidatedResolutions) || returnTrue : returnFalse;
128882
129777
  const customHasInvalidLibResolutions = host.resolveLibrary ? maybeBind(host, host.hasInvalidatedLibResolutions) || returnTrue : returnFalse;