Skip to content

Commit d34b865

Browse files
Respond to CR
1 parent aff02e8 commit d34b865

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/server/typingsInstaller/typingsInstaller.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ namespace ts.server.typingsInstaller {
309309
continue;
310310
}
311311

312-
const newVersion = Semver.parse(this.typesRegistry.get(packageName)[`ts${ts.versionMajorMinor}`]);
312+
// packageName is guaranteed to exist in typesRegistry by filterTypings
313+
const distTags = this.typesRegistry.get(packageName);
314+
const newVersion = Semver.parse(distTags[`ts${ts.versionMajorMinor}`] || distTags["latest"]);
313315
const newTyping: JsTyping.CachedTyping = { typingLocation: typingFile, version: newVersion };
314316
this.packageNameToTypingLocation.set(packageName, newTyping);
315317
installedTypingFiles.push(typingFile);

src/services/semver.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @internal */
22
namespace ts {
3-
function intOfString(str: string): number {
3+
function stringToInt(str: string): number {
44
const n = parseInt(str, 10);
55
if (isNaN(n)) {
66
throw new Error(`Error in parseInt(${JSON.stringify(str)})`);
@@ -28,10 +28,10 @@ namespace ts {
2828
// "A normal version number MUST take the form X.Y.Z where X, Y, and Z are non-negative integers, and MUST NOT contain leading zeroes."
2929
const rgx = isPrerelease ? /^(\d+)\.(\d+)\.0-next.(\d+)$/ : /^(\d+)\.(\d+)\.(\d+)$/;
3030
const match = rgx.exec(semver);
31-
return match ? new Semver(intOfString(match[1]), intOfString(match[2]), intOfString(match[3]), isPrerelease) : undefined;
31+
return match ? new Semver(stringToInt(match[1]), stringToInt(match[2]), stringToInt(match[3]), isPrerelease) : undefined;
3232
}
3333

34-
constructor(
34+
private constructor(
3535
readonly major: number, readonly minor: number, readonly patch: number,
3636
/**
3737
* If true, this is `major.minor.0-next.patch`.
@@ -49,7 +49,9 @@ namespace ts {
4949

5050
greaterThan(sem: Semver): boolean {
5151
return this.major > sem.major || this.major === sem.major
52-
&& (this.minor > sem.minor || this.minor === sem.minor && this.patch > sem.patch);
52+
&& (this.minor > sem.minor || this.minor === sem.minor
53+
&& (!this.isPrerelease && sem.isPrerelease || this.isPrerelease === sem.isPrerelease
54+
&& this.patch > sem.patch));
5355
}
5456
}
5557
}

0 commit comments

Comments
 (0)