mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Baselining tsc --watch output just like tsc baselines for easier updates (#35710)
* Baselining tsc --watch output * Fix lint errors
This commit is contained in:
@@ -169,8 +169,9 @@ namespace ts {
|
||||
|
||||
function executeCommandLineWorker(
|
||||
sys: System,
|
||||
cb: ExecuteCommandLineCallbacks | undefined,
|
||||
cb: ExecuteCommandLineCallbacks,
|
||||
commandLine: ParsedCommandLine,
|
||||
maxNumberOfFilesToIterateForInvalidation: number | undefined
|
||||
) {
|
||||
let reportDiagnostic = createDiagnosticReporter(sys);
|
||||
if (commandLine.options.build) {
|
||||
@@ -236,7 +237,7 @@ namespace ts {
|
||||
}
|
||||
else if (commandLine.fileNames.length === 0) {
|
||||
const searchPath = normalizePath(sys.getCurrentDirectory());
|
||||
configFileName = findConfigFile(searchPath, sys.fileExists);
|
||||
configFileName = findConfigFile(searchPath, fileName => sys.fileExists(fileName));
|
||||
}
|
||||
|
||||
if (commandLine.fileNames.length === 0 && !configFileName) {
|
||||
@@ -273,27 +274,29 @@ namespace ts {
|
||||
);
|
||||
if (isWatchSet(configParseResult.options)) {
|
||||
if (reportWatchModeWithoutSysSupport(sys, reportDiagnostic)) return;
|
||||
createWatchOfConfigFile(
|
||||
return createWatchOfConfigFile(
|
||||
sys,
|
||||
cb,
|
||||
reportDiagnostic,
|
||||
configParseResult,
|
||||
commandLineOptions,
|
||||
commandLine.watchOptions
|
||||
commandLine.watchOptions,
|
||||
maxNumberOfFilesToIterateForInvalidation
|
||||
);
|
||||
}
|
||||
else if (isIncrementalCompilation(configParseResult.options)) {
|
||||
performIncrementalCompilation(
|
||||
sys,
|
||||
reportDiagnostic,
|
||||
cb,
|
||||
reportDiagnostic,
|
||||
configParseResult
|
||||
);
|
||||
}
|
||||
else {
|
||||
performCompilation(
|
||||
sys,
|
||||
reportDiagnostic,
|
||||
cb,
|
||||
reportDiagnostic,
|
||||
configParseResult
|
||||
);
|
||||
}
|
||||
@@ -311,27 +314,29 @@ namespace ts {
|
||||
);
|
||||
if (isWatchSet(commandLineOptions)) {
|
||||
if (reportWatchModeWithoutSysSupport(sys, reportDiagnostic)) return;
|
||||
createWatchOfFilesAndCompilerOptions(
|
||||
return createWatchOfFilesAndCompilerOptions(
|
||||
sys,
|
||||
cb,
|
||||
reportDiagnostic,
|
||||
commandLine.fileNames,
|
||||
commandLineOptions,
|
||||
commandLine.watchOptions
|
||||
commandLine.watchOptions,
|
||||
maxNumberOfFilesToIterateForInvalidation
|
||||
);
|
||||
}
|
||||
else if (isIncrementalCompilation(commandLineOptions)) {
|
||||
performIncrementalCompilation(
|
||||
sys,
|
||||
reportDiagnostic,
|
||||
cb,
|
||||
reportDiagnostic,
|
||||
{ ...commandLine, options: commandLineOptions }
|
||||
);
|
||||
}
|
||||
else {
|
||||
performCompilation(
|
||||
sys,
|
||||
reportDiagnostic,
|
||||
cb,
|
||||
reportDiagnostic,
|
||||
{ ...commandLine, options: commandLineOptions }
|
||||
);
|
||||
}
|
||||
@@ -346,23 +351,35 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
export interface ExecuteCommandLineCallbacks {
|
||||
onCompilerHostCreate: (host: CompilerHost) => void;
|
||||
onCompilationComplete: (config: ParsedCommandLine) => void;
|
||||
onSolutionBuilderHostCreate: (host: SolutionBuilderHost<BuilderProgram> | SolutionBuilderWithWatchHost<BuilderProgram>) => void;
|
||||
onSolutionBuildComplete: (configs: readonly ParsedCommandLine[]) => void;
|
||||
}
|
||||
export type ExecuteCommandLineCallbacks = (program: Program | EmitAndSemanticDiagnosticsBuilderProgram | ParsedCommandLine) => void;
|
||||
export function executeCommandLine(
|
||||
system: System,
|
||||
cb: ExecuteCommandLineCallbacks,
|
||||
commandLineArgs: readonly string[],
|
||||
): void {
|
||||
maxNumberOfFilesToIterateForInvalidation?: number
|
||||
) {
|
||||
if (isBuild(commandLineArgs)) {
|
||||
return performBuild(
|
||||
system,
|
||||
cb,
|
||||
commandLineArgs.slice(1)
|
||||
);
|
||||
const { buildOptions, watchOptions, projects, errors } = parseBuildCommand(commandLineArgs.slice(1));
|
||||
if (buildOptions.generateCpuProfile && system.enableCPUProfiler) {
|
||||
system.enableCPUProfiler(buildOptions.generateCpuProfile, () => performBuild(
|
||||
system,
|
||||
cb,
|
||||
buildOptions,
|
||||
watchOptions,
|
||||
projects,
|
||||
errors
|
||||
));
|
||||
}
|
||||
else {
|
||||
return performBuild(
|
||||
system,
|
||||
cb,
|
||||
buildOptions,
|
||||
watchOptions,
|
||||
projects,
|
||||
errors
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const commandLine = parseCommandLine(commandLineArgs, path => system.readFile(path));
|
||||
@@ -370,11 +387,12 @@ namespace ts {
|
||||
system.enableCPUProfiler(commandLine.options.generateCpuProfile, () => executeCommandLineWorker(
|
||||
system,
|
||||
cb,
|
||||
commandLine
|
||||
commandLine,
|
||||
maxNumberOfFilesToIterateForInvalidation
|
||||
));
|
||||
}
|
||||
else {
|
||||
executeCommandLineWorker(system, cb, commandLine);
|
||||
return executeCommandLineWorker(system, cb, commandLine, maxNumberOfFilesToIterateForInvalidation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,9 +405,9 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function performBuildWorker(
|
||||
function performBuild(
|
||||
sys: System,
|
||||
cb: ExecuteCommandLineCallbacks | undefined,
|
||||
cb: ExecuteCommandLineCallbacks,
|
||||
buildOptions: BuildOptions,
|
||||
watchOptions: WatchOptions | undefined,
|
||||
projects: string[],
|
||||
@@ -437,12 +455,10 @@ namespace ts {
|
||||
createBuilderStatusReporter(sys, shouldBePretty(sys, buildOptions)),
|
||||
createWatchStatusReporter(sys, buildOptions)
|
||||
);
|
||||
if (cb && cb.onSolutionBuilderHostCreate) cb.onSolutionBuilderHostCreate(buildHost);
|
||||
updateCreateProgram(sys, buildHost);
|
||||
buildHost.afterProgramEmitAndDiagnostics = program => reportStatistics(sys, program.getProgram());
|
||||
updateSolutionBuilderHost(sys, cb, buildHost);
|
||||
const builder = createSolutionBuilderWithWatch(buildHost, projects, buildOptions, watchOptions);
|
||||
builder.build();
|
||||
return;
|
||||
return builder;
|
||||
}
|
||||
|
||||
const buildHost = createSolutionBuilderHost(
|
||||
@@ -452,43 +468,12 @@ namespace ts {
|
||||
createBuilderStatusReporter(sys, shouldBePretty(sys, buildOptions)),
|
||||
createReportErrorSummary(sys, buildOptions)
|
||||
);
|
||||
if (cb && cb.onSolutionBuilderHostCreate) cb.onSolutionBuilderHostCreate(buildHost);
|
||||
updateCreateProgram(sys, buildHost);
|
||||
buildHost.afterProgramEmitAndDiagnostics = program => reportStatistics(sys, program.getProgram());
|
||||
updateSolutionBuilderHost(sys, cb, buildHost);
|
||||
const builder = createSolutionBuilder(buildHost, projects, buildOptions);
|
||||
const exitStatus = buildOptions.clean ? builder.clean() : builder.build();
|
||||
if (cb && cb.onSolutionBuildComplete) cb.onSolutionBuildComplete(builder.getAllParsedConfigs());
|
||||
return sys.exit(exitStatus);
|
||||
}
|
||||
|
||||
function performBuild(
|
||||
sys: System,
|
||||
cb: ExecuteCommandLineCallbacks | undefined,
|
||||
args: readonly string[]
|
||||
) {
|
||||
const { buildOptions, watchOptions, projects, errors } = parseBuildCommand(args);
|
||||
if (buildOptions.generateCpuProfile && sys.enableCPUProfiler) {
|
||||
sys.enableCPUProfiler(buildOptions.generateCpuProfile, () => performBuildWorker(
|
||||
sys,
|
||||
cb,
|
||||
buildOptions,
|
||||
watchOptions,
|
||||
projects,
|
||||
errors
|
||||
));
|
||||
}
|
||||
else {
|
||||
performBuildWorker(
|
||||
sys,
|
||||
cb,
|
||||
buildOptions,
|
||||
watchOptions,
|
||||
projects,
|
||||
errors
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function createReportErrorSummary(sys: System, options: CompilerOptions | BuildOptions): ReportEmitErrorSummary | undefined {
|
||||
return shouldBePretty(sys, options) ?
|
||||
errorCount => sys.write(getErrorSummaryText(errorCount, sys.newLine)) :
|
||||
@@ -497,13 +482,12 @@ namespace ts {
|
||||
|
||||
function performCompilation(
|
||||
sys: System,
|
||||
cb: ExecuteCommandLineCallbacks,
|
||||
reportDiagnostic: DiagnosticReporter,
|
||||
cb: ExecuteCommandLineCallbacks | undefined,
|
||||
config: ParsedCommandLine
|
||||
) {
|
||||
const { fileNames, options, projectReferences } = config;
|
||||
const host = createCompilerHostWorker(options, /*setParentPos*/ undefined, sys);
|
||||
if (cb && cb.onCompilerHostCreate) cb.onCompilerHostCreate(host);
|
||||
const currentDirectory = host.getCurrentDirectory();
|
||||
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames());
|
||||
changeCompilerHostLikeToUseCache(host, fileName => toPath(fileName, currentDirectory, getCanonicalFileName));
|
||||
@@ -524,20 +508,19 @@ namespace ts {
|
||||
createReportErrorSummary(sys, options)
|
||||
);
|
||||
reportStatistics(sys, program);
|
||||
if (cb && cb.onCompilationComplete) cb.onCompilationComplete(config);
|
||||
cb(program);
|
||||
return sys.exit(exitStatus);
|
||||
}
|
||||
|
||||
function performIncrementalCompilation(
|
||||
sys: System,
|
||||
cb: ExecuteCommandLineCallbacks,
|
||||
reportDiagnostic: DiagnosticReporter,
|
||||
cb: ExecuteCommandLineCallbacks | undefined,
|
||||
config: ParsedCommandLine
|
||||
) {
|
||||
const { options, fileNames, projectReferences } = config;
|
||||
enableStatistics(sys, options);
|
||||
const host = createIncrementalCompilerHost(options, sys);
|
||||
if (cb && cb.onCompilerHostCreate) cb.onCompilerHostCreate(host);
|
||||
const exitStatus = ts.performIncrementalCompilation({
|
||||
host,
|
||||
system: sys,
|
||||
@@ -547,12 +530,27 @@ namespace ts {
|
||||
projectReferences,
|
||||
reportDiagnostic,
|
||||
reportErrorSummary: createReportErrorSummary(sys, options),
|
||||
afterProgramEmitAndDiagnostics: builderProgram => reportStatistics(sys, builderProgram.getProgram())
|
||||
afterProgramEmitAndDiagnostics: builderProgram => {
|
||||
reportStatistics(sys, builderProgram.getProgram());
|
||||
cb(builderProgram);
|
||||
}
|
||||
});
|
||||
if (cb && cb.onCompilationComplete) cb.onCompilationComplete(config);
|
||||
return sys.exit(exitStatus);
|
||||
}
|
||||
|
||||
function updateSolutionBuilderHost(
|
||||
sys: System,
|
||||
cb: ExecuteCommandLineCallbacks,
|
||||
buildHost: SolutionBuilderHostBase<EmitAndSemanticDiagnosticsBuilderProgram>
|
||||
) {
|
||||
updateCreateProgram(sys, buildHost);
|
||||
buildHost.afterProgramEmitAndDiagnostics = program => {
|
||||
reportStatistics(sys, program.getProgram());
|
||||
cb(program);
|
||||
};
|
||||
buildHost.afterEmitBundle = cb;
|
||||
}
|
||||
|
||||
function updateCreateProgram<T extends BuilderProgram>(sys: System, host: { createProgram: CreateProgram<T>; }) {
|
||||
const compileUsingBuilder = host.createProgram;
|
||||
host.createProgram = (rootNames, options, host, oldProgram, configFileParsingDiagnostics, projectReferences) => {
|
||||
@@ -564,12 +562,19 @@ namespace ts {
|
||||
};
|
||||
}
|
||||
|
||||
function updateWatchCompilationHost(sys: System, watchCompilerHost: WatchCompilerHost<EmitAndSemanticDiagnosticsBuilderProgram>) {
|
||||
function updateWatchCompilationHost(
|
||||
sys: System,
|
||||
cb: ExecuteCommandLineCallbacks,
|
||||
watchCompilerHost: WatchCompilerHost<EmitAndSemanticDiagnosticsBuilderProgram>,
|
||||
maxNumberOfFilesToIterateForInvalidation: number | undefined
|
||||
) {
|
||||
updateCreateProgram(sys, watchCompilerHost);
|
||||
watchCompilerHost.maxNumberOfFilesToIterateForInvalidation = maxNumberOfFilesToIterateForInvalidation;
|
||||
const emitFilesUsingBuilder = watchCompilerHost.afterProgramCreate!; // TODO: GH#18217
|
||||
watchCompilerHost.afterProgramCreate = builderProgram => {
|
||||
emitFilesUsingBuilder(builderProgram);
|
||||
reportStatistics(sys, builderProgram.getProgram());
|
||||
cb(builderProgram);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -579,10 +584,12 @@ namespace ts {
|
||||
|
||||
function createWatchOfConfigFile(
|
||||
sys: System,
|
||||
cb: ExecuteCommandLineCallbacks,
|
||||
reportDiagnostic: DiagnosticReporter,
|
||||
configParseResult: ParsedCommandLine,
|
||||
optionsToExtend: CompilerOptions,
|
||||
watchOptionsToExtend: WatchOptions | undefined
|
||||
watchOptionsToExtend: WatchOptions | undefined,
|
||||
maxNumberOfFilesToIterateForInvalidation: number | undefined
|
||||
) {
|
||||
const watchCompilerHost = createWatchCompilerHostOfConfigFile(
|
||||
configParseResult.options.configFilePath!,
|
||||
@@ -593,17 +600,19 @@ namespace ts {
|
||||
reportDiagnostic,
|
||||
createWatchStatusReporter(sys, configParseResult.options)
|
||||
); // TODO: GH#18217
|
||||
updateWatchCompilationHost(sys, watchCompilerHost);
|
||||
updateWatchCompilationHost(sys, cb, watchCompilerHost, maxNumberOfFilesToIterateForInvalidation);
|
||||
watchCompilerHost.configFileParsingResult = configParseResult;
|
||||
createWatchProgram(watchCompilerHost);
|
||||
return createWatchProgram(watchCompilerHost);
|
||||
}
|
||||
|
||||
function createWatchOfFilesAndCompilerOptions(
|
||||
sys: System,
|
||||
cb: ExecuteCommandLineCallbacks,
|
||||
reportDiagnostic: DiagnosticReporter,
|
||||
rootFiles: string[],
|
||||
options: CompilerOptions,
|
||||
watchOptions: WatchOptions | undefined
|
||||
watchOptions: WatchOptions | undefined,
|
||||
maxNumberOfFilesToIterateForInvalidation: number | undefined
|
||||
) {
|
||||
const watchCompilerHost = createWatchCompilerHostOfFilesAndCompilerOptions(
|
||||
rootFiles,
|
||||
@@ -614,8 +623,8 @@ namespace ts {
|
||||
reportDiagnostic,
|
||||
createWatchStatusReporter(sys, options)
|
||||
);
|
||||
updateWatchCompilationHost(sys, watchCompilerHost);
|
||||
createWatchProgram(watchCompilerHost);
|
||||
updateWatchCompilationHost(sys, cb, watchCompilerHost, maxNumberOfFilesToIterateForInvalidation);
|
||||
return createWatchProgram(watchCompilerHost);
|
||||
}
|
||||
|
||||
function canReportDiagnostics(system: System, compilerOptions: CompilerOptions) {
|
||||
|
||||
Reference in New Issue
Block a user