Skip to content

Commit 58cb9a7

Browse files
author
Andy Hanson
committed
Use "ts2.2" (or "ts2.3", etc.) NPM tag in typingsInstaller
1 parent 445421b commit 58cb9a7

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/harness/unittests/typingsInstaller.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ namespace ts.projectSystem {
4444
});
4545
}
4646

47+
import typingsName = server.typingsInstaller.typingsName;
48+
4749
describe("typingsInstaller", () => {
4850
it("configured projects (typings installed) 1", () => {
4951
const file1 = {
@@ -519,32 +521,32 @@ namespace ts.projectSystem {
519521
const commander = {
520522
path: "/a/data/node_modules/@types/commander/index.d.ts",
521523
content: "declare const commander: { x: number }",
522-
typings: "@types/commander"
524+
typings: typingsName("commander")
523525
};
524526
const jquery = {
525527
path: "/a/data/node_modules/@types/jquery/index.d.ts",
526528
content: "declare const jquery: { x: number }",
527-
typings: "@types/jquery"
529+
typings: typingsName("jquery")
528530
};
529531
const lodash = {
530532
path: "/a/data/node_modules/@types/lodash/index.d.ts",
531533
content: "declare const lodash: { x: number }",
532-
typings: "@types/lodash"
534+
typings: typingsName("lodash")
533535
};
534536
const cordova = {
535537
path: "/a/data/node_modules/@types/cordova/index.d.ts",
536538
content: "declare const cordova: { x: number }",
537-
typings: "@types/cordova"
539+
typings: typingsName("cordova")
538540
};
539541
const grunt = {
540542
path: "/a/data/node_modules/@types/grunt/index.d.ts",
541543
content: "declare const grunt: { x: number }",
542-
typings: "@types/grunt"
544+
typings: typingsName("grunt")
543545
};
544546
const gulp = {
545547
path: "/a/data/node_modules/@types/gulp/index.d.ts",
546548
content: "declare const gulp: { x: number }",
547-
typings: "@types/gulp"
549+
typings: typingsName("gulp")
548550
};
549551

550552
const host = createServerHost([lodashJs, commanderJs, file3]);
@@ -554,7 +556,7 @@ namespace ts.projectSystem {
554556
}
555557
installWorker(_requestId: number, args: string[], _cwd: string, cb: TI.RequestCompletedAction): void {
556558
let typingFiles: (FileOrFolder & { typings: string })[] = [];
557-
if (args.indexOf("@types/commander") >= 0) {
559+
if (args.indexOf(typingsName("commander")) >= 0) {
558560
typingFiles = [commander, jquery, lodash, cordova];
559561
}
560562
else {
@@ -982,7 +984,7 @@ namespace ts.projectSystem {
982984
return;
983985
}
984986
if (response.kind === server.EventEndInstallTypes) {
985-
assert.deepEqual(response.packagesToInstall, ["@types/commander"]);
987+
assert.deepEqual(response.packagesToInstall, [typingsName("commander")]);
986988
seenTelemetryEvent = true;
987989
return;
988990
}

src/server/typingsInstaller/typingsInstaller.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,7 @@ namespace ts.server.typingsInstaller {
295295
this.log.writeLine(`Installing typings ${JSON.stringify(typingsToInstall)}`);
296296
}
297297
const filteredTypings = this.filterTypings(typingsToInstall);
298-
const scopedTypings = filteredTypings.map(x => `@types/${x}`);
299-
if (scopedTypings.length === 0) {
298+
if (filteredTypings.length === 0) {
300299
if (this.log.isEnabled()) {
301300
this.log.writeLine(`All typings are known to be missing or invalid - no need to go any further`);
302301
}
@@ -316,6 +315,7 @@ namespace ts.server.typingsInstaller {
316315
projectName: req.projectName
317316
});
318317

318+
const scopedTypings = filteredTypings.map(typingsName);
319319
this.installTypingsAsync(requestId, scopedTypings, cachePath, ok => {
320320
try {
321321
if (!ok) {
@@ -429,4 +429,10 @@ namespace ts.server.typingsInstaller {
429429
protected abstract installWorker(requestId: number, args: string[], cwd: string, onRequestCompleted: RequestCompletedAction): void;
430430
protected abstract sendResponse(response: SetTypings | InvalidateCachedTypings | BeginInstallTypes | EndInstallTypes): void;
431431
}
432+
433+
/* @internal */
434+
export function typingsName(packageName: string): string {
435+
return `@types/${packageName}@ts${versionMajorMinor}`;
436+
}
437+
const versionMajorMinor = version.split(".").slice(0, 2).join(".");
432438
}

0 commit comments

Comments
 (0)