-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
util: mark deprecated objects with symbol #52568
Conversation
return deprecated; | ||
} | ||
|
||
deprecate.isDeprecated = SymbolFor('nodejs.util.deprecate.isDeprecated'); |
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.
Is there a particular reason this is a global symbol in the registry? Cross version compat if we vendor deprecated stuff e.g. from strearms?
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.
No, no specific reason. I noticed that other Symbols within the util
object were formatted the same way, and I wanted to follow the trend, is there a better way?
Can you please add tests? |
I've added I'll add some tests later today |
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.
If we ship this, we then have it applied to every function, class constructor etc... we have deprecated, which seems a big change, but I dont see the return. Can you please describe more the use case?
I believe that the comments on issue #22543 give some use cases, but I see it as a way for developers to anticipate deprecations. For example, they can use the |
punycode is deprecated 😄 but thats beside the point, if we want developers to know we runtime deprecate so they will see the warning. |
I'm aware that puny_code is deprecated, that's why it was my example. The warnings are nice, but they aren't programmatic, an end user can't really use them in their code |
But how do you know something is deprecated? Manually calling |
Yes. |
I'm trying to immagine the use case: const { readFile } = require('node:fs');
if(util.isDeprecated(readFile)){
// do what? 😅
} You will know with a warning anyways |
True, maybe this PR isn't the best, I can always close it and focus on a different part of Node. |
I just found a use case, I was just trying to print NodeJS internals, but only non-deprecated ones, as their was no way to do it |
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.
Deprecations are fine-grained in many cases, e.g., a function's behavior might be deprecated under certain circumstances only.
I don't see what problem this is solving properly.
It was something that I figured would help in the experimental REPL, but I think your right |
Fixes #22543
This PR marks deprecated objects with a custom symbol, to make it easier for developers to know what functions have been deprecated.