From 453f5f2e92810a72b86ec6d2c589cdb51e8c98c9 Mon Sep 17 00:00:00 2001 From: Dave Gaeddert Date: Fri, 14 Jan 2022 14:13:24 -0600 Subject: [PATCH] Sort keys in all JSON dumps --- importmap/core.py | 4 ++-- importmap/templatetags/importmap.py | 4 ++-- test_project/importmap.lock | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/importmap/core.py b/importmap/core.py index 5f5e919..c9b04ba 100644 --- a/importmap/core.py +++ b/importmap/core.py @@ -33,7 +33,7 @@ class LockfileSchema(Schema): def hash_for_data(data): - return hashlib.md5(json.dumps(data).encode("utf-8")).hexdigest() + return hashlib.md5(json.dumps(data, sort_keys=True).encode("utf-8")).hexdigest() class Importmap: @@ -102,7 +102,7 @@ def load_lockfile(self): def save_lockfile(self, lockfile): with open(self.lock_filename, "w+") as f: - json.dump(lockfile, f, indent=2) + json.dump(lockfile, f, indent=2, sort_keys=True) def delete_lockfile(self): if os.path.exists(self.lock_filename): diff --git a/importmap/templatetags/importmap.py b/importmap/templatetags/importmap.py index 969359b..d2e532c 100644 --- a/importmap/templatetags/importmap.py +++ b/importmap/templatetags/importmap.py @@ -14,6 +14,6 @@ def importmap_scripts(): importmap.load() if settings.DEBUG: - return {"importmap": json.dumps(importmap.map_dev, indent=2)} + return {"importmap": json.dumps(importmap.map_dev, indent=2, sort_keys=True)} else: - return {"importmap": json.dumps(importmap.map)} + return {"importmap": json.dumps(importmap.map, sort_keys=True)} diff --git a/test_project/importmap.lock b/test_project/importmap.lock index b8e17d5..9aa86d5 100644 --- a/test_project/importmap.lock +++ b/test_project/importmap.lock @@ -1,8 +1,7 @@ { - "config_hash": "09d6237cdd891aad07de60f54689d130", - "importmap": { + "importmap_dev": { "imports": { - "react": "https://ga.jspm.io/npm:react@17.0.2/index.js" + "react": "https://ga.jspm.io/npm:react@17.0.2/dev.index.js" }, "scopes": { "https://ga.jspm.io/": { @@ -10,14 +9,15 @@ } } }, - "importmap_dev": { + "importmap": { "imports": { - "react": "https://ga.jspm.io/npm:react@17.0.2/dev.index.js" + "react": "https://ga.jspm.io/npm:react@17.0.2/index.js" }, "scopes": { "https://ga.jspm.io/": { "object-assign": "https://ga.jspm.io/npm:object-assign@4.1.1/index.js" } } - } + }, + "config_hash": "09d6237cdd891aad07de60f54689d130" } \ No newline at end of file