From d1201f35d2cd7173e09eb169e4e4f90031877d69 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 24 Oct 2021 13:04:38 -0400 Subject: [PATCH] figure out the list based on the hints only --- examples/list.js | 3 +++ src/reporters/base-reporter.js | 2 +- src/reporters/console/console-reporter.js | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/list.js b/examples/list.js index c52321e..3e5d280 100644 --- a/examples/list.js +++ b/examples/list.js @@ -13,3 +13,6 @@ const hints = { }; report.list('The same list with hints', someList, hints); + +report.info('The same list with just the hints'); +report.list('just the hints', hints); diff --git a/src/reporters/base-reporter.js b/src/reporters/base-reporter.js index cca782f..8fd962e 100644 --- a/src/reporters/base-reporter.js +++ b/src/reporters/base-reporter.js @@ -188,7 +188,7 @@ export default class BaseReporter { } // TODO - list(key: string, items: Array, hints?: Object) {} + list(key: string, items: Array|Object, hints?: Object) {} // Outputs basic tree structure to console tree(key: string, obj: Trees, {force = false}: {force?: boolean} = {}) {} diff --git a/src/reporters/console/console-reporter.js b/src/reporters/console/console-reporter.js index 3a0b44c..0d95778 100644 --- a/src/reporters/console/console-reporter.js +++ b/src/reporters/console/console-reporter.js @@ -134,7 +134,7 @@ export default class ConsoleReporter extends BaseReporter { this.log(String(value), {force: true}); } - list(title: string, items: Array, hints?: Object) { + list(title: string, items: Array|Object, hints?: Object) { /** * Because in the original Yarn code list() is called starting with a "key: * string" argument that is ignored, we don't assume that a title has been @@ -142,6 +142,11 @@ export default class ConsoleReporter extends BaseReporter { */ this._logCategory('list', 'magenta', typeof title === 'string' ? this.format.bold(title) : ''); + if( !Array.isArray(items) ) { + hints = items; + items = Object.keys(hints); + } + const gutterWidth = (this._lastCategorySize || 2) - 1; if (hints) {