From 7cccb7422bb9be7a2e87d71ca59c8dabd32c07ec Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 26 Sep 2024 15:57:12 -0400 Subject: [PATCH] fix(info): move "version" field to top of json output (#25890) --- cli/tools/info.rs | 6 +++++- .../specs/info/json_deps_order/076_info_json_deps_order.out | 2 +- tests/specs/info/json_file/json_output/main.out | 2 +- tests/specs/info/multiple_redirects/main.out | 2 +- .../npm/cjs_with_deps/cjs_with_deps/main_info_json.out | 2 +- .../npm/info_chalk_display/cjs_with_deps/main_info_json.out | 2 +- .../cjs_with_deps/main_info_json.out | 2 +- .../npm/info_chalk_json/cjs_with_deps/main_info_json.out | 2 +- .../cjs_with_deps/main_info_json.out | 2 +- tests/specs/npm/info_cli_chalk_display/info/chalk_json.out | 2 +- tests/specs/npm/info_cli_chalk_json/info/chalk_json.out | 2 +- .../peer_deps_with_copied_folders/main_info_json.out | 2 +- .../peer_deps_with_copied_folders/main_info_json.out | 2 +- .../cjs_with_deps/main_info_json.out | 2 +- tests/testdata/npm/cjs_with_deps/main_info_json.out | 2 +- .../npm/peer_deps_with_copied_folders/main_info_json.out | 2 +- 16 files changed, 20 insertions(+), 16 deletions(-) diff --git a/cli/tools/info.rs b/cli/tools/info.rs index b92887d53a..1c83abe3bb 100644 --- a/cli/tools/info.rs +++ b/cli/tools/info.rs @@ -82,7 +82,11 @@ pub async fn info( if info_flags.json { 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()); + output.shift_insert( + 0, + "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)?; diff --git a/tests/specs/info/json_deps_order/076_info_json_deps_order.out b/tests/specs/info/json_deps_order/076_info_json_deps_order.out index 33d58da16a..92bf1d0130 100644 --- a/tests/specs/info/json_deps_order/076_info_json_deps_order.out +++ b/tests/specs/info/json_deps_order/076_info_json_deps_order.out @@ -1,4 +1,5 @@ { + "version": 1, "roots": [ "file://[WILDCARD]/076_info_json_deps_order.ts" ], @@ -160,6 +161,5 @@ } ], "redirects": {}, - "version": 1, "npmPackages": {} } diff --git a/tests/specs/info/json_file/json_output/main.out b/tests/specs/info/json_file/json_output/main.out index d4c2f234da..bc8f4d0f84 100644 --- a/tests/specs/info/json_file/json_output/main.out +++ b/tests/specs/info/json_file/json_output/main.out @@ -1,4 +1,5 @@ { + "version": 1, "roots": [ "file://[WILDCARD]/json_output/main.ts" ], @@ -87,6 +88,5 @@ } ], "redirects": {}, - "version": 1, "npmPackages": {} } diff --git a/tests/specs/info/multiple_redirects/main.out b/tests/specs/info/multiple_redirects/main.out index 9cc1066a93..0021047deb 100644 --- a/tests/specs/info/multiple_redirects/main.out +++ b/tests/specs/info/multiple_redirects/main.out @@ -2,6 +2,7 @@ Download http://localhost:4548/subdir/redirects/redirect1.js Download http://localhost:4546/subdir/redirects/redirect1.js Download http://localhost:4545/subdir/redirects/redirect1.js { + "version": 1, "roots": [ "file:///[WILDLINE]/multiple_redirects/main.ts" ], @@ -43,6 +44,5 @@ Download http://localhost:4545/subdir/redirects/redirect1.js "http://localhost:4546/subdir/redirects/redirect1.js": "http://localhost:4545/subdir/redirects/redirect1.js", "http://localhost:4548/subdir/redirects/redirect1.js": "http://localhost:4546/subdir/redirects/redirect1.js" }, - "version": 1, "npmPackages": {} } diff --git a/tests/specs/npm/cjs_with_deps/cjs_with_deps/main_info_json.out b/tests/specs/npm/cjs_with_deps/cjs_with_deps/main_info_json.out index af1ef13518..137b9f8ce5 100644 --- a/tests/specs/npm/cjs_with_deps/cjs_with_deps/main_info_json.out +++ b/tests/specs/npm/cjs_with_deps/cjs_with_deps/main_info_json.out @@ -1,4 +1,5 @@ { + "version": 1, "roots": [ "file://[WILDCARD]/main.js" ], @@ -51,7 +52,6 @@ "npm:chai@4.3": "npm:/chai@4.3.6", "npm:chalk@4": "npm:/chalk@4.1.2" }, - "version": 1, "npmPackages": { "ansi-styles@4.3.0": { "name": "ansi-styles", diff --git a/tests/specs/npm/info_chalk_display/cjs_with_deps/main_info_json.out b/tests/specs/npm/info_chalk_display/cjs_with_deps/main_info_json.out index af1ef13518..137b9f8ce5 100644 --- a/tests/specs/npm/info_chalk_display/cjs_with_deps/main_info_json.out +++ b/tests/specs/npm/info_chalk_display/cjs_with_deps/main_info_json.out @@ -1,4 +1,5 @@ { + "version": 1, "roots": [ "file://[WILDCARD]/main.js" ], @@ -51,7 +52,6 @@ "npm:chai@4.3": "npm:/chai@4.3.6", "npm:chalk@4": "npm:/chalk@4.1.2" }, - "version": 1, "npmPackages": { "ansi-styles@4.3.0": { "name": "ansi-styles", diff --git a/tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main_info_json.out b/tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main_info_json.out index af1ef13518..137b9f8ce5 100644 --- a/tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main_info_json.out +++ b/tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main_info_json.out @@ -1,4 +1,5 @@ { + "version": 1, "roots": [ "file://[WILDCARD]/main.js" ], @@ -51,7 +52,6 @@ "npm:chai@4.3": "npm:/chai@4.3.6", "npm:chalk@4": "npm:/chalk@4.1.2" }, - "version": 1, "npmPackages": { "ansi-styles@4.3.0": { "name": "ansi-styles", diff --git a/tests/specs/npm/info_chalk_json/cjs_with_deps/main_info_json.out b/tests/specs/npm/info_chalk_json/cjs_with_deps/main_info_json.out index af1ef13518..137b9f8ce5 100644 --- a/tests/specs/npm/info_chalk_json/cjs_with_deps/main_info_json.out +++ b/tests/specs/npm/info_chalk_json/cjs_with_deps/main_info_json.out @@ -1,4 +1,5 @@ { + "version": 1, "roots": [ "file://[WILDCARD]/main.js" ], @@ -51,7 +52,6 @@ "npm:chai@4.3": "npm:/chai@4.3.6", "npm:chalk@4": "npm:/chalk@4.1.2" }, - "version": 1, "npmPackages": { "ansi-styles@4.3.0": { "name": "ansi-styles", diff --git a/tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main_info_json.out b/tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main_info_json.out index af1ef13518..137b9f8ce5 100644 --- a/tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main_info_json.out +++ b/tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main_info_json.out @@ -1,4 +1,5 @@ { + "version": 1, "roots": [ "file://[WILDCARD]/main.js" ], @@ -51,7 +52,6 @@ "npm:chai@4.3": "npm:/chai@4.3.6", "npm:chalk@4": "npm:/chalk@4.1.2" }, - "version": 1, "npmPackages": { "ansi-styles@4.3.0": { "name": "ansi-styles", diff --git a/tests/specs/npm/info_cli_chalk_display/info/chalk_json.out b/tests/specs/npm/info_cli_chalk_display/info/chalk_json.out index d54155270b..21fc7edf1a 100644 --- a/tests/specs/npm/info_cli_chalk_display/info/chalk_json.out +++ b/tests/specs/npm/info_cli_chalk_display/info/chalk_json.out @@ -1,4 +1,5 @@ { + "version": 1, "roots": [ "npm:chalk@4" ], @@ -12,7 +13,6 @@ "redirects": { "npm:chalk@4": "npm:/chalk@4.1.2" }, - "version": 1, "npmPackages": { "ansi-styles@4.3.0": { "name": "ansi-styles", diff --git a/tests/specs/npm/info_cli_chalk_json/info/chalk_json.out b/tests/specs/npm/info_cli_chalk_json/info/chalk_json.out index d54155270b..21fc7edf1a 100644 --- a/tests/specs/npm/info_cli_chalk_json/info/chalk_json.out +++ b/tests/specs/npm/info_cli_chalk_json/info/chalk_json.out @@ -1,4 +1,5 @@ { + "version": 1, "roots": [ "npm:chalk@4" ], @@ -12,7 +13,6 @@ "redirects": { "npm:chalk@4": "npm:/chalk@4.1.2" }, - "version": 1, "npmPackages": { "ansi-styles@4.3.0": { "name": "ansi-styles", diff --git a/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_info_json.out b/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_info_json.out index 1a5f07c971..46cc35c650 100644 --- a/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_info_json.out +++ b/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_info_json.out @@ -1,4 +1,5 @@ { + "version": 1, "roots": [ "[WILDCARD]/peer_deps_with_copied_folders/main.ts" ], @@ -51,7 +52,6 @@ "npm:@denotest/peer-dep-test-child@1": "npm:/@denotest/peer-dep-test-child@1.0.0", "npm:@denotest/peer-dep-test-child@2": "npm:/@denotest/peer-dep-test-child@2.0.0" }, - "version": 1, "npmPackages": { "@denotest/peer-dep-test-child@1.0.0_@denotest+peer-dep-test-peer@1.0.0": { "name": "@denotest/peer-dep-test-child", diff --git a/tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main_info_json.out b/tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main_info_json.out index 1a5f07c971..46cc35c650 100644 --- a/tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main_info_json.out +++ b/tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main_info_json.out @@ -1,4 +1,5 @@ { + "version": 1, "roots": [ "[WILDCARD]/peer_deps_with_copied_folders/main.ts" ], @@ -51,7 +52,6 @@ "npm:@denotest/peer-dep-test-child@1": "npm:/@denotest/peer-dep-test-child@1.0.0", "npm:@denotest/peer-dep-test-child@2": "npm:/@denotest/peer-dep-test-child@2.0.0" }, - "version": 1, "npmPackages": { "@denotest/peer-dep-test-child@1.0.0_@denotest+peer-dep-test-peer@1.0.0": { "name": "@denotest/peer-dep-test-child", diff --git a/tests/specs/npm/node_modules_dir_with_deps/cjs_with_deps/main_info_json.out b/tests/specs/npm/node_modules_dir_with_deps/cjs_with_deps/main_info_json.out index af1ef13518..137b9f8ce5 100644 --- a/tests/specs/npm/node_modules_dir_with_deps/cjs_with_deps/main_info_json.out +++ b/tests/specs/npm/node_modules_dir_with_deps/cjs_with_deps/main_info_json.out @@ -1,4 +1,5 @@ { + "version": 1, "roots": [ "file://[WILDCARD]/main.js" ], @@ -51,7 +52,6 @@ "npm:chai@4.3": "npm:/chai@4.3.6", "npm:chalk@4": "npm:/chalk@4.1.2" }, - "version": 1, "npmPackages": { "ansi-styles@4.3.0": { "name": "ansi-styles", diff --git a/tests/testdata/npm/cjs_with_deps/main_info_json.out b/tests/testdata/npm/cjs_with_deps/main_info_json.out index af1ef13518..137b9f8ce5 100644 --- a/tests/testdata/npm/cjs_with_deps/main_info_json.out +++ b/tests/testdata/npm/cjs_with_deps/main_info_json.out @@ -1,4 +1,5 @@ { + "version": 1, "roots": [ "file://[WILDCARD]/main.js" ], @@ -51,7 +52,6 @@ "npm:chai@4.3": "npm:/chai@4.3.6", "npm:chalk@4": "npm:/chalk@4.1.2" }, - "version": 1, "npmPackages": { "ansi-styles@4.3.0": { "name": "ansi-styles", diff --git a/tests/testdata/npm/peer_deps_with_copied_folders/main_info_json.out b/tests/testdata/npm/peer_deps_with_copied_folders/main_info_json.out index df6541aa8e..d87496d6d5 100644 --- a/tests/testdata/npm/peer_deps_with_copied_folders/main_info_json.out +++ b/tests/testdata/npm/peer_deps_with_copied_folders/main_info_json.out @@ -1,4 +1,5 @@ { + "version": 1, "roots": [ "[WILDCARD]/npm/peer_deps_with_copied_folders/main.ts" ], @@ -51,7 +52,6 @@ "npm:@denotest/peer-dep-test-child@1": "npm:/@denotest/peer-dep-test-child@1.0.0", "npm:@denotest/peer-dep-test-child@2": "npm:/@denotest/peer-dep-test-child@2.0.0" }, - "version": 1, "npmPackages": { "@denotest/peer-dep-test-child@1.0.0_@denotest+peer-dep-test-peer@1.0.0": { "name": "@denotest/peer-dep-test-child",