Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/generateInheritedPackageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/updateCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ export function updateCommand(cwd: string) {
const { packageJsonPath, ...output } = info;

const newLine = detectNewline(fs.readFileSync(info.packageJsonPath, 'utf-8')) || os.EOL;

// Sort dependencies before outputing them like package managers do
['dependencies', 'devDependencies'].map(function(key){
if (output[key]) {
output[key] = Object.keys(output[key]).sort().reduce(function(newObject, packageName) {
newObject[packageName] = output[key][packageName];
return newObject;
}, {});
}
});
fs.writeFileSync(
info.packageJsonPath,
JSON.stringify(output, null, 2).replace(/\n/g, newLine) + newLine
Expand Down