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: https://github.com/nodejs/node/issues/26546 PR-URL: https://github.com/nodejs/node/pull/26820 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Masashi Hirano <shisama07@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
This commit is contained in:
parent
8df9fdcc39
commit
415a825dc0
44
lib/repl.js
44
lib/repl.js
@ -51,8 +51,12 @@ const {
|
|||||||
isIdentifierStart,
|
isIdentifierStart,
|
||||||
isIdentifierChar
|
isIdentifierChar
|
||||||
} = require('internal/deps/acorn/acorn/dist/acorn');
|
} = require('internal/deps/acorn/acorn/dist/acorn');
|
||||||
const internalUtil = require('internal/util');
|
const {
|
||||||
const util = require('util');
|
decorateErrorStack,
|
||||||
|
isError,
|
||||||
|
deprecate
|
||||||
|
} = require('internal/util');
|
||||||
|
const { inspect } = require('internal/util/inspect');
|
||||||
const Stream = require('stream');
|
const Stream = require('stream');
|
||||||
const vm = require('vm');
|
const vm = require('vm');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
@ -61,7 +65,7 @@ const { Interface } = require('readline');
|
|||||||
const { Console } = require('console');
|
const { Console } = require('console');
|
||||||
const CJSModule = require('internal/modules/cjs/loader');
|
const CJSModule = require('internal/modules/cjs/loader');
|
||||||
const domain = require('domain');
|
const domain = require('domain');
|
||||||
const debug = util.debuglog('repl');
|
const debug = require('internal/util/debuglog').debuglog('repl');
|
||||||
const {
|
const {
|
||||||
ERR_CANNOT_WATCH_SIGINT,
|
ERR_CANNOT_WATCH_SIGINT,
|
||||||
ERR_INVALID_ARG_TYPE,
|
ERR_INVALID_ARG_TYPE,
|
||||||
@ -120,8 +124,8 @@ function hasOwnProperty(obj, prop) {
|
|||||||
// This is the default "writer" value, if none is passed in the REPL options,
|
// This is the default "writer" value, if none is passed in the REPL options,
|
||||||
// and it can be overridden by custom print functions, such as `probe` or
|
// and it can be overridden by custom print functions, such as `probe` or
|
||||||
// `eyes.js`.
|
// `eyes.js`.
|
||||||
const writer = exports.writer = (obj) => util.inspect(obj, writer.options);
|
const writer = exports.writer = (obj) => inspect(obj, writer.options);
|
||||||
writer.options = { ...util.inspect.defaultOptions, showProxy: true };
|
writer.options = { ...inspect.defaultOptions, showProxy: true };
|
||||||
|
|
||||||
exports._builtinLibs = builtinLibs;
|
exports._builtinLibs = builtinLibs;
|
||||||
|
|
||||||
@ -204,10 +208,10 @@ function REPLServer(prompt,
|
|||||||
|
|
||||||
let rli = this;
|
let rli = this;
|
||||||
Object.defineProperty(this, 'rli', {
|
Object.defineProperty(this, 'rli', {
|
||||||
get: util.deprecate(() => rli,
|
get: deprecate(() => rli,
|
||||||
'REPLServer.rli is deprecated', 'DEP0124'),
|
'REPLServer.rli is deprecated', 'DEP0124'),
|
||||||
set: util.deprecate((val) => rli = val,
|
set: deprecate((val) => rli = val,
|
||||||
'REPLServer.rli is deprecated', 'DEP0124'),
|
'REPLServer.rli is deprecated', 'DEP0124'),
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
@ -430,7 +434,7 @@ function REPLServer(prompt,
|
|||||||
if (typeof e === 'object' && e !== null) {
|
if (typeof e === 'object' && e !== null) {
|
||||||
const pstrace = Error.prepareStackTrace;
|
const pstrace = Error.prepareStackTrace;
|
||||||
Error.prepareStackTrace = prepareStackTrace(pstrace);
|
Error.prepareStackTrace = prepareStackTrace(pstrace);
|
||||||
internalUtil.decorateErrorStack(e);
|
decorateErrorStack(e);
|
||||||
Error.prepareStackTrace = pstrace;
|
Error.prepareStackTrace = pstrace;
|
||||||
|
|
||||||
if (e.domainThrown) {
|
if (e.domainThrown) {
|
||||||
@ -438,7 +442,7 @@ function REPLServer(prompt,
|
|||||||
delete e.domainThrown;
|
delete e.domainThrown;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (internalUtil.isError(e)) {
|
if (isError(e)) {
|
||||||
if (e.stack) {
|
if (e.stack) {
|
||||||
if (e.name === 'SyntaxError') {
|
if (e.name === 'SyntaxError') {
|
||||||
// Remove stack trace.
|
// Remove stack trace.
|
||||||
@ -482,10 +486,12 @@ function REPLServer(prompt,
|
|||||||
|
|
||||||
self.clearBufferedCommand();
|
self.clearBufferedCommand();
|
||||||
Object.defineProperty(this, 'bufferedCommand', {
|
Object.defineProperty(this, 'bufferedCommand', {
|
||||||
get: util.deprecate(() => self[kBufferedCommandSymbol],
|
get: deprecate(() => self[kBufferedCommandSymbol],
|
||||||
'REPLServer.bufferedCommand is deprecated', 'DEP0074'),
|
'REPLServer.bufferedCommand is deprecated',
|
||||||
set: util.deprecate((val) => self[kBufferedCommandSymbol] = val,
|
'DEP0074'),
|
||||||
'REPLServer.bufferedCommand is deprecated', 'DEP0074'),
|
set: deprecate((val) => self[kBufferedCommandSymbol] = val,
|
||||||
|
'REPLServer.bufferedCommand is deprecated',
|
||||||
|
'DEP0074'),
|
||||||
enumerable: true
|
enumerable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -518,7 +524,7 @@ function REPLServer(prompt,
|
|||||||
writer.options.colors = self.useColors;
|
writer.options.colors = self.useColors;
|
||||||
|
|
||||||
if (options[kStandaloneREPL]) {
|
if (options[kStandaloneREPL]) {
|
||||||
Object.defineProperty(util.inspect, 'replDefaults', {
|
Object.defineProperty(inspect, 'replDefaults', {
|
||||||
get() {
|
get() {
|
||||||
return writer.options;
|
return writer.options;
|
||||||
},
|
},
|
||||||
@ -567,7 +573,7 @@ function REPLServer(prompt,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.parseREPLKeyword = util.deprecate(
|
self.parseREPLKeyword = deprecate(
|
||||||
_parseREPLKeyword,
|
_parseREPLKeyword,
|
||||||
'REPLServer.parseREPLKeyword() is deprecated',
|
'REPLServer.parseREPLKeyword() is deprecated',
|
||||||
'DEP0075');
|
'DEP0075');
|
||||||
@ -924,7 +930,7 @@ REPLServer.prototype.setPrompt = function setPrompt(prompt) {
|
|||||||
Interface.prototype.setPrompt.call(this, prompt);
|
Interface.prototype.setPrompt.call(this, prompt);
|
||||||
};
|
};
|
||||||
|
|
||||||
REPLServer.prototype.turnOffEditorMode = util.deprecate(
|
REPLServer.prototype.turnOffEditorMode = deprecate(
|
||||||
function() { _turnOffEditorMode(this); },
|
function() { _turnOffEditorMode(this); },
|
||||||
'REPLServer.turnOffEditorMode() is deprecated',
|
'REPLServer.turnOffEditorMode() is deprecated',
|
||||||
'DEP0078');
|
'DEP0078');
|
||||||
@ -1315,7 +1321,7 @@ REPLServer.prototype.defineCommand = function(keyword, cmd) {
|
|||||||
this.commands[keyword] = cmd;
|
this.commands[keyword] = cmd;
|
||||||
};
|
};
|
||||||
|
|
||||||
REPLServer.prototype.memory = util.deprecate(
|
REPLServer.prototype.memory = deprecate(
|
||||||
_memory,
|
_memory,
|
||||||
'REPLServer.memory() is deprecated',
|
'REPLServer.memory() is deprecated',
|
||||||
'DEP0082');
|
'DEP0082');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user