Skip to content

Commit 6bcb6c8

Browse files
committed
fix: sort dependencies in example package.json
1 parent 8553b18 commit 6bcb6c8

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/create-react-native-library/src/utils/generateExampleApp.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from 'fs-extra';
22
import path from 'path';
33
import https from 'https';
44
import { spawn } from './spawn';
5+
import sortObjectKeys from './sortObjectKeys';
56

67
export type ExampleType = 'vanilla' | 'test-app' | 'expo' | 'none';
78

@@ -239,6 +240,12 @@ export default async function generateExampleApp({
239240
});
240241
}
241242

243+
for (const field of ['dependencies', 'devDependencies']) {
244+
if (pkg[field]) {
245+
pkg[field] = sortObjectKeys(pkg[field]);
246+
}
247+
}
248+
242249
await fs.writeJSON(path.join(directory, 'package.json'), pkg, {
243250
spaces: 2,
244251
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function sortObjectKeys<T extends Record<string, unknown>>(
2+
obj: T
3+
): T {
4+
return (Object.keys(obj) as (keyof T)[]).sort().reduce((acc, key) => {
5+
acc[key] = obj[key];
6+
return acc;
7+
}, {} as T);
8+
}

0 commit comments

Comments
 (0)