@typescript-deploys/pr-build 5.9.0-pr-61732-3 → 5.9.0-pr-61739-2

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
@@ -18,7 +18,7 @@ and limitations under the License.
18
18
 
19
19
  // src/compiler/corePublic.ts
20
20
  var versionMajorMinor = "5.9";
21
- var version = `${versionMajorMinor}.0-insiders.20250519`;
21
+ var version = `${versionMajorMinor}.0-insiders.20250520`;
22
22
 
23
23
  // src/compiler/core.ts
24
24
  var emptyArray = [];
@@ -39622,40 +39622,19 @@ 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
- }
39640
39625
  function createResolvedModuleWithFailedLookupLocations(resolved, isExternalLibraryImport, failedLookupLocations, affectingLocations, diagnostics, resultFromCache, cache, alternateResult) {
39641
- var _a;
39642
39626
  if (resultFromCache) {
39643
39627
  if (!(cache == null ? void 0 : cache.isReadonly)) {
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
- }
39628
+ resultFromCache.failedLookupLocations = updateResolutionField(resultFromCache.failedLookupLocations, failedLookupLocations);
39629
+ resultFromCache.affectingLocations = updateResolutionField(resultFromCache.affectingLocations, affectingLocations);
39630
+ resultFromCache.resolutionDiagnostics = updateResolutionField(resultFromCache.resolutionDiagnostics, diagnostics);
39651
39631
  return resultFromCache;
39652
39632
  } else {
39653
39633
  return {
39654
- resolvedModule: resultFromCache.resolvedModule,
39634
+ ...resultFromCache,
39655
39635
  failedLookupLocations: initializeResolutionFieldForReadonlyCache(resultFromCache.failedLookupLocations, failedLookupLocations),
39656
39636
  affectingLocations: initializeResolutionFieldForReadonlyCache(resultFromCache.affectingLocations, affectingLocations),
39657
- resolutionDiagnostics: initializeResolutionFieldForReadonlyCache(resultFromCache.resolutionDiagnostics, diagnostics),
39658
- alternateResult: resultFromCache.alternateResult
39637
+ resolutionDiagnostics: initializeResolutionFieldForReadonlyCache(resultFromCache.resolutionDiagnostics, diagnostics)
39659
39638
  };
39660
39639
  }
39661
39640
  }
@@ -39909,14 +39888,16 @@ function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFil
39909
39888
  affectingLocations: initializeResolutionField(affectingLocations),
39910
39889
  resolutionDiagnostics: initializeResolutionField(diagnostics)
39911
39890
  };
