mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-09 16:39:46 -05:00
Fix incorrect handling of preserveWatchOutput flag is in config file
Fixes #25620
This commit is contained in:
@@ -475,16 +475,15 @@ namespace ts {
|
||||
|
||||
// From tsc we want to get already parsed result and hence check for rootFileNames
|
||||
let newLine = updateNewLine();
|
||||
if (configFileName && host.configFileParsingResult) {
|
||||
setConfigFileParsingResult(host.configFileParsingResult);
|
||||
newLine = updateNewLine();
|
||||
}
|
||||
reportWatchDiagnostic(Diagnostics.Starting_compilation_in_watch_mode);
|
||||
if (configFileName) {
|
||||
if (configFileName && !host.configFileParsingResult) {
|
||||
newLine = getNewLineCharacter(optionsToExtendForConfigFile, () => host.getNewLine());
|
||||
if (host.configFileParsingResult) {
|
||||
setConfigFileParsingResult(host.configFileParsingResult);
|
||||
}
|
||||
else {
|
||||
Debug.assert(!rootFileNames);
|
||||
parseConfigFile();
|
||||
}
|
||||
Debug.assert(!rootFileNames);
|
||||
parseConfigFile();
|
||||
newLine = updateNewLine();
|
||||
}
|
||||
|
||||
|
||||
@@ -434,7 +434,7 @@ namespace ts {
|
||||
|
||||
function createFileWatcherWithTriggerLogging<H, T, U, V, X, Y>(host: H, file: string, cb: WatchCallback<U, V>, flags: T, passThrough: V | undefined, detailInfo1: X | undefined, detailInfo2: Y | undefined, addWatch: AddWatch<H, T, U, undefined>, log: (s: string) => void, watchCaption: string, getDetailWatchInfo: GetDetailWatchInfo<X, Y> | undefined): FileWatcher {
|
||||
return addWatch(host, file, (fileName, cbOptional) => {
|
||||
const triggerredInfo = `${watchCaption}:: Triggered with ${fileName}${cbOptional !== undefined ? cbOptional : ""}:: ${getWatchInfo(file, flags, detailInfo1, detailInfo2, getDetailWatchInfo)}`;
|
||||
const triggerredInfo = `${watchCaption}:: Triggered with ${fileName} ${cbOptional !== undefined ? cbOptional : ""}:: ${getWatchInfo(file, flags, detailInfo1, detailInfo2, getDetailWatchInfo)}`;
|
||||
log(triggerredInfo);
|
||||
const start = timestamp();
|
||||
cb(fileName, cbOptional, passThrough);
|
||||
|
||||
@@ -2315,63 +2315,97 @@ declare module "fs" {
|
||||
describe("tsc-watch console clearing", () => {
|
||||
const currentDirectoryLog = "Current directory: / CaseSensitiveFileNames: false\n";
|
||||
const fileWatcherAddedLog = [
|
||||
"FileWatcher:: Added:: WatchInfo: f.ts 250 Source file\n",
|
||||
"FileWatcher:: Added:: WatchInfo: /f.ts 250 Source file\n",
|
||||
"FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 250 Source file\n"
|
||||
];
|
||||
|
||||
const file: File = {
|
||||
path: "/f.ts",
|
||||
content: ""
|
||||
};
|
||||
|
||||
function getProgramSynchronizingLog(options: CompilerOptions) {
|
||||
return [
|
||||
"Synchronizing program\n",
|
||||
"CreatingProgramWith::\n",
|
||||
" roots: [\"f.ts\"]\n",
|
||||
" roots: [\"/f.ts\"]\n",
|
||||
` options: ${JSON.stringify(options)}\n`
|
||||
];
|
||||
}
|
||||
|
||||
function checkConsoleClearing(options: CompilerOptions = {}) {
|
||||
const file = {
|
||||
path: "f.ts",
|
||||
content: ""
|
||||
};
|
||||
const files = [file, libFile];
|
||||
const disableConsoleClear = options.diagnostics || options.extendedDiagnostics || options.preserveWatchOutput;
|
||||
function isConsoleClearDisabled(options: CompilerOptions) {
|
||||
return options.diagnostics || options.extendedDiagnostics || options.preserveWatchOutput;
|
||||
}
|
||||
|
||||
function verifyCompilation(host: WatchedSystem, options: CompilerOptions, initialDisableOptions?: CompilerOptions) {
|
||||
const disableConsoleClear = isConsoleClearDisabled(options);
|
||||
const hasLog = options.extendedDiagnostics || options.diagnostics;
|
||||
const host = createWatchedSystem(files);
|
||||
createWatchOfFilesAndCompilerOptions([file.path], host, options);
|
||||
checkOutputErrorsInitial(host, emptyArray, disableConsoleClear, hasLog ? [
|
||||
checkOutputErrorsInitial(host, emptyArray, initialDisableOptions ? isConsoleClearDisabled(initialDisableOptions) : disableConsoleClear, hasLog ? [
|
||||
currentDirectoryLog,
|
||||
...getProgramSynchronizingLog(options),
|
||||
...(options.extendedDiagnostics ? fileWatcherAddedLog : emptyArray)
|
||||
] : undefined);
|
||||
|
||||
file.content = "//";
|
||||
host.reloadFS(files);
|
||||
host.modifyFile(file.path, "//");
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
checkOutputErrorsIncremental(host, emptyArray, disableConsoleClear, hasLog ? [
|
||||
"FileWatcher:: Triggered with /f.ts1:: WatchInfo: f.ts 250 Source file\n",
|
||||
"FileWatcher:: Triggered with /f.ts 1:: WatchInfo: /f.ts 250 Source file\n",
|
||||
"Scheduling update\n",
|
||||
"Elapsed:: 0ms FileWatcher:: Triggered with /f.ts1:: WatchInfo: f.ts 250 Source file\n"
|
||||
"Elapsed:: 0ms FileWatcher:: Triggered with /f.ts 1:: WatchInfo: /f.ts 250 Source file\n"
|
||||
] : undefined, hasLog ? getProgramSynchronizingLog(options) : undefined);
|
||||
}
|
||||
|
||||
function checkConsoleClearingUsingCommandLineOptions(options: CompilerOptions = {}) {
|
||||
const files = [file, libFile];
|
||||
const host = createWatchedSystem(files);
|
||||
createWatchOfFilesAndCompilerOptions([file.path], host, options);
|
||||
verifyCompilation(host, options);
|
||||
}
|
||||
|
||||
it("without --diagnostics or --extendedDiagnostics", () => {
|
||||
checkConsoleClearing();
|
||||
checkConsoleClearingUsingCommandLineOptions();
|
||||
});
|
||||
it("with --diagnostics", () => {
|
||||
checkConsoleClearing({
|
||||
checkConsoleClearingUsingCommandLineOptions({
|
||||
diagnostics: true,
|
||||
});
|
||||
});
|
||||
it("with --extendedDiagnostics", () => {
|
||||
checkConsoleClearing({
|
||||
checkConsoleClearingUsingCommandLineOptions({
|
||||
extendedDiagnostics: true,
|
||||
});
|
||||
});
|
||||
it("with --preserveWatchOutput", () => {
|
||||
checkConsoleClearing({
|
||||
checkConsoleClearingUsingCommandLineOptions({
|
||||
preserveWatchOutput: true,
|
||||
});
|
||||
});
|
||||
|
||||
describe("when preserveWatchOutput is true in config file", () => {
|
||||
const compilerOptions: CompilerOptions = {
|
||||
preserveWatchOutput: true
|
||||
};
|
||||
const configFile: File = {
|
||||
path: "/tsconfig.json",
|
||||
content: JSON.stringify({ compilerOptions })
|
||||
};
|
||||
const files = [file, configFile, libFile];
|
||||
it("using createWatchOfConfigFile ", () => {
|
||||
const host = createWatchedSystem(files);
|
||||
createWatchOfConfigFile(configFile.path, host);
|
||||
// Initially console is cleared if --preserveOutput is not provided since the config file is yet to be parsed
|
||||
verifyCompilation(host, compilerOptions, {});
|
||||
});
|
||||
it("when createWatchProgram is invoked with configFileParseResult on WatchCompilerHostOfConfigFile", () => {
|
||||
const host = createWatchedSystem(files);
|
||||
const reportDiagnostic = createDiagnosticReporter(host);
|
||||
const optionsToExtend: CompilerOptions = {};
|
||||
const configParseResult = parseConfigFileWithSystem(configFile.path, optionsToExtend, host, reportDiagnostic)!;
|
||||
const watchCompilerHost = createWatchCompilerHostOfConfigFile(configParseResult.options.configFilePath!, optionsToExtend, host, /*createProgram*/ undefined, reportDiagnostic, createWatchStatusReporter(host));
|
||||
watchCompilerHost.configFileParsingResult = configParseResult;
|
||||
createWatchProgram(watchCompilerHost);
|
||||
verifyCompilation(host, compilerOptions);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("tsc-watch with different polling/non polling options", () => {
|
||||
|
||||
Reference in New Issue
Block a user