mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 00:29:09 -05:00
feat(cli): add origin data dir to deno info (#10589)
Co-authored-by: Nayeem Rahman <nayeemrmn99@gmail.com> Co-authored-by: Luca Casonato <lucacasonato@yahoo.com> Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
This commit is contained in:
parent
d5d59bb794
commit
b21fa78a1e
11 changed files with 75 additions and 18 deletions
|
@ -791,6 +791,11 @@ TypeScript compiler cache: Subdirectory containing TS compiler output.",
|
|||
.arg(Arg::with_name("file").takes_value(true).required(false))
|
||||
.arg(reload_arg().requires("file"))
|
||||
.arg(ca_file_arg())
|
||||
.arg(
|
||||
location_arg()
|
||||
.conflicts_with("file")
|
||||
.help("Show files used for origin bound APIs like the Web Storage API when running a script with '--location=<HREF>'")
|
||||
)
|
||||
// TODO(lucacasonato): remove for 2.0
|
||||
.arg(no_check_arg().hidden(true))
|
||||
.arg(import_map_arg())
|
||||
|
@ -1577,6 +1582,7 @@ fn fmt_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|||
fn info_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
||||
reload_arg_parse(flags, matches);
|
||||
import_map_arg_parse(flags, matches);
|
||||
location_arg_parse(flags, matches);
|
||||
ca_file_arg_parse(flags, matches);
|
||||
let json = matches.is_present("json");
|
||||
flags.subcommand = DenoSubcommand::Info {
|
||||
|
|
31
cli/main.rs
31
cli/main.rs
|
@ -204,11 +204,12 @@ pub fn create_main_worker(
|
|||
no_color: !colors::use_color(),
|
||||
get_error_class_fn: Some(&crate::errors::get_error_class_name),
|
||||
location: program_state.flags.location.clone(),
|
||||
location_data_dir: program_state.flags.location.clone().map(|loc| {
|
||||
origin_storage_dir: program_state.flags.location.clone().map(|loc| {
|
||||
program_state
|
||||
.dir
|
||||
.root
|
||||
.clone()
|
||||
// TODO(@crowlKats): change to origin_data for 2.0
|
||||
.join("location_data")
|
||||
.join(checksum::gen(&[loc.to_string().as_bytes()]))
|
||||
}),
|
||||
|
@ -267,19 +268,34 @@ where
|
|||
fn print_cache_info(
|
||||
state: &Arc<ProgramState>,
|
||||
json: bool,
|
||||
location: Option<deno_core::url::Url>,
|
||||
) -> Result<(), AnyError> {
|
||||
let deno_dir = &state.dir.root;
|
||||
let modules_cache = &state.file_fetcher.get_http_cache_location();
|
||||
let typescript_cache = &state.dir.gen_cache.location;
|
||||
let registry_cache =
|
||||
&state.dir.root.join(lsp::language_server::REGISTRIES_PATH);
|
||||
let mut origin_dir = state.dir.root.join("location_data");
|
||||
|
||||
if let Some(location) = &location {
|
||||
origin_dir =
|
||||
origin_dir.join(&checksum::gen(&[location.to_string().as_bytes()]));
|
||||
}
|
||||
|
||||
if json {
|
||||
let output = json!({
|
||||
let mut output = json!({
|
||||
"denoDir": deno_dir,
|
||||
"modulesCache": modules_cache,
|
||||
"typescriptCache": typescript_cache,
|
||||
"registryCache": registry_cache,
|
||||
"originStorage": origin_dir,
|
||||
});
|
||||
|
||||
if location.is_some() {
|
||||
output["localStorage"] =
|
||||
serde_json::to_value(origin_dir.join("local_storage"))?;
|
||||
}
|
||||
|
||||
write_json_to_stdout(&output)
|
||||
} else {
|
||||
println!("{} {:?}", colors::bold("DENO_DIR location:"), deno_dir);
|
||||
|
@ -298,6 +314,14 @@ fn print_cache_info(
|
|||
colors::bold("Language server registries cache:"),
|
||||
registry_cache,
|
||||
);
|
||||
println!("{} {:?}", colors::bold("Origin storage:"), origin_dir);
|
||||
if location.is_some() {
|
||||
println!(
|
||||
"{} {:?}",
|
||||
colors::bold("Local Storage:"),
|
||||
origin_dir.join("local_storage"),
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -393,6 +417,7 @@ async fn info_command(
|
|||
maybe_specifier: Option<String>,
|
||||
json: bool,
|
||||
) -> Result<(), AnyError> {
|
||||
let location = flags.location.clone();
|
||||
let program_state = ProgramState::build(flags).await?;
|
||||
if let Some(specifier) = maybe_specifier {
|
||||
let specifier = resolve_url_or_path(&specifier)?;
|
||||
|
@ -420,7 +445,7 @@ async fn info_command(
|
|||
}
|
||||
} else {
|
||||
// If it was just "deno info" print location of caches and exit
|
||||
print_cache_info(&program_state, json)
|
||||
print_cache_info(&program_state, json, location)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -193,7 +193,7 @@ pub async fn run(
|
|||
no_color: !colors::use_color(),
|
||||
get_error_class_fn: Some(&get_error_class_name),
|
||||
location: metadata.location,
|
||||
location_data_dir: None,
|
||||
origin_storage_dir: None,
|
||||
blob_url_store,
|
||||
broadcast_channel,
|
||||
};
|
||||
|
|
|
@ -2,3 +2,4 @@ DENO_DIR location: "[WILDCARD]"
|
|||
Remote modules cache: "[WILDCARD]deps"
|
||||
Emitted modules cache: "[WILDCARD]gen"
|
||||
Language server registries cache: "[WILDCARD]registries"
|
||||
Origin storage: "[WILDCARD]location_data"
|
||||
|
|
6
cli/tests/041_info_flag_location.out
Normal file
6
cli/tests/041_info_flag_location.out
Normal file
|
@ -0,0 +1,6 @@
|
|||
DENO_DIR location: "[WILDCARD]"
|
||||
Remote modules cache: "[WILDCARD]deps"
|
||||
Emitted modules cache: "[WILDCARD]gen"
|
||||
Language server registries cache: "[WILDCARD]registries"
|
||||
Origin storage: "[WILDCARD]location_data[WILDCARD]"
|
||||
Local Storage: "[WILDCARD]location_data[WILDCARD]local_storage"
|
|
@ -2,5 +2,6 @@
|
|||
"denoDir": "[WILDCARD]",
|
||||
"modulesCache": "[WILDCARD]deps",
|
||||
"typescriptCache": "[WILDCARD]gen",
|
||||
"registryCache": "[WILDCARD]registries"
|
||||
"registryCache": "[WILDCARD]registries",
|
||||
"originStorage": "[WILDCARD]location_data"
|
||||
}
|
8
cli/tests/info_json_location.out
Normal file
8
cli/tests/info_json_location.out
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"denoDir": "[WILDCARD]",
|
||||
"modulesCache": "[WILDCARD]deps",
|
||||
"typescriptCache": "[WILDCARD]gen",
|
||||
"registryCache": "[WILDCARD]registries",
|
||||
"originStorage": "[WILDCARD]location_data[WILDCARD]",
|
||||
"localStorage": "[WILDCARD]location_data[WILDCARD]local_storage"
|
||||
}
|
|
@ -2846,11 +2846,21 @@ console.log("finish");
|
|||
output: "041_info_flag.out",
|
||||
});
|
||||
|
||||
itest!(_042_info_flag_location {
|
||||
args: "info --location https://deno.land",
|
||||
output: "041_info_flag_location.out",
|
||||
});
|
||||
|
||||
itest!(info_json {
|
||||
args: "info --json --unstable",
|
||||
output: "info_json.out",
|
||||
});
|
||||
|
||||
itest!(info_json_location {
|
||||
args: "info --json --unstable --location https://deno.land",
|
||||
output: "info_json_location.out",
|
||||
});
|
||||
|
||||
itest!(_042_dyn_import_evalcontext {
|
||||
args: "run --quiet --allow-read --reload 042_dyn_import_evalcontext.ts",
|
||||
output: "042_dyn_import_evalcontext.ts.out",
|
||||
|
|
|
@ -13,9 +13,9 @@ use std::fmt;
|
|||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct LocationDataDir(PathBuf);
|
||||
struct OriginStorageDir(PathBuf);
|
||||
|
||||
pub fn init(location_data_dir: Option<PathBuf>) -> Extension {
|
||||
pub fn init(origin_storage_dir: Option<PathBuf>) -> Extension {
|
||||
Extension::builder()
|
||||
.js(include_js_files!(
|
||||
prefix "deno:extensions/webstorage",
|
||||
|
@ -34,8 +34,8 @@ pub fn init(location_data_dir: Option<PathBuf>) -> Extension {
|
|||
),
|
||||
])
|
||||
.state(move |state| {
|
||||
if let Some(location_data_dir) = location_data_dir.clone() {
|
||||
state.put(LocationDataDir(location_data_dir));
|
||||
if let Some(origin_storage_dir) = origin_storage_dir.clone() {
|
||||
state.put(OriginStorageDir(origin_storage_dir));
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
|
@ -55,7 +55,7 @@ fn get_webstorage(
|
|||
) -> Result<&Connection, AnyError> {
|
||||
let conn = if persistent {
|
||||
if state.try_borrow::<LocalStorage>().is_none() {
|
||||
let path = state.try_borrow::<LocationDataDir>().ok_or_else(|| {
|
||||
let path = state.try_borrow::<OriginStorageDir>().ok_or_else(|| {
|
||||
DomExceptionNotSupportedError::new(
|
||||
"LocalStorage is not supported in this context.",
|
||||
)
|
||||
|
|
|
@ -41,7 +41,7 @@ async fn main() -> Result<(), AnyError> {
|
|||
no_color: false,
|
||||
get_error_class_fn: Some(&get_error_class_name),
|
||||
location: None,
|
||||
location_data_dir: None,
|
||||
origin_storage_dir: None,
|
||||
blob_url_store: BlobUrlStore::default(),
|
||||
broadcast_channel: InMemoryBroadcastChannel::default(),
|
||||
};
|
||||
|
|
|
@ -69,7 +69,7 @@ pub struct WorkerOptions {
|
|||
pub no_color: bool,
|
||||
pub get_error_class_fn: Option<GetErrorClassFn>,
|
||||
pub location: Option<Url>,
|
||||
pub location_data_dir: Option<std::path::PathBuf>,
|
||||
pub origin_storage_dir: Option<std::path::PathBuf>,
|
||||
pub blob_url_store: BlobUrlStore,
|
||||
pub broadcast_channel: InMemoryBroadcastChannel,
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ impl MainWorker {
|
|||
options.user_agent.clone(),
|
||||
options.ca_data.clone(),
|
||||
),
|
||||
deno_webstorage::init(options.location_data_dir.clone()),
|
||||
deno_webstorage::init(options.origin_storage_dir.clone()),
|
||||
deno_crypto::init(options.seed),
|
||||
deno_broadcast_channel::init(
|
||||
options.broadcast_channel.clone(),
|
||||
|
@ -307,7 +307,7 @@ mod tests {
|
|||
no_color: true,
|
||||
get_error_class_fn: None,
|
||||
location: None,
|
||||
location_data_dir: None,
|
||||
origin_storage_dir: None,
|
||||
blob_url_store: BlobUrlStore::default(),
|
||||
broadcast_channel: InMemoryBroadcastChannel::default(),
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue