镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

lib: reduce internal usage of public require('util') #26546

Description

@joyeecheung

A few patterns (modulo destructuring):

  1. Replace require('util').inherits() usages under lib: Remove util.inherits usage internally? #24395
// Change this
util.inherits(A, B);

// To this
Object.setPrototypeOf(A.prototype, B.prototype);
Object.setPrototypeOf(A, B);
  1. Replace require('util').inspect with require('internal/util/inspect').inspect
  2. Replace require('util').format with require('internal/util/inspect').format
  3. Replace require('util').debuglog with require('internal/util/debuglog').debuglog
  4. Replace require('util').types with require('internal/util/types')
  5. Replace require('util').deprecate with require('internal/util').deprecate
  6. Replace require('util').promisify with require('internal/util').promisify

List of JS files that can be refactored:

Refactored Subsystem Files PR
assert lib/assert.js#L32, lib/internal/assert/assertion_error.js#L3 #26762, #26750
bootstrap lib/internal/bootstrap/node.js#L192 #26547
child_process lib/child_process.js#L24, lib/internal/child_process.js#L21 #26769, #26773
console lib/internal/console/constructor.js#L18 #26777
dgram lib/dgram.js#L48 #26770
domain lib/domain.js#L29
encoding lib/internal/encoding.js#L330 #26779
errors lib/internal/error-serdes.js#L83, lib/internal/errors.js#L210 #26782, #26781
fs lib/internal/fs/utils.js#L15 #26783
http lib/_http_agent.js#L25, lib/_http_common.js#L39, lib/_http_outgoing.js#L26, lib/_http_server.js#L24 #26548
http2 lib/internal/http2/core.js#L21 #26789
https lib/https.js#L28 #26772
inspector lib/inspector.js#L19
lib lib/internal/policy/manifest.js#L7 #26833
module lib/internal/modules/cjs/loader.js#L26, lib/internal/modules/esm/create_dynamic_module.js#L4, lib/internal/modules/esm/loader.js#L21, lib/internal/modules/esm/module_map.js#L7, lib/internal/modules/esm/translators.js#L22 #26802, #26803, #26804, #26805, #26806
net lib/net.js#L26 #26807
process lib/internal/process/per_thread.js#L18 #26817
readline lib/readline.js#L35 #26818
repl lib/internal/repl/history.js#L7, lib/repl.js#L55 #26819 #26820
stream lib/internal/js_stream_socket.js#L4, lib/internal/streams/buffer_list.js#L4, lib/internal/streams/lazy_transform.js#L7, lib/stream.js#L46 #26698
timers lib/internal/timers.js#L19, lib/timers.js#L43
tls lib/_tls_wrap.js#L30 #26747
trace_events lib/trace_events.js#L22 #26822
tty lib/tty.js#L24 #26797
url lib/internal/url.js#L3 #26808
vm lib/internal/vm/source_text_module.js#L3, lib/vm.js#L35 #26716
worker lib/internal/main/worker_thread.js#L46, lib/internal/worker/io.js#L17 #26814, #26810
zlib lib/zlib.js#L38 #26716

Activity

  1. added
    help wantedIssues that need assistance from volunteers or PRs that need help to proceed.
    utilIssues and PRs related to the built-in util module.
    good first issueIssues that are suitable for first-time contributors.
    on Mar 9, 2019
  2. micheleriva commented on Mar 9, 2019

    @micheleriva

    I can work on it 🎉

  3. joyeecheung commented on Mar 10, 2019

    @joyeecheung
    MemberAuthor

    @micheleriva That's great! If possible please try to refactor each file in single commit and submit them as separate PRs, otherwise the PR is bound to require manual backport.

  4. SimonSchick commented on Mar 10, 2019

    @SimonSchick
    Contributor

    @joyeecheung Just curious, in many cases util.inherits could be replaced by class ... extends ... instead, is there a reason setPrototypeOf should be used instead?

  5. micheleriva commented on Mar 10, 2019

    @micheleriva

    @joyeecheung ok no prob! So I'll close my PR #26552 in flavour of single PRs.

  6. joyeecheung commented on Mar 10, 2019

    @joyeecheung
    MemberAuthor

    @SimonSchick For public ES5-style classes we have to support instantiation without new so we cannot refactor them to ES6 classes.

  7. SimonSchick commented on Mar 10, 2019

    @SimonSchick
    Contributor

    I was talking about those that do not support instantiation without new.

    Might also be worth mentioning that we dealt with the same issue in sequelize using Proxys https://github.com/sequelize/sequelize/blob/master/lib/utils/classToInvokable.js#L9
    I'm not sure what the exact performance penalties are tho.

  8. added a commit that references this issue on Mar 12, 2019
  9. dnishar1 commented on Mar 12, 2019

    @dnishar1

    I can work on it!

  10. joyeecheung commented on Mar 13, 2019

    @joyeecheung
    MemberAuthor

    I was talking about those that do not support instantiation without new.

    @SimonSchick I guess if you are sure those do not support instantiation without new, those could be refactored if the tests are happy (probably also needs a CITGM run anyway because undoing util.inherits also removes the hacky super_ property on the classes)

  11. 157 remaining items

  12. added a commit that references this issue on Apr 10, 2019
  13. karansapolia commented on Jun 3, 2019

    @karansapolia

    Was looking for issues to work on and noticed that required changes have already been made and merged for timers in lib/internal/timers.js and lib/timers.js. Corresponding PRs can be updated in the original post.

  14. lesagi commented on Sep 28, 2019

    @lesagi

    Any reason that this is still open?
    Seems like everything was refactored? (given what @karansapolia said).

  15. BridgeAR commented on Oct 3, 2019

    @BridgeAR
    Member

    I can only find a single require('util') in lib at the moment that could be replaced. I'll open a PR for that and close this issue as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueIssues that are suitable for first-time contributors.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions