Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Make watchOptions separate from compilerOptions
  • Loading branch information
sheetalkamat committed Dec 10, 2019
commit 909f4585cc653ed574c94fd74ce9ae316cf0dd42
182 changes: 111 additions & 71 deletions src/compiler/commandLineParser.ts

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3309,6 +3309,14 @@
"category": "Error",
"code": 5077
},
"Unknown watch option '{0}'.": {
"category": "Error",
"code": 5078
},
"Unknown watch option '{0}'. Did you mean '{1}'?": {
"category": "Error",
"code": 5079
},

"Generates a sourcemap for each corresponding '.d.ts' file.": {
"category": "Message",
Expand Down
42 changes: 21 additions & 21 deletions src/compiler/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ namespace ts {
}

/* @internal */
export type HostWatchFile = (fileName: string, callback: FileWatcherCallback, pollingInterval: PollingInterval, options: CompilerOptions | undefined) => FileWatcher;
export type HostWatchFile = (fileName: string, callback: FileWatcherCallback, pollingInterval: PollingInterval, options: WatchOptions | undefined) => FileWatcher;
/* @internal */
export type HostWatchDirectory = (fileName: string, callback: DirectoryWatcherCallback, recursive: boolean, options: CompilerOptions | undefined) => FileWatcher;
export type HostWatchDirectory = (fileName: string, callback: DirectoryWatcherCallback, recursive: boolean, options: WatchOptions | undefined) => FileWatcher;

/* @internal */
export const missingFileModifiedTime = new Date(0); // Any subsequent modification will occur after this time
Expand Down Expand Up @@ -314,7 +314,7 @@ namespace ts {
const toCanonicalName = createGetCanonicalFileName(useCaseSensitiveFileNames);
return nonPollingWatchFile;

function nonPollingWatchFile(fileName: string, callback: FileWatcherCallback, _pollingInterval: PollingInterval, fallbackOptions: CompilerOptions | undefined): FileWatcher {
function nonPollingWatchFile(fileName: string, callback: FileWatcherCallback, _pollingInterval: PollingInterval, fallbackOptions: WatchOptions | undefined): FileWatcher {
const filePath = toCanonicalName(fileName);
fileWatcherCallbacks.add(filePath, callback);
const dirPath = getDirectoryPath(filePath) || ".";
Expand All @@ -335,7 +335,7 @@ namespace ts {
};
}

function createDirectoryWatcher(dirName: string, dirPath: string, fallbackOptions: CompilerOptions | undefined) {
function createDirectoryWatcher(dirName: string, dirPath: string, fallbackOptions: WatchOptions | undefined) {
const watcher = fsWatch(
dirName,
FileSystemEntryKind.Directory,
Expand Down Expand Up @@ -475,7 +475,7 @@ namespace ts {

const cache = createMap<HostDirectoryWatcher>();
const callbackCache = createMultiMap<{ dirName: string; callback: DirectoryWatcherCallback; }>();
const cacheToUpdateChildWatches = createMap<{ dirName: string; options: CompilerOptions | undefined; }>();
const cacheToUpdateChildWatches = createMap<{ dirName: string; options: WatchOptions | undefined; }>();
let timerToUpdateChildWatches: any;

const filePathComparer = getStringComparer(!host.useCaseSensitiveFileNames);
Expand All @@ -488,7 +488,7 @@ namespace ts {
/**
* Create the directory watcher for the dirPath.
*/
function createDirectoryWatcher(dirName: string, options: CompilerOptions | undefined, callback?: DirectoryWatcherCallback): ChildDirectoryWatcher {
function createDirectoryWatcher(dirName: string, options: WatchOptions | undefined, callback?: DirectoryWatcherCallback): ChildDirectoryWatcher {
const dirPath = toCanonicalFilePath(dirName) as Path;
let directoryWatcher = cache.get(dirPath);
if (directoryWatcher) {
Expand Down Expand Up @@ -561,7 +561,7 @@ namespace ts {
});
}

function nonSyncUpdateChildWatches(dirName: string, dirPath: Path, fileName: string, options: CompilerOptions | undefined) {
function nonSyncUpdateChildWatches(dirName: string, dirPath: Path, fileName: string, options: WatchOptions | undefined) {
// Iterate through existing children and update the watches if needed
const parentWatcher = cache.get(dirPath);
if (parentWatcher && host.directoryExists(dirName)) {
Expand All @@ -575,7 +575,7 @@ namespace ts {
removeChildWatches(parentWatcher);
}

function scheduleUpdateChildWatches(dirName: string, dirPath: Path, options: CompilerOptions | undefined) {
function scheduleUpdateChildWatches(dirName: string, dirPath: Path, options: WatchOptions | undefined) {
if (!cacheToUpdateChildWatches.has(dirPath)) {
cacheToUpdateChildWatches.set(dirPath, { dirName, options });
}
Expand Down Expand Up @@ -623,7 +623,7 @@ namespace ts {
}
}

function updateChildWatches(dirName: string, dirPath: Path, options: CompilerOptions | undefined) {
function updateChildWatches(dirName: string, dirPath: Path, options: WatchOptions | undefined) {
// Iterate through existing children and update the watches if needed
const parentWatcher = cache.get(dirPath);
if (parentWatcher) {
Expand All @@ -634,7 +634,7 @@ namespace ts {
/**
* Watch the directories in the parentDir
*/
function watchChildDirectories(parentDir: string, existingChildWatches: ChildWatches, options: CompilerOptions | undefined): ChildWatches {
function watchChildDirectories(parentDir: string, existingChildWatches: ChildWatches, options: WatchOptions | undefined): ChildWatches {
let newChildWatches: ChildDirectoryWatcher[] | undefined;
enumerateInsertsAndDeletes<string, ChildDirectoryWatcher>(
host.directoryExists(parentDir) ? mapDefined(host.getAccessibleSortedChildDirectories(parentDir), child => {
Expand Down Expand Up @@ -682,7 +682,7 @@ namespace ts {
/*@internal*/
export type FsWatchCallback = (eventName: "rename" | "change", relativeFileName: string | undefined) => void;
/*@internal*/
export type FsWatch = (fileOrDirectory: string, entryKind: FileSystemEntryKind, callback: FsWatchCallback, recursive: boolean, fallbackPollingInterval: PollingInterval, fallbackOptions: CompilerOptions | undefined) => FileWatcher;
export type FsWatch = (fileOrDirectory: string, entryKind: FileSystemEntryKind, callback: FsWatchCallback, recursive: boolean, fallbackPollingInterval: PollingInterval, fallbackOptions: WatchOptions | undefined) => FileWatcher;

/*@internal*/
export const enum FileSystemEntryKind {
Expand Down Expand Up @@ -770,7 +770,7 @@ namespace ts {
watchDirectory
};

function watchFile(fileName: string, callback: FileWatcherCallback, pollingInterval: PollingInterval, options: CompilerOptions | undefined): FileWatcher {
function watchFile(fileName: string, callback: FileWatcherCallback, pollingInterval: PollingInterval, options: WatchOptions | undefined): FileWatcher {
options = updateOptionsForWatchFile(options, useNonPollingWatchers);
const watchFileKind = Debug.assertDefined(options.watchFile);
switch (watchFileKind) {
Expand Down Expand Up @@ -804,7 +804,7 @@ namespace ts {
(dynamicPollingWatchFile = createDynamicPriorityPollingWatchFile({ getModifiedTime, setTimeout }));
}

function updateOptionsForWatchFile(options: CompilerOptions | undefined, useNonPollingWatchers?: boolean): CompilerOptions {
function updateOptionsForWatchFile(options: WatchOptions | undefined, useNonPollingWatchers?: boolean): WatchOptions {
if (options && options.watchFile !== undefined) return options;
switch (tscWatchFile) {
case "PriorityPollingInterval":
Expand Down Expand Up @@ -834,8 +834,8 @@ namespace ts {
function generateWatchFileOptions(
watchFile: WatchFileKind,
fallbackPolling: PollingWatchKind,
options: CompilerOptions | undefined
): CompilerOptions {
options: WatchOptions | undefined
): WatchOptions {
const defaultFallbackPolling = options?.fallbackPolling;
return {
watchFile,
Expand All @@ -845,7 +845,7 @@ namespace ts {
};
}

function watchDirectory(directoryName: string, callback: DirectoryWatcherCallback, recursive: boolean, options: CompilerOptions | undefined): FileWatcher {
function watchDirectory(directoryName: string, callback: DirectoryWatcherCallback, recursive: boolean, options: WatchOptions | undefined): FileWatcher {
if (fsSupportsRecursiveFsWatch) {
return fsWatch(
directoryName,
Expand All @@ -871,7 +871,7 @@ namespace ts {
return hostRecursiveDirectoryWatcher(directoryName, callback, recursive, options);
}

function nonRecursiveWatchDirectory(directoryName: string, callback: DirectoryWatcherCallback, recursive: boolean, options: CompilerOptions | undefined): FileWatcher {
function nonRecursiveWatchDirectory(directoryName: string, callback: DirectoryWatcherCallback, recursive: boolean, options: WatchOptions | undefined): FileWatcher {
Debug.assert(!recursive);
options = updateOptionsForWatchDirectory(options);
const watchDirectoryKind = Debug.assertDefined(options.watchDirectory);
Expand Down Expand Up @@ -904,7 +904,7 @@ namespace ts {
}
}

function updateOptionsForWatchDirectory(options: CompilerOptions | undefined): CompilerOptions {
function updateOptionsForWatchDirectory(options: WatchOptions | undefined): WatchOptions {
if (options && options.watchDirectory !== undefined) return options;
switch (tscWatchDirectory) {
case "RecursiveDirectoryUsingFsWatchFile":
Expand Down Expand Up @@ -1039,8 +1039,8 @@ namespace ts {
* @pollingInterval - this parameter is used in polling-based watchers and ignored in watchers that
* use native OS file watching
*/
watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number, options?: CompilerOptions): FileWatcher;
watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean, options?: CompilerOptions): FileWatcher;
watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number, options?: WatchOptions): FileWatcher;
watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean, options?: WatchOptions): FileWatcher;
resolvePath(path: string): string;
fileExists(path: string): boolean;
directoryExists(path: string): boolean;
Expand Down Expand Up @@ -1439,7 +1439,7 @@ namespace ts {
callback: FsWatchCallback,
recursive: boolean,
fallbackPollingInterval: PollingInterval,
fallbackOptions: CompilerOptions | undefined
fallbackOptions: WatchOptions | undefined
): FileWatcher {
let options: any;
let lastDirectoryPartWithDirectorySeparator: string | undefined;
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/tsbuildPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1760,7 +1760,7 @@ namespace ts {
invalidateProjectAndScheduleBuilds(state, resolvedPath, ConfigFileProgramReloadLevel.Full);
},
PollingInterval.High,
parsed?.options,
parsed?.watchOptions,
WatchType.ConfigFile,
resolved
));
Expand Down Expand Up @@ -1821,7 +1821,7 @@ namespace ts {
invalidateProjectAndScheduleBuilds(state, resolvedPath, ConfigFileProgramReloadLevel.Partial);
},
flags,
parsed?.options,
parsed?.watchOptions,
WatchType.WildcardDirectory,
resolved
)
Expand All @@ -1839,7 +1839,7 @@ namespace ts {
input,
() => invalidateProjectAndScheduleBuilds(state, resolvedPath, ConfigFileProgramReloadLevel.None),
PollingInterval.Low,
parsed?.options,
parsed?.watchOptions,
path as Path,
WatchType.SourceFile,
resolved
Expand Down
13 changes: 9 additions & 4 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5047,13 +5047,16 @@ namespace ts {
/* @internal */ showConfig?: boolean;
useDefineForClassFields?: boolean;

// Watch options
[option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined;
}

export interface WatchOptions {
watchFile?: WatchFileKind;
watchDirectory?: WatchDirectoryKind;
fallbackPolling?: PollingWatchKind;
synchronousWatchDirectory?: boolean;

[option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined;
[option: string]: CompilerOptionsValue | undefined;
}

export interface TypeAcquisition {
Expand Down Expand Up @@ -5143,6 +5146,7 @@ namespace ts {
typeAcquisition?: TypeAcquisition;
fileNames: string[];
projectReferences?: readonly ProjectReference[];
watchOptions?: WatchOptions;
raw?: any;
errors: Diagnostic[];
wildcardDirectories?: MapLike<WatchDirectoryFlags>;
Expand Down Expand Up @@ -5223,7 +5227,8 @@ namespace ts {
}

/* @internal */
export interface DidYouMeanOptionalDiagnostics {
export interface DidYouMeanOptionsDiagnostics {
optionDeclarations: CommandLineOption[];
unknownOptionDiagnostic: DiagnosticMessage,
unknownDidYouMeanDiagnostic: DiagnosticMessage,
}
Expand All @@ -5232,7 +5237,7 @@ namespace ts {
export interface TsConfigOnlyOption extends CommandLineOptionBase {
type: "object";
elementOptions?: Map<CommandLineOption>;
extraKeyDiagnostics?: DidYouMeanOptionalDiagnostics;
extraKeyDiagnostics?: DidYouMeanOptionsDiagnostics;
}

/* @internal */
Expand Down
22 changes: 13 additions & 9 deletions src/compiler/watchPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ namespace ts {
/** Compiler options */
options: CompilerOptions;

watchOptions?: WatchOptions;

/** Project References */
projectReferences?: readonly ProjectReference[];
}
Expand All @@ -147,6 +149,8 @@ namespace ts {
/** Options to extend */
optionsToExtend?: CompilerOptions;

// TODO

/**
* Used to generate source file names from the config file and its include, exclude, files rules
* and also to cache the directory stucture
Expand All @@ -159,7 +163,6 @@ namespace ts {
*/
/*@internal*/
export interface WatchCompilerHostOfConfigFile<T extends BuilderProgram> extends WatchCompilerHost<T> {
optionsToExtend?: CompilerOptions;
configFileParsingResult?: ParsedCommandLine;
}

Expand Down Expand Up @@ -237,7 +240,7 @@ namespace ts {
const useCaseSensitiveFileNames = host.useCaseSensitiveFileNames();
const currentDirectory = host.getCurrentDirectory();
const { configFileName, optionsToExtend: optionsToExtendForConfigFile = {}, createProgram } = host;
let { rootFiles: rootFileNames, options: compilerOptions, projectReferences } = host;
let { rootFiles: rootFileNames, options: compilerOptions, watchOptions, projectReferences } = host;
let configFileSpecs: ConfigFileSpecs;
let configFileParsingDiagnostics: Diagnostic[] | undefined;
let canConfigFileJsonReportNoInputFiles = false;
Expand Down Expand Up @@ -270,7 +273,7 @@ namespace ts {
writeLog(`Current directory: ${currentDirectory} CaseSensitiveFileNames: ${useCaseSensitiveFileNames}`);
let configFileWatcher: FileWatcher | undefined;
if (configFileName) {
configFileWatcher = watchFile(host, configFileName, scheduleProgramReload, PollingInterval.High, compilerOptions, WatchType.ConfigFile);
configFileWatcher = watchFile(host, configFileName, scheduleProgramReload, PollingInterval.High, watchOptions, WatchType.ConfigFile);
}

const compilerHost = createCompilerHostFromProgramHost(host, () => compilerOptions, directoryStructureHost) as CompilerHost & ResolutionCacheHost;
Expand All @@ -285,8 +288,8 @@ namespace ts {
// Members for ResolutionCacheHost
compilerHost.toPath = toPath;
compilerHost.getCompilationSettings = () => compilerOptions;
compilerHost.watchDirectoryOfFailedLookupLocation = (dir, cb, flags) => watchDirectory(host, dir, cb, flags, compilerOptions, WatchType.FailedLookupLocations);
compilerHost.watchTypeRootsDirectory = (dir, cb, flags) => watchDirectory(host, dir, cb, flags, compilerOptions, WatchType.TypeRoots);
compilerHost.watchDirectoryOfFailedLookupLocation = (dir, cb, flags) => watchDirectory(host, dir, cb, flags, watchOptions, WatchType.FailedLookupLocations);
compilerHost.watchTypeRootsDirectory = (dir, cb, flags) => watchDirectory(host, dir, cb, flags, watchOptions, WatchType.TypeRoots);
compilerHost.getCachedDirectoryStructureHost = () => cachedDirectoryStructureHost;
compilerHost.onInvalidatedResolution = scheduleProgramUpdate;
compilerHost.onChangedAutomaticTypeDirectiveNames = () => {
Expand Down Expand Up @@ -469,7 +472,7 @@ namespace ts {
(hostSourceFile as FilePresentOnHost).sourceFile = sourceFile;
hostSourceFile.version = sourceFile.version;
if (!hostSourceFile.fileWatcher) {
hostSourceFile.fileWatcher = watchFilePath(host, fileName, onSourceFileChange, PollingInterval.Low, compilerOptions, path, WatchType.SourceFile);
hostSourceFile.fileWatcher = watchFilePath(host, fileName, onSourceFileChange, PollingInterval.Low, watchOptions, path, WatchType.SourceFile);
}
}
else {
Expand All @@ -482,7 +485,7 @@ namespace ts {
}
else {
if (sourceFile) {
const fileWatcher = watchFilePath(host, fileName, onSourceFileChange, PollingInterval.Low, compilerOptions, path, WatchType.SourceFile);
const fileWatcher = watchFilePath(host, fileName, onSourceFileChange, PollingInterval.Low, watchOptions, path, WatchType.SourceFile);
sourceFilesCache.set(path, { sourceFile, version: sourceFile.version, fileWatcher });
}
else {
Expand Down Expand Up @@ -617,6 +620,7 @@ namespace ts {
function setConfigFileParsingResult(configFileParseResult: ParsedCommandLine) {
rootFileNames = configFileParseResult.fileNames;
compilerOptions = configFileParseResult.options;
watchOptions = configFileParseResult.watchOptions;
configFileSpecs = configFileParseResult.configFileSpecs!; // TODO: GH#18217
projectReferences = configFileParseResult.projectReferences;
configFileParsingDiagnostics = getConfigFileParsingDiagnostics(configFileParseResult).slice();
Expand Down Expand Up @@ -645,7 +649,7 @@ namespace ts {
}

function watchMissingFilePath(missingFilePath: Path) {
return watchFilePath(host, missingFilePath, onMissingFileChange, PollingInterval.Medium, compilerOptions, missingFilePath, WatchType.MissingFile);
return watchFilePath(host, missingFilePath, onMissingFileChange, PollingInterval.Medium, watchOptions, missingFilePath, WatchType.MissingFile);
}

function onMissingFileChange(fileName: string, eventKind: FileWatcherEventKind, missingFilePath: Path) {
Expand Down Expand Up @@ -709,7 +713,7 @@ namespace ts {
}
},
flags,
compilerOptions,
watchOptions,
WatchType.WildcardDirectory
);
}
Expand Down
Loading