Sort package keys before output

Package managers ususally sort package keys alphabetically. If you newly
inherit then you may get a bunch of additions which will then be
unalphabatized, leading to a messy diff if a new package is added with
the package manager.
This commit is contained in:
Nick Palmer 2021-02-11 13:52:25 -06:00
Родитель a174bc56b7
Коммит b3309c06d1
2 изменённых файлов: 5 добавлений и 3 удалений

Просмотреть файл

@ -70,7 +70,7 @@ function shouldUpdate(mine: any, theirs: any) {
let result = false;
for (const [key, value] of Object.entries(theirs)) {
if (mine[key] !== value) {
if (!mine || mine[key] !== value) {
result = true;
}
}

Просмотреть файл

@ -15,8 +15,10 @@ export function updateCommand(cwd: string) {
// Sort dependencies before outputing them like package managers do
['dependencies', 'devDependencies'].map(function(key){
if (output[key]) {
const keys = Object.keys(output[key]).sort();
output[key] = JSON.parse(JSON.stringify(output[key], keys));
output[key] = Object.keys(output[key]).sort().reduce(function(newObject, packageName) {
newObject[packageName] = output[key][packageName];
return newObject;
}, {});
}
});
fs.writeFileSync(