Skip to content

Commit 3d15185

Browse files
committed
update
1 parent 95527eb commit 3d15185

File tree

1 file changed

+8
-27
lines changed

1 file changed

+8
-27
lines changed

src/ts.ts

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export class TSServiceManager {
4343
export class TSService {
4444
private readonly watch: ts.WatchOfConfigFile<ts.BuilderProgram>;
4545

46+
private readonly tsconfigPath: string;
47+
4648
public readonly extraFileExtensions: string[];
4749

4850
private currTarget = {
@@ -53,9 +55,8 @@ export class TSService {
5355

5456
private readonly fileWatchCallbacks = new Map<string, () => void>();
5557

56-
private readonly dirWatchCallbacks = new Map<string, () => void>();
57-
5858
public constructor(tsconfigPath: string, extraFileExtensions: string[]) {
59+
this.tsconfigPath = tsconfigPath;
5960
this.extraFileExtensions = extraFileExtensions;
6061
this.watch = this.createWatch(tsconfigPath, extraFileExtensions);
6162
}
@@ -77,31 +78,13 @@ export class TSService {
7778
filePath: normalized,
7879
dirMap,
7980
};
80-
for (const { filePath: targetPath, dirMap: map } of [
81-
this.currTarget,
82-
lastTarget,
83-
]) {
81+
for (const { filePath: targetPath } of [this.currTarget, lastTarget]) {
8482
if (!targetPath) continue;
85-
if (ts.sys.fileExists(targetPath)) {
86-
getFileNamesIncludingVirtualTSX(
87-
targetPath,
88-
this.extraFileExtensions
89-
).forEach((vFilePath) => {
90-
this.fileWatchCallbacks.get(vFilePath)?.();
91-
});
92-
} else {
83+
if (!ts.sys.fileExists(targetPath)) {
9384
// Signal a directory change to request a re-scan of the directory
9485
// because it targets a file that does not actually exist.
95-
for (const dirName of map.keys()) {
96-
this.dirWatchCallbacks.get(dirName)?.();
97-
}
86+
this.fileWatchCallbacks.get(normalizeFileName(this.tsconfigPath))?.();
9887
}
99-
}
100-
101-
const refreshTargetPaths = [normalized, lastTarget.filePath].filter(
102-
(s) => s
103-
);
104-
for (const targetPath of refreshTargetPaths) {
10588
getFileNamesIncludingVirtualTSX(
10689
targetPath,
10790
this.extraFileExtensions
@@ -281,12 +264,10 @@ export class TSService {
281264
};
282265
};
283266
// Use watchCompilerHost but don't actually watch the files and directories.
284-
watchCompilerHost.watchDirectory = (dirName, callback) => {
285-
const normalized = normalizeFileName(dirName);
286-
this.dirWatchCallbacks.set(normalized, () => callback(dirName));
267+
watchCompilerHost.watchDirectory = () => {
287268
return {
288269
close: () => {
289-
this.dirWatchCallbacks.delete(normalized);
270+
// noop
290271
},
291272
};
292273
};

0 commit comments

Comments
 (0)