Skip to content

"tsc --watch should clear screen on new compilation" Two: Electric Boogaloo #20389

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 5 commits into from
Dec 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/compiler/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -436,6 +437,9 @@ namespace ts {
}

const nodeSystem: System = {
clearScreen: () => {
process.stdout.write("\x1Bc");
},
args: process.argv.slice(2),
newLine: _os.EOL,
useCaseSensitiveFileNames,
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
33 changes: 33 additions & 0 deletions src/harness/unittests/tscWatchMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}
9 changes: 9 additions & 0 deletions src/harness/virtualFileSystemWithWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down Expand Up @@ -604,6 +605,10 @@ interface Array<T> {}`
this.timeoutCallbacks.unregister(timeoutId);
}

clearScreen(): void {
this.screenClears += 1;
}

checkTimeoutQueueLengthAndRun(expected: number) {
this.checkTimeoutQueueLength(expected);
this.runQueuedTimeoutCallbacks();
Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down