-
Notifications
You must be signed in to change notification settings - Fork 566
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
Atomic copyFile
to foreign.js
breaks filewatchers
#3862
Comments
A few additional thoughts for what they're worth:
I'd view this request as an enhancement rather than a bug as |
Thanks for writing this up. I'm going to remove the "bug" label because I agree that this isn't a bug, but it's still worth considering. Also, I think it's worth noting that although FFI files are usually small, we can't assume that they always are. A data point: the largest FFI file in the official package set currently is Data.HashMap/foreign.js at 33K, which I agree is not large enough to worry about. However I wouldn't be surprised if there's some proprietary projects which generate enormous FFI files using tools for whatever reason. |
I have to feel that somehow FFI files shouldn't be really huge - that there should be a best practice that tends to limit it somehow. Can't offer any solid evidence for this tho' Basically if an FFI file is huge it must have some very large JS functions in it or a huge number of FFI endpoints (or both). In the former case, it seems like maybe the bulk of the JS could live somewhere else (ie installed by npm or something) and in the latter, seems like it'd be undesirable too, so many signatures to maintain, huge surface area. So, it would be nice to hear of any proprietary projects that have needed this, and hear the rationale for it. |
Eh, I would say "FFI files should not be larger than x KB" is a constraint that is reasonable to impose within a style guide, but not reasonable to impose within the actual compiler. |
Agreed. |
Nontrivial work does occur in FFI files, but a convenient, fast edit/refresh cycle also takes on increased importance in those cases because JavaScript doesn't provide PureScript's guarantees and mistakes only show up when you run the thing. If large files produced by tooling are a real concern, in principle the compiler could impose some size-based, documented cutoff and safe-write those on the theory that the user is less likely to depend on file watchers detecting when they change. It seems to me though that even in this case a user is more likely to be surprised and frustrated by the failure of a watcher in that case than slower/unsafer duplication of the file. |
This might be undesirable feature creep, but a CLI flag to enable safe-write could meet the needs of all users. Also, I initially started writing this as a |
Yeah, I would prefer to copy "unsafely" all of the time rather than make this configurable via a CLI flag. No worries re labelling - I agree that the bug template fits this issue better, I just wanted to explain why I removed the label. |
We just observed a bug due to not writing normal JS output files atomically in Slack. We saw this appearing in the output:
Using atomic writes (i.e. writing the file to a temporary directory and then only moving it to its desired destination when it’s complete) would have avoided this. Then again, this particular issue was probably caused by having two |
Given that bugs arising from non-atomic copies do pop up in practice, I'm not really very keen on changing this. Ideally we would be moving in the other direction, i.e. making more of the filesystem operations the compiler performs atomic. An example of a bug arising from non-atomic copies which I often run into is in GHC, where it's common to see errors along the lines of:
although I believe this is now fixed in newer versions of GHC. I'm actually a bit bewildered that webpack and parcel ask you so shamelessly to turn off this functionality in your editors; it exists for a very good reason. In my mind it's definitely webpack and parcel which ought to be fixed here, not purs. |
I agree. I'm hoping snowpack doesn't have this issue, so that when ES modules output is available, we'll have a better iterative development option. |
Description
Filewatchers of bundlers like parcel and webpack break when their inputs are atomically overwritten.
purs
does this forforeign.js
files, and so automatic rebundling is not triggered upon changes in FFI .js code.To Reproduce
A repo with steps to reproduce this issue is available here:
https://github.com/milesfrain/ffi-reload
Expected behavior
Ideally
output/**/foreign.js
files would be written in the same way asoutput/**/index.js
files, withwriteTextFile
:purescript/src/Language/PureScript/Make/Actions.hs
Line 225 in 1d78a36
instead of atomic
copyFile
:purescript/src/Language/PureScript/Make/Monad.hs
Line 186 in 1d78a36
While it is less efficient to read-then-write these files, the performance hit should be negligible with these small FFI files, and it seems like a worthwhile tradeoff to improve interoperability with the web development ecosystem.
Additional context
@blonkhart (on slack) shared a workaround for
parcel
using an updatedchokidar
dependency:PureScript version
0.13.6
The text was updated successfully, but these errors were encountered: