Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
Sort keys in all JSON dumps
Browse files Browse the repository at this point in the history
  • Loading branch information
davegaeddert committed Jan 14, 2022
1 parent 455f9a6 commit 453f5f2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions importmap/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions importmap/templatetags/importmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
12 changes: 6 additions & 6 deletions test_project/importmap.lock
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"config_hash": "09d6237cdd891aad07de60f54689d130",
"importmap": {
"importmap_dev": {
"imports": {
"react": "https://ga.jspm.io/npm:[email protected]/index.js"
"react": "https://ga.jspm.io/npm:[email protected]/dev.index.js"
},
"scopes": {
"https://ga.jspm.io/": {
"object-assign": "https://ga.jspm.io/npm:[email protected]/index.js"
}
}
},
"importmap_dev": {
"importmap": {
"imports": {
"react": "https://ga.jspm.io/npm:[email protected]/dev.index.js"
"react": "https://ga.jspm.io/npm:[email protected]/index.js"
},
"scopes": {
"https://ga.jspm.io/": {
"object-assign": "https://ga.jspm.io/npm:[email protected]/index.js"
}
}
}
},
"config_hash": "09d6237cdd891aad07de60f54689d130"
}

0 comments on commit 453f5f2

Please sign in to comment.