Skip to content

Commit 0a3afb5

Browse files
authored
treat failures to resolve module name as missing packages (#12237)
1 parent dcaad61 commit 0a3afb5

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: () => { }
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 {
@@ -189,8 +197,9 @@ namespace ts.server.typingsInstaller {
189197
if (!packageName) {
190198
continue;
191199
}
192-
const typingFile = typingToFileName(cacheLocation, packageName, this.installTypingHost);
200+
const typingFile = typingToFileName(cacheLocation, packageName, this.installTypingHost, this.log);
193201
if (!typingFile) {
202+
this.missingTypingsSet[packageName] = true;
194203
continue;
195204
}
196205
const existingTypingFile = this.packageNameToTypingLocation[packageName];
@@ -315,16 +324,13 @@ namespace ts.server.typingsInstaller {
315324

316325
// TODO: watch project directory
317326
if (this.log.isEnabled()) {
318-
this.log.writeLine(`Requested to install typings ${JSON.stringify(scopedTypings)}, installed typings ${JSON.stringify(scopedTypings)}`);
327+
this.log.writeLine(`Installed typings ${JSON.stringify(scopedTypings)}`);
319328
}
320329
const installedTypingFiles: string[] = [];
321-
for (const t of scopedTypings) {
322-
const packageName = getBaseFileName(t);
323-
if (!packageName) {
324-
continue;
325-
}
326-
const typingFile = typingToFileName(cachePath, packageName, this.installTypingHost);
330+
for (const packageName of filteredTypings) {
331+
const typingFile = typingToFileName(cachePath, packageName, this.installTypingHost, this.log);
327332
if (!typingFile) {
333+
this.missingTypingsSet[packageName] = true;
328334
continue;
329335
}
330336
if (!this.packageNameToTypingLocation[packageName]) {

0 commit comments

Comments
 (0)