From 3a993c89f30f0b4b8ded5220d2e2a72973acc9e3 Mon Sep 17 00:00:00 2001 From: Jason Ramsay Date: Wed, 31 Aug 2016 21:14:24 -0700 Subject: [PATCH] update runInstall --- src/compiler/checker.ts | 3 ++ .../typingsInstaller/nodeTypingsInstaller.ts | 36 ++++++++++++++----- .../typingsInstaller/typingsInstaller.ts | 4 ++- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d38ce359e8..a209db4e73 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18627,6 +18627,9 @@ namespace ts { continue; } const file = host.getSourceFile(resolvedDirective.resolvedFileName); + if (!file) { + continue; + } fileToDirective.set(file.path, key); } } diff --git a/src/server/typingsInstaller/nodeTypingsInstaller.ts b/src/server/typingsInstaller/nodeTypingsInstaller.ts index 278d8d6302..3745b32029 100644 --- a/src/server/typingsInstaller/nodeTypingsInstaller.ts +++ b/src/server/typingsInstaller/nodeTypingsInstaller.ts @@ -93,13 +93,11 @@ namespace ts.server.typingsInstaller { const id = this.installRunCount; this.installRunCount++; let execInstallCmdCount = 0; - const installedTypings: string[] = []; - const expr = /^.*(@types\/\w+)\S*\s*$/gm; - let match: RegExpExecArray; + let filteredTypings: string[] = []; for (const typing of typingsToInstall) { - const command = `npm install @types/${typing} --save-dev`; + const command = `npm view @types/${typing} --silent name`; if (this.log.isEnabled()) { - this.log.writeLine(`Running npm install @types ${id}, command '${command}'. cache path '${cachePath}'`); + this.log.writeLine(`Running npm view @types ${id}, command '${command}'.`); } this.exec(command, { cwd: cachePath }, (err, stdout, stderr) => { execInstallCmdCount++; @@ -107,11 +105,33 @@ namespace ts.server.typingsInstaller { this.log.writeLine(`npm install @types ${id} stdout: ${stdout}`); this.log.writeLine(`npm install @types ${id} stderr: ${stderr}`); } - while (match = expr.exec(stdout)) { - installedTypings.push(`node_modules/${match[1]}`); + if (stdout !== "") { + filteredTypings.push(typing); } if (execInstallCmdCount >= typingsToInstall.length) { - postInstallAction(installedTypings); + const command = `npm install ${filteredTypings.map(t => "@types/" + t).join(" ")} --save-dev -json`; + if (this.log.isEnabled()) { + this.log.writeLine(`Running npm install @types ${id}, command '${command}'. cache path '${cachePath}'`); + } + this.exec(command, { cwd: cachePath }, (err, stdout, stderr) => { + if (this.log.isEnabled()) { + this.log.writeLine(`npm install @types ${id} stdout: ${stdout}`); + this.log.writeLine(`npm install @types ${id} stderr: ${stderr}`); + } + const installedTypings: string[] = []; + try { + const response = JSON.parse(stdout); + if (response.dependencies) { + for (const typing in response.dependencies) { + installedTypings.push(typing); + } + } + } + catch (e) { + this.log.writeLine(`Error parsing installed @types dependencies. Error details: ${e.message}`); + } + postInstallAction(installedTypings); + }); } }); } diff --git a/src/server/typingsInstaller/typingsInstaller.ts b/src/server/typingsInstaller/typingsInstaller.ts index 619b307316..2905fb9aff 100644 --- a/src/server/typingsInstaller/typingsInstaller.ts +++ b/src/server/typingsInstaller/typingsInstaller.ts @@ -26,7 +26,6 @@ namespace ts.server.typingsInstaller { private packageNameToTypingLocation: Map = createMap(); private missingTypingsSet: Map = createMap(); private knownCachesSet: Map = createMap(); - private projectWatchers: Map = createMap(); abstract readonly installTypingHost: InstallTypingHost; @@ -203,6 +202,9 @@ namespace ts.server.typingsInstaller { if (!typingFile) { continue; } + if (!this.packageNameToTypingLocation[packageName]) { + this.packageNameToTypingLocation[packageName] = typingFile; + } installedTypingFiles.push(typingFile); } if (this.log.isEnabled()) {