diff options
author | William Perron <hey@wperron.io> | 2020-11-27 16:51:47 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-27 16:51:47 -0500 |
commit | 57f163510aafd5c045dda0fa5e505d0cc7042a5a (patch) | |
tree | 7308fdb909fedb5e78bef83bb50d653333c76be6 | |
parent | b8d3caa5d586c6957866261bd5f51c85ad3a2c91 (diff) |
fix(cli): make output of deno info --json deterministic (#8483)
Fixes #8458
-rw-r--r-- | cli/module_graph.rs | 4 | ||||
-rw-r--r-- | cli/tests/076_info_json_deps_order.out | 38 | ||||
-rw-r--r-- | cli/tests/076_info_json_deps_order.ts | 1 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 5 | ||||
-rw-r--r-- | core/module_specifier.rs | 4 |
5 files changed, 49 insertions, 3 deletions
diff --git a/cli/module_graph.rs b/cli/module_graph.rs index b6759a9d2..8c6f69552 100644 --- a/cli/module_graph.rs +++ b/cli/module_graph.rs @@ -41,8 +41,8 @@ use regex::Regex; use serde::Deserialize; use serde::Deserializer; use std::cell::RefCell; -use std::collections::HashMap; use std::collections::HashSet; +use std::collections::{BTreeSet, HashMap}; use std::error::Error; use std::fmt; use std::path::PathBuf; @@ -1098,7 +1098,7 @@ impl Graph { .modules .iter() .map(|(specifier, module)| { - let mut deps = HashSet::new(); + let mut deps = BTreeSet::new(); for (_, dep) in module.dependencies.iter() { if let Some(code_dep) = &dep.maybe_code { deps.insert(code_dep.clone()); diff --git a/cli/tests/076_info_json_deps_order.out b/cli/tests/076_info_json_deps_order.out new file mode 100644 index 000000000..0c125122f --- /dev/null +++ b/cli/tests/076_info_json_deps_order.out @@ -0,0 +1,38 @@ +{ + "compiled": null, + "depCount": 4, + "fileType": "TypeScript", + "files": { + "[WILDCARD]cli/tests/076_info_json_deps_order.ts": { + "deps": [ + "[WILDCARD]cli/tests/recursive_imports/A.ts" + ], + "size": [WILDCARD] + }, + "[WILDCARD]cli/tests/recursive_imports/A.ts": { + "deps": [ + "[WILDCARD]cli/tests/recursive_imports/B.ts", + "[WILDCARD]cli/tests/recursive_imports/common.ts" + ], + "size": [WILDCARD] + }, + "[WILDCARD]cli/tests/recursive_imports/B.ts": { + "deps": [ + "[WILDCARD]cli/tests/recursive_imports/C.ts", + "[WILDCARD]cli/tests/recursive_imports/common.ts" + ], + "size": [WILDCARD] + }, + "[WILDCARD]cli/tests/recursive_imports/C.ts": { + "deps": [ + "[WILDCARD]cli/tests/recursive_imports/A.ts", + "[WILDCARD]cli/tests/recursive_imports/common.ts" + ], + "size": [WILDCARD] + }, + "[WILDCARD]cli/tests/recursive_imports/common.ts": { + "deps": [], + "size": [WILDCARD] + } + }, +[WILDCARD] diff --git a/cli/tests/076_info_json_deps_order.ts b/cli/tests/076_info_json_deps_order.ts new file mode 100644 index 000000000..f9d35fd5a --- /dev/null +++ b/cli/tests/076_info_json_deps_order.ts @@ -0,0 +1 @@ +import { A } from "./recursive_imports/A.ts"; diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index cd2252681..39147f038 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -2434,6 +2434,11 @@ itest!(_075_import_local_query_hash { output: "075_import_local_query_hash.ts.out", }); +itest!(_076_info_json_deps_order { + args: "info --unstable --json 076_info_json_deps_order.ts", + output: "076_info_json_deps_order.out", +}); + itest!(js_import_detect { args: "run --quiet --reload js_import_detect.ts", output: "js_import_detect.ts.out", diff --git a/core/module_specifier.rs b/core/module_specifier.rs index aec568d47..29edc8771 100644 --- a/core/module_specifier.rs +++ b/core/module_specifier.rs @@ -48,7 +48,9 @@ impl fmt::Display for ModuleResolutionError { } } -#[derive(Debug, Clone, Eq, Hash, PartialEq, serde::Serialize)] +#[derive( + Debug, Clone, Eq, Hash, PartialEq, serde::Serialize, Ord, PartialOrd, +)] /// Resolved module specifier pub struct ModuleSpecifier(Url); |