Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
figure out the list based on the hints only
Browse files Browse the repository at this point in the history
  • Loading branch information
yanick committed Oct 24, 2021
1 parent c7e730c commit d1201f3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions examples/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion src/reporters/base-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export default class BaseReporter {
}

// TODO
list(key: string, items: Array<string>, hints?: Object) {}
list(key: string, items: Array<string>|Object, hints?: Object) {}

// Outputs basic tree structure to console
tree(key: string, obj: Trees, {force = false}: {force?: boolean} = {}) {}
Expand Down
7 changes: 6 additions & 1 deletion src/reporters/console/console-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,19 @@ export default class ConsoleReporter extends BaseReporter {
this.log(String(value), {force: true});
}

list(title: string, items: Array<string>, hints?: Object) {
list(title: string, items: Array<string>|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
* passed in or is a valid string, to avoid creating a breaking change.
*/
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) {
Expand Down

0 comments on commit d1201f3

Please sign in to comment.