diff options
author | Kamil Ogórek <kamil.ogorek@gmail.com> | 2024-09-05 10:51:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-05 08:51:40 +0000 |
commit | 2c4d99a4586a8aa143feb8614e3b0d4de09dd190 (patch) | |
tree | 0c07ee12254da10d9710616be8cc98a32c0f35c7 /cli/tools/info.rs | |
parent | 49340b96f6b3603186e03f0102b99bc4a34a1b63 (diff) |
feat: include version number in all --json based outputs (#25335)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/tools/info.rs')
-rw-r--r-- | cli/tools/info.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/cli/tools/info.rs b/cli/tools/info.rs index a32f9dc45..6aa044a92 100644 --- a/cli/tools/info.rs +++ b/cli/tools/info.rs @@ -11,7 +11,6 @@ use deno_core::anyhow::bail; use deno_core::error::AnyError; use deno_core::resolve_url_or_path; use deno_core::serde_json; -use deno_core::serde_json::json; use deno_graph::Dependency; use deno_graph::GraphKind; use deno_graph::Module; @@ -35,6 +34,8 @@ use crate::npm::CliNpmResolver; use crate::npm::ManagedCliNpmResolver; use crate::util::checksum; +const JSON_SCHEMA_VERSION: u8 = 1; + pub async fn info( flags: Arc<Flags>, info_flags: InfoFlags, @@ -79,7 +80,10 @@ pub async fn info( } if info_flags.json { - let mut json_graph = json!(graph); + let mut json_graph = serde_json::json!(graph); + if let Some(output) = json_graph.as_object_mut() { + output.insert("version".to_string(), JSON_SCHEMA_VERSION.into()); + } add_npm_packages_to_json(&mut json_graph, npm_resolver.as_ref()); display::write_json_to_stdout(&json_graph)?; } else { @@ -121,7 +125,8 @@ fn print_cache_info( let local_storage_dir = origin_dir.join("local_storage"); if json { - let mut output = json!({ + let mut json_output = serde_json::json!({ + "version": JSON_SCHEMA_VERSION, "denoDir": deno_dir, "modulesCache": modules_cache, "npmCache": npm_cache, @@ -131,10 +136,10 @@ fn print_cache_info( }); if location.is_some() { - output["localStorage"] = serde_json::to_value(local_storage_dir)?; + json_output["localStorage"] = serde_json::to_value(local_storage_dir)?; } - display::write_json_to_stdout(&output) + display::write_json_to_stdout(&json_output) } else { println!("{} {}", colors::bold("DENO_DIR location:"), deno_dir); println!( |