mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
feat: print cache location when no arg in deno info (#2752)
This commit is contained in:
parent
54982e948e
commit
9bd473d8ac
6 changed files with 108 additions and 58 deletions
25
cli/flags.rs
25
cli/flags.rs
|
@ -259,8 +259,17 @@ The declaration file could be saved and used for typing information.",
|
|||
),
|
||||
).subcommand(
|
||||
SubCommand::with_name("info")
|
||||
.about("Show source file related info")
|
||||
.long_about("Show source file related info.
|
||||
.about("Show info about cache or info related to source file")
|
||||
.long_about("Show info about cache or info related to source file.
|
||||
|
||||
deno info
|
||||
|
||||
The following information is shown:
|
||||
|
||||
DENO_DIR: location of directory containing Deno-related files
|
||||
Remote modules cache: location of directory containing remote modules
|
||||
TypeScript compiler cache: location of directory containing TS compiler output
|
||||
|
||||
|
||||
deno info https://deno.land/std@v0.11/http/file_server.ts
|
||||
|
||||
|
@ -271,7 +280,7 @@ The following information is shown:
|
|||
compiled: TypeScript only. shown local path of compiled source code.
|
||||
map: TypeScript only. shown local path of source map.
|
||||
deps: Dependency tree of the source file.",
|
||||
).arg(Arg::with_name("file").takes_value(true).required(true)),
|
||||
).arg(Arg::with_name("file").takes_value(true).required(false)),
|
||||
).subcommand(
|
||||
SubCommand::with_name("eval")
|
||||
.about("Eval script")
|
||||
|
@ -748,8 +757,9 @@ pub fn flags_from_vec(
|
|||
DenoSubcommand::Run
|
||||
}
|
||||
("info", Some(info_match)) => {
|
||||
let file: &str = info_match.value_of("file").unwrap();
|
||||
argv.extend(vec![file.to_string()]);
|
||||
if info_match.is_present("file") {
|
||||
argv.push(info_match.value_of("file").unwrap().to_string());
|
||||
}
|
||||
DenoSubcommand::Info
|
||||
}
|
||||
("install", Some(install_match)) => {
|
||||
|
@ -1119,6 +1129,11 @@ mod tests {
|
|||
assert_eq!(flags, DenoFlags::default());
|
||||
assert_eq!(subcommand, DenoSubcommand::Info);
|
||||
assert_eq!(argv, svec!["deno", "script.ts"]);
|
||||
|
||||
let (flags, subcommand, argv) = flags_from_vec(svec!["deno", "info"]);
|
||||
assert_eq!(flags, DenoFlags::default());
|
||||
assert_eq!(subcommand, DenoSubcommand::Info);
|
||||
assert_eq!(argv, svec!["deno"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
134
cli/main.rs
134
cli/main.rs
|
@ -56,7 +56,6 @@ use deno::ErrBox;
|
|||
use deno::ModuleSpecifier;
|
||||
use flags::DenoFlags;
|
||||
use flags::DenoSubcommand;
|
||||
use futures::future;
|
||||
use futures::lazy;
|
||||
use futures::Future;
|
||||
use log::Level;
|
||||
|
@ -99,7 +98,62 @@ fn js_check(r: Result<(), ErrBox>) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: we might want to rethink how this method works
|
||||
fn create_worker_and_state(
|
||||
flags: DenoFlags,
|
||||
argv: Vec<String>,
|
||||
) -> (Worker, ThreadSafeState) {
|
||||
use crate::shell::Shell;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
let shell = Arc::new(Mutex::new(Shell::new()));
|
||||
let progress = Progress::new();
|
||||
progress.set_callback(move |_done, _completed, _total, status, msg| {
|
||||
if !status.is_empty() {
|
||||
let mut s = shell.lock().unwrap();
|
||||
s.status(status, msg).expect("shell problem");
|
||||
}
|
||||
});
|
||||
// TODO(kevinkassimo): maybe make include_deno_namespace also configurable?
|
||||
let state =
|
||||
ThreadSafeState::new(flags, argv, ops::op_selector_std, progress, true)
|
||||
.unwrap();
|
||||
let worker = Worker::new(
|
||||
"main".to_string(),
|
||||
startup_data::deno_isolate_init(),
|
||||
state.clone(),
|
||||
);
|
||||
|
||||
(worker, state)
|
||||
}
|
||||
|
||||
fn types_command() {
|
||||
let content = include_str!(concat!(
|
||||
env!("GN_OUT_DIR"),
|
||||
"/gen/cli/lib/lib.deno_runtime.d.ts"
|
||||
));
|
||||
println!("{}", content);
|
||||
}
|
||||
|
||||
fn print_cache_info(worker: Worker) {
|
||||
let state = worker.state;
|
||||
|
||||
println!(
|
||||
"{} {:?}",
|
||||
ansi::bold("DENO_DIR location:".to_string()),
|
||||
state.dir.root
|
||||
);
|
||||
println!(
|
||||
"{} {:?}",
|
||||
ansi::bold("Remote modules cache:".to_string()),
|
||||
state.dir.deps_cache.location
|
||||
);
|
||||
println!(
|
||||
"{} {:?}",
|
||||
ansi::bold("TypeScript compiler cache:".to_string()),
|
||||
state.dir.gen_cache.location
|
||||
);
|
||||
}
|
||||
|
||||
pub fn print_file_info(
|
||||
worker: Worker,
|
||||
module_specifier: &ModuleSpecifier,
|
||||
|
@ -181,48 +235,13 @@ pub fn print_file_info(
|
|||
})
|
||||
}
|
||||
|
||||
fn create_worker_and_state(
|
||||
flags: DenoFlags,
|
||||
argv: Vec<String>,
|
||||
) -> (Worker, ThreadSafeState) {
|
||||
use crate::shell::Shell;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
let shell = Arc::new(Mutex::new(Shell::new()));
|
||||
let progress = Progress::new();
|
||||
progress.set_callback(move |_done, _completed, _total, status, msg| {
|
||||
if !status.is_empty() {
|
||||
let mut s = shell.lock().unwrap();
|
||||
s.status(status, msg).expect("shell problem");
|
||||
}
|
||||
});
|
||||
// TODO(kevinkassimo): maybe make include_deno_namespace also configurable?
|
||||
let state =
|
||||
ThreadSafeState::new(flags, argv, ops::op_selector_std, progress, true)
|
||||
.unwrap();
|
||||
let worker = Worker::new(
|
||||
"main".to_string(),
|
||||
startup_data::deno_isolate_init(),
|
||||
state.clone(),
|
||||
);
|
||||
fn info_command(flags: DenoFlags, argv: Vec<String>) {
|
||||
let (mut worker, state) = create_worker_and_state(flags, argv.clone());
|
||||
|
||||
(worker, state)
|
||||
}
|
||||
|
||||
fn types_command() {
|
||||
let content = include_str!(concat!(
|
||||
env!("GN_OUT_DIR"),
|
||||
"/gen/cli/lib/lib.deno_runtime.d.ts"
|
||||
));
|
||||
println!("{}", content);
|
||||
}
|
||||
|
||||
fn fetch_or_info_command(
|
||||
flags: DenoFlags,
|
||||
argv: Vec<String>,
|
||||
print_info: bool,
|
||||
) {
|
||||
let (mut worker, state) = create_worker_and_state(flags, argv);
|
||||
// If it was just "deno info" print location of caches and exit
|
||||
if argv.len() == 1 {
|
||||
return print_cache_info(worker);
|
||||
}
|
||||
|
||||
let main_module = state.main_module().unwrap();
|
||||
let main_future = lazy(move || {
|
||||
|
@ -233,13 +252,7 @@ fn fetch_or_info_command(
|
|||
worker
|
||||
.execute_mod_async(&main_module, true)
|
||||
.map_err(print_err_and_exit)
|
||||
.and_then(move |()| {
|
||||
if print_info {
|
||||
future::Either::A(print_file_info(worker, &main_module))
|
||||
} else {
|
||||
future::Either::B(future::ok(worker))
|
||||
}
|
||||
})
|
||||
.and_then(move |()| print_file_info(worker, &main_module))
|
||||
.and_then(|worker| {
|
||||
worker.then(|result| {
|
||||
js_check(result);
|
||||
|
@ -250,6 +263,23 @@ fn fetch_or_info_command(
|
|||
tokio_util::run(main_future);
|
||||
}
|
||||
|
||||
fn fetch_command(flags: DenoFlags, argv: Vec<String>) {
|
||||
let (mut worker, state) = create_worker_and_state(flags, argv.clone());
|
||||
|
||||
let main_module = state.main_module().unwrap();
|
||||
let main_future = lazy(move || {
|
||||
// Setup runtime.
|
||||
js_check(worker.execute("denoMain()"));
|
||||
debug!("main_module {}", main_module);
|
||||
|
||||
worker.execute_mod_async(&main_module, true).then(|result| {
|
||||
js_check(result);
|
||||
Ok(())
|
||||
})
|
||||
});
|
||||
tokio_util::run(main_future);
|
||||
}
|
||||
|
||||
fn eval_command(flags: DenoFlags, argv: Vec<String>) {
|
||||
let (mut worker, state) = create_worker_and_state(flags, argv);
|
||||
// Wrap provided script in async function so asynchronous methods
|
||||
|
@ -391,8 +421,8 @@ fn main() {
|
|||
DenoSubcommand::Bundle => bundle_command(flags, argv),
|
||||
DenoSubcommand::Completions => {}
|
||||
DenoSubcommand::Eval => eval_command(flags, argv),
|
||||
DenoSubcommand::Fetch => fetch_or_info_command(flags, argv, false),
|
||||
DenoSubcommand::Info => fetch_or_info_command(flags, argv, true),
|
||||
DenoSubcommand::Fetch => fetch_command(flags, argv),
|
||||
DenoSubcommand::Info => info_command(flags, argv),
|
||||
DenoSubcommand::Install => run_script(flags, argv),
|
||||
DenoSubcommand::Repl => run_repl(flags, argv),
|
||||
DenoSubcommand::Run => run_script(flags, argv),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# The output assumes 003_relative_import.ts has already been run earlier
|
||||
# and its output is cached to $DENO_DIR.
|
||||
args: info http://127.0.0.1:4545/tests/019_media_types.ts
|
||||
output: tests/022_info_flag.out
|
||||
output: tests/022_info_flag_script.out
|
3
tests/041_info_flag.out
Normal file
3
tests/041_info_flag.out
Normal file
|
@ -0,0 +1,3 @@
|
|||
DENO_DIR location: "[WILDCARD]"
|
||||
Remote modules cache: "[WILDCARD]deps"
|
||||
TypeScript compiler cache: "[WILDCARD]gen"
|
2
tests/041_info_flag.test
Normal file
2
tests/041_info_flag.test
Normal file
|
@ -0,0 +1,2 @@
|
|||
args: info
|
||||
output: tests/041_info_flag.out
|
Loading…
Add table
Reference in a new issue