Skip to content

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

Closed
@joyeecheung

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

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