Skip to content

Commit e40f294

Browse files
committed
Revert "Do not watch child directories of the sym link folders"
This reverts commit 3280865.
1 parent 3280865 commit e40f294

File tree

3 files changed

+16
-70
lines changed

3 files changed

+16
-70
lines changed

src/compiler/sys.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ namespace ts {
337337
getAccessileSortedChildDirectories(path: string): ReadonlyArray<string>;
338338
directoryExists(dir: string): boolean;
339339
filePathComparer: Comparer<string>;
340-
realpath(s: string): string;
341340
}
342341

343342
/**
@@ -393,12 +392,9 @@ namespace ts {
393392
function watchChildDirectories(parentDir: string, existingChildWatches: ChildWatches, callback: DirectoryWatcherCallback): ChildWatches {
394393
let newChildWatches: DirectoryWatcher[] | undefined;
395394
enumerateInsertsAndDeletes<string, DirectoryWatcher>(
396-
host.directoryExists(parentDir) ? mapDefined(host.getAccessileSortedChildDirectories(parentDir), child => {
397-
const childFullName = getNormalizedAbsolutePath(child, parentDir);
398-
return host.filePathComparer(childFullName, host.realpath(childFullName)) === Comparison.EqualTo ? childFullName : undefined;
399-
}) : emptyArray,
395+
host.directoryExists(parentDir) ? host.getAccessileSortedChildDirectories(parentDir) : emptyArray,
400396
existingChildWatches,
401-
(child, childWatcher) => host.filePathComparer(child, childWatcher.dirName),
397+
(child, childWatcher) => host.filePathComparer(getNormalizedAbsolutePath(child, parentDir), childWatcher.dirName),
402398
createAndAddChildDirectoryWatcher,
403399
closeFileWatcher,
404400
addChildDirectoryWatcher
@@ -410,7 +406,7 @@ namespace ts {
410406
* Create new childDirectoryWatcher and add it to the new ChildDirectoryWatcher list
411407
*/
412408
function createAndAddChildDirectoryWatcher(childName: string) {
413-
const result = createDirectoryWatcher(childName, callback);
409+
const result = createDirectoryWatcher(getNormalizedAbsolutePath(childName, parentDir), callback);
414410
addChildDirectoryWatcher(result);
415411
}
416412

