diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 5ca2bcee1d60d..4fb85fb36c417 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -2258,6 +2258,8 @@ namespace ts { * Adds a trailing directory separator to a path, if it does not already have one. * @param path The path. */ + export function ensureTrailingDirectorySeparator(path: Path): Path; + export function ensureTrailingDirectorySeparator(path: string): string; export function ensureTrailingDirectorySeparator(path: string) { if (path.charAt(path.length - 1) !== directorySeparator) { return path + directorySeparator; diff --git a/src/harness/unittests/typingsInstaller.ts b/src/harness/unittests/typingsInstaller.ts index 5bf968064f6df..9b874b2aca62e 100644 --- a/src/harness/unittests/typingsInstaller.ts +++ b/src/harness/unittests/typingsInstaller.ts @@ -141,12 +141,15 @@ namespace ts.projectSystem { checkNumberOfProjects(projectService, { configuredProjects: 1 }); const p = configuredProjectAt(projectService, 0); checkProjectActualFiles(p, [file1.path, tsconfig.path]); + checkWatchedFiles(host, [tsconfig.path, libFile.path, packageJson.path, "/a/b/bower_components", "/a/b/node_modules"]); installer.installAll(/*expectedCount*/ 1); checkNumberOfProjects(projectService, { configuredProjects: 1 }); host.checkTimeoutQueueLengthAndRun(2); checkProjectActualFiles(p, [file1.path, jquery.path, tsconfig.path]); + // should not watch jquery + checkWatchedFiles(host, [tsconfig.path, libFile.path, packageJson.path, "/a/b/bower_components", "/a/b/node_modules"]); }); it("inferred project (typings installed)", () => { diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index b05d2ab6c95ed..d7b6d814fe55e 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -389,6 +389,7 @@ namespace ts.server { public readonly useSingleInferredProject: boolean; public readonly useInferredProjectPerProjectRoot: boolean; public readonly typingsInstaller: ITypingsInstaller; + private readonly globalCacheLocationDirectoryPath: Path; public readonly throttleWaitMilliseconds?: number; private readonly eventHandler?: ProjectServiceEventHandler; @@ -423,6 +424,8 @@ namespace ts.server { } this.currentDirectory = this.host.getCurrentDirectory(); this.toCanonicalFileName = createGetCanonicalFileName(this.host.useCaseSensitiveFileNames); + this.globalCacheLocationDirectoryPath = this.typingsInstaller.globalTypingsCacheLocation && + ensureTrailingDirectorySeparator(this.toPath(this.typingsInstaller.globalTypingsCacheLocation)); this.throttledOperations = new ThrottledOperations(this.host, this.logger); if (this.typesMapLocation) { @@ -1725,7 +1728,10 @@ namespace ts.server { private watchClosedScriptInfo(info: ScriptInfo) { Debug.assert(!info.fileWatcher); // do not watch files with mixed content - server doesn't know how to interpret it - if (!info.isDynamicOrHasMixedContent()) { + // do not watch files in the global cache location + if (!info.isDynamicOrHasMixedContent() && + (!this.globalCacheLocationDirectoryPath || + !startsWith(info.path, this.globalCacheLocationDirectoryPath))) { const { fileName } = info; info.fileWatcher = this.watchFactory.watchFilePath( this.host, diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index a2f9506dc1cac..3e095dba77de3 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -7847,6 +7847,7 @@ declare namespace ts.server { readonly useSingleInferredProject: boolean; readonly useInferredProjectPerProjectRoot: boolean; readonly typingsInstaller: ITypingsInstaller; + private readonly globalCacheLocationDirectoryPath; readonly throttleWaitMilliseconds?: number; private readonly eventHandler?; readonly globalPlugins: ReadonlyArray;