Skip to content
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

lib: runtime deprecated access to process.binding('util') #37787

Closed

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Mar 17, 2021

The various isType() functions exposed by process.binding('util')
are already available via util.types, and the rest really aren't
safe for external use. Deprecate access with the intent of removing
access in the near future.

/cc @ljharb since I know lodash still references this for Node.js version < 10 (for those users still on < 10.x this deprecation message will never print anyway).

and @addaleax whom I know has opinions on this stuff ;-)

Signed-off-by: James M Snell jasnell@gmail.com

The various `isType()` functions exposed by process.binding('util')
are already available via `util.types`, and the rest really aren't
safe for external use. Deprecate access with the intent of removing
access in the near future.

Signed-off-by: James M Snell <jasnell@gmail.com>
@jasnell jasnell added semver-major PRs that contain breaking changes and should be released in the next major version. deprecations Issues and PRs related to deprecations. labels Mar 17, 2021
@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Mar 17, 2021
@ljharb
Copy link
Member

ljharb commented Mar 17, 2021

Thanks for the ping. Is this just when accessing util via process.binding?

@jasnell
Copy link
Member Author

jasnell commented Mar 17, 2021

Yes, it's only triggered when accessing process.binding('util') directly

@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soooo... I don't want to reiterate the exact same conversation we had in #37485, but I would stick to my original suggestion, which would be to not runtime-deprecate it and instead make it so that process.binding('util') returns { ...require('util').types } (or the currently available subset, if we're picky and are okay with a few more lines in our code), and just leave it like that forever. Is there anything speaking against that? The code required to implement that should be fairly trivial.

@jasnell
Copy link
Member Author

jasnell commented Mar 18, 2021

I guess the bit I'm struggling with is why we would do that. require('util/types') is available and is what everyone should be using, and it covers more use cases than process.binding('util'). The lodash case has been the most prominent use of these internal APIs and that has already been handled in newer versions -- folks that are using old Node.js versions won't be impacted and folks using the newer versions are already using util/types. In other words, I'm not sure there's any actual benefit to modifying this.

Even with that said, a runtime deprecation of the current exports is still appropriate given that there are other methods and constants exposed here that do not make sense to expose in any scenario. The step after runtime deprecation does not have to be removal -- the step after deprecation could be easily be replacing the current process.binding('util') with an alias for util/types as suggested, in which case the status would change to "Legacy" and should remain undocumented.

tl;dr ... we can do both. runtime deprecate the current and replace it after.

@jasnell jasnell removed the needs-ci PRs that need a full CI run. label Mar 19, 2021
@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the bit I'm struggling with is why we would do that. ``

Again – not trying to rehash the entire conversation here, but the point is that there’s still a decent amount of code that does use process.binding('util') for type checking, and whether that’s because people don’t upgrade deep dependencies is not actually relevant here. (Just like there is a decent amount of code that still uses atob and btoa, by the way… and we have just introduced those because of that!)

So: The reason why we do that is that we care about our users, which involves caring about backwards compatibility and making transitions between Node.js versions as smoothly as possible when it comes at trivial cost to us.

I do realize that it’s frustrating when somebody is objecting without putting in the work to provide an alternative, so: #37819

@ljharb
Copy link
Member

ljharb commented Mar 19, 2021

Could we perhaps do both? it'd be two semver-majors, ofc, but at least then we can get there.

@jasnell
Copy link
Member Author

jasnell commented Mar 19, 2021

I'm not going to worry about this. @addaleax's alternative PR is fine.

@jasnell jasnell closed this Mar 19, 2021
addaleax added a commit that referenced this pull request Mar 27, 2021
Ref: #37485 (review)
Ref: #37787

PR-URL: #37819
Refs: #37787
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecations Issues and PRs related to deprecations. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants