Node: repl: respect util.inspect.defaultOptions

Created on 13 Feb 2020  路  3Comments  路  Source: nodejs/node

Papercut issue that I found difficult to explain in a few words to someone who got stung by it.

$ node
Welcome to Node.js v14.0.0-pre.
Type ".help" for more information.
> console.log([[[[[]]]]])
[ [ [ [Array] ] ] ]
undefined
> [[[[[]]]]]
[ [ [ [Array] ] ] ]

So far, so normal. But now:

> util.inspect.defaultOptions.depth = 42
42
> console.log([[[[[]]]]])
[
  [ [ [ [] ] ] ]
]
undefined
> [[[[[]]]]]
[ [ [ [Array] ] ] ]  // unaffected

Ideally the REPL would use the util.inspect.defaultOptions from the REPL context to format results.

repl

Most helpful comment

This is working as expected. The defaultOptions are used while starting the REPL instance. There is another option that may be modified to change the repl writer settings during execution (util.inspect.replOptions). These will only work in the standalone repl.

I do plan on adding a configuration file for the REPL that allows to set the defaults up front.

All 3 comments

I can try to take a look at this soon :)

REPL聽options should聽inherit from聽defaultOptions and聽only聽override what聽differs from聽the聽defaults.

This is working as expected. The defaultOptions are used while starting the REPL instance. There is another option that may be modified to change the repl writer settings during execution (util.inspect.replOptions). These will only work in the standalone repl.

I do plan on adding a configuration file for the REPL that allows to set the defaults up front.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fanjunzhi picture fanjunzhi  路  3Comments

vsemozhetbyt picture vsemozhetbyt  路  3Comments

addaleax picture addaleax  路  3Comments

Brekmister picture Brekmister  路  3Comments

sandeepks1 picture sandeepks1  路  3Comments