Skip to content

Commit

Permalink
fix src/config.ts: Remove sort_object (#152)
Browse files Browse the repository at this point in the history
Fixed #151

I've tried running manually load and parse `Cargo.lock` and it runs fine
until `sort_object` is called.

Since `Cargo.lock` is auto-generated and usually sorted, I think there
is no need for sorting.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
  • Loading branch information
NobodyXu committed Jun 27, 2023
1 parent 2656b87 commit be7377e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 57 deletions.
21 changes: 2 additions & 19 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64224,7 +64224,7 @@ class CacheConfig {
}
}
}
hasher.update(JSON.stringify(sort_object(parsed)));
hasher.update(JSON.stringify(parsed));
parsedKeyFiles.push(cargo_manifest);
}
catch (_e) { // Fallback to caching them as regular file
Expand All @@ -64247,7 +64247,7 @@ class CacheConfig {
const packages = parsed.package.filter((p) => {
"source" in p || "checksum" in p;
});
hasher.update(JSON.stringify(sort_object(packages)));
hasher.update(JSON.stringify(packages));
parsedKeyFiles.push(cargo_lock);
}
catch (_e) { // Fallback to caching them as regular file
Expand Down Expand Up @@ -64387,23 +64387,6 @@ function sort_and_uniq(a) {
return accumulator;
}, []);
}
function sort_object(o) {
if (Array.isArray(o)) {
return o.sort().map(sort_object);
}
else if (typeof o === 'object' && o != null) {
return Object
.keys(o)
.sort()
.reduce(function (a, k) {
a[k] = sort_object(o[k]);
return a;
}, {});
}
else {
return o;
}
}

;// CONCATENATED MODULE: ./src/cleanup.ts

Expand Down
21 changes: 2 additions & 19 deletions dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64224,7 +64224,7 @@ class CacheConfig {
}
}
}
hasher.update(JSON.stringify(sort_object(parsed)));
hasher.update(JSON.stringify(parsed));
parsedKeyFiles.push(cargo_manifest);
}
catch (_e) { // Fallback to caching them as regular file
Expand All @@ -64247,7 +64247,7 @@ class CacheConfig {
const packages = parsed.package.filter((p) => {
"source" in p || "checksum" in p;
});
hasher.update(JSON.stringify(sort_object(packages)));
hasher.update(JSON.stringify(packages));
parsedKeyFiles.push(cargo_lock);
}
catch (_e) { // Fallback to caching them as regular file
Expand Down Expand Up @@ -64387,23 +64387,6 @@ function sort_and_uniq(a) {
return accumulator;
}, []);
}
function sort_object(o) {
if (Array.isArray(o)) {
return o.sort().map(sort_object);
}
else if (typeof o === 'object' && o != null) {
return Object
.keys(o)
.sort()
.reduce(function (a, k) {
a[k] = sort_object(o[k]);
return a;
}, {});
}
else {
return o;
}
}

;// CONCATENATED MODULE: ./src/cleanup.ts

Expand Down
21 changes: 2 additions & 19 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class CacheConfig {
}
}

hasher.update(JSON.stringify(sort_object(parsed)));
hasher.update(JSON.stringify(parsed));

parsedKeyFiles.push(cargo_manifest);
} catch (_e) { // Fallback to caching them as regular file
Expand Down Expand Up @@ -200,7 +200,7 @@ export class CacheConfig {
"source" in p || "checksum" in p
});

hasher.update(JSON.stringify(sort_object(packages)));
hasher.update(JSON.stringify(packages));

parsedKeyFiles.push(cargo_lock);
} catch (_e) { // Fallback to caching them as regular file
Expand Down Expand Up @@ -367,20 +367,3 @@ function sort_and_uniq(a: string[]) {
[]
);
}

function sort_object(o: any): any {
if (Array.isArray(o)) {
return o.sort().map(sort_object);
} else if (typeof o === 'object' && o != null) {
return Object
.keys(o)
.sort()
.reduce(function(a: any, k) {
a[k] = sort_object(o[k]);

return a;
}, {});
} else {
return o;
}
}

0 comments on commit be7377e

Please sign in to comment.