-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[Bug?] 'watchFiles' does not appear to be watched after errors #1063
Comments
What would be the desired behavior here? Falling back to the previous The fundamental issue here is that FWIW the plugin should be able to handle this itself by using try/catch and returning Random thought: I wonder if an API change could help. For example, maybe instead of returning |
I think #1037 is probably the right philosophy. I think there is an expectation that when watch mode is enabled, whether or not a build is successful, esbuild should act like a persistent dev server. So specifically, when watch mode is enabled, I think it makes more sense for esbuild to never crash unless there’s some kind of fatal condition (like
Ah, that makes sense. How can you watch when you don’t know what to watch? I hadn’t thought about that condition.
This makes sense on its face but I think it’s not necessarily the right design simply because every plugin author needs to implement their own error-handling. That seems like a good idea, and I even think with a language like Go this is very reasonable and sort of the expectation, but I don’t think that will happen most of the time with JS / node-based plugins. At least it’d be nice -- from a user’s perspective -- if I can throw together Sass and MDX plugins and not worry about how Sass or MDX handles errors, and just leave it up to the stack trace that gets reported back to me by esbuild. I know this design is a little dirty but I think this is somewhat inevitable with JS / node-based error-handling. Of course, this is just my opinion, but there are so many ways JS / node programs can error even when they are typed (e.g TypeScript). There are thrown errors, callback errors, I’m not against returning
It sounds like the difference here is that his gives plugins a chance to be preemptive about which files / directories are to be watched versus gathering this info from the return statement, which may be iffy because of unhandled errors / exceptions. It makes sense that you would want to do this but with Sass at least, I believe I only get access to So I think if and error occurs during watch mode, esbuild should still watch export interface Result {
/**
* The compiled CSS.
*
* Write this to a file, or serve it out as needed.
*/
css: Buffer;
/**
* The source map.
*/
map?: Buffer;
stats: {
/**
* The path to the scss file, or `data` if the source was not a file.
*/
entry: string;
/**
* `Date.now()` before the compilation.
*/
start: number;
/**
* `Date.now()` after the compilation.
*/
end: number;
/**
* `end - start`
*/
duration: number;
/**
* Absolute paths to all related files in no particular order.
*/
includedFiles: string[];
};
} Having worked with esbuild and the watch features for a little while, my experience can be summed up as this: while the watch features are convenient and ideally engineered, they are less ergonomic than simply implementing your own watcher implementation. Therefore I’ve found using If you’re curious about my real-world use case, the relevant esbuild code is here. Essentially what I’m doing is using Go as the parent process and creating an IPC service that uses JSON to communicate with node over stdio. That is implemented here. That simply gives me channels to pipe in stdin and get back stdout or stderr. I’m using stdin to send commands and stdout to get build responses from esbuild, specifically errors and warnings messages that I use the new formatter API to format and report back to the user when a build breaks. stderr is reserved for operational errors and are treated as exceptions to Go (e.g. will panic). OK so now that that’s out of the way, I need to be able to predictably trigger rebuilds on file changes. Theoretically I can use esbuild for this but the problems are the following:
The point is that I’ve found using esbuild’s watch features to not be composable. Alternatively, by simply using I should mention that this is how and where I tell esbuild to programmatically rebuild from Go. My watch mode is not CPU optimized yet but it does make my life easy because I have so much less to worry about by simply greedily watching |
As a esbuild user I find myself sharing the same experience of @zaydek on watch vs incremental so I prefer to avoid watch mode altogether but, as plugin developer, I can see people prefer a pre-packaged solution so I am doing my best to make it work. @evanw I think that #1037 is a reasonable expectation and despite for now I fixed this issue by returning What I would like is that esbuild, which already has this cache, leaves it unmodified until the next successful build so that errors can be fixed and the change detected by the last successful build watched files if that makes sense. |
I’m experimenting with the new
watchFiles
API that was included in 0.10.0 and noticed that when a plugin throws,watchFiles
are no longer being watched. It’s a little hard to put into words so I recorded a small video.Essentially, after I syntactically break Sass and save, I see
watch.onRebuild
fires, but then further saves (where the source Sass file actually changes, but is still syntactically broken), furtherwatch.onRebuild
events do not fire.Minimal repro here: https://github.com/zaydek/esbuild-watchfiles-bug.
Edit: If the video doesn’t appear for any reason, you can download it from here.
sass-rebuild-bug.mov
The text was updated successfully, but these errors were encountered: