-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
events: deprecate EventEmitter.defaultMaxListeners getter/setter #18712
events: deprecate EventEmitter.defaultMaxListeners getter/setter #18712
Conversation
doc/api/events.md
Outdated
@@ -283,6 +284,25 @@ the event emitter instance, the event’s name and the number of attached | |||
listeners, respectively. | |||
Its `name` property is set to `'MaxListenersExceededWarning'`. | |||
|
|||
This property is deprecated. Please use `EventEmitter.setDefaultMaxListeners` |
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.
.setDefaultMaxListeners
-> .getDefaultMaxListeners
?
doc/api/events.md
Outdated
added: REPLACEME | ||
--> | ||
|
||
- `count` {Number} |
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.
{Number}
-> {number}
(primitives are lowercased).
162f130
to
228e98b
Compare
A nit:
will become
But this can be done in a separate PR if this is more appropriate) |
I thought we had decided that only the setter function needs to be exported, while the live binding would suffice in place of the getter? |
@TimothyGu dunno, that feels a bit inconsistent in terms of behavior and seeing as we have crypto.getFips, i thought this seemed better. |
228e98b
to
00563d7
Compare
@nodejs/core anyone wanna review this? |
00563d7
to
8041f07
Compare
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.
I’m not necessarily on board with a runtime deprecation for this.
Is this popular and used? This might be around some old code snippets.
Also, these values are somewhat process-altering and “against” the immutability of ESM.
I’m more leaning towards removing these completely. Do we have an usecase for these to exists?
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.
Doing a runtime deprecation like this is too soon IMO - we can deprecate it in the docs rather than in runtime and deprecate it in runtime later.
This looks heavily used in the ecosystem, so runtime-deprecation in 10.x could be too disruptive, given that there is no fallback yet. +1 for doc-deprecation with |
On a second look, most of the grep results most likely come from re-packaging copies of Raw grep gist: https://gist.github.com/ChALkeR/127ea95c65297d533f37ae91391e9188. Filtered grep (to exclude The filtered results are significantly smaller. In fact, I'm ok with runtime-deprecating based on that, but I would still prefer pending-deprecation first, and getting the new getters/setters backported. It's a documented public API, and it should go through doc-deprecation first if there are no strong reasons to rush it. |
for a docs only, the only difference to this is that the setter and getter wouldn't be wrapped in |
8041f07
to
622d2d0
Compare
Yep, a docs-only deprecation means listing a new deprecation code in deprecations.md and adding note to the API doc indicating that the thing has been deprecated. Super simple. |
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.
LGTM
Is this still relevant if we can make Proxies work? |
This is relevant anyway for any named export solution. |
But with proxies being supported, setters and getters can be supported fine on named exports right? The only potential issue is surely how to set a named export from the ES module side? |
Honestly I find getters and setters on named exports very confusing anyway. Wrapping it with proxies would work but be confusing anyway, and deprecating them in favor of functions that are on root exports seems reasonable to me. |
a8a3133
to
5bb0e90
Compare
In preparation for upcoming ESM interop and to remain consistent with other getters/setters being removed
5bb0e90
to
023bfc6
Compare
@nodejs/tsc i assume one of you people need to review this? |
I don’t think I’m on board with ever deprecating this. This has been around for years, and there’s nothing wrong with using it. If ESM compatibility is the concern here, then yes, let’s add the getter/setter functions and say that that’s what you’re supposed to use then. |
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.
Making -1 explicit
I'm with @addaleax on this one. |
For clarity, in ESM world |
That's the idea, yes. |
With the named exports+live binding for builtin modules PR (unfiltered for setters) I believe both getters/setters are supported. import events, { defaultMaxListeners } from "events"
console.log(defaultMaxListeners)
// 10
console.log(events.defaultMaxListeners)
// 10
events.defaultMaxListeners = 4
console.log(defaultMaxListeners)
// 4 |
...thats basically deprecating it anyway? having a well designed api is part of having an api, and just as important as the functionality. if we're saying to use the shiny new x instead of y, we should also explicitly say don't use y
when i added this in my named exports pr i got pushback for "singling out events" which led to this pr. i'm fine with only having the default export as long as i'm actually able to implement it without pushback |
Deprecating means that something should not be used. However, there is no reason not to use this in CJS, right? We don’t do CJS users a favor by deprecating this (esp. not with
We could also leave out getter/setter properties for these cases, and leave the corresponding get/set functions in place, right? (I mean, I think only exporting |
i don't see any distinction between this pr and #18335 to that respect. additionally migrating between esm and cjs is already enough of a headache without trying to figure out getters and setters vs methods that get and set and in which cases they were migrated and in which cases they weren't etc |
Setters on builtin modules aren't necessarily an ESM problem anymore folks. |
|
As @targos said:
This means that this line, @jdalton, ... import events, { defaultMaxListeners } from "events" ...makes no sense in terms of ESM, as "events" exports only the class So IMHO, @targos's point makes this PR not needed. |
The static side of a class is not really different than any other object one could set |
True! And in CJS, you would be correct, as you can use destructuring to access that: But the deprecation in this PR, if I understood correctly, is for ESM times. But in ESM, we're only default-exporting the class, and doing |
No, there's an open PR to allow exactly that (pulling named exports off whatever the exported object is, in addition to a default). There was originally an issue with not knowing if fields/getters/setters would work, but it has since been resolved, as @jdalton keeps saying. This property doesn't need to be deprecated for any technical reason any more. |
@giltayar, @weswigham |
@jdalton i just want to be clear that i'm not comfortable landing named exports if you can whether its by this pr or a condition in the loader to only expose a default export doesn't matter very much to me. |
@devsnek how is it meaningfully different to import |
So maybe the problem is with #18131. We're doing split-personality here. In one personality, we want a default export: We're thinking CJS destructuring, when it actually isn't applicable to ESM-think. I believe we should decide, per module, if we're exporting a default value or some named exports. Yes, the spec supports exporting both, but I don't believe the idea was to export the properties of the default object as named exports. And if we decide, as I believe we should, to export all the functions in To sum up: we should decide on a module by module basis whether we want the exports to be exported using default, or using named, but never both. In |
@weswigham the point of named exports is not to just blindly copy an object to a module namespace, its to expose a well designed api to esm users. imagine the api that would be exposed if we rewrote every builtin with es module syntax, and thats what should be exposed. |
@weswigham - to answer your question to @devsnek: because, in ESM-think, what is exported from |
i'm going to close this pr and use it as my reasoning for special casing named exports. thanks to all involved for a productive discussion |
Stop using the esm transition as an excuse to rewrite APIs. Either rewrite them on their own merits for all users, or leave them be. It's not required from a technical perspective (just like that nonsense of automatically filtering underscore prefixed names). |
In preparation for upcoming ESM interop and to remain consistent with
other getters/setters being removed
Refs: #18131
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
events