-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Conversation
@@ -45,7 +45,7 @@ export async function buildTree( | |||
const treesByKey = {}; | |||
const trees = []; | |||
const hoisted = await linker.getFlatHoistedTree(patterns); | |||
|
|||
//console.log(hoisted); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 I could. I considered 0 to be a non-depth and it circumvents filtering, i.e. Zero-indexing the tree structure shouldn't be too hard, just handle no-filtering differently |
It's always bugged me that npm used 0-indexing for 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.) |
@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." |
I vote Lets match npm here |
@wyze @samccone Depth is now indexed at 0. I've also added support for a few other Below are the commands supported in this PR
|
// Place your settings in this file to overwrite default and user settings. | ||
{ | ||
"javascript.validate.enable": false | ||
} |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
@@ -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'; |
There was a problem hiding this comment.
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 | |||
}; | |||
|
|||
|
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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`; |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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.
@olingern Please rebase and make the requested changes and see if we can land this! |
@wyze Will do shortly! Thanks for the feedback! |
@wyze Changes made, along with one logic fix. My tests pass locally, I'm not sure what's up with travis-ci and appveyor. |
@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. |
Thanks again for all the iteration here @olingern! Would you mind opening a PR over on yarnpkg/website to add documentation for this? |
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
yarn ls depth 2
`