Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/compiler/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,4 +852,8 @@ namespace ts {
directory = parentPath;
}
}

export function isNodeModulesDirectory(dirPath: Path) {
return endsWith(dirPath, "/node_modules");
}
}
4 changes: 0 additions & 4 deletions src/compiler/resolutionCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,6 @@ namespace ts {
return cache && cache.get(moduleName);
}

function isNodeModulesDirectory(dirPath: Path) {
return endsWith(dirPath, "/node_modules");
}

function isNodeModulesAtTypesDirectory(dirPath: Path) {
return endsWith(dirPath, "/node_modules/@types");
}
Expand Down
7 changes: 7 additions & 0 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,13 @@ namespace ts.server {
const jsconfigFileName = asNormalizedPath(combinePaths(searchPath, "jsconfig.json"));
result = action(jsconfigFileName, combinePaths(canonicalSearchPath, "jsconfig.json"));
if (result) return jsconfigFileName;

// If we started within node_modules, don't look outside node_modules.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add tests so we have coverage for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this was originally a draft PR to get feedback and I forgot to add them when I promoted it. Will do.

// Otherwise, we might pick up a very large project and pull in the world,
// causing an editor delay.
if (isNodeModulesDirectory(canonicalSearchPath)) {
break;
}
}

const parentPath = asNormalizedPath(getDirectoryPath(searchPath));
Expand Down