Skip to content

Commit ec45c1e

Browse files
committed
refactor: solve conflicts
1 parent f319325 commit ec45c1e

File tree

3 files changed

+8
-51
lines changed

3 files changed

+8
-51
lines changed

crates/cli/src/commands/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
pub mod add;
22
pub mod install;
3+
pub mod list;
34
pub mod run;
45
pub mod store;
56

67
use std::{env, ffi::OsString, path::PathBuf};
78

89
use crate::commands::{
9-
add::AddCommandArgs, install::InstallCommandArgs, run::RunCommandArgs, store::StoreSubcommands,
10+
add::AddCommandArgs, install::InstallCommandArgs, list::ListArgs, run::RunCommandArgs,
11+
store::StoreSubcommands,
1012
};
1113
use clap::{Parser, Subcommand};
1214

@@ -46,4 +48,6 @@ pub enum Subcommands {
4648
/// Managing the package store.
4749
#[clap(subcommand)]
4850
Store(StoreSubcommands),
51+
/// List all dependencies installed based on package.json
52+
List(ListArgs),
4953
}

crates/cli/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub async fn run_cli() -> Result<()> {
2525

2626
async fn run_commands(cli: Cli) -> Result<()> {
2727
let package_json_path = cli.current_dir.join("package.json");
28+
let node_modules_path = cli.current_dir.join("node_modules");
2829

2930
match &cli.subcommand {
3031
Subcommands::Init => {
@@ -100,7 +101,8 @@ async fn run_commands(cli: Cli) -> Result<()> {
100101
Subcommands::List(args) => {
101102
let group = args.get_scope();
102103
let depth = args.get_depth();
103-
PackageJson::from_path(&package_json_path)?.list(group, &node_modules_path, depth)?;
104+
let manager = PackageManager::new(&package_json_path)?;
105+
manager.list(&manager.package_json, group, &node_modules_path, depth)?;
104106
}
105107
}
106108

crates/package_json/src/lib.rs

-49
Original file line numberDiff line numberDiff line change
@@ -197,55 +197,6 @@ impl PackageJson {
197197
Err(PackageJsonError::NoScript(command.to_string()))
198198
}
199199
}
200-
201-
pub fn list(&self, dependency_group: DependencyGroup, node_modules_path: &PathBuf, depth: u32) -> Result<String, PackageJsonError> {
202-
let mut scope: String = String::new();
203-
let default = Value::default();
204-
match dependency_group {
205-
DependencyGroup::Dev => {
206-
let mut dependencies = self
207-
.value
208-
.get("devDependencies")
209-
.unwrap_or(&default)
210-
.as_object()
211-
.into_iter();
212-
213-
let dep = dependencies.next();
214-
while !dep.is_none() {
215-
let tree: String = dep.unwrap()
216-
.into_iter()
217-
.map(|(name, version)| {
218-
let mut res = format!("{}@{}", name, version);
219-
220-
if depth > 1 {
221-
let nested = PackageJson::from_path(&node_modules_path.join(name))
222-
.unwrap();
223-
let unwraped = nested.list(DependencyGroup::Dev, node_modules_path, depth);
224-
res = format!("\n\t{}", unwraped.unwrap())
225-
}
226-
227-
res
228-
}).collect();
229-
scope = format!("{:?}\n", tree);
230-
}
231-
232-
},
233-
DependencyGroup::Default => scope = "dependencies".to_string(),
234-
_ => scope = "all".to_string()
235-
}
236-
237-
// let binding = Value::default();
238-
// let mut dependencies = self.value.get(scope).unwrap_or(&binding).as_object().into_iter();
239-
240-
// let mut dep = dependencies.next();
241-
// while !dep.is_none() {
242-
// println!("{:?}", dep);
243-
// dep = dependencies.next();
244-
// }
245-
246-
Ok(scope.clone())
247-
}
248-
249200
}
250201

251202
#[cfg(test)]

0 commit comments

Comments
 (0)