Merge pull request #24596 from uniqueiniquity/handleMissingRegistryEntries

Handle missing registry entries
This commit is contained in:
Benjamin Lichtman 2018-06-04 09:47:10 -07:00 committed by GitHub
commit 7b8426d81c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -1340,6 +1340,27 @@ namespace ts.projectSystem {
assert.deepEqual(result.newTypingNames, ["bar"]);
});
it("should gracefully handle packages that have been removed from the types-registry", () => {
const f = {
path: "/a/b/app.js",
content: ""
};
const node = {
path: "/a/b/node.d.ts",
content: ""
};
const host = createServerHost([f, node]);
const cache = createMapFromTemplate<JsTyping.CachedTyping>({ node: { typingLocation: node.path, version: Semver.parse("1.3.0") } });
const logger = trackingLogger();
const result = JsTyping.discoverTypings(host, logger.log, [f.path], getDirectoryPath(<Path>f.path), emptySafeList, cache, { enable: true }, ["fs", "bar"], emptyMap);
assert.deepEqual(logger.finish(), [
'Inferred typings from unresolved imports: ["node","bar"]',
'Result: {"cachedTypingPaths":[],"newTypingNames":["node","bar"],"filesToWatch":["/a/b/bower_components","/a/b/node_modules"]}',
]);
assert.deepEqual(result.cachedTypingPaths, []);
assert.deepEqual(result.newTypingNames, ["node", "bar"]);
});
it("should search only 2 levels deep", () => {
const app = {
path: "/app.js",

View File

@ -160,7 +160,8 @@ namespace ts.JsTyping {
}
// Add the cached typing locations for inferred typings that are already installed
packageNameToTypingLocation.forEach((typing, name) => {
if (inferredTypings.has(name) && inferredTypings.get(name) === undefined && isTypingUpToDate(typing, typesRegistry.get(name)!)) {
const registryEntry = typesRegistry.get(name);
if (inferredTypings.has(name) && inferredTypings.get(name) === undefined && registryEntry !== undefined && isTypingUpToDate(typing, registryEntry)) {
inferredTypings.set(name, typing.typingLocation);
}
});