-
Notifications
You must be signed in to change notification settings - Fork 225
Expand file tree
/
Copy pathdependencies.ts
More file actions
46 lines (39 loc) · 1.07 KB
/
dependencies.ts
File metadata and controls
46 lines (39 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import path from 'path';
import fs from 'fs-extra';
import sortObjectKeys from '../utils/sortObjectKeys';
type PackageJson = {
devDependencies?: Record<string, string>;
};
export async function alignDependencyVersionsWithExampleApp(
pkg: PackageJson,
folder: string
) {
const examplePackageJson = await fs.readJSON(
path.join(folder, 'example', 'package.json')
);
const PACKAGES_TO_COPY = [
'react',
'react-native',
'@types/react',
'@react-native/babel-preset',
];
const devDependencies: Record<string, string> = {};
PACKAGES_TO_COPY.forEach((name) => {
if (name) {
const version =
examplePackageJson.dependencies?.[name] ??
examplePackageJson.devDependencies?.[name];
if (version != null) {
devDependencies[name] = version;
} else if (pkg.devDependencies?.[name] == null) {
throw new Error(
`Couldn't find the package "${name}" in the example app.`
);
}
}
});
pkg['devDependencies'] = sortObjectKeys({
...pkg['devDependencies'],
...devDependencies,
});
}