Skip to content

Commit 04aaa32

Browse files
authored
add 'installSuccess' flag to telemetry, cache misses if npm install fails (microsoft#12163) (microsoft#12240)
* add 'installSuccess' flag to telemetry, cache misses if npm install fails * fix typo
2 parents 6a67f80 + f11e8a3 commit 04aaa32

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

src/server/protocol.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,6 +2081,10 @@ namespace ts.server.protocol {
20812081
* Comma separated list of installed typing packages
20822082
*/
20832083
installedPackages: string;
2084+
/**
2085+
* true if install request succeeded, otherwise - false
2086+
*/
2087+
installSuccess: boolean;
20842088
}
20852089

20862090
export interface NavBarResponse extends Response {

src/server/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ namespace ts.server {
299299
const body: protocol.TypingsInstalledTelemetryEventBody = {
300300
telemetryEventName: "typingsInstalled",
301301
payload: {
302-
installedPackages: response.packagesToInstall.join(",")
302+
installedPackages: response.packagesToInstall.join(","),
303+
installSuccess: response.installSuccess
303304
}
304305
};
305306
const eventName: protocol.TelemetryEventName = "telemetry";

src/server/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ declare namespace ts.server {
6868
export interface TypingsInstallEvent extends TypingInstallerResponse {
6969
readonly packagesToInstall: ReadonlyArray<string>;
7070
readonly kind: EventInstall;
71+
readonly installSuccess: boolean;
7172
}
7273

7374
export interface InstallTypingHost extends JsTyping.TypingResolutionHost {

src/server/typingsInstaller/nodeTypingsInstaller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ namespace ts.server.typingsInstaller {
135135
}
136136
const command = `${this.npmPath} install ${args.join(" ")} --save-dev`;
137137
const start = Date.now();
138-
this.exec(command, { cwd }, (_err, stdout, stderr) => {
138+
this.exec(command, { cwd }, (err, stdout, stderr) => {
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
@@ -218,7 +218,7 @@ namespace ts.server.typingsInstaller {
218218
this.knownCachesSet[cacheLocation] = true;
219219
}
220220

221-
private filterAndMapToScopedName(typingsToInstall: string[]) {
221+
private filterTypings(typingsToInstall: string[]) {
222222
if (typingsToInstall.length === 0) {
223223
return typingsToInstall;
224224
}
@@ -230,7 +230,7 @@ namespace ts.server.typingsInstaller {
230230
const validationResult = validatePackageName(typing);
231231
if (validationResult === PackageNameValidationResult.Ok) {
232232
if (typing in this.typesRegistry) {
233-
result.push(`@types/${typing}`);
233+
result.push(typing);
234234
}
235235
else {
236236
if (this.log.isEnabled()) {
@@ -286,7 +286,8 @@ namespace ts.server.typingsInstaller {
286286
if (this.log.isEnabled()) {
287287
this.log.writeLine(`Installing typings ${JSON.stringify(typingsToInstall)}`);
288288
}
289-
const scopedTypings = this.filterAndMapToScopedName(typingsToInstall);
289+
const filteredTypings = this.filterTypings(typingsToInstall);
290+
const scopedTypings = filteredTypings.map(x => `@types/${x}`);
290291
if (scopedTypings.length === 0) {
291292
if (this.log.isEnabled()) {
292293
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 {
303304
if (this.telemetryEnabled) {
304305
this.sendResponse(<TypingsInstallEvent>{
305306
kind: EventInstall,
306-
packagesToInstall: scopedTypings
307+
packagesToInstall: scopedTypings,
308+
installSuccess: ok
307309
});
308310
}
309311

310312
if (!ok) {
313+
if (this.log.isEnabled()) {
314+
this.log.writeLine(`install request failed, marking packages as missing to prevent repeated requests: ${JSON.stringify(filteredTypings)}`);
315+
}
316+
for (const typing of filteredTypings) {
317+
this.missingTypingsSet[typing] = true;
318+
}
311319
return;
312320
}
313321

0 commit comments

Comments
 (0)