Use undefined instead of empty array, and check for existence of "node_modules/@types" instead of just for "node_modules".
This commit is contained in:
parent
0e8e5ec3e5
commit
cbd00b9a92
|
@ -182,23 +182,22 @@ namespace ts {
|
||||||
return currentDirectory && getDefaultTypeRoots(currentDirectory, host);
|
return currentDirectory && getDefaultTypeRoots(currentDirectory, host);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the path to every node_modules/@types directory from some ancestor directory.
|
||||||
|
* Returns undefined if there are none.
|
||||||
|
*/
|
||||||
function getDefaultTypeRoots(currentDirectory: string, host: ModuleResolutionHost): string[] | undefined {
|
function getDefaultTypeRoots(currentDirectory: string, host: ModuleResolutionHost): string[] | undefined {
|
||||||
return map(getAllNodeModulesDirectories(currentDirectory, host), nodeModules => combinePaths(nodeModules, "@types"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the path to every node_modules directory from some ancestor directory. */
|
|
||||||
function getAllNodeModulesDirectories(currentDirectory: string, host: ModuleResolutionHost): string[] | undefined {
|
|
||||||
if (!host.directoryExists) {
|
if (!host.directoryExists) {
|
||||||
return [combinePaths(currentDirectory, "node_modules")];
|
return [combinePaths(currentDirectory, "node_modules")];
|
||||||
// And if it doesn't exist, tough.
|
// And if it doesn't exist, tough.
|
||||||
}
|
}
|
||||||
|
|
||||||
const all: string[] = [];
|
let typeRoots: string[];
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const nodeModules = combinePaths(currentDirectory, "node_modules");
|
const atTypes = combinePaths(currentDirectory, nodeModulesAtTypes);
|
||||||
if (host.directoryExists(nodeModules)) {
|
if (host.directoryExists(atTypes)) {
|
||||||
all.push(nodeModules);
|
(typeRoots || (typeRoots = [])).push(atTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
const parent = getDirectoryPath(currentDirectory);
|
const parent = getDirectoryPath(currentDirectory);
|
||||||
|
@ -208,8 +207,10 @@ namespace ts {
|
||||||
currentDirectory = parent;
|
currentDirectory = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
return all;
|
return typeRoots;
|
||||||
}
|
}
|
||||||
|
const nodeModulesAtTypes = combinePaths("node_modules", "@types");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.
|
* @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.
|
||||||
* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups
|
* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
[
|
[
|
||||||
"======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory '/src/node_modules/@types'. ========",
|
"======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory not set. ========",
|
||||||
"Resolving with primary search path '/src/node_modules/@types'",
|
"Root directory cannot be determined, skipping primary search paths.",
|
||||||
"File '/src/node_modules/@types/jquery/package.json' does not exist.",
|
|
||||||
"File '/src/node_modules/@types/jquery/index.d.ts' does not exist.",
|
|
||||||
"Looking up in 'node_modules' folder, initial location '/src'",
|
"Looking up in 'node_modules' folder, initial location '/src'",
|
||||||
"File '/src/node_modules/jquery.ts' does not exist.",
|
"File '/src/node_modules/jquery.ts' does not exist.",
|
||||||
"File '/src/node_modules/jquery.d.ts' does not exist.",
|
"File '/src/node_modules/jquery.d.ts' does not exist.",
|
||||||
|
|
Loading…
Reference in a new issue