-
Notifications
You must be signed in to change notification settings - Fork 210
/
Copy pathdependencies.ts
58 lines (50 loc) · 1.53 KB
/
dependencies.ts
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
47
48
49
50
51
52
53
54
55
56
57
58
import path from 'path';
import fs from 'fs-extra';
import type { TemplateConfiguration } from '../template';
import sortObjectKeys from '../utils/sortObjectKeys';
type PackageJson = {
devDependencies?: Record<string, string>;
};
export async function alignDependencyVersionsWithExampleApp(
pkg: PackageJson,
folder: string,
config: TemplateConfiguration
) {
const examplePackageJson = await fs.readJSON(
path.join(folder, 'example', 'package.json')
);
const PACKAGES_TO_COPY = [
'react',
'react-native',
'@types/react',
'@react-native/babel-preset',
];
if (
config.example === 'vanilla' &&
(config.project.moduleConfig === 'turbo-modules' ||
config.project.viewConfig === 'fabric-view')
) {
// React Native doesn't provide the community CLI as a dependency.
// We have to read the version from the example app and put to the root package json
PACKAGES_TO_COPY.push('@react-native-community/cli');
}
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,
});
}