-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
module: expose module.format #59904
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
base: main
Are you sure you want to change the base?
module: expose module.format #59904
Conversation
|
Review requested:
|
To help users relying on require.cache determine the format of a cached module. Refs: nodejs#59868
5a9485e to
ad8f4cd
Compare
|
I'm concerned that exposing this means that minor changes to the flow, like as we work on hooks, suddenly become breaking changes because the format might be known at a different point in the process; or it's defined as one thing at one point and then reassigned later, and the point of reassignment becomes a breaking change. I think users can already get this value via the hooks; what's the use case for making it easier? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #59904 +/- ##
==========================================
+ Coverage 88.29% 88.30% +0.01%
==========================================
Files 702 702
Lines 206875 206919 +44
Branches 39797 39815 +18
==========================================
+ Hits 182655 182725 +70
+ Misses 16226 16213 -13
+ Partials 7994 7981 -13
🚀 New features to boost your workflow:
|
See #59868 - Webpack is directly checking entries from the
I am somewhat hesitant about it because of this as well though I think the docs should make it clear enough:
|
|
doesn't this make "changing the format of a module" always a breaking change, which it needn't be at the moment? |
In what circumstance would we change the format of the module? Note that the documentation is making it clear that it's not going to be accurate, or always defined. I think if that's defined to be breaking then changing it would already break hooks. |
This is basically a way of saying “we’re exposing a bit of Node internals here, and you shouldn’t expect us to honor semver with regards to the behavior of this internal feature.” But in reality, are people really going to respect that? When Webpack opens a bug issue because some minor change in the module loader breaks something on their side because of how we treat Or alternatively, maybe we expose |
I think yes, it's inevitable that we will have to do this for the internals until people actually migrate off using them. As always the docs just discourage people from using them, but when there's no practical alternative for them because of their own legacy, which I think is happening in the case of Webpack (from a brief look of what they are doing I am skeptical whether "migrating to use the experimental hooks which have their own quirks and are only available since v20" is a viable alternative, but maybe @alexander-akait knows more), then making the legacy a bit more practical for them in the meantime is what it takes for a good overall end UX. I think "we are working on a better experimental alternative" isn't really a practical response for "there are code being broken right now", what would be more practical would be "we are working on a better experimental alternative, but at the mean time, use this this band-aid to at least regress fewer end users".
I think that'll incur a breaking change for the packages that are already relying on |
|
People rewrite a module from CJS into ESM all the time, and potentially back to CJS as well. Refactoring shouldn't be forced to be a breaking change. |
|
If that was considered a breaking change, then it is already breaking even if this property isn't exposed, because that format change would be visible in the loader hooks already. It doesn't seem exposing it in one more path (which actually covers less) would make that much of a difference. Though I'd say just like results and contexts in loader hooks, those who access it should not assume one particular module must be in a certain format because that can always be customised by somebody else. |
JakobJingleheimer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌
This doesn't expose it for ESM, right, only CJS modules?
| The [detected format][Determining module system] of the module. Possible values are documented | ||
| in [`load` customization hooks][]. | ||
|
|
||
| This property is not guaranteed to be defined on the `module` object, nor to be accurate. If |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"nor be accurate". Maybe a little bit more on why and why a user might want to use this anyway?
This exposes it for any module that's been directly required and is therefore in the |
|
@joyeecheung loader hooks don't count, because that's node-level superpowers. In a loaderless node application, it's not currently a breaking change, and this makes it one (unless this information was restricted to loader hooks, ofc) |
Why are loader hooks node-level superpowers but
In an application that doesn't access the |
To help users relying on require.cache determine the format of a cached module.
Refs: #59868