Skip to content

Commit

Permalink
Cherry-pick PR #49246 into release-4.7 (#49250)
Browse files Browse the repository at this point in the history
Component commits:
b846905 Add failing test

66d51e5 Fix the implicit glob key so that recursive keys are not differing just by directory seperator Fixes #49078

f93951f Reset the reload level once program is loaded

Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
  • Loading branch information
TypeScript Bot and sheetalkamat authored Jun 1, 2022
1 parent 3551935 commit 197aaef
Show file tree
Hide file tree
Showing 5 changed files with 432 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3542,7 +3542,7 @@ namespace ts {
}
if (isImplicitGlob(spec.substring(spec.lastIndexOf(directorySeparator) + 1))) {
return {
key: useCaseSensitiveFileNames ? spec : toFileNameLowerCase(spec),
key: removeTrailingDirectorySeparator(useCaseSensitiveFileNames ? spec : toFileNameLowerCase(spec)),
flags: WatchDirectoryFlags.Recursive
};
}
Expand Down
1 change: 1 addition & 0 deletions src/compiler/watchPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ namespace ts {

function reloadFileNamesFromConfigFile() {
writeLog("Reloading new file names and options");
reloadLevel = ConfigFileProgramReloadLevel.None;
rootFileNames = getFileNamesFromConfigSpecs(compilerOptions.configFile!.configFileSpecs!, getNormalizedAbsolutePath(getDirectoryPath(configFileName), currentDirectory), compilerOptions, parseConfigFileHost, extraFileExtensions);
if (updateErrorForNoInputFiles(rootFileNames, getNormalizedAbsolutePath(configFileName, currentDirectory), compilerOptions.configFile!.configFileSpecs!, configFileParsingDiagnostics!, canConfigFileJsonReportNoInputFiles)) {
hasChangedConfigFileParsingErrors = true;
Expand Down
9 changes: 9 additions & 0 deletions src/testRunner/unittests/config/tsconfigParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,5 +421,14 @@ namespace ts {
const parsedCommand = parseJsonConfigFileContent(parsed.config, sys, "/foo.bar");
assert.deepEqual(parsedCommand.wildcardDirectories, { "/foo.bar/src": WatchDirectoryFlags.Recursive });
});

it("correctly parses wild card directories from implicit glob when two keys differ only in directory seperator", () => {
const parsed = parseConfigFileTextToJson("/foo.bar/tsconfig.json", JSON.stringify({
include: ["./", "./**/*.json"]
}));

const parsedCommand = parseJsonConfigFileContent(parsed.config, sys, "/foo");
assert.deepEqual(parsedCommand.wildcardDirectories, { "/foo": WatchDirectoryFlags.Recursive });
});
});
}
33 changes: 33 additions & 0 deletions src/testRunner/unittests/tscWatch/programUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,39 @@ export class A {
]
});

verifyTscWatch({
scenario,
subScenario: "correctly parses wild card directories from implicit glob when two keys differ only in directory seperator",
commandLineArgs: ["-w", "--extendedDiagnostics"],
sys: () => {
const file1 = {
path: `${projectRoot}/f1.ts`,
content: "export const x = 1"
};
const file2 = {
path: `${projectRoot}/f2.ts`,
content: "export const y = 1"
};
const configFile = {
path: `${projectRoot}/tsconfig.json`,
content: JSON.stringify({ compilerOptions: { composite: true }, include: ["./", "./**/*.json"] })
};
return createWatchedSystem([file1, file2, libFile, configFile], { currentDirectory: projectRoot });
},
changes: [
{
caption: "Add new file",
change: sys => sys.writeFile(`${projectRoot}/new-file.ts`, "export const z = 1;"),
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(1),
},
{
caption: "Import new file",
change: sys => sys.prependFile(`${projectRoot}/f1.ts`, `import { z } from "./new-file";`),
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(1),
}
]
});

verifyTscWatch({
scenario,
subScenario: "can correctly update configured project when set of root files has changed through include",
Expand Down
Loading

0 comments on commit 197aaef

Please sign in to comment.