mirror of
https://github.com/denoland/deno.git
synced 2025-03-04 01:44:26 -05:00
Module dep pretty printing in --info
This commit is contained in:
parent
0412ab2308
commit
061a9353ba
3 changed files with 48 additions and 15 deletions
|
@ -91,19 +91,21 @@ impl Modules {
|
||||||
pub struct Deps {
|
pub struct Deps {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub deps: Option<Vec<Deps>>,
|
pub deps: Option<Vec<Deps>>,
|
||||||
depth: usize,
|
prefix: String,
|
||||||
|
is_last: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deps {
|
impl Deps {
|
||||||
pub fn new(modules: &Modules, module_name: &str) -> Deps {
|
pub fn new(modules: &Modules, module_name: &str) -> Deps {
|
||||||
let mut seen = HashSet::new();
|
let mut seen = HashSet::new();
|
||||||
let id = modules.get_id(module_name).unwrap();
|
let id = modules.get_id(module_name).unwrap();
|
||||||
Self::helper(&mut seen, 0, modules, id)
|
Self::helper(&mut seen, "".to_string(), true, modules, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn helper(
|
fn helper(
|
||||||
seen: &mut HashSet<deno_mod>,
|
seen: &mut HashSet<deno_mod>,
|
||||||
depth: usize,
|
prefix: String,
|
||||||
|
is_last: bool,
|
||||||
modules: &Modules,
|
modules: &Modules,
|
||||||
id: deno_mod,
|
id: deno_mod,
|
||||||
) -> Deps {
|
) -> Deps {
|
||||||
|
@ -111,20 +113,29 @@ impl Deps {
|
||||||
if seen.contains(&id) {
|
if seen.contains(&id) {
|
||||||
Deps {
|
Deps {
|
||||||
name,
|
name,
|
||||||
depth,
|
prefix,
|
||||||
deps: None,
|
deps: None,
|
||||||
|
is_last,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
seen.insert(id);
|
seen.insert(id);
|
||||||
let child_ids = modules.get_children(id).unwrap();
|
let child_ids = modules.get_children(id).unwrap();
|
||||||
|
let child_count = child_ids.iter().count();
|
||||||
let deps = child_ids
|
let deps = child_ids
|
||||||
.iter()
|
.iter()
|
||||||
.map(|dep_id| Self::helper(seen, depth + 1, modules, *dep_id))
|
.enumerate()
|
||||||
.collect();
|
.map(|(index, dep_id)| {
|
||||||
|
let new_is_last = index == child_count - 1;
|
||||||
|
let mut new_prefix = prefix.clone();
|
||||||
|
new_prefix.push(if is_last { ' ' } else { '│' });
|
||||||
|
new_prefix.push(' ');
|
||||||
|
Self::helper(seen, new_prefix, new_is_last, modules, *dep_id)
|
||||||
|
}).collect();
|
||||||
Deps {
|
Deps {
|
||||||
name,
|
name,
|
||||||
depth,
|
prefix,
|
||||||
deps: Some(deps),
|
deps: Some(deps),
|
||||||
|
is_last,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,10 +143,19 @@ impl Deps {
|
||||||
|
|
||||||
impl fmt::Display for Deps {
|
impl fmt::Display for Deps {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
for _i in 0..self.depth {
|
let mut has_children = false;
|
||||||
write!(f, "| ")?;
|
if let Some(ref deps) = self.deps {
|
||||||
|
has_children = !deps.is_empty();
|
||||||
}
|
}
|
||||||
write!(f, "{}", self.name)?;
|
write!(
|
||||||
|
f,
|
||||||
|
"{}{}─{} {}",
|
||||||
|
self.prefix,
|
||||||
|
if self.is_last { "└" } else { "├" },
|
||||||
|
if has_children { "┬" } else { "─" },
|
||||||
|
self.name
|
||||||
|
)?;
|
||||||
|
|
||||||
if let Some(ref deps) = self.deps {
|
if let Some(ref deps) = self.deps {
|
||||||
for d in deps {
|
for d in deps {
|
||||||
write!(f, "\n{}", d)?;
|
write!(f, "\n{}", d)?;
|
||||||
|
@ -179,5 +199,10 @@ pub fn print_file_info(
|
||||||
}
|
}
|
||||||
|
|
||||||
let deps = Deps::new(modules, &out.module_name);
|
let deps = Deps::new(modules, &out.module_name);
|
||||||
println!("{} {}", ansi::bold("deps:".to_string()), deps);
|
println!("{}{}", ansi::bold("deps:\n".to_string()), deps.name);
|
||||||
|
if let Some(ref depsdeps) = deps.deps {
|
||||||
|
for d in depsdeps {
|
||||||
|
println!("{}", d);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
local: [WILDCARD]deps/http/127.0.0.1_PORT4545/tests/003_relative_import.ts
|
local: [WILDCARD]deps/http/127.0.0.1_PORT4545/tests/019_media_types.ts
|
||||||
type: TypeScript
|
type: TypeScript
|
||||||
compiled: [WILDCARD].js
|
compiled: [WILDCARD].js
|
||||||
map: [WILDCARD].js.map
|
map: [WILDCARD].js.map
|
||||||
deps: http://127.0.0.1:4545/tests/003_relative_import.ts
|
deps:
|
||||||
| http://127.0.0.1:4545/tests/subdir/print_hello.ts
|
http://127.0.0.1:4545/tests/019_media_types.ts
|
||||||
|
├── http://localhost:4545/tests/subdir/mt_text_typescript.t1.ts
|
||||||
|
├── http://localhost:4545/tests/subdir/mt_video_vdn.t2.ts
|
||||||
|
├── http://localhost:4545/tests/subdir/mt_video_mp2t.t3.ts
|
||||||
|
├── http://localhost:4545/tests/subdir/mt_application_x_typescript.t4.ts
|
||||||
|
├── http://localhost:4545/tests/subdir/mt_text_javascript.j1.js
|
||||||
|
├── http://localhost:4545/tests/subdir/mt_application_ecmascript.j2.js
|
||||||
|
├── http://localhost:4545/tests/subdir/mt_text_ecmascript.j3.js
|
||||||
|
└── http://localhost:4545/tests/subdir/mt_application_x_javascript.j4.js
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# The output assumes 003_relative_import.ts has already been run earlier
|
# The output assumes 003_relative_import.ts has already been run earlier
|
||||||
# and its output is cached to $DENO_DIR.
|
# and its output is cached to $DENO_DIR.
|
||||||
args: --info http://127.0.0.1:4545/tests/003_relative_import.ts
|
args: --info http://127.0.0.1:4545/tests/019_media_types.ts
|
||||||
output: tests/022_info_flag.out
|
output: tests/022_info_flag.out
|
||||||
|
|
Loading…
Add table
Reference in a new issue