-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macOS: TypeScript installs recursive file watchers on ~/Library
leading to access prompts
#59831
Comments
Here is a quick and dirty patch: diff --git a/extensions/typescript-language-features/src/tsServer/fileWatchingManager.ts b/extensions/typescript-language-features/src/tsServer/fileWatchingManager.ts
index 27b9ec3d7f6c..d9a4e02ee7db 100644
--- a/extensions/typescript-language-features/src/tsServer/fileWatchingManager.ts
+++ b/extensions/typescript-language-features/src/tsServer/fileWatchingManager.ts
@@ -60,6 +60,12 @@ export class FileWatcherManager implements IDisposable {
if (watchParentDirs && uri.scheme !== Schemes.untitled) {
// We need to watch the parent directories too for when these are deleted / created
for (let dirUri = Utils.dirname(uri); dirUri.path.length > 1; dirUri = Utils.dirname(dirUri)) {
+ // on macOS, avoid turning `~/Library/Caches/typescript/5.5/...` into a watcher on `~/Library`
+ // this prevents security alerts, due to a parcel-bundler/watcher bug trying to open(~/Library/Containers)
+ // https://github.com/microsoft/vscode/issues/208105#issuecomment-2323462416
+ if (dirUri.path.endsWith('/Library/Caches')) {
+ break;
+ }
const dirWatcher: DirWatcherEntry = { uri: dirUri, listeners: [] };
let parentDirWatcher = this._dirWatchers.get(dirUri); |
it's not clear to me why the extension is trying to traverse upward and install additional watcher up through the root? perhaps the proper fix is: --- a/extensions/typescript-language-features/src/tsServer/serverProcess.browser.ts
+++ b/extensions/typescript-language-features/src/tsServer/serverProcess.browser.ts
@@ -115,7 +115,7 @@ class WorkerServerProcess implements TsServerProcess {
}
case 'watchDirectory':
case 'watchFile': {
- this._watches.create(event.data.id, vscode.Uri.from(event.data.uri), /*watchParentDirs*/ true, !!event.data.recursive, {
+ this._watches.create(event.data.id, vscode.Uri.from(event.data.uri), /*watchParentDirs*/ false, !!event.data.recursive, {
change: uri => this._watcher.postMessage({ type: 'watch', event: 'change', uri }),
create: uri => this._watcher.postMessage({ type: 'watch', event: 'create', uri }),
|
I think I understand.. the intention of the Unfortunately it doesn't appear that For the initially requested directory, FileWatcherManager.create appends const watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(uri, isRecursive ? '**' : '*'), !listeners.create, !listeners.change, !listeners.delete); |
Never mind, the issue is not related to I found in tsserver.log that it is explicitly requesting a resursive watcher on ~/Library, because it infers the default cache location of ~/Library/Caches/typescript/5.5/node_modules is rooted there. EDIT: It appears I may be using another typescript extension that's causing this issue |
I believe this is where a directory watcher on ~/Library is installed: TypeScript/src/server/project.ts Lines 1601 to 1604 in a709f98
|
@tmm1 we need a tsserver log for this issue so we can determine what is the best way to fix this. Thanks |
Okay. This is hard to reproduce as it happens very intermittently (not sure when tsserver decides to use I will remember to capture and share the logs next time. |
Here is what I see when things go haywire:
|
I need the complete log pls. You can replace all sensitive information in the log but file list is important to see whats going on |
From the log it seems like you have plugin enabled. Can you please disable the plugins and then generate new tsserver log file and see if this still repros. I am still trying to find why "Library" is watched instead of "node_modules" in it and have no repro yet Edit1: I think for some reason your current directory sent to tsserver is "/" which is what probably causing this . will need to really see if i can repro it that way. But may be your plugin is causing that to happen? Edit2: Yes the repro needs the current directory to be "/" and then i am able to see the issue. |
I am not able to repro easily without the plugin. I believe what's happening is that the plugin uses in-memory documents with no real file path. These are causing confusion in resolving project root and resulting in file watchers on strangely rooted directories. cc #59508 |
Yeah but its not issue when its using correct location of vscode which is normally a path thats not "/" and we will watch "node_modules" instead of determining what to watch based off of "root directory". Plugin is what is causing current directory for tsserver to be "/" and not something like "/Applications/Visual Studio Code.app/Contents/Resources/app/bin" You can create a document that's not on disk by: |
🔎 Search Terms
file watcher
🕗 Version & Regression Information
🙁 Actual behavior
We have seen a user in microsoft/vscode#208105 report that TypeScript installed a recursive file watcher on
~/Library
. This can trigger permission dialogs on macOS starting from 14.x.🙂 Expected behavior
TypeScript should not install recursive file watchers so broadly.
//cc @DanielRosenwasser @sheetalkamat maybe you could comment how such a path can be used for watching? Are there global installations of TypeScript in
~/Library
?The text was updated successfully, but these errors were encountered: