-
Notifications
You must be signed in to change notification settings - Fork 21
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
feat: Implement ls
command
#17
base: main
Are you sure you want to change the base?
Conversation
crates/cli/src/commands.rs
Outdated
/// Indicates what dependencies to omit while running | ||
/// ls | ||
#[arg(long = "omit", short = 'O')] | ||
pub omit: 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.
It seems like pnpm
has different characteristics than npm on this. Can you follow pnpm? https://pnpm.io/cli/list
0cdaceb
to
ed1c4aa
Compare
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.
Here I'm quite stuck (sorry for the silly question, still getting used to Rust
ownership concept).
I've tried several things but always stopped upon the issue of the lifetime of the strings within the loop.
cc: @anonrig
for (name, version) in dependencies { | ||
// let label = format!("{} - {}", name, version); | ||
// print!("{}", label); | ||
let mut tree = helper::create_tree(name, version); | ||
|
||
if depth > 1 { | ||
let path = format!("{}{}{}", &name, MAIN_SEPARATOR, "package.json"); | ||
let pjson = PackageJson::from_path(&node_modules_path.join(path))?; | ||
let subtree = self.list( | ||
&pjson, | ||
DependencyGroup::Default, | ||
node_modules_path, | ||
depth - 1, | ||
)?; | ||
|
||
tree.push(subtree); | ||
} | ||
|
||
root.push(tree.clone()); | ||
} |
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.
Basically, here, I'm losing the reference to the name
and version
, after the scope of the loop ends, which is expected.
The main issue comes at the moment of trying the build the whole tree for a single manifest.
My initial idea was to use a recursive data structure (Tree), read its dependencies, mount it into a three representation; and continue accordingly to the depth
passed.
Sadly, the way I initially designed seems to not play well with the borrowed concept 🤔
Another option was to convert it to an iterator and use the utils function to map it and print it back. But wanted to keep it as last resort.
Any thoughts? 🤔
This PR attempts to introduce the
ls
command, similar tonpm
andpnpm
versions.Its initial version aims for simplicity and just provides a tree-like representation of the modules installed based on the
package.json
manifest with options to omitdev
ordependencies
accordingly.