39912
- if (containingDirectory) {
39913
- cache == null ? void 0 : cache.setPerDirectoryAndNonRelativeNameCacheResult(
39891
+ if (containingDirectory && cache && !cache.isReadonly) {
39892
+ cache.getOrCreateCacheForDirectory(containingDirectory, redirectedReference).set(
39914
39893
  typeReferenceDirectiveName,
39894
+ /*mode*/
39915
39895
  resolutionMode,
39916
- containingDirectory,
39917
- redirectedReference,
39918
39896
  result
39919
39897
  );
39898
+ if (!isExternalModuleNameRelative(typeReferenceDirectiveName)) {
39899
+ cache.getOrCreateCacheForNonRelativeName(typeReferenceDirectiveName, resolutionMode, redirectedReference).set(containingDirectory, result);
39900
+ }
39920
39901
  }
39921
39902
  if (traceEnabled) traceResult(result);
39922
39903
  return result;
@@ -40102,9 +40083,6 @@ function compilerOptionValueToString(value) {
40102
40083
  function getKeyForCompilerOptions(options, affectingOptionDeclarations) {
40103
40084
  return affectingOptionDeclarations.map((option) => compilerOptionValueToString(getCompilerOptionValue(options, option))).join("|") + `|${options.pathsBasePath}`;
40104
40085
  }
40105
- function computeRedirectsCacheKey(options) {
40106
- return getKeyForCompilerOptions(options, moduleResolutionOptionDeclarations);
40107
- }
40108
40086
  function createCacheWithRedirects(ownOptions, optionsToRedirectsKey) {
40109
40087
  const redirectsMap = /* @__PURE__ */ new Map();
40110
40088
  const redirectsKeyToMap = /* @__PURE__ */ new Map();
@@ -40115,11 +40093,7 @@ function createCacheWithRedirects(ownOptions, optionsToRedirectsKey) {
40115
40093
  getOrCreateMapOfCacheRedirects,
40116
40094
  update,
40117
40095
  clear: clear2,
40118
- forEach: forEach2,
40119
- compact: compact2,
40120
- getOwnMap: () => ownMap,
40121
- getOwnOptions: () => ownOptions,
40122
- redirectsKeyToMap
40096
+ getOwnMap: () => ownMap
40123
40097
  };
40124
40098
  function getMapOfCacheRedirects(redirectedReference) {
40125
40099
  return redirectedReference ? getOrCreateMap(
@@ -40177,33 +40151,10 @@ function createCacheWithRedirects(ownOptions, optionsToRedirectsKey) {
40177
40151
  function getRedirectsCacheKey(options) {
40178
40152
  let result = optionsToRedirectsKey.get(options);
40179
40153
  if (!result) {
40180
- optionsToRedirectsKey.set(options, result = computeRedirectsCacheKey(options));
40154
+ optionsToRedirectsKey.set(options, result = getKeyForCompilerOptions(options, moduleResolutionOptionDeclarations));
40181
40155
  }
40182
40156
  return result;
40183
40157
  }
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
- }
40207
40158
  }
40208
40159
  function createPackageJsonInfoCache(currentDirectory, getCanonicalFileName) {
40209
40160
  let cache;
@@ -40230,7 +40181,7 @@ function getOrCreateCache(cacheWithRedirects, redirectedReference, key, create)
40230
40181
  }
40231
40182
  return result;
40232
40183
  }
40233
- function createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, options, optionsToRedirectsKey, getValidResolution) {
40184
+ function createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, options, optionsToRedirectsKey) {
40234
40185
  const directoryToModuleNameMap = createCacheWithRedirects(options, optionsToRedirectsKey);
40235
40186
  return {
40236
40187
  getFromDirectoryCache,
@@ -40252,7 +40203,7 @@ function createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileNam
40252
40203
  function getFromDirectoryCache(name, mode, directoryName, redirectedReference) {
40253
40204
  var _a, _b;
40254
40205
  const path = toPath(directoryName, currentDirectory, getCanonicalFileName);
40255
- return getValidResolution((_b = (_a = directoryToModuleNameMap.getMapOfCacheRedirects(redirectedReference)) == null ? void 0 : _a.get(path)) == null ? void 0 : _b.get(name, mode));
40206
+ return (_b = (_a = directoryToModuleNameMap.getMapOfCacheRedirects(redirectedReference)) == null ? void 0 : _a.get(path)) == null ? void 0 : _b.get(name, mode);
40256
40207
  }
40257
40208
  }
40258
40209
  function createModeAwareCacheKey(specifier, mode) {
@@ -40279,7 +40230,7 @@ function createModeAwareCache() {
40279
40230
  forEach(cb) {
40280
40231
  return underlying.forEach((elem, key) => {
40281
40232
  const [specifier, mode] = memoizedReverseKeys.get(key);
40282
- return cb(elem, specifier, mode, key);
40233
+ return cb(elem, specifier, mode);
40283
40234
  });
40284
40235
  },
40285
40236
  size() {
@@ -40294,20 +40245,18 @@ function createModeAwareCache() {
40294
40245
  }
40295
40246
  }
40296
40247
  function getOriginalOrResolvedModuleFileName(result) {
40297
- const resolvedModule = !result.globalCacheResolution ? result.resolvedModule : result.globalCacheResolution.primary.resolvedModule;
40298
- return resolvedModule && (resolvedModule.originalPath || resolvedModule.resolvedFileName);
40248
+ return result.resolvedModule && (result.resolvedModule.originalPath || result.resolvedModule.resolvedFileName);
40299
40249
  }
40300
40250
  function getOriginalOrResolvedTypeReferenceFileName(result) {
40301
40251
  return result.resolvedTypeReferenceDirective && (result.resolvedTypeReferenceDirective.originalPath || result.resolvedTypeReferenceDirective.resolvedFileName);
40302
40252
  }
40303
- function createNonRelativeNameResolutionCache(currentDirectory, getCanonicalFileName, options, getResolvedFileName, optionsToRedirectsKey, getValidResolution) {
40253
+ function createNonRelativeNameResolutionCache(currentDirectory, getCanonicalFileName, options, getResolvedFileName, optionsToRedirectsKey) {
40304
40254
  const moduleNameToDirectoryMap = createCacheWithRedirects(options, optionsToRedirectsKey);
40305
40255
  return {
40306
40256
  getFromNonRelativeNameCache,
40307
40257
  getOrCreateCacheForNonRelativeName,
40308
40258
  clear: clear2,
40309
- update,
40310
- moduleNameToDirectoryMap
40259
+ update
40311
40260
  };
40312
40261
  function clear2() {
40313
40262
  moduleNameToDirectoryMap.clear();
@@ -40318,79 +40267,38 @@ function createNonRelativeNameResolutionCache(currentDirectory, getCanonicalFile
40318
40267
  function getFromNonRelativeNameCache(nonRelativeModuleName, mode, directoryName, redirectedReference) {
40319
40268
  var _a, _b;
40320
40269
  Debug.assert(!isExternalModuleNameRelative(nonRelativeModuleName));
40321
- return (_b = (_a = moduleNameToDirectoryMap.getMapOfCacheRedirects(redirectedReference)) == null ? void 0 : _a.get(
40322
- createModeAwareCacheKey(nonRelativeModuleName, mode)
40323
- )) == null ? void 0 : _b.get(directoryName);
40270
+ return (_b = (_a = moduleNameToDirectoryMap.getMapOfCacheRedirects(redirectedReference)) == null ? void 0 : _a.get(createModeAwareCacheKey(nonRelativeModuleName, mode))) == null ? void 0 : _b.get(directoryName);
40324
40271
  }
40325
40272
  function getOrCreateCacheForNonRelativeName(nonRelativeModuleName, mode, redirectedReference) {
40326
40273
  Debug.assert(!isExternalModuleNameRelative(nonRelativeModuleName));
40327
- return getOrCreateCache(
40328
- moduleNameToDirectoryMap,
40329
- redirectedReference,
40330
- createModeAwareCacheKey(nonRelativeModuleName, mode),
40331
- createPerModuleNameCache
40332
- );
40274
+ return getOrCreateCache(moduleNameToDirectoryMap, redirectedReference, createModeAwareCacheKey(nonRelativeModuleName, mode), createPerModuleNameCache);
40333
40275
  }
40334
40276
  function createPerModuleNameCache() {
40335
40277
  const directoryPathMap = /* @__PURE__ */ new Map();
40336
- return { get, set, deleteByPath, directoryPathMap };
40278
+ return { get, set };
40337
40279
  function get(directory) {
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
- }
40280
+ return directoryPathMap.get(toPath(directory, currentDirectory, getCanonicalFileName));
40354
40281
  }
40355
- function set(directory, result, primary) {
40282
+ function set(directory, result) {
40356
40283
  const path = toPath(directory, currentDirectory, getCanonicalFileName);
40357
- if (getByPath(
40358
- path,
40359
- primary,
40360
- /*forSet*/
40361
- true
40362
- )) {
40284
+ if (directoryPathMap.has(path)) {
40363
40285
  return;
40364
40286
  }
40365
- if (!primary) deleteByPath(path);
40366
40287
  directoryPathMap.set(path, result);
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) {
40288
+ const resolvedFileName = getResolvedFileName(result);
40289
+ const commonPrefix = resolvedFileName && getCommonPrefix(path, resolvedFileName);
40375
40290
  let current = path;
40376
40291
  while (current !== commonPrefix) {
40377
40292
  const parent = getDirectoryPath(current);
40378
- if (parent === current || getByPath(
40379
- parent,
40380
- primary,
40381
- /*forSet*/
40382
- true
40383
- )) {
40293
+ if (parent === current || directoryPathMap.has(parent)) {
40384
40294
  break;
40385
40295
  }
40386
- action(parent);
40296
+ directoryPathMap.set(parent, result);
40387
40297
  current = parent;
40388
40298
  }
40389
40299
  }
40390
40300
  function getCommonPrefix(directory, resolution) {
40391
- const resolvedFileName = getResolvedFileName(resolution);
40392
- if (!resolvedFileName) return void 0;
40393
- const resolutionDirectory = toPath(getDirectoryPath(resolvedFileName), currentDirectory, getCanonicalFileName);
40301
+ const resolutionDirectory = toPath(getDirectoryPath(resolution), currentDirectory, getCanonicalFileName);
40394
40302
  let i = 0;
40395
40303
  const limit = Math.min(directory.length, resolutionDirectory.length);
40396
40304
  while (i < limit && directory.charCodeAt(i) === resolutionDirectory.charCodeAt(i)) {
@@ -40411,130 +40319,69 @@ function createNonRelativeNameResolutionCache(currentDirectory, getCanonicalFile
40411
40319
  }
40412
40320
  }
40413
40321
  }
40414
- function createModuleOrTypeReferenceResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache, getResolvedFileName, optionsToRedirectsKey, getValidResolution) {
40322
+ function createModuleOrTypeReferenceResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache, getResolvedFileName, optionsToRedirectsKey) {
40415
40323
  optionsToRedirectsKey ?? (optionsToRedirectsKey = /* @__PURE__ */ new Map());
40416
- getValidResolution ?? (getValidResolution = identity);
40417
40324
  const perDirectoryResolutionCache = createPerDirectoryResolutionCache(
40418
40325
  currentDirectory,
40419
40326
  getCanonicalFileName,
40420
40327
  options,
40421
- optionsToRedirectsKey,
40422
- getValidResolution
40328
+ optionsToRedirectsKey
40423
40329
  );
40424
40330
  const nonRelativeNameResolutionCache = createNonRelativeNameResolutionCache(
40425
40331
  currentDirectory,
40426
40332
  getCanonicalFileName,
40427
40333
  options,
40428
40334
  getResolvedFileName,
40429
- optionsToRedirectsKey,
40430
- getValidResolution
40335
+ optionsToRedirectsKey
40431
40336
  );
40432
40337
  packageJsonInfoCache ?? (packageJsonInfoCache = createPackageJsonInfoCache(currentDirectory, getCanonicalFileName));
40433
- const cache = {
40338
+ return {
40434
40339
  ...packageJsonInfoCache,
40435
40340
  ...perDirectoryResolutionCache,
40436
40341
  ...nonRelativeNameResolutionCache,
40437
40342
  clear: clear2,
40438
40343
  update,
40439
- gc,
40440
- compact: compact2,
40441
- setPerDirectoryAndNonRelativeNameCacheResult,
40442
- options: () => options,
40443
40344
  getPackageJsonInfoCache: () => packageJsonInfoCache,
40444
- optionsToRedirectsKey,
40445
- print
40345
+ clearAllExceptPackageJsonInfoCache,
40346
+ optionsToRedirectsKey
40446
40347
  };
40447
- return cache;
40448
40348
  function clear2() {
40449
- perDirectoryResolutionCache.clear();
40450
- nonRelativeNameResolutionCache.clear();
40349
+ clearAllExceptPackageJsonInfoCache();
40451
40350
  packageJsonInfoCache.clear();
40452
40351
  }
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
- }
40352
+ function clearAllExceptPackageJsonInfoCache() {
40353
+ perDirectoryResolutionCache.clear();
40354
+ nonRelativeNameResolutionCache.clear();
40490
40355
  }
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
- });
40356
+ function update(options2) {
40357
+ perDirectoryResolutionCache.update(options2);
40358
+ nonRelativeNameResolutionCache.update(options2);
40510
40359
  }
40511
40360
  }
40512
- function createModuleResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache, optionsToRedirectsKey, getValidResolution) {
40361
+ function createModuleResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache, optionsToRedirectsKey) {
40513
40362
  const result = createModuleOrTypeReferenceResolutionCache(
40514
40363
  currentDirectory,
40515
40364
  getCanonicalFileName,
40516
40365
  options,
40517
40366
  packageJsonInfoCache,
40518
40367
  getOriginalOrResolvedModuleFileName,
40519
- optionsToRedirectsKey,
40520
- getValidResolution
40368
+ optionsToRedirectsKey
40521
40369
  );
40522
40370
  result.getOrCreateCacheForModuleName = (nonRelativeName, mode, redirectedReference) => result.getOrCreateCacheForNonRelativeName(nonRelativeName, mode, redirectedReference);
40523
40371
  return result;
40524
40372
  }
40525
- function createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache, optionsToRedirectsKey, getValidResolution) {
40373
+ function createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache, optionsToRedirectsKey) {
40526
40374
  return createModuleOrTypeReferenceResolutionCache(
40527
40375
  currentDirectory,
40528
40376
  getCanonicalFileName,
40529
40377
  options,
40530
40378
  packageJsonInfoCache,
40531
40379
  getOriginalOrResolvedTypeReferenceFileName,
40532
- optionsToRedirectsKey,
40533
- getValidResolution
40380
+ optionsToRedirectsKey
40534
40381
  );
40535
40382
  }
40536
40383
  function getOptionsForLibraryResolution(options) {
40537
- return { moduleResolution: 2 /* Node10 */, traceResolution: options == null ? void 0 : options.traceResolution };
40384
+ return { moduleResolution: 2 /* Node10 */, traceResolution: options.traceResolution };
40538
40385
  }
40539
40386
  function resolveLibrary(libraryName, resolveFrom, compilerOptions, host, cache) {
40540
40387
  return resolveModuleName(libraryName, resolveFrom, getOptionsForLibraryResolution(compilerOptions), host, cache);
@@ -40587,13 +40434,12 @@ function resolveModuleName(moduleName, containingFile, compilerOptions, host, ca
40587
40434
  default:
40588
40435
  return Debug.fail(`Unexpected moduleResolution: ${moduleResolution}`);
40589
40436
  }
40590
- cache == null ? void 0 : cache.setPerDirectoryAndNonRelativeNameCacheResult(
40591
- moduleName,
40592
- resolutionMode,
40593
- containingDirectory,
40594
- redirectedReference,
40595
- result
40596
- );
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
+ }
40597
40443
  }
40598
40444
  if (traceEnabled) {
40599
40445
  if (result.resolvedModule) {
@@ -40872,7 +40718,7 @@ function nodeModuleNameResolverWorker(features, moduleName, containingDirectory,
40872
40718
  result = tryResolve(extensions, state);
40873
40719
  }
40874
40720
  let alternateResult;
40875
- if (!state.resultFromCache && state.resolvedPackageDirectory && !isConfigLookup && !isExternalModuleNameRelative(moduleName)) {
40721
+ if (state.resolvedPackageDirectory && !isConfigLookup && !isExternalModuleNameRelative(moduleName)) {
40876
40722
  const wantedTypesButGotJs = (result == null ? void 0 : result.value) && extensions & (1 /* TypeScript */ | 4 /* Declaration */) && !extensionIsOk(1 /* TypeScript */ | 4 /* Declaration */, result.value.resolved.extension);
40877
40723
  if (((_a = result == null ? void 0 : result.value) == null ? void 0 : _a.isExternalLibraryImport) && wantedTypesButGotJs && features & 8 /* Exports */ && (conditions == null ? void 0 : conditions.includes("import"))) {
40878
40724
  traceIfEnabled(state, Diagnostics.Resolution_of_non_relative_name_failed_trying_with_modern_Node_resolution_features_disabled_to_see_if_npm_library_needs_configuration_update);
@@ -121647,10 +121493,6 @@ function loadWithModeAwareCache(entries, containingFile, redirectedReference, op
121647
121493
  return resolutions;
121648
121494
  }
121649
121495
  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
- }
121654
121496
  function getInferredLibraryNameResolveFrom(options, currentDirectory, libFileName) {
121655
121497
  const containingDirectory = options.configFilePath ? getDirectoryPath(options.configFilePath) : currentDirectory;
121656
121498
  return combinePaths(containingDirectory, `__lib_node_modules_lookup_${libFileName}__.ts`);
@@ -121879,7 +121721,7 @@ function createCreateProgramOptions(rootNames, options, host, oldProgram, config
121879
121721
  };
121880
121722
  }
121881
121723
  function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _configFileParsingDiagnostics) {
121882
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
121724
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
121883
121725
  let _createProgramOptions = isArray(_rootNamesOrOptions) ? createCreateProgramOptions(_rootNamesOrOptions, _options, _host, _oldProgram, _configFileParsingDiagnostics) : _rootNamesOrOptions;
121884
121726
  const { rootNames, options, configFileParsingDiagnostics, projectReferences, typeScriptVersion: typeScriptVersion2, host: createProgramOptionsHost } = _createProgramOptions;
121885
121727
  let { oldProgram } = _createProgramOptions;
@@ -122020,6 +121862,7 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
122020
121862
  let projectReferenceRedirects;
122021
121863
  let mapFromFileToProjectReferenceRedirects;
122022
121864
  let mapFromToProjectReferenceRedirectSource;
121865
+ let hasResolvedReferencencesInNodeModules = false;
122023
121866
  const useSourceOfProjectReferenceRedirect = !!((_d = host.useSourceOfProjectReferenceRedirect) == null ? void 0 : _d.call(host)) && !options.disableSourceOfProjectReferenceRedirect;
122024
121867
  const { onProgramCreateComplete, fileExists, directoryExists } = updateHostForUseSourceOfProjectReferenceRedirect({
122025
121868
  compilerHost: host,
@@ -122084,10 +121927,9 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
122084
121927
  automaticTypeDirectiveResolutions = createModeAwareCache();
122085
121928
  if (automaticTypeDirectiveNames.length) {
122086
121929
  (_k = tracing) == null ? void 0 : _k.push(tracing.Phase.Program, "processTypeReferences", { count: automaticTypeDirectiveNames.length });
122087
- const resolutions = resolveTypeReferenceDirectiveNamesReusingOldState(
122088
- automaticTypeDirectiveNames,
122089
- getAutomaticTypeDirectiveContainingFile(options, currentDirectory)
122090
- );
121930
+ const containingDirectory = options.configFilePath ? getDirectoryPath(options.configFilePath) : currentDirectory;
121931
+ const containingFilename = combinePaths(containingDirectory, inferredTypesContainingFile);
121932
+ const resolutions = resolveTypeReferenceDirectiveNamesReusingOldState(automaticTypeDirectiveNames, containingFilename);
122091
121933
  for (let i = 0; i < automaticTypeDirectiveNames.length; i++) {
122092
121934
  automaticTypeDirectiveResolutions.set(
122093
121935
  automaticTypeDirectiveNames[i],
@@ -122108,17 +121950,6 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
122108
121950
  );
122109
121951
  }
122110
121952
  (_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
- );
122122
121953
  }
122123
121954
  if (rootNames.length && !skipDefaultLib) {
122124
121955
  const defaultLibraryFileName = getDefaultLibraryFileName();
@@ -122254,7 +122085,6 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
122254
122085
  getResolvedProjectReferenceByPath,
122255
122086
  forEachResolvedProjectReference: forEachResolvedProjectReference2,
122256
122087
  isSourceOfProjectReferenceRedirect,
122257
- getRedirectReferenceForResolution,
122258
122088
  getRedirectReferenceForResolutionFromSourceOfProject,
122259
122089
  getCompilerOptionsForFile,
122260
122090
  getDefaultResolutionModeForFile: getDefaultResolutionModeForFile2,
@@ -122266,7 +122096,7 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
122266
122096
  readFile,
122267
122097
  directoryExists,
122268
122098
  getSymlinkCache,
122269
- realpath: (_p = host.realpath) == null ? void 0 : _p.bind(host),
122099
+ realpath: (_o = host.realpath) == null ? void 0 : _o.bind(host),
122270
122100
  useCaseSensitiveFileNames: () => host.useCaseSensitiveFileNames(),
122271
122101
  getCanonicalFileName,
122272
122102
  getFileIncludeReasons: () => programDiagnostics.getFileReasons(),
@@ -122280,7 +122110,7 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
122280
122110
  }
122281
122111
  mark("afterProgram");
122282
122112
  measure("Program", "beforeProgram", "afterProgram");
122283
- (_q = tracing) == null ? void 0 : _q.pop();
122113
+ (_p = tracing) == null ? void 0 : _p.pop();
122284
122114
  return program;
122285
122115
  function getResolvedModule(file, moduleName, mode) {
122286
122116
  var _a2;
@@ -122458,7 +122288,6 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
122458
122288
  redirectedReference: getRedirectReferenceForResolution(containingFile),
122459
122289
  nameAndModeGetter: moduleResolutionNameAndModeGetter,
122460
122290
  resolutionWorker: resolveModuleNamesWorker,
122461
- onReusedResolutions: maybeBind(host, host.onReusedModuleResolutions),
122462
122291
  getResolutionFromOldProgram: (name, mode) => oldProgram == null ? void 0 : oldProgram.getResolvedModule(containingFile, name, mode),
122463
122292
  getResolved: getResolvedModuleFromResolution,
122464
122293
  canReuseResolutionsInFile: () => containingFile === (oldProgram == null ? void 0 : oldProgram.getSourceFile(containingFile.fileName)) && !hasInvalidatedResolutions(containingFile.path),
@@ -122474,7 +122303,6 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
122474
122303
  redirectedReference: containingSourceFile && getRedirectReferenceForResolution(containingSourceFile),
122475
122304
  nameAndModeGetter: typeReferenceResolutionNameAndModeGetter,
122476
122305
  resolutionWorker: resolveTypeReferenceDirectiveNamesWorker,
122477
- onReusedResolutions: maybeBind(host, host.onReusedTypeReferenceDirectiveResolutions),
122478
122306
  getResolutionFromOldProgram: (name, mode) => {
122479
122307
  var _a2;
122480
122308
  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);
@@ -122490,21 +122318,12 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
122490
122318
  redirectedReference,
122491
122319
  nameAndModeGetter,
122492
122320
  resolutionWorker,
122493
- onReusedResolutions,
122494
122321
  getResolutionFromOldProgram,
122495
122322
  getResolved,
122496
122323
  canReuseResolutionsInFile,
122497
122324
  resolveToOwnAmbientModule
122498
122325
  }) {
122499
- if (!entries.length) {
122500
- onReusedResolutions == null ? void 0 : onReusedResolutions(
122501
- entries,
122502
- containingSourceFile,
122503
- redirectedReference,
122504
- options
122505
- );
122506
- return emptyArray;
122507
- }
122326
+ if (!entries.length) return emptyArray;
122508
122327
  if (structureIsReused === 0 /* Not */ && (!resolveToOwnAmbientModule || !containingSourceFile.ambientModuleNames.length)) {
122509
122328
  return resolutionWorker(
122510
122329
  entries,
@@ -122559,20 +122378,8 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
122559
122378
  (unknownEntries ?? (unknownEntries = [])).push(entry);
122560
122379
  (unknownEntryIndices ?? (unknownEntryIndices = [])).push(i);
122561
122380
  }
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
- );
122381
+ if (!unknownEntries) return result;
122382
+ const resolutions = resolutionWorker(unknownEntries, containingFile, reusedNames);
122576
122383
  if (!result) return resolutions;
122577
122384
  resolutions.forEach((resolution, index) => result[unknownEntryIndices[index]] = resolution);
122578
122385
  return result;
@@ -123599,7 +123406,7 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
123599
123406
  return typeof result === "object" ? { ...result, languageVersion, setExternalModuleIndicator: setExternalModuleIndicator2, jsDocParsingMode: host2.jsDocParsingMode } : { languageVersion, impliedNodeFormat: result, setExternalModuleIndicator: setExternalModuleIndicator2, jsDocParsingMode: host2.jsDocParsingMode };
123600
123407
  }
123601
123408
  function findSourceFileWorker(fileName, isDefaultLib, ignoreNoDefaultLib, reason, packageId) {
123602
- var _a2, _b2;
123409
+ var _a2;
123603
123410
  const path = toPath3(fileName);
123604
123411
  if (useSourceOfProjectReferenceRedirect) {
123605
123412
  let source = getSourceOfProjectReferenceRedirect(path);
@@ -123744,8 +123551,6 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
123744
123551
  processingOtherFiles.push(file);
123745
123552
  }
123746
123553
  (filesWithReferencesProcessed ?? (filesWithReferencesProcessed = /* @__PURE__ */ new Set())).add(file.path);
123747
- } else {
123748
- (_b2 = host.onSourceFileNotCreated) == null ? void 0 : _b2.call(host, sourceFileOptions);
123749
123554
  }
123750
123555
  return file;
123751
123556
  }
@@ -123800,6 +123605,7 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
123800
123605
  }
123801
123606
  function getSourceOfProjectReferenceRedirect(path) {
123802
123607
  if (!isDeclarationFileName(path)) return void 0;
123608
+ if (!hasResolvedReferencencesInNodeModules && pathContainsNodeModules(path)) return void 0;
123803
123609
  if (mapFromToProjectReferenceRedirectSource === void 0) {
123804
123610
  mapFromToProjectReferenceRedirectSource = /* @__PURE__ */ new Map();
123805
123611
  forEachResolvedProjectReference2((resolvedRef) => {
@@ -123843,19 +123649,8 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
123843
123649
  });
123844
123650
  }
123845
123651
  function processTypeReferenceDirectives(file) {
123846
- var _a2;
123847
123652
  const typeDirectives = file.typeReferenceDirectives;
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
- }
123653
+ if (!typeDirectives.length) return;
123859
123654
  const resolutions = (resolvedTypeReferenceDirectiveNamesProcessing == null ? void 0 : resolvedTypeReferenceDirectiveNamesProcessing.get(file.path)) || resolveTypeReferenceDirectiveNamesReusingOldState(typeDirectives, file);
123860
123655
  const resolutionsInFile = createModeAwareCache();
123861
123656
  (resolvedTypeReferenceDirectiveNames ?? (resolvedTypeReferenceDirectiveNames = /* @__PURE__ */ new Map())).set(file.path, resolutionsInFile);
@@ -123982,7 +123777,6 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
123982
123777
  return host.getCanonicalFileName(fileName);
123983
123778
  }
123984
123779
  function processImportedModules(file) {
123985
- var _a2;
123986
123780
  collectExternalModuleReferences(file);
123987
123781
  if (file.imports.length || file.moduleAugmentations.length) {
123988
123782
  const moduleNames = getModuleNames(file);
@@ -124026,15 +123820,6 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
124026
123820
  currentNodeModulesDepth--;
124027
123821
  }
124028
123822
  }
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
- );
124038
123823
  }
124039
123824
  }
124040
123825
  function checkSourceFilesBelongToPath(sourceFiles, rootDirectory) {
@@ -124118,6 +123903,9 @@ function createProgram(_rootNamesOrOptions, _options, _host, _oldProgram, _confi
124118
123903
  sourceFile.path = sourceFilePath;
124119
123904
  sourceFile.resolvedPath = sourceFilePath;
124120
123905
  sourceFile.originalFileName = refPath;
123906
+ if (!hasResolvedReferencencesInNodeModules && (pathContainsNodeModules(sourceFile.resolvedPath) || pathContainsNodeModules(sourceFile.path))) {
123907
+ hasResolvedReferencencesInNodeModules = true;
123908
+ }
124121
123909
  const resolvedRef = { commandLine, sourceFile };
124122
123910
  projectReferenceRedirects.set(sourceFilePath, resolvedRef);
124123
123911
  if (commandLine.projectReferences) {
@@ -127201,7 +126989,7 @@ function createEmitAndSemanticDiagnosticsBuilderProgram(newProgramOrRootNames, h
127201
126989
  );
127202
126990
  }
127203
126991
 
127204
- // src/compiler/sharedResolutionCache.ts
126992
+ // src/compiler/resolutionCache.ts
127205
126993
  function removeIgnoredPath(path) {
127206
126994
  if (endsWith(path, "/node_modules/.staging")) {
127207
126995
  return removeSuffix(path, "/.staging");
@@ -127332,930 +127120,24 @@ function getDirectoryOfFailedLookupWatch(dirComponents, dirPathComponents, lengt
127332
127120
  packageDirPath: packageDirLength !== void 0 ? getPathFromPathComponents(dirPathComponents, packageDirLength) : void 0
127333
127121
  };
127334
127122
  }
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
127123
+ function getDirectoryToWatchFailedLookupLocationFromTypeRoot(typeRoot, typeRootPath, rootPath, rootPathComponents, isRootWatchable, getCurrentDirectory, preferNonRecursiveWatch, filterCustomPath) {
127124
+ const typeRootPathComponents = getPathComponents(typeRootPath);
127125
+ if (isRootWatchable && isInDirectoryPath(rootPathComponents, typeRootPathComponents)) {
127126
+ return rootPath;
127127
+ }
127128
+ typeRoot = isRootedDiskPath(typeRoot) ? normalizePath(typeRoot) : getNormalizedAbsolutePath(typeRoot, getCurrentDirectory());
127129
+ const toWatch = getDirectoryToWatchFromFailedLookupLocationDirectory(
127130
+ getPathComponents(typeRoot),
127131
+ typeRootPathComponents,
127132
+ typeRootPathComponents.length,
127133
+ perceivedOsRootLengthForWatching(typeRootPathComponents, typeRootPathComponents.length),
127134
+ typeRootPathComponents.indexOf("node_modules"),
127135
+ rootPathComponents,
127136
+ typeRootPathComponents.lastIndexOf("node_modules"),
127137
+ preferNonRecursiveWatch
128249
127138
  );
127139
+ return toWatch && filterCustomPath(toWatch.dirPath) ? toWatch.dirPath : void 0;
128250
127140
  }
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
128259
127141
  function getRootDirectoryOfResolutionCache(rootDirForResolution, getCurrentDirectory) {
128260
127142
  const normalized = getNormalizedAbsolutePath(rootDirForResolution, getCurrentDirectory());
128261
127143
  return !isDiskPathRoot(normalized) ? removeTrailingDirectorySeparator(normalized) : normalized;
@@ -128278,157 +127160,103 @@ function createModuleResolutionLoaderUsingGlobalCache(containingFile, redirected
128278
127160
  )
128279
127161
  };
128280
127162
  }
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
- }
128303
127163
  function resolveModuleNameUsingGlobalCache(resolutionHost, moduleResolutionCache, moduleName, containingFile, compilerOptions, redirectedReference, mode) {
128304
- var _a;
128305
127164
  const host = getModuleResolutionHost(resolutionHost);
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
- };
127165
+ const primaryResult = resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference, mode);
127166
+ if (!resolutionHost.getGlobalTypingsCacheLocation) {
127167
+ return primaryResult;
127168
+ }
127169
+ const globalCache = resolutionHost.getGlobalTypingsCacheLocation();
127170
+ if (globalCache !== void 0 && !isExternalModuleNameRelative(moduleName) && !(primaryResult.resolvedModule && extensionIsTS(primaryResult.resolvedModule.extension))) {
127171
+ const { resolvedModule, failedLookupLocations, affectingLocations, resolutionDiagnostics } = loadModuleFromGlobalCache(
127172
+ Debug.checkDefined(resolutionHost.globalCacheResolutionModuleName)(moduleName),
127173
+ resolutionHost.projectName,
127174
+ compilerOptions,
127175
+ host,
127176
+ globalCache,
127177
+ moduleResolutionCache
127178
+ );
127179
+ if (resolvedModule) {
127180
+ primaryResult.resolvedModule = resolvedModule;
127181
+ primaryResult.failedLookupLocations = updateResolutionField(primaryResult.failedLookupLocations, failedLookupLocations);
127182
+ primaryResult.affectingLocations = updateResolutionField(primaryResult.affectingLocations, affectingLocations);
127183
+ primaryResult.resolutionDiagnostics = updateResolutionField(primaryResult.resolutionDiagnostics, resolutionDiagnostics);
127184
+ return primaryResult;
127185
+ }
128334
127186
  }
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;
127187
+ return primaryResult;
128346
127188
  }
128347
- function createResolutionCache(resolutionHost, rootDirForResolution, sharedCache = createSharedResolutionCache(resolutionHost)) {
127189
+ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesWhenResolvingModule) {
127190
+ let filesWithChangedSetOfUnresolvedImports;
128348
127191
  let filesWithInvalidatedResolutions;
127192
+ let filesWithInvalidatedNonRelativeUnresolvedImports;
127193
+ const nonRelativeExternalModuleResolutions = /* @__PURE__ */ new Set();
127194
+ const resolutionsWithFailedLookups = /* @__PURE__ */ new Set();
127195
+ const resolutionsWithOnlyAffectingLocations = /* @__PURE__ */ new Set();
127196
+ const resolvedFileToResolution = /* @__PURE__ */ new Map();
128349
127197
  const impliedFormatPackageJsons = /* @__PURE__ */ new Map();
128350
- const filesReferencingResolution = /* @__PURE__ */ new Map();
128351
127198
  let hasChangedAutomaticTypeDirectiveNames = false;
128352
127199
  let affectingPathChecksForFile;
127200
+ let affectingPathChecks;
127201
+ let failedLookupChecks;
127202
+ let startsWithPathChecks;
127203
+ let isInDirectoryChecks;
128353
127204
  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;
128361
127205
  const getCurrentDirectory = memoize(() => resolutionHost.getCurrentDirectory());
127206
+ const cachedDirectoryStructureHost = resolutionHost.getCachedDirectoryStructureHost();
128362
127207
  const resolvedModuleNames = /* @__PURE__ */ new Map();
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
127208
+ const moduleResolutionCache = createModuleResolutionCache(
127209
+ getCurrentDirectory(),
127210
+ resolutionHost.getCanonicalFileName,
127211
+ resolutionHost.getCompilationSettings()
128375
127212
  );
128376
127213
  const resolvedTypeReferenceDirectives = /* @__PURE__ */ new Map();
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
127214
+ const typeReferenceDirectiveResolutionCache = createTypeReferenceDirectiveResolutionCache(
127215
+ getCurrentDirectory(),
127216
+ resolutionHost.getCanonicalFileName,
127217
+ resolutionHost.getCompilationSettings(),
127218
+ moduleResolutionCache.getPackageJsonInfoCache(),
127219
+ moduleResolutionCache.optionsToRedirectsKey
128388
127220
  );
128389
127221
  const resolvedLibraries = /* @__PURE__ */ new Map();
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
127222
+ const libraryResolutionCache = createModuleResolutionCache(
127223
+ getCurrentDirectory(),
127224
+ resolutionHost.getCanonicalFileName,
127225
+ getOptionsForLibraryResolution(resolutionHost.getCompilationSettings()),
127226
+ moduleResolutionCache.getPackageJsonInfoCache()
128401
127227
  );
128402
- let resolutionsResolvedWithGlobalCache = 0;
128403
- let resolutionsResolvedWithoutGlobalCache = 0;
128404
- const rootDirInfo = getRootDirInfo(rootDirForResolution);
128405
- const redirectsToRootDirInfo = /* @__PURE__ */ new Map();
127228
+ const directoryWatchesOfFailedLookups = /* @__PURE__ */ new Map();
127229
+ const fileWatchesOfAffectingLocations = /* @__PURE__ */ new Map();
127230
+ const rootDir = getRootDirectoryOfResolutionCache(rootDirForResolution, getCurrentDirectory);
127231
+ const rootPath = resolutionHost.toPath(rootDir);
127232
+ const rootPathComponents = getPathComponents(rootPath);
127233
+ const isRootWatchable = canWatchDirectoryOrFile(rootPathComponents);
127234
+ const isSymlinkCache = /* @__PURE__ */ new Map();
127235
+ const packageDirWatchers = /* @__PURE__ */ new Map();
127236
+ const dirPathToSymlinkPackageRefCount = /* @__PURE__ */ new Map();
128406
127237
  const typeRootsWatches = /* @__PURE__ */ new Map();
128407
- const cache = {
128408
- resolutionHost,
128409
- sharedCache,
127238
+ return {
128410
127239
  rootDirForResolution,
128411
127240
  resolvedModuleNames,
128412
127241
  resolvedTypeReferenceDirectives,
128413
127242
  resolvedLibraries,
128414
- moduleResolutionCache,
128415
- typeReferenceDirectiveResolutionCache,
128416
- libraryResolutionCache,
128417
- filesReferencingResolution,
128418
- typeRootsWatches,
128419
- countResolutionsResolvedWithGlobalCache: () => resolutionsResolvedWithGlobalCache,
128420
- countResolutionsResolvedWithoutGlobalCache: () => resolutionsResolvedWithoutGlobalCache,
128421
- watchResolution,
127243
+ resolvedFileToResolution,
127244
+ resolutionsWithFailedLookups,
127245
+ resolutionsWithOnlyAffectingLocations,
127246
+ directoryWatchesOfFailedLookups,
127247
+ fileWatchesOfAffectingLocations,
127248
+ packageDirWatchers,
127249
+ dirPathToSymlinkPackageRefCount,
127250
+ watchFailedLookupLocationsOfExternalModuleResolutions,
127251
+ getModuleResolutionCache: () => moduleResolutionCache,
127252
+ startRecordingFilesWithChangedResolutions,
127253
+ finishRecordingFilesWithChangedResolutions,
128422
127254
  // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
128423
127255
  // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
128424
127256
  startCachingPerDirectoryResolution,
128425
127257
  finishCachingPerDirectoryResolution,
128426
- compactCaches,
128427
127258
  resolveModuleNameLiterals,
128428
127259
  resolveTypeReferenceDirectiveReferences,
128429
- onReusedModuleResolutions,
128430
- onReusedTypeReferenceDirectiveResolutions,
128431
- onSourceFileNotCreated,
128432
127260
  resolveLibrary: resolveLibrary2,
128433
127261
  resolveSingleModuleNameWithoutWatching,
128434
127262
  removeResolutionsFromProjectReferenceRedirects,
@@ -128436,72 +127264,37 @@ function createResolutionCache(resolutionHost, rootDirForResolution, sharedCache
128436
127264
  hasChangedAutomaticTypeDirectiveNames: () => hasChangedAutomaticTypeDirectiveNames,
128437
127265
  invalidateResolutionOfFile,
128438
127266
  invalidateResolutionsOfFailedLookupLocations,
128439
- invalidateResolutionsWithGlobalCachePass,
128440
- invalidateResolutionsWithoutGlobalCachePass,
128441
- invalidateUnresolvedResolutionsWithGlobalCachePass,
127267
+ setFilesWithInvalidatedNonRelativeUnresolvedImports,
128442
127268
  createHasInvalidatedResolutions,
127269
+ isFileWithInvalidatedNonRelativeUnresolvedImports,
128443
127270
  updateTypeRootsWatch,
128444
127271
  closeTypeRootsWatch,
128445
127272
  clear: clear2,
128446
- onChangesAffectModuleResolution,
128447
- // Used by shared cache
128448
- getRootDirInfoForResolution: maybeBind(resolutionHost, resolutionHost.getRootDirInfoForResolution) ?? getRootDirInfoOfRedirectedReference,
128449
- invalidateAffectingFileWatcher,
128450
- invalidateResolution,
128451
- invalidateTypeRoot,
128452
- getValidResolution
127273
+ onChangesAffectModuleResolution
128453
127274
  };
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
- }
128486
127275
  function clear2() {
128487
- pendingRemoveResolutionsOfFile = void 0;
128488
- potentiallyUnreferencedResolutions = void 0;
128489
- newUnresolvedResolutionCachePassResolutions = void 0;
128490
- redirectsToRootDirInfo.clear();
127276
+ clearMap(directoryWatchesOfFailedLookups, closeFileWatcherOf);
127277
+ clearMap(fileWatchesOfAffectingLocations, closeFileWatcherOf);
127278
+ isSymlinkCache.clear();
127279
+ packageDirWatchers.clear();
127280
+ dirPathToSymlinkPackageRefCount.clear();
127281
+ nonRelativeExternalModuleResolutions.clear();
128491
127282
  closeTypeRootsWatch();
128492
- sharedCache.clear(cache);
128493
127283
  resolvedModuleNames.clear();
128494
127284
  resolvedTypeReferenceDirectives.clear();
128495
- filesReferencingResolution.clear();
128496
- resolutionsResolvedWithGlobalCache = 0;
128497
- resolutionsResolvedWithoutGlobalCache = 0;
127285
+ resolvedFileToResolution.clear();
127286
+ resolutionsWithFailedLookups.clear();
127287
+ resolutionsWithOnlyAffectingLocations.clear();
127288
+ failedLookupChecks = void 0;
127289
+ startsWithPathChecks = void 0;
127290
+ isInDirectoryChecks = void 0;
127291
+ affectingPathChecks = void 0;
128498
127292
  affectingPathChecksForFile = void 0;
128499
127293
  allModuleAndTypeResolutionsAreInvalidated = false;
128500
- resolutionsWithGlobalCachePassAreInvalidated = false;
128501
- resolutionsWithoutGlobalCachePassAreInvalidated = false;
128502
- unresolvedResolutionsWithGlobalCachePassAreInvalidated = false;
128503
127294
  moduleResolutionCache.clear();
128504
127295
  typeReferenceDirectiveResolutionCache.clear();
127296
+ moduleResolutionCache.update(resolutionHost.getCompilationSettings());
127297
+ typeReferenceDirectiveResolutionCache.update(resolutionHost.getCompilationSettings());
128505
127298
  libraryResolutionCache.clear();
128506
127299
  impliedFormatPackageJsons.clear();
128507
127300
  resolvedLibraries.clear();
@@ -128509,28 +127302,48 @@ function createResolutionCache(resolutionHost, rootDirForResolution, sharedCache
128509
127302
  }
128510
127303
  function onChangesAffectModuleResolution() {
128511
127304
  allModuleAndTypeResolutionsAreInvalidated = true;
127305
+ moduleResolutionCache.clearAllExceptPackageJsonInfoCache();
127306
+ typeReferenceDirectiveResolutionCache.clearAllExceptPackageJsonInfoCache();
127307
+ moduleResolutionCache.update(resolutionHost.getCompilationSettings());
127308
+ typeReferenceDirectiveResolutionCache.update(resolutionHost.getCompilationSettings());
127309
+ }
127310
+ function startRecordingFilesWithChangedResolutions() {
127311
+ filesWithChangedSetOfUnresolvedImports = [];
127312
+ }
127313
+ function finishRecordingFilesWithChangedResolutions() {
127314
+ const collected = filesWithChangedSetOfUnresolvedImports;
127315
+ filesWithChangedSetOfUnresolvedImports = void 0;
127316
+ return collected;
127317
+ }
127318
+ function isFileWithInvalidatedNonRelativeUnresolvedImports(path) {
127319
+ if (!filesWithInvalidatedNonRelativeUnresolvedImports) {
127320
+ return false;
127321
+ }
127322
+ const value = filesWithInvalidatedNonRelativeUnresolvedImports.get(path);
127323
+ return !!value && !!value.length;
128512
127324
  }
128513
127325
  function createHasInvalidatedResolutions(customHasInvalidatedResolutions, customHasInvalidatedLibResolutions) {
128514
127326
  invalidateResolutionsOfFailedLookupLocations();
128515
127327
  const collected = filesWithInvalidatedResolutions;
128516
127328
  filesWithInvalidatedResolutions = void 0;
128517
127329
  return {
128518
- hasInvalidatedResolutions: (path) => customHasInvalidatedResolutions(path) || allModuleAndTypeResolutionsAreInvalidated || resolutionsWithGlobalCachePassAreInvalidated || resolutionsWithoutGlobalCachePassAreInvalidated || unresolvedResolutionsWithGlobalCachePassAreInvalidated || !!(collected == null ? void 0 : collected.has(path)),
127330
+ hasInvalidatedResolutions: (path) => customHasInvalidatedResolutions(path) || allModuleAndTypeResolutionsAreInvalidated || !!(collected == null ? void 0 : collected.has(path)) || isFileWithInvalidatedNonRelativeUnresolvedImports(path),
128519
127331
  hasInvalidatedLibResolutions: (libFileName) => {
128520
127332
  var _a;
128521
- return customHasInvalidatedLibResolutions(libFileName) || !!((_a = sharedCache.watchedResolutionInfoMap.get(resolvedLibraries == null ? void 0 : resolvedLibraries.get(libFileName))) == null ? void 0 : _a.isInvalidated);
127333
+ return customHasInvalidatedLibResolutions(libFileName) || !!((_a = resolvedLibraries == null ? void 0 : resolvedLibraries.get(libFileName)) == null ? void 0 : _a.isInvalidated);
128522
127334
  }
128523
127335
  };
128524
127336
  }
128525
- function startCachingPerDirectoryResolution(options) {
127337
+ function startCachingPerDirectoryResolution() {
128526
127338
  moduleResolutionCache.isReadonly = void 0;
128527
127339
  typeReferenceDirectiveResolutionCache.isReadonly = void 0;
128528
127340
  libraryResolutionCache.isReadonly = void 0;
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;
127341
+ moduleResolutionCache.getPackageJsonInfoCache().isReadonly = void 0;
127342
+ moduleResolutionCache.clearAllExceptPackageJsonInfoCache();
127343
+ typeReferenceDirectiveResolutionCache.clearAllExceptPackageJsonInfoCache();
127344
+ libraryResolutionCache.clearAllExceptPackageJsonInfoCache();
127345
+ watchFailedLookupLocationOfNonRelativeModuleResolutions();
127346
+ isSymlinkCache.clear();
128534
127347
  }
128535
127348
  function cleanupLibResolutionWatching(newProgram) {
128536
127349
  resolvedLibraries.forEach((resolution, libFileName) => {
@@ -128539,35 +127352,32 @@ function createResolutionCache(resolutionHost, rootDirForResolution, sharedCache
128539
127352
  stopWatchFailedLookupLocationOfResolution(
128540
127353
  resolution,
128541
127354
  resolutionHost.toPath(getInferredLibraryNameResolveFrom(resolutionHost.getCompilationSettings(), getCurrentDirectory(), libFileName)),
128542
- libraryResolutionCache
127355
+ getResolvedModuleFromResolution
128543
127356
  );
128544
127357
  resolvedLibraries.delete(libFileName);
128545
127358
  }
128546
127359
  });
128547
127360
  }
128548
- function finishCachingPerDirectoryResolution(newProgram, oldProgram, skipCacheCompact) {
127361
+ function finishCachingPerDirectoryResolution(newProgram, oldProgram) {
127362
+ filesWithInvalidatedNonRelativeUnresolvedImports = void 0;
128549
127363
  allModuleAndTypeResolutionsAreInvalidated = false;
128550
- resolutionsWithGlobalCachePassAreInvalidated = false;
128551
- resolutionsWithoutGlobalCachePassAreInvalidated = false;
128552
- unresolvedResolutionsWithGlobalCachePassAreInvalidated = false;
128553
- newUnresolvedResolutionCachePassResolutions = void 0;
128554
- let potentiallyUnReferencedFileWatcherOfAffectingLocation;
127364
+ watchFailedLookupLocationOfNonRelativeModuleResolutions();
128555
127365
  if (newProgram !== oldProgram) {
128556
- const releaseFileWatcherOfAffectingLocation = (location) => {
128557
- sharedCache.releaseFileWatcherOfAffectingLocation(location);
128558
- (potentiallyUnReferencedFileWatcherOfAffectingLocation ?? (potentiallyUnReferencedFileWatcherOfAffectingLocation = /* @__PURE__ */ new Set())).add(location);
128559
- };
128560
127366
  cleanupLibResolutionWatching(newProgram);
128561
127367
  newProgram == null ? void 0 : newProgram.getSourceFiles().forEach((newFile) => {
128562
127368
  var _a;
128563
127369
  const expected = ((_a = newFile.packageJsonLocations) == null ? void 0 : _a.length) ?? 0;
128564
127370
  const existing = impliedFormatPackageJsons.get(newFile.resolvedPath) ?? emptyArray;
128565
127371
  for (let i = existing.length; i < expected; i++) {
128566
- sharedCache.createFileWatcherOfAffectingLocation(newFile.packageJsonLocations[i]);
127372
+ createFileWatcherOfAffectingLocation(
127373
+ newFile.packageJsonLocations[i],
127374
+ /*forResolution*/
127375
+ false
127376
+ );
128567
127377
  }
128568
127378
  if (existing.length > expected) {
128569
127379
  for (let i = expected; i < existing.length; i++) {
128570
- releaseFileWatcherOfAffectingLocation(existing[i]);
127380
+ fileWatchesOfAffectingLocations.get(existing[i]).files--;
128571
127381
  }
128572
127382
  }
128573
127383
  if (expected) impliedFormatPackageJsons.set(newFile.resolvedPath, newFile.packageJsonLocations);
@@ -128576,68 +127386,38 @@ function createResolutionCache(resolutionHost, rootDirForResolution, sharedCache
128576
127386
  impliedFormatPackageJsons.forEach((existing, path) => {
128577
127387
  const newFile = newProgram == null ? void 0 : newProgram.getSourceFileByPath(path);
128578
127388
  if (!newFile || newFile.resolvedPath !== path) {
128579
- existing.forEach(releaseFileWatcherOfAffectingLocation);
127389
+ existing.forEach((location) => fileWatchesOfAffectingLocations.get(location).files--);
128580
127390
  impliedFormatPackageJsons.delete(path);
128581
127391
  }
128582
127392
  });
128583
- cleanupRedirectRootDirInfo(newProgram);
128584
- }
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
127393
  }
128591
- sharedCache.finishCachingPerDirectoryResolution();
127394
+ directoryWatchesOfFailedLookups.forEach(closeDirectoryWatchesOfFailedLookup);
127395
+ fileWatchesOfAffectingLocations.forEach(closeFileWatcherOfAffectingLocation);
127396
+ packageDirWatchers.forEach(closePackageDirWatcher);
128592
127397
  hasChangedAutomaticTypeDirectiveNames = false;
128593
- if (!skipCacheCompact) compactCaches(newProgram);
128594
127398
  moduleResolutionCache.isReadonly = true;
128595
127399
  typeReferenceDirectiveResolutionCache.isReadonly = true;
128596
127400
  libraryResolutionCache.isReadonly = true;
128597
127401
  moduleResolutionCache.getPackageJsonInfoCache().isReadonly = true;
127402
+ isSymlinkCache.clear();
128598
127403
  }
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
- });
127404
+ function closePackageDirWatcher(watcher, packageDirPath) {
127405
+ if (watcher.dirPathToWatcher.size === 0) {
127406
+ packageDirWatchers.delete(packageDirPath);
128606
127407
  }
128607
- moduleResolutionCache.compact(
128608
- availableOptions,
128609
- /*skipOptionsToRedirectsKeyCleanup*/
128610
- true
128611
- );
128612
- typeReferenceDirectiveResolutionCache.compact(availableOptions);
128613
- libraryResolutionCache.compact();
128614
- sharedCache.compactCaches(availableOptions, cache);
128615
127408
  }
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;
127409
+ function closeDirectoryWatchesOfFailedLookup(watcher, path) {
127410
+ if (watcher.refCount === 0) {
127411
+ directoryWatchesOfFailedLookups.delete(path);
127412
+ watcher.watcher.close();
128623
127413
  }
128624
127414
  }
128625
- function onSourceFileNotCreated(sourceFileOptions) {
127415
+ function closeFileWatcherOfAffectingLocation(watcher, path) {
128626
127416
  var _a;
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);
127417
+ if (watcher.files === 0 && watcher.resolutions === 0 && !((_a = watcher.symlinks) == null ? void 0 : _a.size)) {
127418
+ fileWatchesOfAffectingLocations.delete(path);
127419
+ watcher.watcher.close();
127420
+ }
128641
127421
  }
128642
127422
  function resolveNamesWithLocalCache({
128643
127423
  entries,
@@ -128646,15 +127426,17 @@ function createResolutionCache(resolutionHost, rootDirForResolution, sharedCache
128646
127426
  redirectedReference,
128647
127427
  options,
128648
127428
  perFileCache,
128649
- moduleOrTypeRefCache,
128650
127429
  reusedNames,
128651
127430
  loader,
128652
127431
  getResolutionWithResolvedFileName,
128653
- onNewResolution
127432
+ deferWatchingNonRelativeResolution,
127433
+ shouldRetryResolution,
127434
+ logChanges
128654
127435
  }) {
128655
127436
  const path = resolutionHost.toPath(containingFile);
128656
127437
  const resolutionsInFile = perFileCache.get(path) || perFileCache.set(path, createModeAwareCache()).get(path);
128657
127438
  const resolvedModules = [];
127439
+ const hasInvalidatedNonRelativeUnresolvedImport = logChanges && isFileWithInvalidatedNonRelativeUnresolvedImports(path);
128658
127440
  const program = resolutionHost.getCurrentProgram();
128659
127441
  const oldRedirect = program && program.getResolvedProjectReferenceToRedirect(containingFile);
128660
127442
  const unmatchedRedirects = oldRedirect ? !redirectedReference || redirectedReference.sourceFile.path !== oldRedirect.sourceFile.path : !!redirectedReference;
@@ -128663,7 +127445,8 @@ function createResolutionCache(resolutionHost, rootDirForResolution, sharedCache
128663
127445
  const name = loader.nameAndMode.getName(entry);
128664
127446
  const mode = loader.nameAndMode.getMode(entry, containingSourceFile, (redirectedReference == null ? void 0 : redirectedReference.commandLine.options) || options);
128665
127447
  let resolution = resolutionsInFile.get(name, mode);
128666
- if (!seenNamesInFile.has(name, mode) && (allModuleAndTypeResolutionsAreInvalidated || unmatchedRedirects || isInvalidatedResolution(resolution))) {
127448
+ if (!seenNamesInFile.has(name, mode) && (allModuleAndTypeResolutionsAreInvalidated || unmatchedRedirects || !resolution || resolution.isInvalidated || // If the name is unresolved import that was invalidated, recalculate
127449
+ hasInvalidatedNonRelativeUnresolvedImport && !isExternalModuleNameRelative(name) && shouldRetryResolution(resolution))) {
128667
127450
  const existingResolution = resolution;
128668
127451
  resolution = loader.resolve(name, mode);
128669
127452
  if (resolutionHost.onDiscoveredSymlink && resolutionIsSymlink(resolution)) {
@@ -128671,15 +127454,15 @@ function createResolutionCache(resolutionHost, rootDirForResolution, sharedCache
128671
127454
  }
128672
127455
  resolutionsInFile.set(name, mode, resolution);
128673
127456
  if (resolution !== existingResolution) {
128674
- watchResolution(resolution, path, getResolutionWithResolvedFileName, redirectedReference);
127457
+ watchFailedLookupLocationsOfExternalModuleResolutions(name, resolution, path, getResolutionWithResolvedFileName, deferWatchingNonRelativeResolution);
128675
127458
  if (existingResolution) {
128676
- stopWatchFailedLookupLocationOfResolution(existingResolution, path, moduleOrTypeRefCache);
127459
+ stopWatchFailedLookupLocationOfResolution(existingResolution, path, getResolutionWithResolvedFileName);
128677
127460
  }
128678
127461
  }
128679
- if (isInvalidatedUnResolvedGlobalCachePassResolution(resolution)) {
128680
- (newUnresolvedResolutionCachePassResolutions ?? (newUnresolvedResolutionCachePassResolutions = /* @__PURE__ */ new Set())).add(resolution);
127462
+ if (logChanges && filesWithChangedSetOfUnresolvedImports && !resolutionIsEqualTo(existingResolution, resolution)) {
127463
+ filesWithChangedSetOfUnresolvedImports.push(path);
127464
+ logChanges = false;
128681
127465
  }
128682
- onNewResolution == null ? void 0 : onNewResolution(existingResolution, resolution, path, name, mode);
128683
127466
  } else {
128684
127467
  const host = getModuleResolutionHost(resolutionHost);
128685
127468
  if (isTraceEnabled(options, host) && !seenNamesInFile.has(name, mode)) {
@@ -128694,76 +127477,43 @@ function createResolutionCache(resolutionHost, rootDirForResolution, sharedCache
128694
127477
  );
128695
127478
  }
128696
127479
  }
128697
- Debug.assert(resolution !== void 0 && !sharedCache.watchedResolutionInfoMap.get(resolution).isInvalidated);
127480
+ Debug.assert(resolution !== void 0 && !resolution.isInvalidated);
128698
127481
  seenNamesInFile.set(name, mode, true);
128699
127482
  resolvedModules.push(resolution);
128700
127483
  }
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();
128727
127484
  reusedNames == null ? void 0 : reusedNames.forEach(
128728
127485
  (entry) => seenNamesInFile.set(
128729
- nameAndModeGetter.getName(entry),
128730
- nameAndModeGetter.getMode(entry, containingSourceFile, (redirectedReference == null ? void 0 : redirectedReference.commandLine.options) || options),
127486
+ loader.nameAndMode.getName(entry),
127487
+ loader.nameAndMode.getMode(entry, containingSourceFile, (redirectedReference == null ? void 0 : redirectedReference.commandLine.options) || options),
128731
127488
  true
128732
127489
  )
128733
127490
  );
128734
127491
  if (resolutionsInFile.size() !== seenNamesInFile.size()) {
128735
127492
  resolutionsInFile.forEach((resolution, name, mode) => {
128736
127493
  if (!seenNamesInFile.has(name, mode)) {
128737
- stopWatchFailedLookupLocationOfResolution(resolution, path, moduleOrTypeRefCache);
127494
+ stopWatchFailedLookupLocationOfResolution(resolution, path, getResolutionWithResolvedFileName);
128738
127495
  resolutionsInFile.delete(name, mode);
128739
127496
  }
128740
127497
  });
128741
127498
  }
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
- });
127499
+ return resolvedModules;
127500
+ function resolutionIsEqualTo(oldResolution, newResolution) {
127501
+ if (oldResolution === newResolution) {
127502
+ return true;
127503
+ }
127504
+ if (!oldResolution || !newResolution) {
127505
+ return false;
127506
+ }
127507
+ const oldResult = getResolutionWithResolvedFileName(oldResolution);
127508
+ const newResult = getResolutionWithResolvedFileName(newResolution);
127509
+ if (oldResult === newResult) {
127510
+ return true;
127511
+ }
127512
+ if (!oldResult || !newResult) {
127513
+ return false;
127514
+ }
127515
+ return oldResult.resolvedFileName === newResult.resolvedFileName;
127516
+ }
128767
127517
  }
128768
127518
  function resolveTypeReferenceDirectiveReferences(typeDirectiveReferences, containingFile, redirectedReference, options, containingSourceFile, reusedNames) {
128769
127519
  return resolveNamesWithLocalCache({
@@ -128774,7 +127524,6 @@ function createResolutionCache(resolutionHost, rootDirForResolution, sharedCache
128774
127524
  options,
128775
127525
  reusedNames,
128776
127526
  perFileCache: resolvedTypeReferenceDirectives,
128777
- moduleOrTypeRefCache: typeReferenceDirectiveResolutionCache,
128778
127527
  loader: createTypeReferenceResolutionLoader(
128779
127528
  containingFile,
128780
127529
  redirectedReference,
@@ -128782,10 +127531,12 @@ function createResolutionCache(resolutionHost, rootDirForResolution, sharedCache
128782
127531
  getModuleResolutionHost(resolutionHost),
128783
127532
  typeReferenceDirectiveResolutionCache
128784
127533
  ),
128785
- getResolutionWithResolvedFileName: getResolvedTypeReferenceDirectiveFromResolution
127534
+ getResolutionWithResolvedFileName: getResolvedTypeReferenceDirectiveFromResolution,
127535
+ shouldRetryResolution: (resolution) => resolution.resolvedTypeReferenceDirective === void 0,
127536
+ deferWatchingNonRelativeResolution: false
128786
127537
  });
128787
127538
  }
128788
- function resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, reusedNames, onNewResolution) {
127539
+ function resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, reusedNames) {
128789
127540
  return resolveNamesWithLocalCache({
128790
127541
  entries: moduleLiterals,
128791
127542
  containingFile,
@@ -128794,7 +127545,6 @@ function createResolutionCache(resolutionHost, rootDirForResolution, sharedCache
128794
127545
  options,
128795
127546
  reusedNames,
128796
127547
  perFileCache: resolvedModuleNames,
128797
- moduleOrTypeRefCache: moduleResolutionCache,
128798
127548
  loader: createModuleResolutionLoaderUsingGlobalCache(
128799
127549
  containingFile,
128800
127550
  redirectedReference,
@@ -128803,26 +127553,30 @@ function createResolutionCache(resolutionHost, rootDirForResolution, sharedCache
128803
127553
  moduleResolutionCache
128804
127554
  ),
128805
127555
  getResolutionWithResolvedFileName: getResolvedModuleFromResolution,
128806
- onNewResolution
127556
+ shouldRetryResolution: (resolution) => !resolution.resolvedModule || !resolutionExtensionIsTSOrJson(resolution.resolvedModule.extension),
127557
+ logChanges: logChangesWhenResolvingModule,
127558
+ deferWatchingNonRelativeResolution: true
127559
+ // Defer non relative resolution watch because we could be using ambient modules
128807
127560
  });
128808
127561
  }
128809
127562
  function resolveLibrary2(libraryName, resolveFrom, options, libFileName) {
128810
127563
  const host = getModuleResolutionHost(resolutionHost);
128811
127564
  let resolution = resolvedLibraries == null ? void 0 : resolvedLibraries.get(libFileName);
128812
- if (isInvalidatedResolution(resolution)) {
127565
+ if (!resolution || resolution.isInvalidated) {
128813
127566
  const existingResolution = resolution;
128814
127567
  resolution = resolveLibrary(libraryName, resolveFrom, options, host, libraryResolutionCache);
128815
127568
  const path = resolutionHost.toPath(resolveFrom);
128816
- watchResolution(
127569
+ watchFailedLookupLocationsOfExternalModuleResolutions(
127570
+ libraryName,
128817
127571
  resolution,
128818
127572
  path,
128819
127573
  getResolvedModuleFromResolution,
128820
- /*redirectedReference*/
128821
- void 0
127574
+ /*deferWatchingNonRelativeResolution*/
127575
+ false
128822
127576
  );
128823
127577
  resolvedLibraries.set(libFileName, resolution);
128824
127578
  if (existingResolution) {
128825
- stopWatchFailedLookupLocationOfResolution(existingResolution, path, libraryResolutionCache);
127579
+ stopWatchFailedLookupLocationOfResolution(existingResolution, path, getResolvedModuleFromResolution);
128826
127580
  }
128827
127581
  } else {
128828
127582
  if (isTraceEnabled(options, host)) {
@@ -128848,7 +127602,7 @@ function createResolutionCache(resolutionHost, rootDirForResolution, sharedCache
128848
127602
  /*mode*/
128849
127603
  void 0
128850
127604
  );
128851
- if (resolution && !sharedCache.watchedResolutionInfoMap.get(resolution).isInvalidated) return resolution;
127605
+ if (resolution && !resolution.isInvalidated) return resolution;
128852
127606
  const data = (_a = resolutionHost.beforeResolveSingleModuleNameWithoutWatching) == null ? void 0 : _a.call(resolutionHost, moduleResolutionCache);
128853
127607
  const host = getModuleResolutionHost(resolutionHost);
128854
127608
  const result = resolveModuleName(
@@ -128861,48 +127615,306 @@ function createResolutionCache(resolutionHost, rootDirForResolution, sharedCache
128861
127615
  (_b = resolutionHost.afterResolveSingleModuleNameWithoutWatching) == null ? void 0 : _b.call(resolutionHost, moduleResolutionCache, moduleName, containingFile, result, data);
128862
127616
  return result;
128863
127617
  }
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++;
127618
+ function isNodeModulesAtTypesDirectory(dirPath) {
127619
+ return endsWith(dirPath, "/node_modules/@types");
127620
+ }
127621
+ function watchFailedLookupLocationsOfExternalModuleResolutions(name, resolution, filePath, getResolutionWithResolvedFileName, deferWatchingNonRelativeResolution) {
127622
+ (resolution.files ?? (resolution.files = /* @__PURE__ */ new Set())).add(filePath);
127623
+ if (resolution.files.size !== 1) return;
127624
+ if (!deferWatchingNonRelativeResolution || isExternalModuleNameRelative(name)) {
127625
+ watchFailedLookupLocationOfResolution(resolution);
128870
127626
  } else {
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;
127627
+ nonRelativeExternalModuleResolutions.add(resolution);
127628
+ }
127629
+ const resolved = getResolutionWithResolvedFileName(resolution);
127630
+ if (resolved && resolved.resolvedFileName) {
127631
+ const key = resolutionHost.toPath(resolved.resolvedFileName);
127632
+ let resolutions = resolvedFileToResolution.get(key);
127633
+ if (!resolutions) resolvedFileToResolution.set(key, resolutions = /* @__PURE__ */ new Set());
127634
+ resolutions.add(resolution);
127635
+ }
127636
+ }
127637
+ function watchFailedLookupLocation(failedLookupLocation, setAtRoot) {
127638
+ const failedLookupLocationPath = resolutionHost.toPath(failedLookupLocation);
127639
+ const toWatch = getDirectoryToWatchFailedLookupLocation(
127640
+ failedLookupLocation,
127641
+ failedLookupLocationPath,
127642
+ rootDir,
127643
+ rootPath,
127644
+ rootPathComponents,
127645
+ isRootWatchable,
127646
+ getCurrentDirectory,
127647
+ resolutionHost.preferNonRecursiveWatch
127648
+ );
127649
+ if (toWatch) {
127650
+ const { dir, dirPath, nonRecursive, packageDir, packageDirPath } = toWatch;
127651
+ if (dirPath === rootPath) {
127652
+ Debug.assert(nonRecursive);
127653
+ Debug.assert(!packageDir);
127654
+ setAtRoot = true;
127655
+ } else {
127656
+ setDirectoryWatcher(dir, dirPath, packageDir, packageDirPath, nonRecursive);
127657
+ }
127658
+ }
127659
+ return setAtRoot;
127660
+ }
127661
+ function watchFailedLookupLocationOfResolution(resolution) {
127662
+ var _a;
127663
+ Debug.assert(!!((_a = resolution.files) == null ? void 0 : _a.size));
127664
+ const { failedLookupLocations, affectingLocations, alternateResult } = resolution;
127665
+ if (!(failedLookupLocations == null ? void 0 : failedLookupLocations.length) && !(affectingLocations == null ? void 0 : affectingLocations.length) && !alternateResult) return;
127666
+ if ((failedLookupLocations == null ? void 0 : failedLookupLocations.length) || alternateResult) resolutionsWithFailedLookups.add(resolution);
127667
+ let setAtRoot = false;
127668
+ if (failedLookupLocations) {
127669
+ for (const failedLookupLocation of failedLookupLocations) {
127670
+ setAtRoot = watchFailedLookupLocation(failedLookupLocation, setAtRoot);
127671
+ }
127672
+ }
127673
+ if (alternateResult) setAtRoot = watchFailedLookupLocation(alternateResult, setAtRoot);
127674
+ if (setAtRoot) {
127675
+ setDirectoryWatcher(
127676
+ rootDir,
127677
+ rootPath,
127678
+ /*packageDir*/
127679
+ void 0,
127680
+ /*packageDirPath*/
127681
+ void 0,
127682
+ /*nonRecursive*/
127683
+ true
127684
+ );
127685
+ }
127686
+ watchAffectingLocationsOfResolution(resolution, !(failedLookupLocations == null ? void 0 : failedLookupLocations.length) && !alternateResult);
127687
+ }
127688
+ function watchAffectingLocationsOfResolution(resolution, addToResolutionsWithOnlyAffectingLocations) {
127689
+ var _a;
127690
+ Debug.assert(!!((_a = resolution.files) == null ? void 0 : _a.size));
127691
+ const { affectingLocations } = resolution;
127692
+ if (!(affectingLocations == null ? void 0 : affectingLocations.length)) return;
127693
+ if (addToResolutionsWithOnlyAffectingLocations) resolutionsWithOnlyAffectingLocations.add(resolution);
127694
+ for (const affectingLocation of affectingLocations) {
127695
+ createFileWatcherOfAffectingLocation(
127696
+ affectingLocation,
127697
+ /*forResolution*/
127698
+ true
127699
+ );
127700
+ }
127701
+ }
127702
+ function createFileWatcherOfAffectingLocation(affectingLocation, forResolution) {
127703
+ const fileWatcher = fileWatchesOfAffectingLocations.get(affectingLocation);
127704
+ if (fileWatcher) {
127705
+ if (forResolution) fileWatcher.resolutions++;
127706
+ else fileWatcher.files++;
127707
+ return;
127708
+ }
127709
+ let locationToWatch = affectingLocation;
127710
+ let isSymlink = false;
127711
+ let symlinkWatcher;
127712
+ if (resolutionHost.realpath) {
127713
+ locationToWatch = resolutionHost.realpath(affectingLocation);
127714
+ if (affectingLocation !== locationToWatch) {
127715
+ isSymlink = true;
127716
+ symlinkWatcher = fileWatchesOfAffectingLocations.get(locationToWatch);
127717
+ }
127718
+ }
127719
+ const resolutions = forResolution ? 1 : 0;
127720
+ const files = forResolution ? 0 : 1;
127721
+ if (!isSymlink || !symlinkWatcher) {
127722
+ const watcher = {
127723
+ watcher: canWatchAffectingLocation(resolutionHost.toPath(locationToWatch)) ? resolutionHost.watchAffectingFileLocation(locationToWatch, (fileName, eventKind) => {
127724
+ cachedDirectoryStructureHost == null ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
127725
+ invalidateAffectingFileWatcher(locationToWatch, moduleResolutionCache.getPackageJsonInfoCache().getInternalMap());
127726
+ resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
127727
+ }) : noopFileWatcher,
127728
+ resolutions: isSymlink ? 0 : resolutions,
127729
+ files: isSymlink ? 0 : files,
127730
+ symlinks: void 0
127731
+ };
127732
+ fileWatchesOfAffectingLocations.set(locationToWatch, watcher);
127733
+ if (isSymlink) symlinkWatcher = watcher;
127734
+ }
127735
+ if (isSymlink) {
127736
+ Debug.assert(!!symlinkWatcher);
127737
+ const watcher = {
127738
+ watcher: {
127739
+ close: () => {
127740
+ var _a;
127741
+ const symlinkWatcher2 = fileWatchesOfAffectingLocations.get(locationToWatch);
127742
+ if (((_a = symlinkWatcher2 == null ? void 0 : symlinkWatcher2.symlinks) == null ? void 0 : _a.delete(affectingLocation)) && !symlinkWatcher2.symlinks.size && !symlinkWatcher2.resolutions && !symlinkWatcher2.files) {
127743
+ fileWatchesOfAffectingLocations.delete(locationToWatch);
127744
+ symlinkWatcher2.watcher.close();
127745
+ }
127746
+ }
127747
+ },
127748
+ resolutions,
127749
+ files,
127750
+ symlinks: void 0
127751
+ };
127752
+ fileWatchesOfAffectingLocations.set(affectingLocation, watcher);
127753
+ (symlinkWatcher.symlinks ?? (symlinkWatcher.symlinks = /* @__PURE__ */ new Set())).add(affectingLocation);
127754
+ }
127755
+ }
127756
+ function invalidateAffectingFileWatcher(path, packageJsonMap) {
127757
+ var _a;
127758
+ const watcher = fileWatchesOfAffectingLocations.get(path);
127759
+ if (watcher == null ? void 0 : watcher.resolutions) (affectingPathChecks ?? (affectingPathChecks = /* @__PURE__ */ new Set())).add(path);
127760
+ if (watcher == null ? void 0 : watcher.files) (affectingPathChecksForFile ?? (affectingPathChecksForFile = /* @__PURE__ */ new Set())).add(path);
127761
+ (_a = watcher == null ? void 0 : watcher.symlinks) == null ? void 0 : _a.forEach((path2) => invalidateAffectingFileWatcher(path2, packageJsonMap));
127762
+ packageJsonMap == null ? void 0 : packageJsonMap.delete(resolutionHost.toPath(path));
127763
+ }
127764
+ function watchFailedLookupLocationOfNonRelativeModuleResolutions() {
127765
+ nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfResolution);
127766
+ nonRelativeExternalModuleResolutions.clear();
127767
+ }
127768
+ function createDirectoryWatcherForPackageDir(dir, dirPath, packageDir, packageDirPath, nonRecursive) {
127769
+ Debug.assert(!nonRecursive);
127770
+ let isSymlink = isSymlinkCache.get(packageDirPath);
127771
+ let packageDirWatcher = packageDirWatchers.get(packageDirPath);
127772
+ if (isSymlink === void 0) {
127773
+ const realPath2 = resolutionHost.realpath(packageDir);
127774
+ isSymlink = realPath2 !== packageDir && resolutionHost.toPath(realPath2) !== packageDirPath;
127775
+ isSymlinkCache.set(packageDirPath, isSymlink);
127776
+ if (!packageDirWatcher) {
127777
+ packageDirWatchers.set(
127778
+ packageDirPath,
127779
+ packageDirWatcher = {
127780
+ dirPathToWatcher: /* @__PURE__ */ new Map(),
127781
+ isSymlink
127782
+ }
127783
+ );
127784
+ } else if (packageDirWatcher.isSymlink !== isSymlink) {
127785
+ packageDirWatcher.dirPathToWatcher.forEach((watcher) => {
127786
+ removeDirectoryWatcher(packageDirWatcher.isSymlink ? packageDirPath : dirPath);
127787
+ watcher.watcher = createDirPathToWatcher();
127788
+ });
127789
+ packageDirWatcher.isSymlink = isSymlink;
127790
+ }
127791
+ } else {
127792
+ Debug.assertIsDefined(packageDirWatcher);
127793
+ Debug.assert(isSymlink === packageDirWatcher.isSymlink);
127794
+ }
127795
+ const forDirPath = packageDirWatcher.dirPathToWatcher.get(dirPath);
127796
+ if (forDirPath) {
127797
+ forDirPath.refCount++;
127798
+ } else {
127799
+ packageDirWatcher.dirPathToWatcher.set(dirPath, {
127800
+ watcher: createDirPathToWatcher(),
127801
+ refCount: 1
127802
+ });
127803
+ if (isSymlink) dirPathToSymlinkPackageRefCount.set(dirPath, (dirPathToSymlinkPackageRefCount.get(dirPath) ?? 0) + 1);
127804
+ }
127805
+ function createDirPathToWatcher() {
127806
+ return isSymlink ? createOrAddRefToDirectoryWatchOfFailedLookups(packageDir, packageDirPath, nonRecursive) : createOrAddRefToDirectoryWatchOfFailedLookups(dir, dirPath, nonRecursive);
127807
+ }
127808
+ }
127809
+ function setDirectoryWatcher(dir, dirPath, packageDir, packageDirPath, nonRecursive) {
127810
+ if (!packageDirPath || !resolutionHost.realpath) {
127811
+ createOrAddRefToDirectoryWatchOfFailedLookups(dir, dirPath, nonRecursive);
127812
+ } else {
127813
+ createDirectoryWatcherForPackageDir(dir, dirPath, packageDir, packageDirPath, nonRecursive);
127814
+ }
127815
+ }
127816
+ function createOrAddRefToDirectoryWatchOfFailedLookups(dir, dirPath, nonRecursive) {
127817
+ let dirWatcher = directoryWatchesOfFailedLookups.get(dirPath);
127818
+ if (dirWatcher) {
127819
+ Debug.assert(!!nonRecursive === !!dirWatcher.nonRecursive);
127820
+ dirWatcher.refCount++;
127821
+ } else {
127822
+ directoryWatchesOfFailedLookups.set(dirPath, dirWatcher = { watcher: createDirectoryWatcher(dir, dirPath, nonRecursive), refCount: 1, nonRecursive });
127823
+ }
127824
+ return dirWatcher;
127825
+ }
127826
+ function stopWatchFailedLookupLocation(failedLookupLocation, removeAtRoot) {
127827
+ const failedLookupLocationPath = resolutionHost.toPath(failedLookupLocation);
127828
+ const toWatch = getDirectoryToWatchFailedLookupLocation(
127829
+ failedLookupLocation,
127830
+ failedLookupLocationPath,
127831
+ rootDir,
127832
+ rootPath,
127833
+ rootPathComponents,
127834
+ isRootWatchable,
127835
+ getCurrentDirectory,
127836
+ resolutionHost.preferNonRecursiveWatch
127837
+ );
127838
+ if (toWatch) {
127839
+ const { dirPath, packageDirPath } = toWatch;
127840
+ if (dirPath === rootPath) {
127841
+ removeAtRoot = true;
127842
+ } else if (packageDirPath && resolutionHost.realpath) {
127843
+ const packageDirWatcher = packageDirWatchers.get(packageDirPath);
127844
+ const forDirPath = packageDirWatcher.dirPathToWatcher.get(dirPath);
127845
+ forDirPath.refCount--;
127846
+ if (forDirPath.refCount === 0) {
127847
+ removeDirectoryWatcher(packageDirWatcher.isSymlink ? packageDirPath : dirPath);
127848
+ packageDirWatcher.dirPathToWatcher.delete(dirPath);
127849
+ if (packageDirWatcher.isSymlink) {
127850
+ const refCount = dirPathToSymlinkPackageRefCount.get(dirPath) - 1;
127851
+ if (refCount === 0) {
127852
+ dirPathToSymlinkPackageRefCount.delete(dirPath);
127853
+ } else {
127854
+ dirPathToSymlinkPackageRefCount.set(dirPath, refCount);
127855
+ }
127856
+ }
127857
+ }
127858
+ } else {
127859
+ removeDirectoryWatcher(dirPath);
127860
+ }
127861
+ }
127862
+ return removeAtRoot;
128894
127863
  }
128895
- function removeResolutionsOfFileFromCache(cache2, filePath, moduleOrTypeRefCache) {
128896
- const resolutions = cache2.get(filePath);
127864
+ function stopWatchFailedLookupLocationOfResolution(resolution, filePath, getResolutionWithResolvedFileName) {
127865
+ Debug.checkDefined(resolution.files).delete(filePath);
127866
+ if (resolution.files.size) return;
127867
+ resolution.files = void 0;
127868
+ const resolved = getResolutionWithResolvedFileName(resolution);
127869
+ if (resolved && resolved.resolvedFileName) {
127870
+ const key = resolutionHost.toPath(resolved.resolvedFileName);
127871
+ const resolutions = resolvedFileToResolution.get(key);
127872
+ if ((resolutions == null ? void 0 : resolutions.delete(resolution)) && !resolutions.size) resolvedFileToResolution.delete(key);
127873
+ }
127874
+ const { failedLookupLocations, affectingLocations, alternateResult } = resolution;
127875
+ if (resolutionsWithFailedLookups.delete(resolution)) {
127876
+ let removeAtRoot = false;
127877
+ if (failedLookupLocations) {
127878
+ for (const failedLookupLocation of failedLookupLocations) {
127879
+ removeAtRoot = stopWatchFailedLookupLocation(failedLookupLocation, removeAtRoot);
127880
+ }
127881
+ }
127882
+ if (alternateResult) removeAtRoot = stopWatchFailedLookupLocation(alternateResult, removeAtRoot);
127883
+ if (removeAtRoot) removeDirectoryWatcher(rootPath);
127884
+ } else if (affectingLocations == null ? void 0 : affectingLocations.length) {
127885
+ resolutionsWithOnlyAffectingLocations.delete(resolution);
127886
+ }
127887
+ if (affectingLocations) {
127888
+ for (const affectingLocation of affectingLocations) {
127889
+ const watcher = fileWatchesOfAffectingLocations.get(affectingLocation);
127890
+ watcher.resolutions--;
127891
+ }
127892
+ }
127893
+ }
127894
+ function removeDirectoryWatcher(dirPath) {
127895
+ const dirWatcher = directoryWatchesOfFailedLookups.get(dirPath);
127896
+ dirWatcher.refCount--;
127897
+ }
127898
+ function createDirectoryWatcher(directory, dirPath, nonRecursive) {
127899
+ return resolutionHost.watchDirectoryOfFailedLookupLocation(directory, (fileOrDirectory) => {
127900
+ const fileOrDirectoryPath = resolutionHost.toPath(fileOrDirectory);
127901
+ if (cachedDirectoryStructureHost) {
127902
+ cachedDirectoryStructureHost.addOrDeleteFileOrDirectory(fileOrDirectory, fileOrDirectoryPath);
127903
+ }
127904
+ scheduleInvalidateResolutionOfFailedLookupLocation(fileOrDirectoryPath, dirPath === fileOrDirectoryPath);
127905
+ }, nonRecursive ? 0 /* None */ : 1 /* Recursive */);
127906
+ }
127907
+ function removeResolutionsOfFileFromCache(cache, filePath, getResolutionWithResolvedFileName) {
127908
+ const resolutions = cache.get(filePath);
128897
127909
  if (resolutions) {
128898
127910
  resolutions.forEach(
128899
127911
  (resolution) => stopWatchFailedLookupLocationOfResolution(
128900
127912
  resolution,
128901
127913
  filePath,
128902
- moduleOrTypeRefCache
127914
+ getResolutionWithResolvedFileName
128903
127915
  )
128904
127916
  );
128905
- cache2.delete(filePath);
127917
+ cache.delete(filePath);
128906
127918
  }
128907
127919
  }
128908
127920
  function removeResolutionsFromProjectReferenceRedirects(filePath) {
@@ -128914,62 +127926,149 @@ function createResolutionCache(resolutionHost, rootDirForResolution, sharedCache
128914
127926
  resolvedProjectReference.commandLine.fileNames.forEach((f) => removeResolutionsOfFile(resolutionHost.toPath(f)));
128915
127927
  }
128916
127928
  function removeResolutionsOfFile(filePath) {
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
- }
127929
+ removeResolutionsOfFileFromCache(resolvedModuleNames, filePath, getResolvedModuleFromResolution);
127930
+ removeResolutionsOfFileFromCache(resolvedTypeReferenceDirectives, filePath, getResolvedTypeReferenceDirectiveFromResolution);
128923
127931
  }
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
- }
127932
+ function invalidateResolutions(resolutions, canInvalidate) {
127933
+ if (!resolutions) return false;
127934
+ let invalidated = false;
127935
+ resolutions.forEach((resolution) => {
127936
+ if (resolution.isInvalidated || !canInvalidate(resolution)) return;
127937
+ resolution.isInvalidated = invalidated = true;
127938
+ for (const containingFilePath of Debug.checkDefined(resolution.files)) {
127939
+ (filesWithInvalidatedResolutions ?? (filesWithInvalidatedResolutions = /* @__PURE__ */ new Set())).add(containingFilePath);
127940
+ hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames || endsWith(containingFilePath, inferredTypesContainingFile);
127941
+ }
127942
+ });
127943
+ return invalidated;
128930
127944
  }
128931
127945
  function invalidateResolutionOfFile(filePath) {
128932
127946
  removeResolutionsOfFile(filePath);
128933
127947
  const prevHasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames;
128934
- if (sharedCache.invalidateResolutionOfFile(filePath) && hasChangedAutomaticTypeDirectiveNames && !prevHasChangedAutomaticTypeDirectiveNames) {
127948
+ if (invalidateResolutions(resolvedFileToResolution.get(filePath), returnTrue) && hasChangedAutomaticTypeDirectiveNames && !prevHasChangedAutomaticTypeDirectiveNames) {
128935
127949
  resolutionHost.onChangedAutomaticTypeDirectiveNames();
128936
127950
  }
128937
127951
  }
128938
- function invalidateResolutionsWithGlobalCachePass() {
128939
- if (resolutionsResolvedWithGlobalCache) resolutionsWithGlobalCachePassAreInvalidated = true;
127952
+ function setFilesWithInvalidatedNonRelativeUnresolvedImports(filesMap) {
127953
+ Debug.assert(filesWithInvalidatedNonRelativeUnresolvedImports === filesMap || filesWithInvalidatedNonRelativeUnresolvedImports === void 0);
127954
+ filesWithInvalidatedNonRelativeUnresolvedImports = filesMap;
128940
127955
  }
128941
- function invalidateResolutionsWithoutGlobalCachePass() {
128942
- if (resolutionsResolvedWithoutGlobalCache) resolutionsWithoutGlobalCachePassAreInvalidated = true;
127956
+ function scheduleInvalidateResolutionOfFailedLookupLocation(fileOrDirectoryPath, isCreatingWatchedDirectory) {
127957
+ if (isCreatingWatchedDirectory) {
127958
+ (isInDirectoryChecks || (isInDirectoryChecks = /* @__PURE__ */ new Set())).add(fileOrDirectoryPath);
127959
+ } else {
127960
+ const updatedPath = removeIgnoredPath(fileOrDirectoryPath);
127961
+ if (!updatedPath) return false;
127962
+ fileOrDirectoryPath = updatedPath;
127963
+ if (resolutionHost.fileIsOpen(fileOrDirectoryPath)) {
127964
+ return false;
127965
+ }
127966
+ const dirOfFileOrDirectory = getDirectoryPath(fileOrDirectoryPath);
127967
+ if (isNodeModulesAtTypesDirectory(fileOrDirectoryPath) || isNodeModulesDirectory(fileOrDirectoryPath) || isNodeModulesAtTypesDirectory(dirOfFileOrDirectory) || isNodeModulesDirectory(dirOfFileOrDirectory)) {
127968
+ (failedLookupChecks || (failedLookupChecks = /* @__PURE__ */ new Set())).add(fileOrDirectoryPath);
127969
+ (startsWithPathChecks || (startsWithPathChecks = /* @__PURE__ */ new Set())).add(fileOrDirectoryPath);
127970
+ } else {
127971
+ if (isEmittedFileOfProgram(resolutionHost.getCurrentProgram(), fileOrDirectoryPath)) {
127972
+ return false;
127973
+ }
127974
+ if (fileExtensionIs(fileOrDirectoryPath, ".map")) {
127975
+ return false;
127976
+ }
127977
+ (failedLookupChecks || (failedLookupChecks = /* @__PURE__ */ new Set())).add(fileOrDirectoryPath);
127978
+ (startsWithPathChecks || (startsWithPathChecks = /* @__PURE__ */ new Set())).add(fileOrDirectoryPath);
127979
+ const packagePath = parseNodeModuleFromPath(
127980
+ fileOrDirectoryPath,
127981
+ /*isFolder*/
127982
+ true
127983
+ );
127984
+ if (packagePath) (startsWithPathChecks || (startsWithPathChecks = /* @__PURE__ */ new Set())).add(packagePath);
127985
+ }
127986
+ }
127987
+ resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
128943
127988
  }
128944
- function invalidateUnresolvedResolutionsWithGlobalCachePass() {
128945
- if (resolutionsResolvedWithGlobalCache) unresolvedResolutionsWithGlobalCachePassAreInvalidated = true;
127989
+ function invalidatePackageJsonMap() {
127990
+ const packageJsonMap = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap();
127991
+ if (packageJsonMap && (failedLookupChecks || startsWithPathChecks || isInDirectoryChecks)) {
127992
+ packageJsonMap.forEach((_value, path) => isInvalidatedFailedLookup(path) ? packageJsonMap.delete(path) : void 0);
127993
+ }
128946
127994
  }
128947
127995
  function invalidateResolutionsOfFailedLookupLocations() {
128948
127996
  var _a;
128949
- let invalidated = allModuleAndTypeResolutionsAreInvalidated;
128950
- if (!allModuleAndTypeResolutionsAreInvalidated && affectingPathChecksForFile) {
127997
+ if (allModuleAndTypeResolutionsAreInvalidated) {
127998
+ affectingPathChecksForFile = void 0;
127999
+ invalidatePackageJsonMap();
128000
+ if (failedLookupChecks || startsWithPathChecks || isInDirectoryChecks || affectingPathChecks) {
128001
+ invalidateResolutions(resolvedLibraries, canInvalidateFailedLookupResolution);
128002
+ }
128003
+ failedLookupChecks = void 0;
128004
+ startsWithPathChecks = void 0;
128005
+ isInDirectoryChecks = void 0;
128006
+ affectingPathChecks = void 0;
128007
+ return true;
128008
+ }
128009
+ let invalidated = false;
128010
+ if (affectingPathChecksForFile) {
128951
128011
  (_a = resolutionHost.getCurrentProgram()) == null ? void 0 : _a.getSourceFiles().forEach((f) => {
128952
128012
  if (some(f.packageJsonLocations, (location) => affectingPathChecksForFile.has(location))) {
128953
128013
  (filesWithInvalidatedResolutions ?? (filesWithInvalidatedResolutions = /* @__PURE__ */ new Set())).add(f.path);
128954
128014
  invalidated = true;
128955
128015
  }
128956
128016
  });
128017
+ affectingPathChecksForFile = void 0;
128957
128018
  }
128958
- affectingPathChecksForFile = void 0;
128959
- return sharedCache.invalidateResolutionsOfFailedLookupLocations() || invalidated;
128019
+ if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks && !affectingPathChecks) {
128020
+ return invalidated;
128021
+ }
128022
+ invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution) || invalidated;
128023
+ invalidatePackageJsonMap();
128024
+ failedLookupChecks = void 0;
128025
+ startsWithPathChecks = void 0;
128026
+ isInDirectoryChecks = void 0;
128027
+ invalidated = invalidateResolutions(resolutionsWithOnlyAffectingLocations, canInvalidatedFailedLookupResolutionWithAffectingLocation) || invalidated;
128028
+ affectingPathChecks = void 0;
128029
+ return invalidated;
128030
+ }
128031
+ function canInvalidateFailedLookupResolution(resolution) {
128032
+ var _a;
128033
+ if (canInvalidatedFailedLookupResolutionWithAffectingLocation(resolution)) return true;
128034
+ if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks) return false;
128035
+ return ((_a = resolution.failedLookupLocations) == null ? void 0 : _a.some((location) => isInvalidatedFailedLookup(resolutionHost.toPath(location)))) || !!resolution.alternateResult && isInvalidatedFailedLookup(resolutionHost.toPath(resolution.alternateResult));
128036
+ }
128037
+ function isInvalidatedFailedLookup(locationPath) {
128038
+ 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);
128039
+ }
128040
+ function canInvalidatedFailedLookupResolutionWithAffectingLocation(resolution) {
128041
+ var _a;
128042
+ return !!affectingPathChecks && ((_a = resolution.affectingLocations) == null ? void 0 : _a.some((location) => affectingPathChecks.has(location)));
128960
128043
  }
128961
128044
  function closeTypeRootsWatch() {
128962
128045
  clearMap(typeRootsWatches, closeFileWatcher);
128963
128046
  }
128964
128047
  function createTypeRootsWatch(typeRoot) {
128965
- return sharedCache.createTypeRootsWatch(typeRoot, cache);
128966
- }
128967
- function invalidateTypeRoot() {
128968
- hasChangedAutomaticTypeDirectiveNames = true;
128969
- resolutionHost.onChangedAutomaticTypeDirectiveNames();
128048
+ return canWatchTypeRootPath(typeRoot) ? resolutionHost.watchTypeRootsDirectory(typeRoot, (fileOrDirectory) => {
128049
+ const fileOrDirectoryPath = resolutionHost.toPath(fileOrDirectory);
128050
+ if (cachedDirectoryStructureHost) {
128051
+ cachedDirectoryStructureHost.addOrDeleteFileOrDirectory(fileOrDirectory, fileOrDirectoryPath);
128052
+ }
128053
+ hasChangedAutomaticTypeDirectiveNames = true;
128054
+ resolutionHost.onChangedAutomaticTypeDirectiveNames();
128055
+ const dirPath = getDirectoryToWatchFailedLookupLocationFromTypeRoot(
128056
+ typeRoot,
128057
+ resolutionHost.toPath(typeRoot),
128058
+ rootPath,
128059
+ rootPathComponents,
128060
+ isRootWatchable,
128061
+ getCurrentDirectory,
128062
+ resolutionHost.preferNonRecursiveWatch,
128063
+ (dirPath2) => directoryWatchesOfFailedLookups.has(dirPath2) || dirPathToSymlinkPackageRefCount.has(dirPath2)
128064
+ );
128065
+ if (dirPath) {
128066
+ scheduleInvalidateResolutionOfFailedLookupLocation(fileOrDirectoryPath, dirPath === fileOrDirectoryPath);
128067
+ }
128068
+ }, 1 /* Recursive */) : noopFileWatcher;
128970
128069
  }
128971
- function updateTypeRootsWatch(options) {
128972
- options ?? (options = resolutionHost.getCompilationSettings());
128070
+ function updateTypeRootsWatch() {
128071
+ const options = resolutionHost.getCompilationSettings();
128973
128072
  if (options.types) {
128974
128073
  closeTypeRootsWatch();
128975
128074
  return;
@@ -128988,6 +128087,10 @@ function createResolutionCache(resolutionHost, rootDirForResolution, sharedCache
128988
128087
  closeTypeRootsWatch();
128989
128088
  }
128990
128089
  }
128090
+ function canWatchTypeRootPath(typeRoot) {
128091
+ if (resolutionHost.getCompilationSettings().typeRoots) return true;
128092
+ return canWatchAtTypes(resolutionHost.toPath(typeRoot));
128093
+ }
128991
128094
  }
128992
128095
  function resolutionIsSymlink(resolution) {
128993
128096
  var _a, _b;
@@ -129755,23 +128858,22 @@ function createWatchProgram(host) {
129755
128858
  compilerHost.getParsedCommandLine = getParsedCommandLine;
129756
128859
  const resolutionCache = createResolutionCache(
129757
128860
  compilerHost,
129758
- configFileName ? getDirectoryPath(getNormalizedAbsolutePath(configFileName, currentDirectory)) : currentDirectory
128861
+ configFileName ? getDirectoryPath(getNormalizedAbsolutePath(configFileName, currentDirectory)) : currentDirectory,
128862
+ /*logChangesWhenResolvingModule*/
128863
+ false
129759
128864
  );
129760
- compilerHost.onSourceFileNotCreated = resolutionCache.onSourceFileNotCreated.bind(resolutionCache);
129761
128865
  compilerHost.resolveModuleNameLiterals = maybeBind(host, host.resolveModuleNameLiterals);
129762
128866
  compilerHost.resolveModuleNames = maybeBind(host, host.resolveModuleNames);
129763
128867
  if (!compilerHost.resolveModuleNameLiterals && !compilerHost.resolveModuleNames) {
129764
128868
  compilerHost.resolveModuleNameLiterals = resolutionCache.resolveModuleNameLiterals.bind(resolutionCache);
129765
- compilerHost.onReusedModuleResolutions = resolutionCache.onReusedModuleResolutions.bind(resolutionCache);
129766
128869
  }
129767
128870
  compilerHost.resolveTypeReferenceDirectiveReferences = maybeBind(host, host.resolveTypeReferenceDirectiveReferences);
129768
128871
  compilerHost.resolveTypeReferenceDirectives = maybeBind(host, host.resolveTypeReferenceDirectives);
129769
128872
  if (!compilerHost.resolveTypeReferenceDirectiveReferences && !compilerHost.resolveTypeReferenceDirectives) {
129770
128873
  compilerHost.resolveTypeReferenceDirectiveReferences = resolutionCache.resolveTypeReferenceDirectiveReferences.bind(resolutionCache);
129771
- compilerHost.onReusedTypeReferenceDirectiveResolutions = resolutionCache.onReusedTypeReferenceDirectiveResolutions.bind(resolutionCache);
129772
128874
  }
129773
128875
  compilerHost.resolveLibrary = !host.resolveLibrary ? resolutionCache.resolveLibrary.bind(resolutionCache) : host.resolveLibrary.bind(host);
129774
- compilerHost.getModuleResolutionCache = host.resolveModuleNameLiterals || host.resolveModuleNames ? maybeBind(host, host.getModuleResolutionCache) : () => resolutionCache.moduleResolutionCache;
128876
+ compilerHost.getModuleResolutionCache = host.resolveModuleNameLiterals || host.resolveModuleNames ? maybeBind(host, host.getModuleResolutionCache) : () => resolutionCache.getModuleResolutionCache();
129775
128877
  const userProvidedResolution = !!host.resolveModuleNameLiterals || !!host.resolveTypeReferenceDirectiveReferences || !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
129776
128878
  const customHasInvalidatedResolutions = userProvidedResolution ? maybeBind(host, host.hasInvalidatedResolutions) || returnTrue : returnFalse;
129777
128879
  const customHasInvalidLibResolutions = host.resolveLibrary ? maybeBind(host, host.hasInvalidatedLibResolutions) || returnTrue : returnFalse;