add 'installSuccess' flag to telemetry, cache misses if npm install fails (#12163)

* add 'installSuccess' flag to telemetry, cache misses if npm install fails

* fix typo
This commit is contained in:
Vladimir Matveev 2016-11-10 16:52:36 -08:00
parent a0338d15e1
commit f11e8a3c69
5 changed files with 22 additions and 8 deletions

View file

@ -2081,6 +2081,10 @@ namespace ts.server.protocol {
* Comma separated list of installed typing packages * Comma separated list of installed typing packages
*/ */
installedPackages: string; installedPackages: string;
/**
* true if install request succeeded, otherwise - false
*/
installSuccess: boolean;
} }
export interface NavBarResponse extends Response { export interface NavBarResponse extends Response {

View file

@ -299,7 +299,8 @@ namespace ts.server {
const body: protocol.TypingsInstalledTelemetryEventBody = { const body: protocol.TypingsInstalledTelemetryEventBody = {
telemetryEventName: "typingsInstalled", telemetryEventName: "typingsInstalled",
payload: { payload: {
installedPackages: response.packagesToInstall.join(",") installedPackages: response.packagesToInstall.join(","),
installSuccess: response.installSuccess
} }
}; };
const eventName: protocol.TelemetryEventName = "telemetry"; const eventName: protocol.TelemetryEventName = "telemetry";

View file

@ -68,6 +68,7 @@ declare namespace ts.server {
export interface TypingsInstallEvent extends TypingInstallerResponse { export interface TypingsInstallEvent extends TypingInstallerResponse {
readonly packagesToInstall: ReadonlyArray<string>; readonly packagesToInstall: ReadonlyArray<string>;
readonly kind: EventInstall; readonly kind: EventInstall;
readonly installSuccess: boolean;
} }
export interface InstallTypingHost extends JsTyping.TypingResolutionHost { export interface InstallTypingHost extends JsTyping.TypingResolutionHost {

View file

@ -135,12 +135,12 @@ namespace ts.server.typingsInstaller {
} }
const command = `${this.npmPath} install ${args.join(" ")} --save-dev`; const command = `${this.npmPath} install ${args.join(" ")} --save-dev`;
const start = Date.now(); const start = Date.now();
this.exec(command, { cwd }, (_err, stdout, stderr) => { this.exec(command, { cwd }, (err, stdout, stderr) => {
if (this.log.isEnabled()) { if (this.log.isEnabled()) {
this.log.writeLine(`npm install #${requestId} took: ${Date.now() - start} ms${sys.newLine}stdout: ${stdout}${sys.newLine}stderr: ${stderr}`); this.log.writeLine(`npm install #${requestId} took: ${Date.now() - start} ms${sys.newLine}stdout: ${stdout}${sys.newLine}stderr: ${stderr}`);
} }
// treat any output on stdout as success // treat absence of error as success
onRequestCompleted(!!stdout); onRequestCompleted(!err);
}); });
} }
} }

View file

@ -218,7 +218,7 @@ namespace ts.server.typingsInstaller {
this.knownCachesSet[cacheLocation] = true; this.knownCachesSet[cacheLocation] = true;
} }
private filterAndMapToScopedName(typingsToInstall: string[]) { private filterTypings(typingsToInstall: string[]) {
if (typingsToInstall.length === 0) { if (typingsToInstall.length === 0) {
return typingsToInstall; return typingsToInstall;
} }
@ -230,7 +230,7 @@ namespace ts.server.typingsInstaller {
const validationResult = validatePackageName(typing); const validationResult = validatePackageName(typing);
if (validationResult === PackageNameValidationResult.Ok) { if (validationResult === PackageNameValidationResult.Ok) {
if (typing in this.typesRegistry) { if (typing in this.typesRegistry) {
result.push(`@types/${typing}`); result.push(typing);
} }
else { else {
if (this.log.isEnabled()) { if (this.log.isEnabled()) {
@ -286,7 +286,8 @@ namespace ts.server.typingsInstaller {
if (this.log.isEnabled()) { if (this.log.isEnabled()) {
this.log.writeLine(`Installing typings ${JSON.stringify(typingsToInstall)}`); this.log.writeLine(`Installing typings ${JSON.stringify(typingsToInstall)}`);
} }
const scopedTypings = this.filterAndMapToScopedName(typingsToInstall); const filteredTypings = this.filterTypings(typingsToInstall);
const scopedTypings = filteredTypings.map(x => `@types/${x}`);
if (scopedTypings.length === 0) { if (scopedTypings.length === 0) {
if (this.log.isEnabled()) { if (this.log.isEnabled()) {
this.log.writeLine(`All typings are known to be missing or invalid - no need to go any further`); this.log.writeLine(`All typings are known to be missing or invalid - no need to go any further`);
@ -303,11 +304,18 @@ namespace ts.server.typingsInstaller {
if (this.telemetryEnabled) { if (this.telemetryEnabled) {
this.sendResponse(<TypingsInstallEvent>{ this.sendResponse(<TypingsInstallEvent>{
kind: EventInstall, kind: EventInstall,
packagesToInstall: scopedTypings packagesToInstall: scopedTypings,
installSuccess: ok
}); });
} }
if (!ok) { if (!ok) {
if (this.log.isEnabled()) {
this.log.writeLine(`install request failed, marking packages as missing to prevent repeated requests: ${JSON.stringify(filteredTypings)}`);
}
for (const typing of filteredTypings) {
this.missingTypingsSet[typing] = true;
}
return; return;
} }