Skip to content

Add support for extraFileExtensions on WatchCompilerHost #37726

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2020
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
5 changes: 3 additions & 2 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,8 @@ namespace ts {
optionsToExtend: CompilerOptions,
host: ParseConfigFileHost,
extendedConfigCache?: Map<ExtendedConfigCacheEntry>,
watchOptionsToExtend?: WatchOptions
watchOptionsToExtend?: WatchOptions,
extraFileExtensions?: readonly FileExtensionInfo[],
): ParsedCommandLine | undefined {
const configFileText = tryReadFile(configFileName, fileName => host.readFile(fileName));
if (!isString(configFileText)) {
Expand All @@ -1483,7 +1484,7 @@ namespace ts {
optionsToExtend,
getNormalizedAbsolutePath(configFileName, cwd),
/*resolutionStack*/ undefined,
/*extraFileExtension*/ undefined,
extraFileExtensions,
extendedConfigCache,
watchOptionsToExtend
);
Expand Down
30 changes: 28 additions & 2 deletions src/compiler/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,23 +413,49 @@ namespace ts {
system.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
}

export interface CreateWatchCompilerHostInput<T extends BuilderProgram> {
system: System;
createProgram?: CreateProgram<T>;
reportDiagnostic?: DiagnosticReporter;
reportWatchStatus?: WatchStatusReporter;
}

export interface CreateWatchCompilerHostOfConfigFileInput<T extends BuilderProgram> extends CreateWatchCompilerHostInput<T> {
configFileName: string;
optionsToExtend?: CompilerOptions;
watchOptionsToExtend?: WatchOptions;
extraFileExtensions?: readonly FileExtensionInfo[];
}
/**
* Creates the watch compiler host from system for config file in watch mode
*/
export function createWatchCompilerHostOfConfigFile<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>(configFileName: string, optionsToExtend: CompilerOptions | undefined, watchOptionsToExtend: WatchOptions | undefined, system: System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter): WatchCompilerHostOfConfigFile<T> {
export function createWatchCompilerHostOfConfigFile<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>({
configFileName, optionsToExtend, watchOptionsToExtend, extraFileExtensions,
system, createProgram, reportDiagnostic, reportWatchStatus
}: CreateWatchCompilerHostOfConfigFileInput<T>): WatchCompilerHostOfConfigFile<T> {
const diagnosticReporter = reportDiagnostic || createDiagnosticReporter(system);
const host = createWatchCompilerHost(system, createProgram, diagnosticReporter, reportWatchStatus) as WatchCompilerHostOfConfigFile<T>;
host.onUnRecoverableConfigFileDiagnostic = diagnostic => reportUnrecoverableDiagnostic(system, diagnosticReporter, diagnostic);
host.configFileName = configFileName;
host.optionsToExtend = optionsToExtend;
host.watchOptionsToExtend = watchOptionsToExtend;
host.extraFileExtensions = extraFileExtensions;
return host;
}

export interface CreateWatchCompilerHostOfFilesAndCompilerOptionsInput<T extends BuilderProgram> extends CreateWatchCompilerHostInput<T> {
rootFiles: string[];
options: CompilerOptions;
watchOptions: WatchOptions | undefined;
projectReferences?: readonly ProjectReference[];
}
/**
* Creates the watch compiler host from system for compiling root files and options in watch mode
*/
export function createWatchCompilerHostOfFilesAndCompilerOptions<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>(rootFiles: string[], options: CompilerOptions, watchOptions: WatchOptions | undefined, system: System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter, projectReferences?: readonly ProjectReference[]): WatchCompilerHostOfFilesAndCompilerOptions<T> {
export function createWatchCompilerHostOfFilesAndCompilerOptions<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>({
rootFiles, options, watchOptions, projectReferences,
system, createProgram, reportDiagnostic, reportWatchStatus
}: CreateWatchCompilerHostOfFilesAndCompilerOptionsInput<T>): WatchCompilerHostOfFilesAndCompilerOptions<T> {
const host = createWatchCompilerHost(system, createProgram, reportDiagnostic || createDiagnosticReporter(system), reportWatchStatus) as WatchCompilerHostOfFilesAndCompilerOptions<T>;
host.rootFiles = rootFiles;
host.options = options;
Expand Down
32 changes: 26 additions & 6 deletions src/compiler/watchPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ namespace ts {

watchOptionsToExtend?: WatchOptions;

extraFileExtensions?: readonly FileExtensionInfo[]

/**
* Used to generate source file names from the config file and its include, exclude, files rules
* and also to cache the directory stucture
Expand Down Expand Up @@ -191,14 +193,32 @@ namespace ts {
/**
* Create the watch compiler host for either configFile or fileNames and its options
*/
export function createWatchCompilerHost<T extends BuilderProgram>(configFileName: string, optionsToExtend: CompilerOptions | undefined, system: System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter, watchOptionsToExtend?: WatchOptions): WatchCompilerHostOfConfigFile<T>;
export function createWatchCompilerHost<T extends BuilderProgram>(configFileName: string, optionsToExtend: CompilerOptions | undefined, system: System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter, watchOptionsToExtend?: WatchOptions, extraFileExtensions?: readonly FileExtensionInfo[]): WatchCompilerHostOfConfigFile<T>;
export function createWatchCompilerHost<T extends BuilderProgram>(rootFiles: string[], options: CompilerOptions, system: System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter, projectReferences?: readonly ProjectReference[], watchOptions?: WatchOptions): WatchCompilerHostOfFilesAndCompilerOptions<T>;
export function createWatchCompilerHost<T extends BuilderProgram>(rootFilesOrConfigFileName: string | string[], options: CompilerOptions | undefined, system: System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter, projectReferencesOrWatchOptionsToExtend?: readonly ProjectReference[] | WatchOptions, watchOptions?: WatchOptions): WatchCompilerHostOfFilesAndCompilerOptions<T> | WatchCompilerHostOfConfigFile<T> {
export function createWatchCompilerHost<T extends BuilderProgram>(rootFilesOrConfigFileName: string | string[], options: CompilerOptions | undefined, system: System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter, projectReferencesOrWatchOptionsToExtend?: readonly ProjectReference[] | WatchOptions, watchOptionsOrExtraFileExtensions?: WatchOptions | readonly FileExtensionInfo[]): WatchCompilerHostOfFilesAndCompilerOptions<T> | WatchCompilerHostOfConfigFile<T> {
if (isArray(rootFilesOrConfigFileName)) {
return createWatchCompilerHostOfFilesAndCompilerOptions(rootFilesOrConfigFileName, options!, watchOptions, system, createProgram, reportDiagnostic, reportWatchStatus, projectReferencesOrWatchOptionsToExtend as readonly ProjectReference[]); // TODO: GH#18217
return createWatchCompilerHostOfFilesAndCompilerOptions({
rootFiles: rootFilesOrConfigFileName,
options: options!,
watchOptions: watchOptionsOrExtraFileExtensions as WatchOptions,
projectReferences: projectReferencesOrWatchOptionsToExtend as readonly ProjectReference[],
system,
createProgram,
reportDiagnostic,
reportWatchStatus,
});
}
else {
return createWatchCompilerHostOfConfigFile(rootFilesOrConfigFileName, options, projectReferencesOrWatchOptionsToExtend as WatchOptions, system, createProgram, reportDiagnostic, reportWatchStatus);
return createWatchCompilerHostOfConfigFile({
configFileName: rootFilesOrConfigFileName,
optionsToExtend: options,
watchOptionsToExtend: projectReferencesOrWatchOptionsToExtend as WatchOptions,
extraFileExtensions: watchOptionsOrExtraFileExtensions as readonly FileExtensionInfo[],
system,
createProgram,
reportDiagnostic,
reportWatchStatus,
});
}
}

Expand Down Expand Up @@ -237,7 +257,7 @@ namespace ts {

const useCaseSensitiveFileNames = host.useCaseSensitiveFileNames();
const currentDirectory = host.getCurrentDirectory();
const { configFileName, optionsToExtend: optionsToExtendForConfigFile = {}, watchOptionsToExtend, createProgram } = host;
const { configFileName, optionsToExtend: optionsToExtendForConfigFile = {}, watchOptionsToExtend, extraFileExtensions, createProgram } = host;
let { rootFiles: rootFileNames, options: compilerOptions, watchOptions, projectReferences } = host;
let configFileSpecs: ConfigFileSpecs;
let configFileParsingDiagnostics: Diagnostic[] | undefined;
Expand Down Expand Up @@ -614,7 +634,7 @@ namespace ts {
}

function parseConfigFile() {
setConfigFileParsingResult(getParsedCommandLineOfConfigFile(configFileName, optionsToExtendForConfigFile, parseConfigFileHost, /*extendedConfigCache*/ undefined, watchOptionsToExtend)!); // TODO: GH#18217
setConfigFileParsingResult(getParsedCommandLineOfConfigFile(configFileName, optionsToExtendForConfigFile, parseConfigFileHost, /*extendedConfigCache*/ undefined, watchOptionsToExtend, extraFileExtensions)!); // TODO: GH#18217
}

function setConfigFileParsingResult(configFileParseResult: ParsedCommandLine) {
Expand Down
28 changes: 13 additions & 15 deletions src/executeCommandLine/executeCommandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,45 +566,43 @@ namespace ts {
}

function createWatchOfConfigFile(
sys: System,
system: System,
cb: ExecuteCommandLineCallbacks,
reportDiagnostic: DiagnosticReporter,
configParseResult: ParsedCommandLine,
optionsToExtend: CompilerOptions,
watchOptionsToExtend: WatchOptions | undefined,
) {
const watchCompilerHost = createWatchCompilerHostOfConfigFile(
configParseResult.options.configFilePath!,
const watchCompilerHost = createWatchCompilerHostOfConfigFile({
configFileName: configParseResult.options.configFilePath!,
optionsToExtend,
watchOptionsToExtend,
sys,
/*createProgram*/ undefined,
system,
reportDiagnostic,
createWatchStatusReporter(sys, configParseResult.options)
); // TODO: GH#18217
updateWatchCompilationHost(sys, cb, watchCompilerHost);
reportWatchStatus: createWatchStatusReporter(system, configParseResult.options)
});
updateWatchCompilationHost(system, cb, watchCompilerHost);
watchCompilerHost.configFileParsingResult = configParseResult;
return createWatchProgram(watchCompilerHost);
}

function createWatchOfFilesAndCompilerOptions(
sys: System,
system: System,
cb: ExecuteCommandLineCallbacks,
reportDiagnostic: DiagnosticReporter,
rootFiles: string[],
options: CompilerOptions,
watchOptions: WatchOptions | undefined,
) {
const watchCompilerHost = createWatchCompilerHostOfFilesAndCompilerOptions(
const watchCompilerHost = createWatchCompilerHostOfFilesAndCompilerOptions({
rootFiles,
options,
watchOptions,
sys,
/*createProgram*/ undefined,
system,
reportDiagnostic,
createWatchStatusReporter(sys, options)
);
updateWatchCompilationHost(sys, cb, watchCompilerHost);
reportWatchStatus: createWatchStatusReporter(system, options)
});
updateWatchCompilationHost(system, cb, watchCompilerHost);
return createWatchProgram(watchCompilerHost);
}

Expand Down
33 changes: 28 additions & 5 deletions src/testRunner/unittests/reuseProgramStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,12 +937,20 @@ namespace ts {
}

function verifyProgramWithoutConfigFile(system: System, rootFiles: string[], options: CompilerOptions) {
const program = createWatchProgram(createWatchCompilerHostOfFilesAndCompilerOptions(rootFiles, options, /*watchOptions*/ undefined, system)).getCurrentProgram().getProgram();
const program = createWatchProgram(createWatchCompilerHostOfFilesAndCompilerOptions({
rootFiles,
options,
watchOptions: undefined,
system
})).getCurrentProgram().getProgram();
verifyProgramIsUptoDate(program, duplicate(rootFiles), duplicate(options));
}

function verifyProgramWithConfigFile(system: System, configFileName: string) {
const program = createWatchProgram(createWatchCompilerHostOfConfigFile(configFileName, {}, /*watchOptionsToExtend*/ undefined, system)).getCurrentProgram().getProgram();
const program = createWatchProgram(createWatchCompilerHostOfConfigFile({
configFileName,
system
})).getCurrentProgram().getProgram();
const { fileNames, options } = parseConfigFileWithSystem(configFileName, {}, /*watchOptionsToExtend*/ undefined, system, notImplemented)!; // TODO: GH#18217
verifyProgramIsUptoDate(program, fileNames, options);
}
Expand Down Expand Up @@ -1081,7 +1089,12 @@ namespace ts {
const rootFiles = [module1.path, module2.path, module3.path];
const system = createTestSystem([module1, module2, module3]);
const options = {};
const program = createWatchProgram(createWatchCompilerHostOfFilesAndCompilerOptions(rootFiles, options, /*watchOptions*/ undefined, system)).getCurrentProgram().getProgram();
const program = createWatchProgram(createWatchCompilerHostOfFilesAndCompilerOptions({
rootFiles,
options,
watchOptions: undefined,
system
})).getCurrentProgram().getProgram();
verifyProgramIsUptoDate(program, duplicate(rootFiles), duplicate(options));
});

Expand Down Expand Up @@ -1112,7 +1125,12 @@ namespace ts {
const newRootFiles = [module1.path, module2.path, module3.path];
const system = createTestSystem([module1, module2, module3]);
const options = {};
const program = createWatchProgram(createWatchCompilerHostOfFilesAndCompilerOptions(rootFiles, options, /*watchOptions*/ undefined, system)).getCurrentProgram().getProgram();
const program = createWatchProgram(createWatchCompilerHostOfFilesAndCompilerOptions({
rootFiles,
options,
watchOptions: undefined,
system
})).getCurrentProgram().getProgram();
verifyProgramIsNotUptoDate(program, duplicate(newRootFiles), duplicate(options));
});
it("has one root file replaced by another", () => {
Expand All @@ -1132,7 +1150,12 @@ namespace ts {
const newRootFiles = [module2.path, module3.path];
const system = createTestSystem([module1, module2, module3]);
const options = {};
const program = createWatchProgram(createWatchCompilerHostOfFilesAndCompilerOptions(rootFiles, options, /*watchOptions*/ undefined, system)).getCurrentProgram().getProgram();
const program = createWatchProgram(createWatchCompilerHostOfFilesAndCompilerOptions({
rootFiles,
options,
watchOptions: undefined,
system
})).getCurrentProgram().getProgram();
verifyProgramIsNotUptoDate(program, duplicate(newRootFiles), duplicate(options));
});
});
Expand Down
8 changes: 4 additions & 4 deletions src/testRunner/unittests/tscWatch/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ namespace ts.tscWatch {

export type Watch = WatchOfConfigFile<EmitAndSemanticDiagnosticsBuilderProgram> | WatchOfFilesAndCompilerOptions<EmitAndSemanticDiagnosticsBuilderProgram>;

export function createWatchOfConfigFile(configFileName: string, host: WatchedSystem, optionsToExtend?: CompilerOptions, watchOptionsToExtend?: WatchOptions) {
const compilerHost = createWatchCompilerHostOfConfigFile(configFileName, optionsToExtend || {}, watchOptionsToExtend, host);
export function createWatchOfConfigFile(configFileName: string, system: WatchedSystem, optionsToExtend?: CompilerOptions, watchOptionsToExtend?: WatchOptions) {
const compilerHost = createWatchCompilerHostOfConfigFile({ configFileName, optionsToExtend, watchOptionsToExtend, system });
return createWatchProgram(compilerHost);
}

export function createWatchOfFilesAndCompilerOptions(rootFiles: string[], host: WatchedSystem, options: CompilerOptions = {}, watchOptions?: WatchOptions) {
const compilerHost = createWatchCompilerHostOfFilesAndCompilerOptions(rootFiles, options, watchOptions, host);
export function createWatchOfFilesAndCompilerOptions(rootFiles: string[], system: WatchedSystem, options: CompilerOptions = {}, watchOptions?: WatchOptions) {
const compilerHost = createWatchCompilerHostOfFilesAndCompilerOptions({ rootFiles, options, watchOptions, system });
return createWatchProgram(compilerHost);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ namespace ts.tscWatch {
solutionBuilder.close();
sys.clearOutput();
}
const host = createWatchCompilerHostOfConfigFile(config, {}, /*watchOptionsToExtend*/ undefined, sys);
const host = createWatchCompilerHostOfConfigFile({
configFileName: config,
system: sys
});
host.useSourceOfProjectReferenceRedirect = returnTrue;
const watch = createWatchProgram(host);
checkProgramActualFiles(watch.getCurrentProgram().getProgram(), expectedProgramFiles);
Expand Down
Loading