"tsc --watch should clear screen on new compilation" Two: Electric Boogaloo (#20389)
* tsc --watch should clear screen on new compilation * added optional clearScreen method to System] * implemented via `x1Bc`, reset screen * fixes 13020 * Feedback on if statements; api .d.ts baseline additions * Stopped clearing screen in tsc.js's reportWatchMode * Added unit tests
This commit is contained in:
parent
e90bf5e81b
commit
08c6dc99c6
6 changed files with 52 additions and 0 deletions
|
@ -72,6 +72,7 @@ namespace ts {
|
|||
/*@internal*/ debugMode?: boolean;
|
||||
setTimeout?(callback: (...args: any[]) => void, ms: number, ...args: any[]): any;
|
||||
clearTimeout?(timeoutId: any): void;
|
||||
clearScreen?(): void;
|
||||
}
|
||||
|
||||
export interface FileWatcher {
|
||||
|
@ -436,6 +437,9 @@ namespace ts {
|
|||
}
|
||||
|
||||
const nodeSystem: System = {
|
||||
clearScreen: () => {
|
||||
process.stdout.write("\x1Bc");
|
||||
},
|
||||
args: process.argv.slice(2),
|
||||
newLine: _os.EOL,
|
||||
useCaseSensitiveFileNames,
|
||||
|
|
|
@ -493,6 +493,10 @@ namespace ts {
|
|||
}
|
||||
|
||||
function updateProgram() {
|
||||
if (watchingHost.system.clearScreen) {
|
||||
watchingHost.system.clearScreen();
|
||||
}
|
||||
|
||||
timerToUpdateProgram = undefined;
|
||||
reportWatchDiagnostic(createCompilerDiagnostic(Diagnostics.File_change_detected_Starting_incremental_compilation));
|
||||
|
||||
|
|
|
@ -2027,4 +2027,37 @@ declare module "fs" {
|
|||
assert.equal(host.readFile(outputFile1), file1.content + host.newLine);
|
||||
});
|
||||
});
|
||||
|
||||
describe("tsc-watch console clearing", () => {
|
||||
it("doesn't clear the console when it starts", () => {
|
||||
const file = {
|
||||
path: "f.ts",
|
||||
content: ""
|
||||
};
|
||||
const host = createWatchedSystem([file]);
|
||||
|
||||
createWatchModeWithoutConfigFile([file.path], host);
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
|
||||
host.checkScreenClears(0);
|
||||
});
|
||||
|
||||
it("clears the console on recompile", () => {
|
||||
const file = {
|
||||
path: "f.ts",
|
||||
content: ""
|
||||
};
|
||||
const host = createWatchedSystem([file]);
|
||||
createWatchModeWithoutConfigFile([file.path], host);
|
||||
|
||||
const modifiedFile = {
|
||||
...file,
|
||||
content: "//"
|
||||
};
|
||||
host.reloadFS([modifiedFile]);
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
|
||||
host.checkScreenClears(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -251,6 +251,7 @@ interface Array<T> {}`
|
|||
private toPath: (f: string) => Path;
|
||||
private timeoutCallbacks = new Callbacks();
|
||||
private immediateCallbacks = new Callbacks();
|
||||
private screenClears = 0;
|
||||
|
||||
readonly watchedDirectories = createMultiMap<TestDirectoryWatcher>();
|
||||
readonly watchedDirectoriesRecursive = createMultiMap<TestDirectoryWatcher>();
|
||||
|
@ -604,6 +605,10 @@ interface Array<T> {}`
|
|||
this.timeoutCallbacks.unregister(timeoutId);
|
||||
}
|
||||
|
||||
clearScreen(): void {
|
||||
this.screenClears += 1;
|
||||
}
|
||||
|
||||
checkTimeoutQueueLengthAndRun(expected: number) {
|
||||
this.checkTimeoutQueueLength(expected);
|
||||
this.runQueuedTimeoutCallbacks();
|
||||
|
@ -638,6 +643,10 @@ interface Array<T> {}`
|
|||
this.immediateCallbacks.unregister(timeoutId);
|
||||
}
|
||||
|
||||
checkScreenClears(expected: number): void {
|
||||
assert.equal(this.screenClears, expected);
|
||||
}
|
||||
|
||||
createDirectory(directoryName: string): void {
|
||||
const folder = this.toFolder(directoryName);
|
||||
|
||||
|
|
|
@ -2762,6 +2762,7 @@ declare namespace ts {
|
|||
realpath?(path: string): string;
|
||||
setTimeout?(callback: (...args: any[]) => void, ms: number, ...args: any[]): any;
|
||||
clearTimeout?(timeoutId: any): void;
|
||||
clearScreen?(): void;
|
||||
}
|
||||
interface FileWatcher {
|
||||
close(): void;
|
||||
|
|
|
@ -2762,6 +2762,7 @@ declare namespace ts {
|
|||
realpath?(path: string): string;
|
||||
setTimeout?(callback: (...args: any[]) => void, ms: number, ...args: any[]): any;
|
||||
clearTimeout?(timeoutId: any): void;
|
||||
clearScreen?(): void;
|
||||
}
|
||||
interface FileWatcher {
|
||||
close(): void;
|
||||
|
|
Loading…
Reference in a new issue