typescript 5.1.0-dev.20230426 → 5.1.0-dev.20230427

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.1";
21
- var version = `${versionMajorMinor}.0-dev.20230426`;
21
+ var version = `${versionMajorMinor}.0-dev.20230427`;
22
22
 
23
23
  // src/compiler/core.ts
24
24
  var emptyArray = [];
@@ -54540,16 +54540,16 @@ function createTypeChecker(host) {
54540
54540
  if (declaration.kind === 175 /* Constructor */) {
54541
54541
  return getDeclaredTypeOfClassOrInterface(getMergedSymbol(declaration.parent.symbol));
54542
54542
  }
54543
+ const typeNode = getEffectiveReturnTypeNode(declaration);
54543
54544
  if (isJSDocSignature(declaration)) {
54544
54545
  const root = getJSDocRoot(declaration);
54545
- if (root && isConstructorDeclaration(root.parent)) {
54546
+ if (root && isConstructorDeclaration(root.parent) && !typeNode) {
54546
54547
  return getDeclaredTypeOfClassOrInterface(getMergedSymbol(root.parent.parent.symbol));
54547
54548
  }
54548
54549
  }
54549
54550
  if (isJSDocConstructSignature(declaration)) {
54550
54551
  return getTypeFromTypeNode(declaration.parameters[0].type);
54551
54552
  }
54552
- const typeNode = getEffectiveReturnTypeNode(declaration);
54553
54553
  if (typeNode) {
54554
54554
  return getTypeFromTypeNode(typeNode);
54555
54555
  }
@@ -66976,6 +66976,7 @@ function createTypeChecker(host) {
66976
66976
  );
66977
66977
  }
66978
66978
  function discriminateContextualTypeByJSXAttributes(node, contextualType) {
66979
+ const jsxChildrenPropertyName = getJsxElementChildrenPropertyName(getJsxNamespaceAt(node));
66979
66980
  return discriminateTypeByDiscriminableItems(
66980
66981
  contextualType,
66981
66982
  concatenate(
@@ -66986,7 +66987,14 @@ function createTypeChecker(host) {
66986
66987
  map(
66987
66988
  filter(getPropertiesOfType(contextualType), (s) => {
66988
66989
  var _a;
66989
- return !!(s.flags & 16777216 /* Optional */) && !!((_a = node == null ? void 0 : node.symbol) == null ? void 0 : _a.members) && !node.symbol.members.has(s.escapedName) && isDiscriminantProperty(contextualType, s.escapedName);
66990
+ if (!(s.flags & 16777216 /* Optional */) || !((_a = node == null ? void 0 : node.symbol) == null ? void 0 : _a.members)) {
66991
+ return false;
66992
+ }
66993
+ const element = node.parent.parent;
66994
+ if (s.escapedName === jsxChildrenPropertyName && isJsxElement(element) && getSemanticJsxChildren(element.children).length) {
66995
+ return false;
66996
+ }
66997
+ return !node.symbol.members.has(s.escapedName) && isDiscriminantProperty(contextualType, s.escapedName);
66990
66998
  }),
66991
66999
  (s) => [() => undefinedType, s.escapedName]
66992
67000
  )
@@ -119633,7 +119641,9 @@ var WatchType = {
119633
119641
  MissingSourceMapFile: "Missing source map file",
119634
119642
  NoopConfigFileForInferredRoot: "Noop Config file for the inferred project root",
119635
119643
  MissingGeneratedFile: "Missing generated file",
119636
- NodeModulesForModuleSpecifierCache: "node_modules for module specifier cache invalidation"
119644
+ NodeModulesForModuleSpecifierCache: "node_modules for module specifier cache invalidation",
119645
+ TypingInstallerLocationFile: "File location for typing installer",
119646
+ TypingInstallerLocationDirectory: "Directory location for typing installer"
119637
119647
  };
119638
119648
  function createWatchFactory(host, options) {
119639
119649
  const watchLogLevel = host.trace ? options.extendedDiagnostics ? 2 /* Verbose */ : options.diagnostics ? 1 /* TriggerOnly */ : 0 /* None */ : 0 /* None */;
package/lib/tsserver.js CHANGED
@@ -2303,7 +2303,7 @@ module.exports = __toCommonJS(server_exports);
2303
2303
 
2304
2304
  // src/compiler/corePublic.ts
2305
2305
  var versionMajorMinor = "5.1";
2306
- var version = `${versionMajorMinor}.0-dev.20230426`;
2306
+ var version = `${versionMajorMinor}.0-dev.20230427`;
2307
2307
  var Comparison = /* @__PURE__ */ ((Comparison3) => {
2308
2308
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
2309
2309
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -6951,10 +6951,10 @@ var LanguageVariant = /* @__PURE__ */ ((LanguageVariant4) => {
6951
6951
  LanguageVariant4[LanguageVariant4["JSX"] = 1] = "JSX";
6952
6952
  return LanguageVariant4;
6953
6953
  })(LanguageVariant || {});
6954
- var WatchDirectoryFlags = /* @__PURE__ */ ((WatchDirectoryFlags4) => {
6955
- WatchDirectoryFlags4[WatchDirectoryFlags4["None"] = 0] = "None";
6956
- WatchDirectoryFlags4[WatchDirectoryFlags4["Recursive"] = 1] = "Recursive";
6957
- return WatchDirectoryFlags4;
6954
+ var WatchDirectoryFlags = /* @__PURE__ */ ((WatchDirectoryFlags3) => {
6955
+ WatchDirectoryFlags3[WatchDirectoryFlags3["None"] = 0] = "None";
6956
+ WatchDirectoryFlags3[WatchDirectoryFlags3["Recursive"] = 1] = "Recursive";
6957
+ return WatchDirectoryFlags3;
6958
6958
  })(WatchDirectoryFlags || {});
6959
6959
  var CharacterCodes = /* @__PURE__ */ ((CharacterCodes2) => {
6960
6960
  CharacterCodes2[CharacterCodes2["nullCharacter"] = 0] = "nullCharacter";
@@ -59190,16 +59190,16 @@ function createTypeChecker(host) {
59190
59190
  if (declaration.kind === 175 /* Constructor */) {
59191
59191
  return getDeclaredTypeOfClassOrInterface(getMergedSymbol(declaration.parent.symbol));
59192
59192
  }
59193
+ const typeNode = getEffectiveReturnTypeNode(declaration);
59193
59194
  if (isJSDocSignature(declaration)) {
59194
59195
  const root = getJSDocRoot(declaration);
59195
- if (root && isConstructorDeclaration(root.parent)) {
59196
+ if (root && isConstructorDeclaration(root.parent) && !typeNode) {
59196
59197
  return getDeclaredTypeOfClassOrInterface(getMergedSymbol(root.parent.parent.symbol));
59197
59198
  }
59198
59199
  }
59199
59200
  if (isJSDocConstructSignature(declaration)) {
59200
59201
  return getTypeFromTypeNode(declaration.parameters[0].type);
59201
59202
  }
59202
- const typeNode = getEffectiveReturnTypeNode(declaration);
59203
59203
  if (typeNode) {
59204
59204
  return getTypeFromTypeNode(typeNode);
59205
59205
  }
@@ -71626,6 +71626,7 @@ function createTypeChecker(host) {
71626
71626
  );
71627
71627
  }
71628
71628
  function discriminateContextualTypeByJSXAttributes(node, contextualType) {
71629
+ const jsxChildrenPropertyName = getJsxElementChildrenPropertyName(getJsxNamespaceAt(node));
71629
71630
  return discriminateTypeByDiscriminableItems(
71630
71631
  contextualType,
71631
71632
  concatenate(
@@ -71636,7 +71637,14 @@ function createTypeChecker(host) {
71636
71637
  map(
71637
71638
  filter(getPropertiesOfType(contextualType), (s) => {
71638
71639
  var _a;
71639
- return !!(s.flags & 16777216 /* Optional */) && !!((_a = node == null ? void 0 : node.symbol) == null ? void 0 : _a.members) && !node.symbol.members.has(s.escapedName) && isDiscriminantProperty(contextualType, s.escapedName);
71640
+ if (!(s.flags & 16777216 /* Optional */) || !((_a = node == null ? void 0 : node.symbol) == null ? void 0 : _a.members)) {
71641
+ return false;
71642
+ }
71643
+ const element = node.parent.parent;
71644
+ if (s.escapedName === jsxChildrenPropertyName && isJsxElement(element) && getSemanticJsxChildren(element.children).length) {
71645
+ return false;
71646
+ }
71647
+ return !node.symbol.members.has(s.escapedName) && isDiscriminantProperty(contextualType, s.escapedName);
71640
71648
  }),
71641
71649
  (s) => [() => undefinedType, s.escapedName]
71642
71650
  )
@@ -117327,7 +117335,7 @@ var WatchLogLevel = /* @__PURE__ */ ((WatchLogLevel2) => {
117327
117335
  WatchLogLevel2[WatchLogLevel2["Verbose"] = 2] = "Verbose";
117328
117336
  return WatchLogLevel2;
117329
117337
  })(WatchLogLevel || {});
117330
- function getWatchFactory(host, watchLogLevel, log, getDetailWatchInfo3) {
117338
+ function getWatchFactory(host, watchLogLevel, log, getDetailWatchInfo2) {
117331
117339
  setSysLog(watchLogLevel === 2 /* Verbose */ ? log : noop);
117332
117340
  const plainInvokeFactory = {
117333
117341
  watchFile: (file, callback, pollingInterval, options) => host.watchFile(file, callback, pollingInterval, options),
@@ -117365,23 +117373,23 @@ function getWatchFactory(host, watchLogLevel, log, getDetailWatchInfo3) {
117365
117373
  return typeof host.useCaseSensitiveFileNames === "boolean" ? host.useCaseSensitiveFileNames : host.useCaseSensitiveFileNames();
117366
117374
  }
117367
117375
  function createExcludeWatcherWithLogging(file, flags, options, detailInfo1, detailInfo2) {
117368
- log(`ExcludeWatcher:: Added:: ${getWatchInfo(file, flags, options, detailInfo1, detailInfo2, getDetailWatchInfo3)}`);
117376
+ log(`ExcludeWatcher:: Added:: ${getWatchInfo(file, flags, options, detailInfo1, detailInfo2, getDetailWatchInfo2)}`);
117369
117377
  return {
117370
- close: () => log(`ExcludeWatcher:: Close:: ${getWatchInfo(file, flags, options, detailInfo1, detailInfo2, getDetailWatchInfo3)}`)
117378
+ close: () => log(`ExcludeWatcher:: Close:: ${getWatchInfo(file, flags, options, detailInfo1, detailInfo2, getDetailWatchInfo2)}`)
117371
117379
  };
117372
117380
  }
117373
117381
  function createFileWatcherWithLogging(file, cb, flags, options, detailInfo1, detailInfo2) {
117374
- log(`FileWatcher:: Added:: ${getWatchInfo(file, flags, options, detailInfo1, detailInfo2, getDetailWatchInfo3)}`);
117382
+ log(`FileWatcher:: Added:: ${getWatchInfo(file, flags, options, detailInfo1, detailInfo2, getDetailWatchInfo2)}`);
117375
117383
  const watcher = triggerInvokingFactory.watchFile(file, cb, flags, options, detailInfo1, detailInfo2);
117376
117384
  return {
117377
117385
  close: () => {
117378
- log(`FileWatcher:: Close:: ${getWatchInfo(file, flags, options, detailInfo1, detailInfo2, getDetailWatchInfo3)}`);
117386
+ log(`FileWatcher:: Close:: ${getWatchInfo(file, flags, options, detailInfo1, detailInfo2, getDetailWatchInfo2)}`);
117379
117387
  watcher.close();
117380
117388
  }
117381
117389
  };
117382
117390
  }
117383
117391
  function createDirectoryWatcherWithLogging(file, cb, flags, options, detailInfo1, detailInfo2) {
117384
- const watchInfo = `DirectoryWatcher:: Added:: ${getWatchInfo(file, flags, options, detailInfo1, detailInfo2, getDetailWatchInfo3)}`;
117392
+ const watchInfo = `DirectoryWatcher:: Added:: ${getWatchInfo(file, flags, options, detailInfo1, detailInfo2, getDetailWatchInfo2)}`;
117385
117393
  log(watchInfo);
117386
117394
  const start2 = timestamp();
117387
117395
  const watcher = triggerInvokingFactory.watchDirectory(file, cb, flags, options, detailInfo1, detailInfo2);
@@ -117389,7 +117397,7 @@ function getWatchFactory(host, watchLogLevel, log, getDetailWatchInfo3) {
117389
117397
  log(`Elapsed:: ${elapsed}ms ${watchInfo}`);
117390
117398
  return {
117391
117399
  close: () => {
117392
- const watchInfo2 = `DirectoryWatcher:: Close:: ${getWatchInfo(file, flags, options, detailInfo1, detailInfo2, getDetailWatchInfo3)}`;
117400
+ const watchInfo2 = `DirectoryWatcher:: Close:: ${getWatchInfo(file, flags, options, detailInfo1, detailInfo2, getDetailWatchInfo2)}`;
117393
117401
  log(watchInfo2);
117394
117402
  const start3 = timestamp();
117395
117403
  watcher.close();
@@ -117404,7 +117412,7 @@ function getWatchFactory(host, watchLogLevel, log, getDetailWatchInfo3) {
117404
117412
  void 0,
117405
117413
  file,
117406
117414
  (...args) => {
117407
- const triggerredInfo = `${key === "watchFile" ? "FileWatcher" : "DirectoryWatcher"}:: Triggered with ${args[0]} ${args[1] !== void 0 ? args[1] : ""}:: ${getWatchInfo(file, flags, options, detailInfo1, detailInfo2, getDetailWatchInfo3)}`;
117415
+ const triggerredInfo = `${key === "watchFile" ? "FileWatcher" : "DirectoryWatcher"}:: Triggered with ${args[0]} ${args[1] !== void 0 ? args[1] : ""}:: ${getWatchInfo(file, flags, options, detailInfo1, detailInfo2, getDetailWatchInfo2)}`;
117408
117416
  log(triggerredInfo);
117409
117417
  const start2 = timestamp();
117410
117418
  cb.call(
@@ -117421,8 +117429,8 @@ function getWatchFactory(host, watchLogLevel, log, getDetailWatchInfo3) {
117421
117429
  detailInfo2
117422
117430
  );
117423
117431
  }
117424
- function getWatchInfo(file, flags, options, detailInfo1, detailInfo2, getDetailWatchInfo4) {
117425
- return `WatchInfo: ${file} ${flags} ${JSON.stringify(options)} ${getDetailWatchInfo4 ? getDetailWatchInfo4(detailInfo1, detailInfo2) : detailInfo2 === void 0 ? detailInfo1 : `${detailInfo1} ${detailInfo2}`}`;
117432
+ function getWatchInfo(file, flags, options, detailInfo1, detailInfo2, getDetailWatchInfo3) {
117433
+ return `WatchInfo: ${file} ${flags} ${JSON.stringify(options)} ${getDetailWatchInfo3 ? getDetailWatchInfo3(detailInfo1, detailInfo2) : detailInfo2 === void 0 ? detailInfo1 : `${detailInfo1} ${detailInfo2}`}`;
117426
117434
  }
117427
117435
  }
117428
117436
  function getFallbackOptions(options) {
@@ -124554,7 +124562,9 @@ var WatchType = {
124554
124562
  MissingSourceMapFile: "Missing source map file",
124555
124563
  NoopConfigFileForInferredRoot: "Noop Config file for the inferred project root",
124556
124564
  MissingGeneratedFile: "Missing generated file",
124557
- NodeModulesForModuleSpecifierCache: "node_modules for module specifier cache invalidation"
124565
+ NodeModulesForModuleSpecifierCache: "node_modules for module specifier cache invalidation",
124566
+ TypingInstallerLocationFile: "File location for typing installer",
124567
+ TypingInstallerLocationDirectory: "Directory location for typing installer"
124558
124568
  };
124559
124569
  function createWatchFactory(host, options) {
124560
124570
  const watchLogLevel = host.trace ? options.extendedDiagnostics ? 2 /* Verbose */ : options.diagnostics ? 1 /* TriggerOnly */ : 0 /* None */ : 0 /* None */;
@@ -127834,6 +127844,7 @@ var EventTypesRegistry = "event::typesRegistry";
127834
127844
  var EventBeginInstallTypes = "event::beginInstallTypes";
127835
127845
  var EventEndInstallTypes = "event::endInstallTypes";
127836
127846
  var EventInitializationFailed = "event::initializationFailed";
127847
+ var ActionWatchTypingLocations = "action::watchTypingLocations";
127837
127848
  var Arguments;
127838
127849
  ((Arguments2) => {
127839
127850
  Arguments2.GlobalCacheLocation = "--globalTypingsCacheLocation";
@@ -171595,6 +171606,7 @@ __export(ts_server_exports3, {
171595
171606
  ActionInvalidate: () => ActionInvalidate,
171596
171607
  ActionPackageInstalled: () => ActionPackageInstalled,
171597
171608
  ActionSet: () => ActionSet,
171609
+ ActionWatchTypingLocations: () => ActionWatchTypingLocations,
171598
171610
  Arguments: () => Arguments,
171599
171611
  AutoImportProviderProject: () => AutoImportProviderProject,
171600
171612
  CharRangeSection: () => CharRangeSection,
@@ -171728,19 +171740,6 @@ function getNpmCommandForInstallation(npmPath, tsVersion, packageNames, remainin
171728
171740
  }
171729
171741
  return { command, remaining: remaining - toSlice };
171730
171742
  }
171731
- function endsWith2(str, suffix, caseSensitive) {
171732
- const expectedPos = str.length - suffix.length;
171733
- return expectedPos >= 0 && (str.indexOf(suffix, expectedPos) === expectedPos || !caseSensitive && compareStringsCaseInsensitive(str.substr(expectedPos), suffix) === 0 /* EqualTo */);
171734
- }
171735
- function isPackageOrBowerJson(fileName, caseSensitive) {
171736
- return endsWith2(fileName, "/package.json", caseSensitive) || endsWith2(fileName, "/bower.json", caseSensitive);
171737
- }
171738
- function sameFiles(a, b, caseSensitive) {
171739
- return a === b || !caseSensitive && compareStringsCaseInsensitive(a, b) === 0 /* EqualTo */;
171740
- }
171741
- function getDetailWatchInfo(projectName, watchers) {
171742
- return `Project: ${projectName} watcher already invoked: ${watchers == null ? void 0 : watchers.isInvoked}`;
171743
- }
171744
171743
  var TypingsInstaller = class {
171745
171744
  constructor(installTypingHost, globalCachePath, safeListPath, typesMapLocation, throttleLimit, log = nullLog) {
171746
171745
  this.installTypingHost = installTypingHost;
@@ -171758,13 +171757,10 @@ var TypingsInstaller = class {
171758
171757
  this.installRunCount = 1;
171759
171758
  this.inFlightRequestCount = 0;
171760
171759
  this.latestDistTag = "latest";
171761
- this.toCanonicalFileName = createGetCanonicalFileName(installTypingHost.useCaseSensitiveFileNames);
171762
- this.globalCachePackageJsonPath = combinePaths(globalCachePath, "package.json");
171763
171760
  const isLoggingEnabled = this.log.isEnabled();
171764
171761
  if (isLoggingEnabled) {
171765
171762
  this.log.writeLine(`Global cache location '${globalCachePath}', safe file path '${safeListPath}', types map path ${typesMapLocation}`);
171766
171763
  }
171767
- this.watchFactory = getWatchFactory(this.installTypingHost, isLoggingEnabled ? 2 /* Verbose */ : 0 /* None */, (s) => this.log.writeLine(s), getDetailWatchInfo);
171768
171764
  this.processCacheLocation(this.globalCachePath);
171769
171765
  }
171770
171766
  closeProject(req) {
@@ -171781,8 +171777,8 @@ var TypingsInstaller = class {
171781
171777
  }
171782
171778
  return;
171783
171779
  }
171784
- clearMap(watchers, closeFileWatcher);
171785
171780
  this.projectWatchers.delete(projectName);
171781
+ this.sendResponse({ kind: ActionWatchTypingLocations, projectName, files: [] });
171786
171782
  if (this.log.isEnabled()) {
171787
171783
  this.log.writeLine(`Closing file watchers for project '${projectName}' - done.`);
171788
171784
  }
@@ -171815,7 +171811,7 @@ var TypingsInstaller = class {
171815
171811
  if (this.log.isEnabled()) {
171816
171812
  this.log.writeLine(`Finished typings discovery: ${JSON.stringify(discoverTypingsResult)}`);
171817
171813
  }
171818
- this.watchFiles(req.projectName, discoverTypingsResult.filesToWatch, req.projectRootPath, req.watchOptions);
171814
+ this.watchFiles(req.projectName, discoverTypingsResult.filesToWatch);
171819
171815
  if (discoverTypingsResult.newTypingNames.length) {
171820
171816
  this.installTypings(req, req.cachePath || this.globalCachePath, discoverTypingsResult.cachedTypingPaths, discoverTypingsResult.newTypingNames);
171821
171817
  } else {
@@ -172016,75 +172012,19 @@ var TypingsInstaller = class {
172016
172012
  host.createDirectory(directory);
172017
172013
  }
172018
172014
  }
172019
- watchFiles(projectName, files, projectRootPath, options) {
172015
+ watchFiles(projectName, files) {
172020
172016
  if (!files.length) {
172021
172017
  this.closeWatchers(projectName);
172022
172018
  return;
172023
172019
  }
172024
- let watchers = this.projectWatchers.get(projectName);
172025
- const toRemove = /* @__PURE__ */ new Map();
172026
- if (!watchers) {
172027
- watchers = /* @__PURE__ */ new Map();
172028
- this.projectWatchers.set(projectName, watchers);
172020
+ const existing = this.projectWatchers.get(projectName);
172021
+ const newSet = new Set(files);
172022
+ if (!existing || forEachKey(newSet, (s) => !existing.has(s)) || forEachKey(existing, (s) => !newSet.has(s))) {
172023
+ this.projectWatchers.set(projectName, newSet);
172024
+ this.sendResponse({ kind: ActionWatchTypingLocations, projectName, files });
172029
172025
  } else {
172030
- copyEntries(watchers, toRemove);
172026
+ this.sendResponse({ kind: ActionWatchTypingLocations, projectName, files: void 0 });
172031
172027
  }
172032
- watchers.isInvoked = false;
172033
- const isLoggingEnabled = this.log.isEnabled();
172034
- const createProjectWatcher = (path, projectWatcherType) => {
172035
- const canonicalPath = this.toCanonicalFileName(path);
172036
- toRemove.delete(canonicalPath);
172037
- if (watchers.has(canonicalPath)) {
172038
- return;
172039
- }
172040
- if (isLoggingEnabled) {
172041
- this.log.writeLine(`${projectWatcherType}:: Added:: WatchInfo: ${path}`);
172042
- }
172043
- const watcher = projectWatcherType === "FileWatcher" /* FileWatcher */ ? this.watchFactory.watchFile(path, () => {
172044
- if (!watchers.isInvoked) {
172045
- watchers.isInvoked = true;
172046
- this.sendResponse({ projectName, kind: ActionInvalidate });
172047
- }
172048
- }, 2e3 /* High */, options, projectName, watchers) : this.watchFactory.watchDirectory(path, (f) => {
172049
- if (watchers.isInvoked || !fileExtensionIs(f, ".json" /* Json */)) {
172050
- return;
172051
- }
172052
- if (isPackageOrBowerJson(f, this.installTypingHost.useCaseSensitiveFileNames) && !sameFiles(f, this.globalCachePackageJsonPath, this.installTypingHost.useCaseSensitiveFileNames)) {
172053
- watchers.isInvoked = true;
172054
- this.sendResponse({ projectName, kind: ActionInvalidate });
172055
- }
172056
- }, 1 /* Recursive */, options, projectName, watchers);
172057
- watchers.set(canonicalPath, isLoggingEnabled ? {
172058
- close: () => {
172059
- this.log.writeLine(`${projectWatcherType}:: Closed:: WatchInfo: ${path}`);
172060
- watcher.close();
172061
- }
172062
- } : watcher);
172063
- };
172064
- for (const file of files) {
172065
- if (file.endsWith("/package.json") || file.endsWith("/bower.json")) {
172066
- createProjectWatcher(file, "FileWatcher" /* FileWatcher */);
172067
- continue;
172068
- }
172069
- if (containsPath(projectRootPath, file, projectRootPath, !this.installTypingHost.useCaseSensitiveFileNames)) {
172070
- const subDirectory = file.indexOf(directorySeparator, projectRootPath.length + 1);
172071
- if (subDirectory !== -1) {
172072
- createProjectWatcher(file.substr(0, subDirectory), "DirectoryWatcher" /* DirectoryWatcher */);
172073
- } else {
172074
- createProjectWatcher(file, "DirectoryWatcher" /* DirectoryWatcher */);
172075
- }
172076
- continue;
172077
- }
172078
- if (containsPath(this.globalCachePath, file, projectRootPath, !this.installTypingHost.useCaseSensitiveFileNames)) {
172079
- createProjectWatcher(this.globalCachePath, "DirectoryWatcher" /* DirectoryWatcher */);
172080
- continue;
172081
- }
172082
- createProjectWatcher(file, "DirectoryWatcher" /* DirectoryWatcher */);
172083
- }
172084
- toRemove.forEach((watch, path) => {
172085
- watch.close();
172086
- watchers.delete(path);
172087
- });
172088
172028
  }
172089
172029
  createSetTypings(request, typings) {
172090
172030
  return {
@@ -172141,7 +172081,6 @@ function createInstallTypingsRequest(project, typeAcquisition, unresolvedImports
172141
172081
  true
172142
172082
  ).concat(project.getExcludedFiles()),
172143
172083
  compilerOptions: project.getCompilationSettings(),
172144
- watchOptions: project.projectService.getWatchOptions(project),
172145
172084
  typeAcquisition,
172146
172085
  unresolvedImports,
172147
172086
  projectRootPath: project.getCurrentDirectory(),
@@ -173759,6 +173698,8 @@ var Project3 = class {
173759
173698
  return path === options.configFilePath ? options.configFile : this.getSourceFile(path);
173760
173699
  }
173761
173700
  close() {
173701
+ this.projectService.typingsCache.onProjectClosed(this);
173702
+ this.closeWatchingTypingLocations();
173762
173703
  if (this.program) {
173763
173704
  for (const f of this.program.getSourceFiles()) {
173764
173705
  this.detachScriptInfoIfNotRoot(f.fileName);
@@ -174049,6 +173990,89 @@ var Project3 = class {
174049
173990
  }
174050
173991
  }
174051
173992
  /** @internal */
173993
+ closeWatchingTypingLocations() {
173994
+ if (this.typingWatchers)
173995
+ clearMap(this.typingWatchers, closeFileWatcher);
173996
+ this.typingWatchers = void 0;
173997
+ }
173998
+ /** @internal */
173999
+ onTypingInstallerWatchInvoke() {
174000
+ this.typingWatchers.isInvoked = true;
174001
+ this.projectService.updateTypingsForProject({ projectName: this.getProjectName(), kind: ActionInvalidate });
174002
+ }
174003
+ /** @internal */
174004
+ watchTypingLocations(files) {
174005
+ if (!files) {
174006
+ this.typingWatchers.isInvoked = false;
174007
+ return;
174008
+ }
174009
+ if (!files.length) {
174010
+ this.closeWatchingTypingLocations();
174011
+ return;
174012
+ }
174013
+ const toRemove = new Map(this.typingWatchers);
174014
+ if (!this.typingWatchers)
174015
+ this.typingWatchers = /* @__PURE__ */ new Map();
174016
+ this.typingWatchers.isInvoked = false;
174017
+ const createProjectWatcher = (path, typingsWatcherType) => {
174018
+ const canonicalPath = this.toPath(path);
174019
+ toRemove.delete(canonicalPath);
174020
+ if (!this.typingWatchers.has(canonicalPath)) {
174021
+ this.typingWatchers.set(
174022
+ canonicalPath,
174023
+ typingsWatcherType === "FileWatcher" /* FileWatcher */ ? this.projectService.watchFactory.watchFile(
174024
+ path,
174025
+ () => !this.typingWatchers.isInvoked ? this.onTypingInstallerWatchInvoke() : this.writeLog(`TypingWatchers already invoked`),
174026
+ 2e3 /* High */,
174027
+ this.projectService.getWatchOptions(this),
174028
+ WatchType.TypingInstallerLocationFile,
174029
+ this
174030
+ ) : this.projectService.watchFactory.watchDirectory(
174031
+ path,
174032
+ (f) => {
174033
+ if (this.typingWatchers.isInvoked)
174034
+ return this.writeLog(`TypingWatchers already invoked`);
174035
+ if (!fileExtensionIs(f, ".json" /* Json */))
174036
+ return this.writeLog(`Ignoring files that are not *.json`);
174037
+ if (comparePaths(f, combinePaths(this.projectService.typingsInstaller.globalTypingsCacheLocation, "package.json"), !this.useCaseSensitiveFileNames()))
174038
+ return this.writeLog(`Ignoring package.json change at global typings location`);
174039
+ this.onTypingInstallerWatchInvoke();
174040
+ },
174041
+ 1 /* Recursive */,
174042
+ this.projectService.getWatchOptions(this),
174043
+ WatchType.TypingInstallerLocationDirectory,
174044
+ this
174045
+ )
174046
+ );
174047
+ }
174048
+ };
174049
+ for (const file of files) {
174050
+ const basename = getBaseFileName(file);
174051
+ if (basename === "package.json" || basename === "bower.json") {
174052
+ createProjectWatcher(file, "FileWatcher" /* FileWatcher */);
174053
+ continue;
174054
+ }
174055
+ if (containsPath(this.currentDirectory, file, this.currentDirectory, !this.useCaseSensitiveFileNames())) {
174056
+ const subDirectory = file.indexOf(directorySeparator, this.currentDirectory.length + 1);
174057
+ if (subDirectory !== -1) {
174058
+ createProjectWatcher(file.substr(0, subDirectory), "DirectoryWatcher" /* DirectoryWatcher */);
174059
+ } else {
174060
+ createProjectWatcher(file, "DirectoryWatcher" /* DirectoryWatcher */);
174061
+ }
174062
+ continue;
174063
+ }
174064
+ if (containsPath(this.projectService.typingsInstaller.globalTypingsCacheLocation, file, this.currentDirectory, !this.useCaseSensitiveFileNames())) {
174065
+ createProjectWatcher(this.projectService.typingsInstaller.globalTypingsCacheLocation, "DirectoryWatcher" /* DirectoryWatcher */);
174066
+ continue;
174067
+ }
174068
+ createProjectWatcher(file, "DirectoryWatcher" /* DirectoryWatcher */);
174069
+ }
174070
+ toRemove.forEach((watch, path) => {
174071
+ watch.close();
174072
+ this.typingWatchers.delete(path);
174073
+ });
174074
+ }
174075
+ /** @internal */
174052
174076
  getCurrentProgram() {
174053
174077
  return this.program;
174054
174078
  }
@@ -175613,7 +175637,7 @@ function forEachReferencedProject(project, cb) {
175613
175637
  (potentialProjectRef) => callbackRefProject(project, cb, potentialProjectRef)
175614
175638
  );
175615
175639
  }
175616
- function getDetailWatchInfo2(watchType, project) {
175640
+ function getDetailWatchInfo(watchType, project) {
175617
175641
  return `${isString(project) ? `Config: ${project} ` : project ? `Project: ${project.getProjectName()} ` : ""}WatchType: ${watchType}`;
175618
175642
  }
175619
175643
  function isScriptInfoWatchedFromNodeModules(info) {
@@ -175759,7 +175783,7 @@ var _ProjectService = class {
175759
175783
  this.watchFactory = this.serverMode !== 0 /* Semantic */ ? {
175760
175784
  watchFile: returnNoopFileWatcher,
175761
175785
  watchDirectory: returnNoopFileWatcher
175762
- } : getWatchFactory(this.host, watchLogLevel, log, getDetailWatchInfo2);
175786
+ } : getWatchFactory(this.host, watchLogLevel, log, getDetailWatchInfo);
175763
175787
  }
175764
175788
  toPath(fileName) {
175765
175789
  return toPath(fileName, this.currentDirectory, this.toCanonicalFileName);
@@ -175845,6 +175869,11 @@ var _ProjectService = class {
175845
175869
  }
175846
175870
  }
175847
175871
  /** @internal */
175872
+ watchTypingLocations(response) {
175873
+ var _a;
175874
+ (_a = this.findProject(response.projectName)) == null ? void 0 : _a.watchTypingLocations(response.files);
175875
+ }
175876
+ /** @internal */
175848
175877
  delayEnsureProjectForOpenFiles() {
175849
175878
  if (!this.openFiles.size)
175850
175879
  return;
@@ -182804,6 +182833,7 @@ __export(ts_server_exports4, {
182804
182833
  ActionInvalidate: () => ActionInvalidate,
182805
182834
  ActionPackageInstalled: () => ActionPackageInstalled,
182806
182835
  ActionSet: () => ActionSet,
182836
+ ActionWatchTypingLocations: () => ActionWatchTypingLocations,
182807
182837
  Arguments: () => Arguments,
182808
182838
  AutoImportProviderProject: () => AutoImportProviderProject,
182809
182839
  CharRangeSection: () => CharRangeSection,
@@ -183415,6 +183445,9 @@ function startNodeSession(options, logger, cancellationToken) {
183415
183445
  this.event(response, "setTypings");
183416
183446
  break;
183417
183447
  }
183448
+ case ActionWatchTypingLocations:
183449
+ this.projectService.watchTypingLocations(response);
183450
+ break;
183418
183451
  default:
183419
183452
  assertType(response);
183420
183453
  }
@@ -22,8 +22,9 @@ declare namespace ts {
22
22
  type EventBeginInstallTypes = "event::beginInstallTypes";
23
23
  type EventEndInstallTypes = "event::endInstallTypes";
24
24
  type EventInitializationFailed = "event::initializationFailed";
25
+ type ActionWatchTypingLocations = "action::watchTypingLocations";
25
26
  interface TypingInstallerResponse {
26
- readonly kind: ActionSet | ActionInvalidate | EventTypesRegistry | ActionPackageInstalled | EventBeginInstallTypes | EventEndInstallTypes | EventInitializationFailed;
27
+ readonly kind: ActionSet | ActionInvalidate | EventTypesRegistry | ActionPackageInstalled | EventBeginInstallTypes | EventEndInstallTypes | EventInitializationFailed | ActionWatchTypingLocations;
27
28
  }
28
29
  interface TypingInstallerRequestWithProjectName {
29
30
  readonly projectName: string;
@@ -32,7 +33,6 @@ declare namespace ts {
32
33
  readonly fileNames: string[];
33
34
  readonly projectRootPath: Path;
34
35
  readonly compilerOptions: CompilerOptions;
35
- readonly watchOptions?: WatchOptions;
36
36
  readonly typeAcquisition: TypeAcquisition;
37
37
  readonly unresolvedImports: SortedReadonlyArray<string>;
38
38
  readonly cachePath?: string;
@@ -84,8 +84,6 @@ declare namespace ts {
84
84
  writeFile(path: string, content: string): void;
85
85
  createDirectory(path: string): void;
86
86
  getCurrentDirectory?(): string;
87
- watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number, options?: WatchOptions): FileWatcher;
88
- watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean, options?: WatchOptions): FileWatcher;
89
87
  }
90
88
  interface SetTypings extends ProjectResponse {
91
89
  readonly typeAcquisition: TypeAcquisition;
@@ -94,6 +92,11 @@ declare namespace ts {
94
92
  readonly unresolvedImports: SortedReadonlyArray<string>;
95
93
  readonly kind: ActionSet;
96
94
  }
95
+ interface WatchTypingLocations extends ProjectResponse {
96
+ /** if files is undefined, retain same set of watchers */
97
+ readonly files: readonly string[] | undefined;
98
+ readonly kind: ActionWatchTypingLocations;
99
+ }
97
100
  namespace protocol {
98
101
  enum CommandTypes {
99
102
  JsxClosingTag = "jsxClosingTag",
@@ -3044,8 +3047,6 @@ declare namespace ts {
3044
3047
  private readonly knownCachesSet;
3045
3048
  private readonly projectWatchers;
3046
3049
  private safeList;
3047
- private readonly toCanonicalFileName;
3048
- private readonly globalCachePackageJsonPath;
3049
3050
  private installRunCount;
3050
3051
  private inFlightRequestCount;
3051
3052
  abstract readonly typesRegistry: Map<string, MapLike<string>>;
@@ -3064,7 +3065,7 @@ declare namespace ts {
3064
3065
  private installTypingsAsync;
3065
3066
  private executeWithThrottling;
3066
3067
  protected abstract installWorker(requestId: number, packageNames: string[], cwd: string, onRequestCompleted: RequestCompletedAction): void;
3067
- protected abstract sendResponse(response: SetTypings | InvalidateCachedTypings | BeginInstallTypes | EndInstallTypes): void;
3068
+ protected abstract sendResponse(response: SetTypings | InvalidateCachedTypings | BeginInstallTypes | EndInstallTypes | WatchTypingLocations): void;
3068
3069
  protected readonly latestDistTag = "latest";
3069
3070
  }
3070
3071
  }