Skip to content

Commit

Permalink
Fix the implicit glob key so that recursive keys are not differing ju…
Browse files Browse the repository at this point in the history
…st directory separator for wildcard directory (#49246)

* Add failing test

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

* Reset the reload level once program is loaded
  • Loading branch information
sheetalkamat committed May 25, 2022
1 parent 1fb2b2d commit 0ad5f82
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
Expand Up @@ -3548,7 +3548,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
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
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
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

0 comments on commit 0ad5f82

Please sign in to comment.