diff --git a/tsc/internal/project/watch.go b/tsc/internal/project/watch.go index 5c55ee3b22e01..f37eb8ef343ab 100644 --- a/tsc/internal/project/watch.go +++ b/tsc/internal/project/watch.go @@ -450,8 +450,8 @@ func perceivedOsRootLengthForWatching(pathComponents []string) int { } return 1 } - if pathComponents[1] == "home" { - // Group /home/username into a single component + if pathComponents[1] == "home" || strings.EqualFold(pathComponents[1], "Users") { + // Group /home/username or /Users/username into a single component return min(3, length) } return 1 diff --git a/tsc/internal/project/watch_test.go b/tsc/internal/project/watch_test.go index 139e190924991..c59fe6452cc1a 100644 --- a/tsc/internal/project/watch_test.go +++ b/tsc/internal/project/watch_test.go @@ -21,6 +21,46 @@ func TestGetPathComponentsForWatching(t *testing.T) { assert.DeepEqual(t, getPathComponentsForWatching(tspath.ToRootedDirectoryPath("C:\\Users\\andrew\\project", "")), []string{"C:/Users/andrew", "project"}) assert.DeepEqual(t, getPathComponentsForWatching(tspath.ToRootedDirectoryPath("/home", "")), []string{"/home"}) assert.DeepEqual(t, getPathComponentsForWatching(tspath.ToRootedDirectoryPath("/home/andrew/project", "")), []string{"/home/andrew", "project"}) + assert.DeepEqual(t, getPathComponentsForWatching(tspath.ToRootedDirectoryPath("/Users", "")), []string{"/Users"}) + assert.DeepEqual(t, getPathComponentsForWatching(tspath.ToRootedDirectoryPath("/Users/andrew", "")), []string{"/Users/andrew"}) + assert.DeepEqual(t, getPathComponentsForWatching(tspath.ToRootedDirectoryPath("/Users/andrew/project", "")), []string{"/Users/andrew", "project"}) +} + +func TestResolutionLookupWatcherOmitsMacOSHomeDirectories(t *testing.T) { + t.Parallel() + + for _, caseSensitivity := range []tspath.CaseSensitivity{tspath.CaseSensitive, tspath.CaseInsensitive} { + usersDirectory := "/Users" + if caseSensitivity == tspath.CaseInsensitive { + usersDirectory = "/users" + } + + var files collections.SyncMap[tspath.PathKey, tspath.RootedFilePath] + for _, fileName := range []tspath.RootedFilePath{ + tspath.ToRootedFilePath(usersDirectory+"/package.json", ""), + tspath.ToRootedFilePath(usersDirectory+"/andrew/package.json", ""), + tspath.ToRootedFilePath(usersDirectory+"/andrew/project/package.json", ""), + tspath.ToRootedFilePath(usersDirectory+"/andrew/other/package.json", ""), + } { + files.Store(caseSensitivity.PathKey(tspath.RootedPath(fileName)), fileName) + } + + result := createResolutionLookupGlobMapper( + tspath.ToRootedDirectoryPath(usersDirectory+"/andrew/project", ""), + "/lib", + "/dev/null", + caseSensitivity, + )(&files) + + assert.DeepEqual(t, result.patternsInsideWorkspace, []string{usersDirectory + "/andrew/project/**/*"}) + assert.DeepEqual(t, result.directoriesOutsideWorkspace, []tspath.RootedDirectoryPath{tspath.ToRootedDirectoryPath(usersDirectory+"/andrew/other", "")}) + assert.DeepEqual(t, result.ignored, map[tspath.RootedDirectoryPath]struct{}{ + tspath.ToRootedDirectoryPath(usersDirectory, ""): {}, + tspath.ToRootedDirectoryPath(usersDirectory+"/andrew", ""): {}, + }) + watcher := newRecursiveDirectoryWatcher(result.directoriesOutsideWorkspace[0], lsproto.WatchKindCreate, true) + assert.Equal(t, string(*watcher.GlobPattern.RelativePattern.BaseUri.URI), "file://"+usersDirectory+"/andrew/other") + } } func TestNilWatchedFilesClone(t *testing.T) {