Skip to content

Commit b350b1c

Browse files
committed
treat failures to resolve module name as missing packages (#12237)
1 parent 57feab3 commit b350b1c

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/server/typingsInstaller/typingsInstaller.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,17 @@ namespace ts.server.typingsInstaller {
1919
writeLine: noop
2020
};
2121

22-
function typingToFileName(cachePath: string, packageName: string, installTypingHost: InstallTypingHost): string {
23-
const result = resolveModuleName(packageName, combinePaths(cachePath, "index.d.ts"), { moduleResolution: ModuleResolutionKind.NodeJs }, installTypingHost);
24-
return result.resolvedModule && result.resolvedModule.resolvedFileName;
22+
function typingToFileName(cachePath: string, packageName: string, installTypingHost: InstallTypingHost, log: Log): string {
23+
try {
24+
const result = resolveModuleName(packageName, combinePaths(cachePath, "index.d.ts"), { moduleResolution: ModuleResolutionKind.NodeJs }, installTypingHost);
25+
return result.resolvedModule && result.resolvedModule.resolvedFileName;
26+
}
27+
catch (e) {
28+
if (log.isEnabled()) {
29+
log.writeLine(`Failed to resolve ${packageName} in folder '${cachePath}': ${(<Error>e).message}`);
30+
}
31+
return undefined;
32+
}
2533
}
2634

2735
export enum PackageNameValidationResult {
@@ -192,8 +200,9 @@ namespace ts.server.typingsInstaller {
192200
if (!packageName) {
193201
continue;
194202
}
195-
const typingFile = typingToFileName(cacheLocation, packageName, this.installTypingHost);
203+
const typingFile = typingToFileName(cacheLocation, packageName, this.installTypingHost, this.log);
196204
if (!typingFile) {
205+
this.missingTypingsSet[packageName] = true;
197206
continue;
198207
}
199208
const existingTypingFile = this.packageNameToTypingLocation[packageName];
@@ -321,16 +330,13 @@ namespace ts.server.typingsInstaller {
321330

322331
// TODO: watch project directory
323332
if (this.log.isEnabled()) {
324-
this.log.writeLine(`Requested to install typings ${JSON.stringify(scopedTypings)}, installed typings ${JSON.stringify(scopedTypings)}`);
333+
this.log.writeLine(`Installed typings ${JSON.stringify(scopedTypings)}`);
325334
}
326335
const installedTypingFiles: string[] = [];
327-
for (const t of scopedTypings) {
328-
const packageName = getBaseFileName(t);
329-
if (!packageName) {
330-
continue;
331-
}
332-
const typingFile = typingToFileName(cachePath, packageName, this.installTypingHost);
336+
for (const packageName of filteredTypings) {
337+
const typingFile = typingToFileName(cachePath, packageName, this.installTypingHost, this.log);
333338
if (!typingFile) {
339+
this.missingTypingsSet[packageName] = true;
334340
continue;
335341
}
336342
if (!this.packageNameToTypingLocation[packageName]) {

0 commit comments

Comments
 (0)