Skip to content

Commit 415a825

Browse files
dnlupZYSzys
authored andcommitted
repl: remove usage of require('util') in repl.js
Use `require('internal/util/inspect').inspect` and `require('internal/util/debuglog').debuglog` instead of `require('util').inspect` and `require('util').debuglog`. Refs: #26546 PR-URL: #26820 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Masashi Hirano <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]>
1 parent 8df9fdc commit 415a825

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

lib/repl.js

+25-19
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ const {
5151
isIdentifierStart,
5252
isIdentifierChar
5353
} = require('internal/deps/acorn/acorn/dist/acorn');
54-
const internalUtil = require('internal/util');
55-
const util = require('util');
54+
const {
55+
decorateErrorStack,
56+
isError,
57+
deprecate
58+
} = require('internal/util');
59+
const { inspect } = require('internal/util/inspect');
5660
const Stream = require('stream');
5761
const vm = require('vm');
5862
const path = require('path');
@@ -61,7 +65,7 @@ const { Interface } = require('readline');
6165
const { Console } = require('console');
6266
const CJSModule = require('internal/modules/cjs/loader');
6367
const domain = require('domain');
64-
const debug = util.debuglog('repl');
68+
const debug = require('internal/util/debuglog').debuglog('repl');
6569
const {
6670
ERR_CANNOT_WATCH_SIGINT,
6771
ERR_INVALID_ARG_TYPE,
@@ -120,8 +124,8 @@ function hasOwnProperty(obj, prop) {
120124
// This is the default "writer" value, if none is passed in the REPL options,
121125
// and it can be overridden by custom print functions, such as `probe` or
122126
// `eyes.js`.
123-
const writer = exports.writer = (obj) => util.inspect(obj, writer.options);
124-
writer.options = { ...util.inspect.defaultOptions, showProxy: true };
127+
const writer = exports.writer = (obj) => inspect(obj, writer.options);
128+
writer.options = { ...inspect.defaultOptions, showProxy: true };
125129

126130
exports._builtinLibs = builtinLibs;
127131

@@ -204,10 +208,10 @@ function REPLServer(prompt,
204208

205209
let rli = this;
206210
Object.defineProperty(this, 'rli', {
207-
get: util.deprecate(() => rli,
208-
'REPLServer.rli is deprecated', 'DEP0124'),
209-
set: util.deprecate((val) => rli = val,
210-
'REPLServer.rli is deprecated', 'DEP0124'),
211+
get: deprecate(() => rli,
212+
'REPLServer.rli is deprecated', 'DEP0124'),
213+
set: deprecate((val) => rli = val,
214+
'REPLServer.rli is deprecated', 'DEP0124'),
211215
enumerable: true,
212216
configurable: true
213217
});
@@ -430,15 +434,15 @@ function REPLServer(prompt,
430434
if (typeof e === 'object' && e !== null) {
431435
const pstrace = Error.prepareStackTrace;
432436
Error.prepareStackTrace = prepareStackTrace(pstrace);
433-
internalUtil.decorateErrorStack(e);
437+
decorateErrorStack(e);
434438
Error.prepareStackTrace = pstrace;
435439

436440
if (e.domainThrown) {
437441
delete e.domain;
438442
delete e.domainThrown;
439443
}
440444

441-
if (internalUtil.isError(e)) {
445+
if (isError(e)) {
442446
if (e.stack) {
443447
if (e.name === 'SyntaxError') {
444448
// Remove stack trace.
@@ -482,10 +486,12 @@ function REPLServer(prompt,
482486

483487
self.clearBufferedCommand();
484488
Object.defineProperty(this, 'bufferedCommand', {
485-
get: util.deprecate(() => self[kBufferedCommandSymbol],
486-
'REPLServer.bufferedCommand is deprecated', 'DEP0074'),
487-
set: util.deprecate((val) => self[kBufferedCommandSymbol] = val,
488-
'REPLServer.bufferedCommand is deprecated', 'DEP0074'),
489+
get: deprecate(() => self[kBufferedCommandSymbol],
490+
'REPLServer.bufferedCommand is deprecated',
491+
'DEP0074'),
492+
set: deprecate((val) => self[kBufferedCommandSymbol] = val,
493+
'REPLServer.bufferedCommand is deprecated',
494+
'DEP0074'),
489495
enumerable: true
490496
});
491497

@@ -518,7 +524,7 @@ function REPLServer(prompt,
518524
writer.options.colors = self.useColors;
519525

520526
if (options[kStandaloneREPL]) {
521-
Object.defineProperty(util.inspect, 'replDefaults', {
527+
Object.defineProperty(inspect, 'replDefaults', {
522528
get() {
523529
return writer.options;
524530
},
@@ -567,7 +573,7 @@ function REPLServer(prompt,
567573
return false;
568574
}
569575

570-
self.parseREPLKeyword = util.deprecate(
576+
self.parseREPLKeyword = deprecate(
571577
_parseREPLKeyword,
572578
'REPLServer.parseREPLKeyword() is deprecated',
573579
'DEP0075');
@@ -924,7 +930,7 @@ REPLServer.prototype.setPrompt = function setPrompt(prompt) {
924930
Interface.prototype.setPrompt.call(this, prompt);
925931
};
926932

927-
REPLServer.prototype.turnOffEditorMode = util.deprecate(
933+
REPLServer.prototype.turnOffEditorMode = deprecate(
928934
function() { _turnOffEditorMode(this); },
929935
'REPLServer.turnOffEditorMode() is deprecated',
930936
'DEP0078');
@@ -1315,7 +1321,7 @@ REPLServer.prototype.defineCommand = function(keyword, cmd) {
13151321
this.commands[keyword] = cmd;
13161322
};
13171323

1318-
REPLServer.prototype.memory = util.deprecate(
1324+
REPLServer.prototype.memory = deprecate(
13191325
_memory,
13201326
'REPLServer.memory() is deprecated',
13211327
'DEP0082');

0 commit comments

Comments
 (0)