mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Use the parent most node_modules directory for module resolution failed lookup locations
This commit is contained in:
@@ -323,19 +323,17 @@ namespace ts {
|
||||
let dir = getDirectoryPath(getNormalizedAbsolutePath(failedLookupLocation, getCurrentDirectory()));
|
||||
let dirPath = getDirectoryPath(failedLookupLocationPath);
|
||||
|
||||
// If directory path contains node module, get the most parent node_modules directory for watching
|
||||
while (dirPath.indexOf("/node_modules/") !== -1) {
|
||||
dir = getDirectoryPath(dir);
|
||||
dirPath = getDirectoryPath(dirPath);
|
||||
}
|
||||
|
||||
// If the directory is node_modules use it to watch
|
||||
if (isNodeModulesDirectory(dirPath)) {
|
||||
return { dir, dirPath };
|
||||
}
|
||||
|
||||
// If directory path contains node module, get the node_modules directory for watching
|
||||
if (dirPath.indexOf("/node_modules/") !== -1) {
|
||||
while (!isNodeModulesDirectory(dirPath)) {
|
||||
dir = getDirectoryPath(dir);
|
||||
dirPath = getDirectoryPath(dirPath);
|
||||
}
|
||||
return { dir, dirPath };
|
||||
}
|
||||
|
||||
// Use some ancestor of the root directory
|
||||
if (rootPath !== undefined) {
|
||||
|
||||
@@ -2399,6 +2399,43 @@ namespace ts.projectSystem {
|
||||
checkWatchedDirectories(host, watchedRecursiveDirectories, /*recursive*/ true);
|
||||
|
||||
});
|
||||
|
||||
it("Failed lookup locations are uses parent most node_modules directory", () => {
|
||||
const file1: FileOrFolder = {
|
||||
path: "/a/b/src/file1.ts",
|
||||
content: 'import { classc } from "module1"'
|
||||
};
|
||||
const module1: FileOrFolder = {
|
||||
path: "/a/b/node_modules/module1/index.d.ts",
|
||||
content: `import { class2 } from "module2";
|
||||
export classc { method2a(): class2; }`
|
||||
};
|
||||
const module2: FileOrFolder = {
|
||||
path: "/a/b/node_modules/module2/index.d.ts",
|
||||
content: "export class2 { method2() { return 10; } }"
|
||||
};
|
||||
const module3: FileOrFolder = {
|
||||
path: "/a/b/node_modules/module/node_modules/module3/index.d.ts",
|
||||
content: "export class3 { method2() { return 10; } }"
|
||||
};
|
||||
const configFile: FileOrFolder = {
|
||||
path: "/a/b/src/tsconfig.json",
|
||||
content: JSON.stringify({ files: [file1.path] })
|
||||
};
|
||||
const files = [file1, module1, module2, module3, configFile, libFile];
|
||||
const host = createServerHost(files);
|
||||
const projectService = createProjectService(host);
|
||||
projectService.openClientFile(file1.path);
|
||||
checkNumberOfProjects(projectService, { configuredProjects: 1 });
|
||||
const project = projectService.configuredProjects.get(configFile.path);
|
||||
assert.isDefined(project);
|
||||
checkProjectActualFiles(project, [file1.path, libFile.path, module1.path, module2.path, configFile.path]);
|
||||
checkWatchedFiles(host, [libFile.path, module1.path, module2.path, configFile.path]);
|
||||
checkWatchedDirectories(host, [], /*recursive*/ false);
|
||||
const watchedRecursiveDirectories = getTypeRootsFromLocation("/a/b/src");
|
||||
watchedRecursiveDirectories.push("/a/b/src", "/a/b/node_modules");
|
||||
checkWatchedDirectories(host, watchedRecursiveDirectories, /*recursive*/ true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Proper errors", () => {
|
||||
|
||||
Reference in New Issue
Block a user