Skip to content

Commit 26f262e

Browse files
committed
use config param to autolink peer deps
1 parent 4a5b4b2 commit 26f262e

File tree

9 files changed

+30
-14
lines changed

9 files changed

+30
-14
lines changed

packages/cli-config/src/loadConfig.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
version,
1212
resolveNodeModuleDir,
1313
UnknownProjectError,
14+
resolveTransitiveDeps,
1415
} from '@react-native-community/cli-tools';
1516
import findDependencies from './findDependencies';
1617
import resolveReactNativePath from './resolveReactNativePath';
@@ -75,7 +76,9 @@ function getReactNativeVersion(reactNativePath: string) {
7576
/**
7677
* Loads CLI configuration
7778
*/
78-
function loadConfig(projectRoot: string = findProjectRoot()): Config {
79+
async function loadConfig(
80+
projectRoot: string = findProjectRoot(),
81+
): Promise<Config> {
7982
let lazyProject: ProjectConfig;
8083
const userConfig = readConfigFromDisk(projectRoot);
8184

@@ -113,11 +116,19 @@ function loadConfig(projectRoot: string = findProjectRoot()): Config {
113116
},
114117
};
115118

119+
const dependencyMap = findDependencies(projectRoot);
120+
let dependencies = Array.from(dependencyMap.keys());
121+
122+
if (userConfig.unstable_autolinkPeerDependencies) {
123+
const installedDependencies = await resolveTransitiveDeps(
124+
projectRoot,
125+
dependencyMap,
126+
);
127+
dependencies = [...dependencies, ...installedDependencies];
128+
}
129+
116130
const finalConfig = Array.from(
117-
new Set([
118-
...Object.keys(userConfig.dependencies),
119-
...findDependencies(projectRoot),
120-
]),
131+
new Set([...Object.keys(userConfig.dependencies), ...dependencies]),
121132
).reduce((acc: Config, dependencyName) => {
122133
const localDependencyRoot =
123134
userConfig.dependencies[dependencyName] &&

packages/cli-config/src/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ export const projectConfig = t
186186
linkConfig: t.func(),
187187
}),
188188
).default({}),
189+
unstable_autolinkPeerDependencies: t.bool(),
189190
})
190191
.unknown(true)
191192
.default();

packages/cli-doctor/src/commands/doctor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ const doctorCommand = (async (_, options, config) => {
175175
Promise.all(categories.map(iterateOverHealthChecks));
176176

177177
const healthchecksPerCategory = await iterateOverCategories(
178-
Object.values(getHealthchecks(options)).filter(
178+
Object.values(await getHealthchecks(options)).filter(
179179
(category) => category !== undefined,
180180
) as HealthCheckCategory[],
181181
);

packages/cli-doctor/src/tools/healthchecks/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import loadConfig from '@react-native-community/cli-config';
2+
import {logger} from '@react-native-community/cli-tools';
13
import nodeJS from './nodeJS';
24
import {yarn, npm} from './packageManagers';
35
import adb from './adb';
@@ -12,11 +14,9 @@ import xcode from './xcode';
1214
import cocoaPods from './cocoaPods';
1315
import iosDeploy from './iosDeploy';
1416
import {Healthchecks, HealthCheckCategory} from '../../types';
15-
import loadConfig from '@react-native-community/cli-config';
1617
import xcodeEnv from './xcodeEnv';
1718
import packager from './packager';
1819
import deepmerge from 'deepmerge';
19-
import {logger} from '@react-native-community/cli-tools';
2020

2121
export const HEALTHCHECK_TYPES = {
2222
ERROR: 'ERROR',
@@ -28,14 +28,16 @@ type Options = {
2828
contributor: boolean | void;
2929
};
3030

31-
export const getHealthchecks = ({contributor}: Options): Healthchecks => {
31+
export const getHealthchecks = async ({
32+
contributor,
33+
}: Options): Promise<Healthchecks> => {
3234
let additionalChecks: HealthCheckCategory[] = [];
3335
let projectSpecificHealthchecks = {};
3436
let config;
3537

3638
// Doctor can run in a detached mode, where there isn't a config so this can fail
3739
try {
38-
config = loadConfig();
40+
config = await loadConfig();
3941
additionalChecks = config.healthChecks;
4042

4143
if (config.reactNativePath) {

packages/cli-tools/src/bun.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {logger} from '@react-native-community/cli-tools';
21
import {execSync} from 'child_process';
32
import findUp from 'find-up';
43
import semver from 'semver';
4+
import logger from './logger';
55

66
export function getBunVersionIfAvailable() {
77
let bunVersion;

packages/cli-tools/src/resolveTransitiveDeps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import chalk from 'chalk';
55
import {prompt} from 'prompts';
66
import execa from 'execa';
77
import semver from 'semver';
8-
import {getLoader, logger} from '@react-native-community/cli-tools';
98
import {DependencyMap} from '@react-native-community/cli-types';
109
import {isProjectUsingYarn} from './yarn';
10+
import {getLoader} from './loader';
11+
import logger from './logger';
1112

1213
export async function fetchAvailableVersions(
1314
packageName: string,

packages/cli-tools/src/yarn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import {execSync} from 'child_process';
1010
import semver from 'semver';
11-
import {logger} from '@react-native-community/cli-tools';
1211
import findUp from 'find-up';
12+
import logger from './logger';
1313

1414
/**
1515
* Use Yarn if available, it's much faster than the npm client.

packages/cli-types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export type UserConfig = Omit<Config, 'root'> & {
135135
ios?: IOSProjectParams;
136136
[key: string]: any;
137137
};
138+
unstable_autolinkPeerDependencies?: boolean;
138139
};
139140

140141
export type UserDependencyConfig = {

packages/cli/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ async function setupAndRun() {
174174

175175
let config: Config | undefined;
176176
try {
177-
config = loadConfig();
177+
config = await loadConfig();
178178

179179
logger.enable();
180180

0 commit comments

Comments
 (0)