Skip to content

Commit

Permalink
fix: use new attribute for repl inspection
Browse files Browse the repository at this point in the history
This updates the custom inspect implementation to use the preferred
attribute for compatibility with newer node versions.

See nfischer/shelljs-plugin-inspect#9 for more
details.
  • Loading branch information
nfischer committed Jan 14, 2022
1 parent 573b15c commit ff785de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -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, {
Expand Down
3 changes: 2 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit ff785de

Please sign in to comment.