-
Notifications
You must be signed in to change notification settings - Fork 15
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
fs
hooks
#63
Comments
There should also be a way to prevent second-run code from doing this; currently i can freeze fs or save a reference to the functions i need. |
Another use cases which would help with, bundling applications. Like Also, similar to PnP/tink, things like Yeoman and Gulp also had a synthetic filesystem implementation. To the point of "not trivial to do it correctly, and it often results in rather hard-to-read implementations", both of these projects had a lot to be desired, and as an end-user I had many issues with their fs implementations (maybe they have gotten better since then, I used them primarily ~5 years ago). |
Thanks @boneskull for the heads up! This is not totally the same as the Audit Hooks initiative, but there might be some overlap.
Also, it aims at providing more hooks than Would it make sense to discuss this further if the goals are not too orthogonals? I am working on a PoC for audit hooks starting with |
I couldn't attend to the meeting yesterday btw, but my main feedback regarding custom fs layers is that it's difficult to test them. First you need to write the tests, of course, but then you need to keep them up-to-date with whatever new functions or options Node releases. This is where the main problem lies: if you forget to implement a property, the option will just be silently ignored and the code will misbehave. There are two ways I could see this being improved:
Also one funny thing I discovered during my journey: it's currently impossible to fully intercept the fs calls that Node runs during the commonjs module resolution. This is because Node doesn't actually use |
Just yesterday we went into a similar problem for "module federation" - download a "module" and execute it as a string, which is kind of FUSE case, with remote file system.
So we fixed the problem by patching Let's check what actually could be used
So all needs is a |
Quick status here as I won't be able to join tonight's meeting. Right now it works by monkeypatching internals of the fs module (for instance bindings.open) when a hook is registered (the goal is to have 0 impact when no hook is enabled). Then, it forwards the value of This works but I am afraid the API is hard to understand (and therefore use right). Also, It does not allow to "make fs lie" (call the callback function with an arbitrary value and prevent the unpatched call). This could be done by having the hook responding with a given Symbol ( |
There's likely to be some overlap with nodejs/diagnostics#180, so it might be worth unifying the concepts. |
So at the tooling working group meeting there was discussion about having a meeting for discussing how the fs hooks, policies, and diagnostics channel efforts are related. Is someone arranging that or do we need someone to lead that effort? |
@Qard good idea. I won't have time to schedule anything before next week however. |
Discussion on this has generally been taken over by the diagnostic hooks meeting and the summit, and the effort is taking place in the Diagnostics WG (nodejs/diagnostics#401) so I'll close this issue. |
The proposal here is for adding a way to add "hooks" to
fs
, allowing user code to alter its behavior.fs
operations would be intercepted, giving an opportunity to do things like change paths, provide buffers or streams corresponding to filenames, etc.There are a number of reasons why folks may want to alter the behaviour of
fs
. Some I can think of quickly:yarn --pnp
/yarn@2
,tink
.ipfs
can be used more transparently.A way to intercept
fs
would enable these sorts of use cases and probably a bunch of others I couldn't think of. This could be implemented as hooks, similar toasync_hooks
. We would, of course, want this to have zero (or nearly zero) overhead when not enabled.Potentially Related: #48
Prior art
FUSE exists today fitting a similar use case at the system level, and could be used as a template for building our own API.
Alternatives existing today
In order to do anything like this today, folks are shimming
fs
directly. While this is generally workable, it's certainly not trivial to do it correctly, and it often results in rather hard-to-read implementations.The text was updated successfully, but these errors were encountered: