Skip to content

Commit 7b8426d

Browse files
Merge pull request microsoft#24596 from uniqueiniquity/handleMissingRegistryEntries
Handle missing registry entries
2 parents 5f6660b + c6bab0f commit 7b8426d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/harness/unittests/typingsInstaller.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,27 @@ namespace ts.projectSystem {
13401340
assert.deepEqual(result.newTypingNames, ["bar"]);
13411341
});
13421342

1343+
it("should gracefully handle packages that have been removed from the types-registry", () => {
1344+
const f = {
1345+
path: "/a/b/app.js",
1346+
content: ""
1347+
};
1348+
const node = {
1349+
path: "/a/b/node.d.ts",
1350+
content: ""
1351+
};
1352+
const host = createServerHost([f, node]);
1353+
const cache = createMapFromTemplate<JsTyping.CachedTyping>({ node: { typingLocation: node.path, version: Semver.parse("1.3.0") } });
1354+
const logger = trackingLogger();
1355+
const result = JsTyping.discoverTypings(host, logger.log, [f.path], getDirectoryPath(<Path>f.path), emptySafeList, cache, { enable: true }, ["fs", "bar"], emptyMap);
1356+
assert.deepEqual(logger.finish(), [
1357+
'Inferred typings from unresolved imports: ["node","bar"]',
1358+
'Result: {"cachedTypingPaths":[],"newTypingNames":["node","bar"],"filesToWatch":["/a/b/bower_components","/a/b/node_modules"]}',
1359+
]);
1360+
assert.deepEqual(result.cachedTypingPaths, []);
1361+
assert.deepEqual(result.newTypingNames, ["node", "bar"]);
1362+
});
1363+
13431364
it("should search only 2 levels deep", () => {
13441365
const app = {
13451366
path: "/app.js",

src/services/jsTyping.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ namespace ts.JsTyping {
160160
}
161161
// Add the cached typing locations for inferred typings that are already installed
162162
packageNameToTypingLocation.forEach((typing, name) => {
163-
if (inferredTypings.has(name) && inferredTypings.get(name) === undefined && isTypingUpToDate(typing, typesRegistry.get(name)!)) {
163+
const registryEntry = typesRegistry.get(name);
164+
if (inferredTypings.has(name) && inferredTypings.get(name) === undefined && registryEntry !== undefined && isTypingUpToDate(typing, registryEntry)) {
164165
inferredTypings.set(name, typing.typingLocation);
165166
}
166167
});

0 commit comments

Comments
 (0)