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

figure out the list based on the hints only #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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