From ff785de5c614fa48545df53a5479398d57e0ebd3 Mon Sep 17 00:00:00 2001 From: Nate Fischer Date: Fri, 14 Jan 2022 13:56:15 -0800 Subject: [PATCH] fix: use new attribute for repl inspection This updates the custom inspect implementation to use the preferred attribute for compatibility with newer node versions. See https://github.com/nfischer/shelljs-plugin-inspect/issues/9 for more details. --- index.js | 12 ++++++++---- test/test.js | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 822625f..0ad711f 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,17 @@ var plugin = require('shelljs/plugin'); +var util = require('util'); var clearModule = require('clear'); +// Newer versions of node use a symbol called util.inspect.custom. +var inspectAttribute = util.inspect.custom || 'inspect'; + function clear() { clearModule(); - return { - inspect: function () { - return ''; - }, + var ret = {}; + ret[inspectAttribute] = function () { + return ''; }; + return ret; } plugin.register('clear', clear, { diff --git a/test/test.js b/test/test.js index cabd0bf..d073a53 100644 --- a/test/test.js +++ b/test/test.js @@ -4,6 +4,7 @@ var pluginClear = require('..'); // If we were using additional plugins, we could load them here var shell = require('shelljs'); +var util = require('util'); require('should'); @@ -36,7 +37,7 @@ describe('plugin-clear', function () { it('has a silent return value', function () { var ret = shell.clear(); - ret.inspect().should.equal(''); + util.inspect(ret).should.equal(''); }); it('does not get added as a method on ShellStrings', function () {