-
Notifications
You must be signed in to change notification settings - Fork 147
Reduce pseudo internal Node APIs #66
Comments
Hi @vkurchatkin! Our usage of pseudo internals falls into a couple buckets.
These are used to either enable a hook or recreate behavior of various code paths.
When possible, operations are guarded by fallbacks or catches to prevent failure. This is especially true for operations that enhance debugging or performance. While it's true some pseudo internal APIs can and do change the ones we're using for hooks tend to be a bit more resilient. They have existed for many years and Node versions. Because so many packages rely on their existence and behavior they are essentially frozen. In addition, to help solidify cow paths I plan to have Lodash take a dependency on Having access to pseudo internals enables some pretty incredible things, but understandably increases the compat and support burden of Node core. This is why, while Node's CJS is a bit of the wild west, Node's ESM support is being planned in such a way to restrict these bits. I'm only closing the issue as |
@jdalton would you be willing to reopen this issue so we can use it as a place to discuss what kind of APIs you might be able to use to avoid relying on internals? |
Done! |
First I said it before, and I'll say it again. IMHO this is a valuable module, that solves the real problem of migrating modules to ESM.
I think that until there is full buy-in from node core, the cons of introducing it to There is an interesting idea in nodejs/node#12349 about implementing a hook for transforming modules during |
🙌
Having buy-in from Node core would rock! If the situation doesn't improve and Node core is still super concerned when the time for Lodash v5 comes closer I could always offer it as a package flavor (like lodash-es) for folks that are up for it.
The The
Neat. I'll give it a look for sure! |
I think having it as a flavor would be awesome for everyone. However, let's do our best to lift the doubts.
@jdalton I briefly looked for this information in the README, and there is no doc for it. Can you please explain how the hooks encapsulation is achieved? I am really worried about this becoming a global hammer. I would be extremely less worried if the API would be: module.exports = require("@std/esm")("./main.mjs").default which would not require monkey patching core internals (if I understand correctly how all of this work). In this way all of that is loaded in sub-tree started from the above file will use The preloader should stay it is as it is a great feature for applications. |
The main hook wraps Lines 33 to 45 in 339f92e
I believe your idea of |
It also reduces the number of internal hooks that we need to expose in core. |
Ok so it looks like using @mcollina's approach should be a winner. To reduce the number of pseudo internals used I'm simply going to copy their source code over to reimplement locally as individual modules (they're just written in JS after all). This means there will be essentially no pseudo internal usage for the primary module use beyond those remaining for guarded bonus functionality (optimized fs operations and error stack cleanup). References I can copy over or inline results from include:
References I can guard or are already guarded:
Leaving just the following unguarded:
The With this there's no longer a hook into the primary module loading mechanism and significantly reduced pseudo internal usage. I'll update the thread with commit references as they come. UpdateFixed by v0.6.0 🎉 🎉 🎉 |
Currently
esm
uses the following APIs:new Module
Module.wrap
Module._compile
Module._extensions
Module._resolveFilename
Module._cache
Module._nodeModulePaths
path._makeLong
process.binding
fs
getStatValues
stat
internalModuleReadFile
internalModuleStat
natives
util
arrow_message_private_symbol
decorated_private_symbol
decorateErrorStack
setHiddenValue
process._tickCallback
process._preload_modules
REPLServer.prototype.createContext
This APIs are considered internal (or private) and shouldn't be used. Their behaviour can be changed or they can disappear at any time, even in patch release, thus breaking
esm
and all of its dependants.The text was updated successfully, but these errors were encountered: