mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Merge pull request #24769 from Microsoft/ignoreWindowsUsersFolder
Do not watch folders like "c:/users/username", "c:/users/username/folderAtRoot"
This commit is contained in:
commit
604bebab86
@ -349,8 +349,32 @@ namespace ts {
|
||||
return endsWith(dirPath, "/node_modules/@types");
|
||||
}
|
||||
|
||||
function isDirectoryAtleastAtLevelFromFSRoot(dirPath: Path, minLevels: number) {
|
||||
for (let searchIndex = getRootLength(dirPath); minLevels > 0; minLevels--) {
|
||||
/**
|
||||
* Filter out paths like
|
||||
* "/", "/user", "/user/username", "/user/username/folderAtRoot",
|
||||
* "c:/", "c:/users", "c:/users/username", "c:/users/username/folderAtRoot", "c:/folderAtRoot"
|
||||
* @param dirPath
|
||||
*/
|
||||
function canWatchDirectory(dirPath: Path) {
|
||||
const rootLength = getRootLength(dirPath);
|
||||
if (dirPath.length === rootLength) {
|
||||
// Ignore "/", "c:/"
|
||||
return false;
|
||||
}
|
||||
|
||||
const nextDirectorySeparator = dirPath.indexOf(directorySeparator, rootLength);
|
||||
if (nextDirectorySeparator === -1) {
|
||||
// ignore "/user", "c:/users" or "c:/folderAtRoot"
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dirPath.charCodeAt(0) !== CharacterCodes.slash &&
|
||||
dirPath.substr(rootLength, nextDirectorySeparator).search(/users/i) === -1) {
|
||||
// Paths like c:/folderAtRoot/subFolder are allowed
|
||||
return true;
|
||||
}
|
||||
|
||||
for (let searchIndex = nextDirectorySeparator + 1, searchLevels = 2; searchLevels > 0; searchLevels--) {
|
||||
searchIndex = dirPath.indexOf(directorySeparator, searchIndex) + 1;
|
||||
if (searchIndex === 0) {
|
||||
// Folder isnt at expected minimun levels
|
||||
@ -360,15 +384,6 @@ namespace ts {
|
||||
return true;
|
||||
}
|
||||
|
||||
function canWatchDirectory(dirPath: Path) {
|
||||
return isDirectoryAtleastAtLevelFromFSRoot(dirPath,
|
||||
// When root is "/" do not watch directories like:
|
||||
// "/", "/user", "/user/username", "/user/username/folderAtRoot"
|
||||
// When root is "c:/" do not watch directories like:
|
||||
// "c:/", "c:/folderAtRoot"
|
||||
dirPath.charCodeAt(0) === CharacterCodes.slash ? 3 : 1);
|
||||
}
|
||||
|
||||
function filterFSRootDirectoriesToWatch(watchPath: DirectoryOfFailedLookupWatch, dirPath: Path): DirectoryOfFailedLookupWatch {
|
||||
if (!canWatchDirectory(dirPath)) {
|
||||
watchPath.ignore = true;
|
||||
|
||||
@ -7564,8 +7564,8 @@ namespace ts.projectSystem {
|
||||
});
|
||||
|
||||
describe("tsserverProjectSystem Watched recursive directories with windows style file system", () => {
|
||||
function verifyWatchedDirectories(useProjectAtRoot: boolean) {
|
||||
const root = useProjectAtRoot ? "c:/" : "c:/myfolder/allproject/";
|
||||
function verifyWatchedDirectories(rootedPath: string, useProjectAtRoot: boolean) {
|
||||
const root = useProjectAtRoot ? rootedPath : `${rootedPath}myfolder/allproject/`;
|
||||
const configFile: File = {
|
||||
path: root + "project/tsconfig.json",
|
||||
content: "{}"
|
||||
@ -7594,12 +7594,22 @@ namespace ts.projectSystem {
|
||||
].concat(useProjectAtRoot ? [] : [root + nodeModulesAtTypes]), /*recursive*/ true);
|
||||
}
|
||||
|
||||
it("When project is in rootFolder", () => {
|
||||
verifyWatchedDirectories(/*useProjectAtRoot*/ true);
|
||||
function verifyRootedDirectoryWatch(rootedPath: string) {
|
||||
it("When project is in rootFolder of style c:/", () => {
|
||||
verifyWatchedDirectories(rootedPath, /*useProjectAtRoot*/ true);
|
||||
});
|
||||
|
||||
it("When files at some folder other than root", () => {
|
||||
verifyWatchedDirectories(rootedPath, /*useProjectAtRoot*/ false);
|
||||
});
|
||||
}
|
||||
|
||||
describe("for rootFolder of style c:/", () => {
|
||||
verifyRootedDirectoryWatch("c:/");
|
||||
});
|
||||
|
||||
it("When files at some folder other than root", () => {
|
||||
verifyWatchedDirectories(/*useProjectAtRoot*/ false);
|
||||
describe("for rootFolder of style c:/users/username", () => {
|
||||
verifyRootedDirectoryWatch("c:/users/username/");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user