Skip to content

Commit 09f29ad

Browse files
vladimamhegazy
authored andcommitted
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
1 parent cc81fa7 commit 09f29ad

5 files changed

Lines changed: 21 additions & 7 deletions

File tree

src/server/protocol.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,6 +1964,10 @@ namespace ts.server.protocol {
19641964
* Comma separated list of installed typing packages
19651965
*/
19661966
installedPackages: string;
1967+
/**
1968+
* true if install request succeeded, otherwise - false
1969+
*/
1970+
installSuccess: boolean;
19671971
}
19681972

19691973
export interface NavBarResponse extends Response {

src/server/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ namespace ts.server {
265265
const body: protocol.TypingsInstalledTelemetryEventBody = {
266266
telemetryEventName: "typingsInstalled",
267267
payload: {
268-
installedPackages: response.packagesToInstall.join(",")
268+
installedPackages: response.packagesToInstall.join(","),
269+
installSuccess: response.installSuccess
269270
}
270271
};
271272
const eventName: protocol.TelemetryEventName = "telemetry";

src/server/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ declare namespace ts.server {
6262
export interface TypingsInstallEvent extends TypingInstallerResponse {
6363
readonly packagesToInstall: ReadonlyArray<string>;
6464
readonly kind: EventInstall;
65+
readonly installSuccess: boolean;
6566
}
6667

6768
export interface InstallTypingHost extends JsTyping.TypingResolutionHost {

src/server/typingsInstaller/nodeTypingsInstaller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ namespace ts.server.typingsInstaller {
139139
if (this.log.isEnabled()) {
140140
this.log.writeLine(`npm install #${requestId} took: ${Date.now() - start} ms${sys.newLine}stdout: ${stdout}${sys.newLine}stderr: ${stderr}`);
141141
}
142-
// treat any output on stdout as success
143-
onRequestCompleted(!!stdout);
142+
// treat absence of error as success
143+
onRequestCompleted(!err);
144144
});
145145
}
146146
}

src/server/typingsInstaller/typingsInstaller.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ namespace ts.server.typingsInstaller {
215215
this.knownCachesSet[cacheLocation] = true;
216216
}
217217

218-
private filterAndMapToScopedName(typingsToInstall: string[]) {
218+
private filterTypings(typingsToInstall: string[]) {
219219
if (typingsToInstall.length === 0) {
220220
return typingsToInstall;
221221
}
@@ -227,7 +227,7 @@ namespace ts.server.typingsInstaller {
227227
const validationResult = validatePackageName(typing);
228228
if (validationResult === PackageNameValidationResult.Ok) {
229229
if (typing in this.typesRegistry) {
230-
result.push(`@types/${typing}`);
230+
result.push(typing);
231231
}
232232
else {
233233
if (this.log.isEnabled()) {
@@ -280,7 +280,8 @@ namespace ts.server.typingsInstaller {
280280
if (this.log.isEnabled()) {
281281
this.log.writeLine(`Installing typings ${JSON.stringify(typingsToInstall)}`);
282282
}
283-
const scopedTypings = this.filterAndMapToScopedName(typingsToInstall);
283+
const filteredTypings = this.filterTypings(typingsToInstall);
284+
const scopedTypings = filteredTypings.map(x => `@types/${x}`);
284285
if (scopedTypings.length === 0) {
285286
if (this.log.isEnabled()) {
286287
this.log.writeLine(`All typings are known to be missing or invalid - no need to go any further`);
@@ -297,11 +298,18 @@ namespace ts.server.typingsInstaller {
297298
if (this.telemetryEnabled) {
298299
this.sendResponse(<TypingsInstallEvent>{
299300
kind: EventInstall,
300-
packagesToInstall: scopedTypings
301+
packagesToInstall: scopedTypings,
302+
installSuccess: ok
301303
});
302304
}
303305

304306
if (!ok) {
307+
if (this.log.isEnabled()) {
308+
this.log.writeLine(`install request failed, marking packages as missing to prevent repeated requests: ${JSON.stringify(filteredTypings)}`);
309+
}
310+
for (const typing of filteredTypings) {
311+
this.missingTypingsSet[typing] = true;
312+
}
305313
return;
306314
}
307315

0 commit comments

Comments
 (0)