Replace disk path operations to use fileNames instead of path (#56476)

Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
This commit is contained in:
Sheetal Nandi
2023-11-27 22:21:29 -08:00
committed by GitHub
co-authored by Andrew Branch
parent c32ad95b96
commit b6121e400c
106 changed files with 976 additions and 659 deletions
+7 -7
View File
@@ -1650,7 +1650,7 @@ export class ProjectService {
*
* @internal
*/
private watchWildcardDirectory(directory: Path, flags: WatchDirectoryFlags, configFileName: NormalizedPath, config: ParsedConfig) {
private watchWildcardDirectory(directory: string, flags: WatchDirectoryFlags, configFileName: NormalizedPath, config: ParsedConfig) {
let watcher: FileWatcher | undefined = this.watchFactory.watchDirectory(
directory,
fileOrDirectory => {
@@ -1658,7 +1658,7 @@ export class ProjectService {
const fsResult = config.cachedDirectoryStructureHost.addOrDeleteFileOrDirectory(fileOrDirectory, fileOrDirectoryPath);
if (
getBaseFileName(fileOrDirectoryPath) === "package.json" && !isInsideNodeModules(fileOrDirectoryPath) &&
(fsResult && fsResult.fileExists || !fsResult && this.host.fileExists(fileOrDirectoryPath))
(fsResult && fsResult.fileExists || !fsResult && this.host.fileExists(fileOrDirectory))
) {
const file = this.getNormalizedAbsolutePath(fileOrDirectory);
this.logger.info(`Config: ${configFileName} Detected new package.json: ${file}`);
@@ -1669,7 +1669,7 @@ export class ProjectService {
const configuredProjectForConfig = this.findConfiguredProjectByProjectName(configFileName);
if (
isIgnoredFileFromWildCardWatching({
watchedDirPath: directory,
watchedDirPath: this.toPath(directory),
fileOrDirectory,
fileOrDirectoryPath,
configFileName,
@@ -2666,9 +2666,9 @@ export class ProjectService {
config!.watchedDirectoriesStale = false;
updateWatchingWildcardDirectories(
config!.watchedDirectories ||= new Map(),
new Map(Object.entries(config!.parsedCommandLine!.wildcardDirectories!)),
config!.parsedCommandLine!.wildcardDirectories,
// Create new directory watcher
(directory, flags) => this.watchWildcardDirectory(directory as Path, flags, configFileName, config!),
(directory, flags) => this.watchWildcardDirectory(directory, flags, configFileName, config!),
);
}
else {
@@ -2759,7 +2759,7 @@ export class ProjectService {
projectRootFilesMap.forEach((value, path) => {
if (!newRootScriptInfoMap.has(path)) {
if (value.info) {
project.removeFile(value.info, project.fileExists(path), /*detachFromProject*/ true);
project.removeFile(value.info, project.fileExists(value.info.fileName), /*detachFromProject*/ true);
}
else {
projectRootFilesMap.delete(path);
@@ -3145,7 +3145,7 @@ export class ProjectService {
}
private getModifiedTime(info: ScriptInfo) {
return (this.host.getModifiedTime!(info.path) || missingFileModifiedTime).getTime();
return (this.host.getModifiedTime!(info.fileName) || missingFileModifiedTime).getTime();
}
private refreshScriptInfo(info: ScriptInfo) {
+3 -3
View File
@@ -1574,7 +1574,7 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
this.program,
this.missingFilesMap || (this.missingFilesMap = new Map()),
// Watch the missing files
missingFilePath => this.addMissingFileWatcher(missingFilePath),
(missingFilePath, missingFileName) => this.addMissingFileWatcher(missingFilePath, missingFileName),
);
if (this.generatedFilesMap) {
@@ -1699,14 +1699,14 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
}
}
private addMissingFileWatcher(missingFilePath: Path): FileWatcher {
private addMissingFileWatcher(missingFilePath: Path, missingFileName: string): FileWatcher {
if (isConfiguredProject(this)) {
// If this file is referenced config file, we are already watching it, no need to watch again
const configFileExistenceInfo = this.projectService.configFileExistenceInfoCache.get(missingFilePath as string as NormalizedPath);
if (configFileExistenceInfo?.config?.projects.has(this.canonicalConfigFilePath)) return noopFileWatcher;
}
const fileWatcher = this.projectService.watchFactory.watchFile(
missingFilePath,
getNormalizedAbsolutePath(missingFileName, this.currentDirectory),
(fileName, eventKind) => {
if (isConfiguredProject(this)) {
this.getCachedDirectoryStructureHost().addOrDeleteFile(fileName, missingFilePath, eventKind);