mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fix the incorrect copy over for watchOptions and fix order of watches for referenced projects (#59871)
This commit is contained in:
@@ -3267,6 +3267,7 @@ function isSuccessfulParsedTsconfig(value: ParsedTsconfig) {
|
||||
interface ExtendsResult {
|
||||
options: CompilerOptions;
|
||||
watchOptions?: WatchOptions;
|
||||
watchOptionsCopied?: boolean;
|
||||
include?: string[];
|
||||
exclude?: string[];
|
||||
files?: string[];
|
||||
@@ -3325,7 +3326,7 @@ function parseConfig(
|
||||
|
||||
ownConfig.options = assign(result.options, ownConfig.options);
|
||||
ownConfig.watchOptions = ownConfig.watchOptions && result.watchOptions ?
|
||||
assign(result.watchOptions, ownConfig.watchOptions) :
|
||||
assignWatchOptions(result, ownConfig.watchOptions) :
|
||||
ownConfig.watchOptions || result.watchOptions;
|
||||
}
|
||||
return ownConfig;
|
||||
@@ -3355,11 +3356,17 @@ function parseConfig(
|
||||
}
|
||||
assign(result.options, extendedConfig.options);
|
||||
result.watchOptions = result.watchOptions && extendedConfig.watchOptions ?
|
||||
assign({}, result.watchOptions, extendedConfig.watchOptions) :
|
||||
assignWatchOptions(result, extendedConfig.watchOptions) :
|
||||
result.watchOptions || extendedConfig.watchOptions;
|
||||
// TODO extend type typeAcquisition
|
||||
}
|
||||
}
|
||||
|
||||
function assignWatchOptions(result: ExtendsResult, watchOptions: WatchOptions) {
|
||||
if (result.watchOptionsCopied) return assign(result.watchOptions!, watchOptions);
|
||||
result.watchOptionsCopied = true;
|
||||
return assign({}, result.watchOptions, watchOptions);
|
||||
}
|
||||
}
|
||||
|
||||
function parseOwnConfigOfJson(
|
||||
|
||||
+21
-13
@@ -435,6 +435,11 @@ export function createWatchProgram<T extends BuilderProgram>(host: WatchCompiler
|
||||
let updateLevel: ProgramUpdateLevel; // level to indicate if the program needs to be reloaded from config file/just filenames etc
|
||||
let missingFilesMap: Map<Path, FileWatcher>; // Map of file watchers for the missing files
|
||||
let watchedWildcardDirectories: Map<string, WildcardDirectoryWatcher>; // map of watchers for the wild card directories in the config file
|
||||
/**
|
||||
* undefined - own watches are stale,
|
||||
* path - for referenced project which need to be watched
|
||||
*/
|
||||
let staleWatches: Map<Path | undefined, string | undefined> | undefined = new Map([[undefined, undefined]]);
|
||||
let timerToUpdateProgram: any; // timer callback to recompile the program
|
||||
let timerToInvalidateFailedLookupResolutions: any; // timer callback to invalidate resolutions for changes in failed lookup locations
|
||||
let parsedConfigs: Map<Path, ParsedConfig> | undefined; // Parsed commandline and watching cached for referenced projects
|
||||
@@ -550,12 +555,6 @@ export function createWatchProgram<T extends BuilderProgram>(host: WatchCompiler
|
||||
builderProgram = readBuilderProgram(compilerOptions, compilerHost) as any as T;
|
||||
synchronizeProgram();
|
||||
|
||||
// Update the wild card directory watch
|
||||
watchConfigFileWildCardDirectories();
|
||||
|
||||
// Update extended config file watch
|
||||
if (configFileName) updateExtendedConfigFilesWatches(toPath(configFileName), compilerOptions, watchOptions, WatchType.ExtendedConfigFile);
|
||||
|
||||
return configFileName ?
|
||||
{ getCurrentProgram: getCurrentBuilderProgram, getProgram: updateProgram, close, getResolutionCache } :
|
||||
{ getCurrentProgram: getCurrentBuilderProgram, getProgram: updateProgram, updateRootFileNames, close, getResolutionCache };
|
||||
@@ -663,6 +662,20 @@ export function createWatchProgram<T extends BuilderProgram>(host: WatchCompiler
|
||||
compilerHost.createDirectory = originalCreateDirectory;
|
||||
compilerHost.writeFile = originalWriteFile!;
|
||||
|
||||
staleWatches?.forEach((configFile, configPath) => {
|
||||
if (!configPath) {
|
||||
// Update the wild card directory watch
|
||||
watchConfigFileWildCardDirectories();
|
||||
|
||||
// Update extended config file watch
|
||||
if (configFileName) updateExtendedConfigFilesWatches(toPath(configFileName), compilerOptions, watchOptions, WatchType.ExtendedConfigFile);
|
||||
}
|
||||
else {
|
||||
const config = parsedConfigs?.get(configPath);
|
||||
if (config) watchReferencedProject(configFile!, configPath, config);
|
||||
}
|
||||
});
|
||||
staleWatches = undefined;
|
||||
return builderProgram;
|
||||
}
|
||||
|
||||
@@ -930,13 +943,8 @@ export function createWatchProgram<T extends BuilderProgram>(host: WatchCompiler
|
||||
}
|
||||
parseConfigFile();
|
||||
hasChangedCompilerOptions = true;
|
||||
(staleWatches ??= new Map()).set(undefined, undefined);
|
||||
synchronizeProgram();
|
||||
|
||||
// Update the wild card directory watch
|
||||
watchConfigFileWildCardDirectories();
|
||||
|
||||
// Update extended config file watch
|
||||
updateExtendedConfigFilesWatches(toPath(configFileName), compilerOptions, watchOptions, WatchType.ExtendedConfigFile);
|
||||
}
|
||||
|
||||
function parseConfigFile() {
|
||||
@@ -996,7 +1004,7 @@ export function createWatchProgram<T extends BuilderProgram>(host: WatchCompiler
|
||||
else {
|
||||
(parsedConfigs ||= new Map()).set(configPath, config = { parsedCommandLine });
|
||||
}
|
||||
watchReferencedProject(configFileName, configPath, config);
|
||||
(staleWatches ??= new Map()).set(configPath, configFileName);
|
||||
return parsedCommandLine;
|
||||
}
|
||||
|
||||
|
||||
@@ -405,4 +405,41 @@ X;`,
|
||||
],
|
||||
baselineDependencies: true,
|
||||
});
|
||||
|
||||
verifyTscWatch({
|
||||
scenario: "projectsWithReferences",
|
||||
subScenario: "watch options differing between projects",
|
||||
sys: () =>
|
||||
solutionBuildWithBaseline(
|
||||
TestServerHost.createWatchedSystem({
|
||||
"/user/username/workspace/project/tsconfig.base.json": jsonToReadableText({
|
||||
watchOptions: {
|
||||
excludeDirectories: ["**/node_modules"],
|
||||
},
|
||||
}),
|
||||
"/user/username/workspace/project/tsconfig.A.json": jsonToReadableText({
|
||||
extends: "./tsconfig.base.json",
|
||||
compilerOptions: { composite: true },
|
||||
include: ["src/a/**/*.ts"],
|
||||
watchOptions: {
|
||||
excludeDirectories: ["**/excludes_by_A"],
|
||||
},
|
||||
}),
|
||||
"/user/username/workspace/project/src/a/a.ts": "export const a = 10;",
|
||||
"/user/username/workspace/project/tsconfig.B.json": jsonToReadableText({
|
||||
extends: "./tsconfig.base.json",
|
||||
include: ["src/b/**/*.ts"],
|
||||
references: [
|
||||
{ path: "./tsconfig.A.json" },
|
||||
],
|
||||
}),
|
||||
"/user/username/workspace/project/src/b/b.ts": "export const b = 10;",
|
||||
}, {
|
||||
currentDirectory: "/user/username/workspace/project",
|
||||
useCaseSensitiveFileNames: false,
|
||||
}),
|
||||
["tsconfig.A.json"],
|
||||
),
|
||||
commandLineArgs: ["-w", "-p", "tsconfig.B.json", "--traceResolution", "--extendedDiagnostics"],
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user