@@ -605,7 +601,14 @@ namespace ts {
605601
exit(exitCode?: number): void {
606602
process.exit(exitCode);
607603
},
608-
realpath,
604+
realpath(path: string): string {
605+
try {
606+
return _fs.realpathSync(path);
607+
}
608+
catch {
609+
return path;
610+
}
611+
},
609612
debugMode: some(<string[]>process.execArgv, arg => /^--(inspect|debug)(-brk)?(=\d+)?$/i.test(arg)),
610613
tryEnableSourceMapsForHost() {
611614
try {
@@ -697,8 +700,7 @@ namespace ts {
697700
filePathComparer: useCaseSensitiveFileNames ? compareStringsCaseSensitive : compareStringsCaseInsensitive,
698701
directoryExists,
699702
getAccessileSortedChildDirectories: path => getAccessibleFileSystemEntries(path).directories,
700-
watchDirectory,
701-
realpath
703+
watchDirectory
702704
});
703705

704706
return (directoryName, callback, recursive) => {
@@ -1041,15 +1043,6 @@ namespace ts {
10411043
return filter<string>(_fs.readdirSync(path), dir => fileSystemEntryExists(combinePaths(path, dir), FileSystemEntryKind.Directory));
10421044
}
10431045

1044-
function realpath(path: string): string {
1045-
try {
1046-
return _fs.realpathSync(path);
1047-
}
1048-
catch {
1049-
return path;
1050-
}
1051-
}
1052-
10531046
function getModifiedTime(path: string) {
10541047
try {
10551048
return _fs.statSync(path).mtime;

src/harness/unittests/tscWatchMode.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,50 +2358,6 @@ declare module "fs" {
23582358
it("uses non recursive dynamic polling when renaming file in subfolder", () => {
23592359
verifyRenamingFileInSubFolder(TestFSWithWatch.Tsc_WatchDirectory.DynamicPolling);
23602360
});
2361-
2362-
it("when there are symlinks to folders in recursive folders", () => {
2363-
const cwd = "/home/user/projects/myproject";
2364-
const file1: FileOrFolder = {
2365-
path: `${cwd}/src/file.ts`,
2366-
content: `import * as a from "a"`
2367-
};
2368-
const tsconfig: FileOrFolder = {
2369-
path: `${cwd}/tsconfig.json`,
2370-
content: `{ "compilerOptions": { "extendedDiagnostics": true, "traceResolution": true }}`
2371-
};
2372-
const realA: FileOrFolder = {
2373-
path: `${cwd}/node_modules/reala/index.d.ts`,
2374-
content: `export {}`
2375-
};
2376-
const realB: FileOrFolder = {
2377-
path: `${cwd}/node_modules/realb/index.d.ts`,
2378-
content: `export {}`
2379-
};
2380-
const symLinkA: FileOrFolder = {
2381-
path: `${cwd}/node_modules/a`,
2382-
symLink: `${cwd}/node_modules/reala`
2383-
};
2384-
const symLinkB: FileOrFolder = {
2385-
path: `${cwd}/node_modules/b`,
2386-
symLink: `${cwd}/node_modules/realb`
2387-
};
2388-
const symLinkBInA: FileOrFolder = {
2389-
path: `${cwd}/node_modules/reala/node_modules/b`,
2390-
symLink: `${cwd}/node_modules/b`
2391-
};
2392-
const symLinkAInB: FileOrFolder = {
2393-
path: `${cwd}/node_modules/realb/node_modules/a`,
2394-
symLink: `${cwd}/node_modules/a`
2395-
};
2396-
const files = [file1, tsconfig, realA, realB, symLinkA, symLinkB, symLinkBInA, symLinkAInB];
2397-
const environmentVariables = createMap<string>();
2398-
environmentVariables.set("TSC_WATCHDIRECTORY", TestFSWithWatch.Tsc_WatchDirectory.NonRecursiveWatchDirectory);
2399-
const host = createWatchedSystem(files, { environmentVariables, currentDirectory: cwd });
2400-
createWatchOfConfigFile("tsconfig.json", host);
2401-
checkWatchedDirectories(host, emptyArray, /*recursive*/ true);
2402-
checkWatchedDirectories(host, [cwd, `${cwd}/node_modules`, `${cwd}/node_modules/@types`, `${cwd}/node_modules/reala`, `${cwd}/node_modules/realb`,
2403-
`${cwd}/node_modules/reala/node_modules`, `${cwd}/node_modules/realb/node_modules`, `${cwd}/src`], /*recursive*/ false);
2404-
});
24052361
});
24062362
});
24072363
}

src/harness/virtualFileSystemWithWatch.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,7 @@ interface Array<T> {}`
314314
directoryExists: path => this.directoryExists(path),
315315
getAccessileSortedChildDirectories: path => this.getDirectories(path),
316316
filePathComparer: this.useCaseSensitiveFileNames ? compareStringsCaseSensitive : compareStringsCaseInsensitive,
317-
watchDirectory,
318-
realpath: s => this.realpath(s)
317+
watchDirectory
319318
});
320319
}
321320
else if (tscWatchDirectory === Tsc_WatchDirectory.NonRecursiveWatchDirectory) {
@@ -324,8 +323,7 @@ interface Array<T> {}`
324323
directoryExists: path => this.directoryExists(path),
325324
getAccessileSortedChildDirectories: path => this.getDirectories(path),
326325
filePathComparer: this.useCaseSensitiveFileNames ? compareStringsCaseSensitive : compareStringsCaseInsensitive,
327-
watchDirectory,
328-
realpath: s => this.realpath(s)
326+
watchDirectory
329327
});
330328
}
331329
else if (tscWatchDirectory === Tsc_WatchDirectory.DynamicPolling) {
@@ -335,8 +333,7 @@ interface Array<T> {}`
335333
directoryExists: path => this.directoryExists(path),
336334
getAccessileSortedChildDirectories: path => this.getDirectories(path),
337335
filePathComparer: this.useCaseSensitiveFileNames ? compareStringsCaseSensitive : compareStringsCaseInsensitive,
338-
watchDirectory,
339-
realpath: s => this.realpath(s)
336+
watchDirectory
340337
});
341338
}
342339
}
@@ -652,7 +649,7 @@ interface Array<T> {}`
652649

653650
const realpath = this.realpath(path);
654651
if (path !== realpath) {
655-
return this.getRealFsEntry(isFsEntry, this.toPath(realpath));
652+
return this.getRealFsEntry(isFsEntry, realpath as Path);
656653
}
657654

658655
return undefined;

0 commit comments

Comments
 (0)