Skip to content

Commit 8378f69

Browse files
committed
Directly assign values for watchFile and watchDirectory in node System
1 parent ae8637c commit 8378f69

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/compiler/sys.ts

+16-19
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,7 @@ namespace ts {
133133
}
134134

135135
/* @internal */
136-
export function createDynamicPriorityPollingWatchFile(host: System): HostWatchFile {
137-
if (!host.getModifiedTime || !host.setTimeout) {
138-
throw notImplemented();
139-
}
140-
136+
export function createDynamicPriorityPollingWatchFile(host: { getModifiedTime: System["getModifiedTime"]; setTimeout: System["setTimeout"]; }): HostWatchFile {
141137
interface WatchedFile extends ts.WatchedFile {
142138
isClosed?: boolean;
143139
unchangedPolls: number;
@@ -555,6 +551,8 @@ namespace ts {
555551
},
556552
readFile,
557553
writeFile,
554+
watchFile: getWatchFile(),
555+
watchDirectory: getWatchDirectory(),
558556
resolvePath: path => _path.resolve(path),
559557
fileExists,
560558
directoryExists,
@@ -574,14 +572,7 @@ namespace ts {
574572
return process.env[name] || "";
575573
},
576574
readDirectory,
577-
getModifiedTime(path) {
578-
try {
579-
return _fs.statSync(path).mtime;
580-
}
581-
catch (e) {
582-
return undefined;
583-
}
584-
},
575+
getModifiedTime,
585576
createHash: _crypto ? createMD5HashUsingNativeCrypto : generateDjb2Hash,
586577
getMemoryUsage() {
587578
if (global.gc) {
@@ -625,9 +616,6 @@ namespace ts {
625616
process.stdout.write("\x1Bc");
626617
}
627618
};
628-
629-
nodeSystem.watchFile = getWatchFile();
630-
nodeSystem.watchDirectory = getWatchDirectory();
631619
return nodeSystem;
632620

633621
function isFileSystemCaseSensitive(): boolean {
@@ -654,13 +642,13 @@ namespace ts {
654642
return fsWatchFile;
655643
case "DynamicPriorityPolling":
656644
// Use polling interval but change the interval depending on file changes and their default polling interval
657-
return createDynamicPriorityPollingWatchFile(nodeSystem);
645+
return createDynamicPriorityPollingWatchFile({ getModifiedTime, setTimeout });
658646
case "UseFsEvents":
659647
// Use notifications from FS to watch with falling back to fs.watchFile
660648
return watchFileUsingFsWatch;
661649
case "UseFsEventsWithFallbackDynamicPolling":
662650
// Use notifications from FS to watch with falling back to dynamic watch file
663-
dynamicPollingWatchFile = createDynamicPriorityPollingWatchFile(nodeSystem);
651+
dynamicPollingWatchFile = createDynamicPriorityPollingWatchFile({ getModifiedTime, setTimeout });
664652
return createWatchFileUsingDynamicWatchFile(dynamicPollingWatchFile);
665653
case "UseFsEventsOnParentDirectory":
666654
// Use notifications from FS to watch with falling back to fs.watchFile
@@ -683,7 +671,7 @@ namespace ts {
683671
const watchDirectory = tscWatchDirectory === "RecursiveDirectoryUsingFsWatchFile" ?
684672
createWatchDirectoryUsing(fsWatchFile) :
685673
tscWatchDirectory === "RecursiveDirectoryUsingDynamicPriorityPolling" ?
686-
createWatchDirectoryUsing(dynamicPollingWatchFile || createDynamicPriorityPollingWatchFile(nodeSystem)) :
674+
createWatchDirectoryUsing(dynamicPollingWatchFile || createDynamicPriorityPollingWatchFile({ getModifiedTime, setTimeout })) :
687675
watchDirectoryUsingFsWatch;
688676
const watchDirectoryRecursively = createRecursiveDirectoryWatcher({
689677
filePathComparer: useCaseSensitiveFileNames ? compareStringsCaseSensitive : compareStringsCaseInsensitive,
@@ -1027,6 +1015,15 @@ namespace ts {
10271015
return filter<string>(_fs.readdirSync(path), dir => fileSystemEntryExists(combinePaths(path, dir), FileSystemEntryKind.Directory));
10281016
}
10291017

1018+
function getModifiedTime(path: string) {
1019+
try {
1020+
return _fs.statSync(path).mtime;
1021+
}
1022+
catch (e) {
1023+
return undefined;
1024+
}
1025+
}
1026+
10301027
/**
10311028
* djb2 hashing algorithm
10321029
* http://www.cse.yorku.ca/~oz/hash.html

0 commit comments

Comments
 (0)