Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add depth specification to ls. Fixes #726 #1463

Merged
merged 1 commit into from
Nov 7, 2016
Merged

add depth specification to ls. Fixes #726 #1463

merged 1 commit into from
Nov 7, 2016

Conversation

olingern
Copy link
Contributor

@olingern olingern commented Oct 25, 2016

Summary
Per #726, filtering the depth of children displayed should be supported.

Test plan
Added support for: yarn ls depth [LEVEL] where the first level is 1.

Examples:

yarn ls depth 1
screen shot 2016-10-25 at 7 37 06 pm

yarn ls depth 2
screen shot 2016-10-25 at 7 37 52 pm
`

@@ -45,7 +45,7 @@ export async function buildTree(
const treesByKey = {};
const trees = [];
const hoisted = await linker.getFlatHoistedTree(patterns);

//console.log(hoisted);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out console.log snuck in there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! When I fully understand the use case of yarn ls that I mentioned in #726, I'll add tests, remove this log, and rebase

@wyze
Copy link
Member

wyze commented Oct 26, 2016

npm ls command starts with depth 0 being the top level dependencies. Should we match that here? Right now you have it as starting from 1.

@olingern
Copy link
Contributor Author

@wyze I could. I considered 0 to be a non-depth and it circumvents filtering, i.e. yarn ls

Zero-indexing the tree structure shouldn't be too hard, just handle no-filtering differently

@hawkrives
Copy link

It's always bugged me that npm used 0-indexing for --depth — especially since the du command is 1-indexed, and I wind up using them together a lot.

I would appreciate it if yarn used 1-indexing, but I'll deal with 0-indexing 😉 (also I have no actual vote in this matter, since I've not written any code here.)

@olingern
Copy link
Contributor Author

@hawkrives @wyze Obviously, I like 1-indexed, but I'm not sure if the goal is to provide a CLI that is synonymous with npm's, or just "inspired."

@samccone
Copy link
Member

I vote Lets match npm here

@olingern
Copy link
Contributor Author

olingern commented Oct 27, 2016

@wyze @samccone Depth is now indexed at 0. I've also added support for a few other ls options. Hopefully, a good direction to go in 😄

Below are the commands supported in this PR
yarn ls --depth [LEVEL]
yarn ls --prod show dependencies only
yarn ls --la / yarn ls --long yarn ls --ll show detailed tree view

  • Detailed tree view was probably the most fun, and difficult to get working (in an elegant way), but it lacks description and repo url that npm has
  • Will be adding tests for all updates in this commit over the next day. Please, feel free to give any feedback.

screen shot 2016-10-27 at 10 49 00 am

// Place your settings in this file to overwrite default and user settings.
{
"javascript.validate.enable": false
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOF please


export function setFlags(commander: Object) {
commander.option('--depth [depth]', 'depth');
commander.option('--prod [prod]', 'prod');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some descriptions to these options? It's not really obvious what they're supposed to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure

extendedTree(key: string, trees: Trees) {
//
const output = ({name, type, registry, reference, children, hint, color}, level, end) => {
const _this = this;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of declaring this?

Copy link
Contributor Author

@olingern olingern Oct 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds support for yarn ls --long or yarn ls --la or yarn ls --ll, which is a nod to npm's npm ls --long

The two paths of outputting a tree diverge enough that I needed to break the original tree function into smaller bits that could be consumed by another function, extendedTree you see here

@olingern
Copy link
Contributor Author

olingern commented Oct 31, 2016

@kittens @wyze To keep this moving along, I reworked this PR to only include work for the yarn ls --depth=[LEVEL] command. The scope of the commit should be much smaller 😉

@@ -4,6 +4,7 @@ import type {Reporter} from '../../reporters/index.js';
import type {InstallCwdRequest, InstallPrepared} from './install.js';
import type {DependencyRequestPatterns} from '../../types.js';
import type Config from '../../config.js';
import type{lsOptions} from './ls.js';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a space between type and {.

@@ -11,6 +11,7 @@ export type Package = {
version: string
};


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra newline.

// types
import type {
Trees,
} from '../../types.js';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be on one line.

Trees,
} from '../../types.js';

export type formattedOutput = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type name should begin with a capitol letter.

const _item = formatColor(fmt.color, fmt.name, fmt.formatter);
const _indent = getIndent(fmt.end, fmt.level);
const _suffix = getSuffix(fmt.hint, fmt.formatter);
return `${_indent}─ ${_item}${_suffix}\n`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the _ from the variables here.

@@ -11,7 +11,10 @@ import Lockfile from '../../lockfile/wrapper.js';
const invariant = require('invariant');

export const requireLockfile = true;
export const noArguments = true;

export type lsOptions = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize the type here too.

@wyze
Copy link
Member

wyze commented Nov 4, 2016

@olingern Please rebase and make the requested changes and see if we can land this!

@olingern
Copy link
Contributor Author

olingern commented Nov 5, 2016

@wyze Will do shortly! Thanks for the feedback!

@olingern
Copy link
Contributor Author

olingern commented Nov 7, 2016

@wyze Changes made, along with one logic fix. My tests pass locally, I'm not sure what's up with travis-ci and appveyor.

@wyze
Copy link
Member

wyze commented Nov 7, 2016

@olingern, I'm not sure if some stuff landed or when you did the rebase, but I just did a fresh rebase on your branch and resolved the conflicts and pushed up. If everything comes back green, we are good to go.

@wyze wyze merged commit 253269f into yarnpkg:master Nov 7, 2016
@wyze
Copy link
Member

wyze commented Nov 7, 2016

Thanks again for all the iteration here @olingern! Would you mind opening a PR over on yarnpkg/website to add documentation for this?

@olingern
Copy link
Contributor Author

olingern commented Nov 8, 2016

@wyze No problem!

PR is open here: #251.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants