feat: sort dependencies alphabetically

... when merging from install/package.json

/cc @pitaj
v1.18.x
Julian Lam 4 years ago
parent 6c4aed8cf4
commit a4dbbc3749

@ -23,14 +23,20 @@ function updatePackageFile() {
const defaultPackageContents = JSON.parse(fs.readFileSync(packageDefaultFilePath, 'utf8'));
const dependencies = {};
let dependencies = {};
Object.entries(oldPackageContents.dependencies || {}).forEach(([dep, version]) => {
if (isPackage.test(dep)) {
dependencies[dep] = version;
}
});
const packageContents = { ...oldPackageContents, ...defaultPackageContents, dependencies: { ...dependencies, ...defaultPackageContents.dependencies } };
// Sort dependencies alphabetically
dependencies = Object.entries({ ...dependencies, ...defaultPackageContents.dependencies }).sort((a, b) => (a < b ? -1 : 1)).reduce((memo, pkg) => {
memo[pkg[0]] = pkg[1];
return memo;
}, {});
const packageContents = { ...oldPackageContents, ...defaultPackageContents, dependencies: dependencies };
fs.writeFileSync(packageFilePath, JSON.stringify(packageContents, null, 2));
}

Loading…
Cancel
Save