diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 857ac30656a..eb1a515f24d 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -63,7 +63,7 @@ namespace ts { interface OutputFingerprint { hash: string; byteOrderMark: boolean; - mtime: Date; + mtime: Date | undefined; } export function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost { @@ -128,6 +128,7 @@ namespace ts { if (fingerprint && fingerprint.byteOrderMark === writeByteOrderMark && fingerprint.hash === hash && + fingerprint.mtime !== undefined && fingerprint.mtime.getTime() === mtimeBefore.getTime()) { return; } diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 4edba26333a..8f6a58a3567 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -482,7 +482,7 @@ namespace ts { getCurrentDirectory(): string; getDirectories(path: string): string[]; readDirectory(path: string, extensions?: ReadonlyArray, exclude?: ReadonlyArray, include?: ReadonlyArray, depth?: number): string[]; - getModifiedTime?(path: string): Date; + getModifiedTime?(path: string): Date | undefined; setModifiedTime?(path: string, time: Date): void; deleteFile?(path: string): void; /** diff --git a/src/compiler/tsbuild.ts b/src/compiler/tsbuild.ts index 5c9c7086db8..d98a161113b 100644 --- a/src/compiler/tsbuild.ts +++ b/src/compiler/tsbuild.ts @@ -848,9 +848,14 @@ namespace ts { const outputs = getAllProjectOutputs(proj); let priorNewestUpdateTime = minimumDate; for (const file of outputs) { + if (isDeclarationFile(file)) { - priorNewestUpdateTime = newer(priorNewestUpdateTime, compilerHost.getModifiedTime!(file)); + const fileModifiedTime = compilerHost.getModifiedTime!(file); + if (fileModifiedTime !== undefined) { + priorNewestUpdateTime = newer(priorNewestUpdateTime, fileModifiedTime); + } } + compilerHost.setModifiedTime!(file, now); } @@ -1058,7 +1063,7 @@ namespace ts { } const inputTime = host.getModifiedTime(inputFile); - if (inputTime > newestInputFileTime) { + if (inputTime !== undefined && inputTime > newestInputFileTime) { newestInputFileName = inputFile; newestInputFileTime = inputTime; } @@ -1090,19 +1095,19 @@ namespace ts { } const outputTime = host.getModifiedTime(output); - if (outputTime < oldestOutputFileTime) { + if (outputTime !== undefined && outputTime < oldestOutputFileTime) { oldestOutputFileTime = outputTime; oldestOutputFileName = output; } // If an output is older than the newest input, we can stop checking // Don't immediately return because we can still be upstream-blocked, which is a higher-priority status - if (outputTime < newestInputFileTime) { + if (outputTime !== undefined && outputTime < newestInputFileTime) { isOutOfDateWithInputs = true; break; } - if (outputTime > newestOutputFileTime) { + if (outputTime !== undefined && outputTime > newestOutputFileTime) { newestOutputFileTime = outputTime; newestOutputFileName = output; } @@ -1117,7 +1122,10 @@ namespace ts { newestDeclarationFileContentChangedTime = newer(unchangedTime, newestDeclarationFileContentChangedTime); } else { - newestDeclarationFileContentChangedTime = newer(newestDeclarationFileContentChangedTime, host.getModifiedTime(output)); + const outputModifiedTime = host.getModifiedTime(output); + if (outputModifiedTime !== undefined) { + newestDeclarationFileContentChangedTime = newer(newestDeclarationFileContentChangedTime, outputModifiedTime); + } } } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index eb8a0c061d5..d0a5add280e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4682,7 +4682,7 @@ namespace ts { export interface UpToDateHost { fileExists(fileName: string): boolean; - getModifiedTime(fileName: string): Date; + getModifiedTime(fileName: string): Date | undefined; getUnchangedTime?(fileName: string): Date | undefined; getLastStatus?(fileName: string): UpToDateStatus | undefined; setLastStatus?(fileName: string, status: UpToDateStatus): void; @@ -4820,7 +4820,7 @@ namespace ts { /* @internal */ hasChangedAutomaticTypeDirectiveNames?: boolean; createHash?(data: string): string; - getModifiedTime?(fileName: string): Date; + getModifiedTime?(fileName: string): Date | undefined; setModifiedTime?(fileName: string, date: Date): void; deleteFile?(fileName: string): void; } diff --git a/src/tsserver/server.ts b/src/tsserver/server.ts index 17f38c3c7ce..741d3c2f8a1 100644 --- a/src/tsserver/server.ts +++ b/src/tsserver/server.ts @@ -676,7 +676,7 @@ namespace ts.server { fs.stat(watchedFile.fileName, (err, stats) => { if (err) { if (err.code === "ENOENT") { - if (watchedFile.mtime.getTime() !== 0) { + if (watchedFile.mtime !== undefined && watchedFile.mtime.getTime() !== 0) { watchedFile.mtime = missingFileModifiedTime; watchedFile.callback(watchedFile.fileName, FileWatcherEventKind.Deleted); }