-
Notifications
You must be signed in to change notification settings - Fork 29.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
internalModuleStat & internalModuleReadJSON prevent resolution override #33423
Comments
No and no. The module loader doesn't use I suppose Node could detect when |
To be clear: I don't want (or really need) That being said, there is currently no way to override this part of the filesystem access, whether it's for instrumentation or other purposes. It's quite unique to this part of Node, and in that there's a decent case that it can be constructed as a bug (just imagine that I never mentioned Basically, all I'm asking is to change: const {
internalModuleReadJSON,
internalModuleStat
} = internalBinding('fs'); Into: const fsBinding = internalBinding('fs'); Nothing would be any more public than it currently is, but it would help people who know what they're doing at very little cost.
I don't think this would be a good idea. It shouldn't be Node's responsibility to account for potential external runtimes, it should be external runtimes that perfectly replicate Node's expected behavior. Problem is, for this to happen, it needs to be technically possible 😃 |
FWIW, Java has figured out how to support virtual file systems (as well as custom class loaders). https://docs.oracle.com/javase/8/docs/technotes/guides/io/fsp/filesystemprovider.html |
What steps will reproduce the bug?
Imagine that the
fs
module is overriden to add support for a virtual filesystem. Make arequire
call towards a virtual file.What is the expected behavior?
The resolution should succeed, since the
fs
methods know how to access the file.What do you see instead?
Cannot find module 'virtual'.
Additional information
This occurs because Node cheats and doesn't actually use all of the
fs
methods. In most cases it does (for examplefs.realpath
,fs.readFile
,fs.readdir
), but not for all. Two methods in particular goes into unique native bindings that cannot be overriden:internalModuleStat
is used instead offs.stat
: https://github.com/nodejs/node/blob/master/lib/internal/modules/cjs/loader.js#L151internalModuleReadJSON
is used instead offs.readFile
:https://github.com/nodejs/node/blob/master/lib/internal/modules/cjs/loader.js#L257
Since those functions aren't exposed (not only do they come from
internalBinding
, they're alsodestructured
so we never have a chance to change their references), we cannot even add the virtual layer to them at all.Would it be possible to use the
fs
primitives or, at least, to exposeinternalModuleStat
& friends in a way we can wrap them?The text was updated successfully, but these errors were encountered: