-
-
Notifications
You must be signed in to change notification settings - Fork 154
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
TSX is not ignoring symlinked dependencies in monorepo #221
Comments
I am definitely interested in helping fix this because the switch to nodemon/ts-node/swc was less than pleasant. I currently have a clone of TSX and am successfully building and testing the referenced project above. Here's what I can tell you so far: The problem code is in here. I have verified the following:
The easiest solution is to check each file against the same |
Here's a fix which does what is expected. My local dependencies (monorepo "packages") are still watched by default. I don't mind manually ignoring them as this only affects monorepos and there are many situations where you would actually want to watch the local dependencies by default (even though they are outside the cwd). |
I added a test in 412a9c4 to verify changes in dependencies are being ignored. "TSX not ignoring node_modules or respecting --ignore flags" seems inaccurate. Seems you're specifically talking about monorepos? |
Hey, so I did some more testing and I found that it has nothing to do with a monorepo per se, but rather if the CWD of the watch script is on a nested directory... which happens a lot in a monorepo. I greatly simplified the sample project to remove workspaces and to show to reproduce the bug with very little fanfare. I completely removed the "workspaces" entry and simplified the code. The README should contain everything you need. |
This comment has been minimized.
This comment has been minimized.
This comment was marked as off-topic.
This comment was marked as off-topic.
The issue is about tsx not ignoring dependencies (not about how to include them in the watcher). Issues are reserved for resolving the root issue. Please avoid off topic conversation. |
I was researching this in more detail since I work in a mono-repo and TSX is consuming a substantial amount of available file handles on my Mac. I use PNPM so many dependencies are found in the root directory instead of the individual package so TSX is listening for changes across node_modules and is often listening to 7000+ files. Root CauseI deep-dived the code across TSX and Chokidar and I think I found the root cause. In
In version 3.6.0 of chokidar, they normalize all ignore paths as follows (link):
Since Possible SolutionsTherefore as I see it, there are several solutions:
Given there are several solutions, I held off writing a PR but would be curious to get your thoughts. WorkaroundThis appears to be a workaround in the meantime for ignoring all node_modules which stopped TSX from listening to parent node_modules:
Automated TestBonus automated test that fails with the current repo adapted from the test in the "exclude (ignore)" section (tests/specs/watch.ts):
|
Nice work! Would you be willing to contribute a fix? |
I could! But would just be curious to know which of the 3 potential solutions would be better |
So because tsx only watches imported files, there's a strict list of files to watch rather than entire directories. My understanding is that there is limited benefit to migrating to Parcel Watcher because it's mainly more performant for watching directories. Since we're only watching individual file paths, I was actually thinking of migrating to Node's native FS watch since it uses the same underlying system watcher. For globbing support, I'm fine with importing a glob library that tests a string against a glob (e.g. glob-to-regexp). If you anticipate a breaking change, we'll queue it for v5. |
@privatenumber yeah, I did some digging. It seems Vite had a similar thought a few years ago (vitejs/vite#12495 (comment)) and they decided not to go in that direction. I looked into the API and I'd also agree that it's probably a bit too low-level, e.g.
So the way I'd see it, we'd have 2 options:
I can make a PR for option 1) if that sounds good. (chokidar v5 + micromatch). I don't think there should be any breaking changes since it's technically fixing the incorrect watch behavior to the intended behavior. However, it could technically be considered a breaking change since we would be no longer tracking changes of node_modules in monorepos which does make it slightly trickier ironically for my use-case since changes to shared code in other packages in the monorepo no longer trigger a reload when changed. |
Chokidar v4* + micromatch sounds great! Thank you RE: inodes RE:
For the final state, I'm hoping we can evaluate the real path of the file and check if that's in |
@privatenumber alright I've pulled together a draft PR, however I stumbled upon an issue while I was at it which I'll mention in the PR (#656)
Sure - that's all in theory but looking at Chokidar there's a lot of extra logic laying around that esp. with cross-platform that could turn into a can of worms quickly. Not sure if it's worth the trade-off especially since Chokidar v4 is quite a bit slimmer.
Yeah - that's definitely possible via fs.realpath. I don't know if there are significant implications but I wonder if it's possible to resolve the path before adding it to the watcher since realpath is an asynchronous operation so wouldn't fit in as an "ignored" synchronous function. |
Bug description
I discovered this while working in a monorepo. I am using TSX to watch my application project (
/apps/my-app
). I was making edits to one of my local dependencies (/packages/utils
) and my application was restarting when I wasn't expecting. As I started to investigate I noticed that:--ignore
flagscwd
All of the above behaviors seem unexpected, especially the last one as it pertains to a monorepo. Here's a repro:
Reproduction
https://github.com/DesignByOnyx/tsx-restart-ignore-bug
Environment
Can you work on a fix?
The text was updated successfully, but these errors were encountered: