Skip to content

Commit 708dde9

Browse files
committed
add --dependency-check flag
1 parent 8df7cca commit 708dde9

File tree

9 files changed

+40
-16
lines changed

9 files changed

+40
-16
lines changed

packages/cli-config/src/loadConfig.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import {
1212
resolveNodeModuleDir,
1313
UnknownProjectError,
1414
} from '@react-native-community/cli-tools';
15+
import findDependencies from './findDependencies';
1516
import resolveReactNativePath from './resolveReactNativePath';
1617
import {
1718
readConfigFromDisk,
1819
readDependencyConfigFromDisk,
1920
} from './readConfigFromDisk';
2021
import assign from './assign';
2122
import merge from './merge';
22-
import findDependencies from './findDependencies';
2323

2424
function getDependencyConfig(
2525
root: string,

packages/cli-platform-android/src/commands/buildAndroid/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface BuildFlags {
1717
tasks?: Array<string>;
1818
extraParams?: Array<string>;
1919
interactive?: boolean;
20+
dependencyCheck?: boolean;
2021
}
2122

2223
async function buildAndroid(
@@ -123,6 +124,11 @@ export const options = [
123124
description:
124125
'Explicitly select build type and flavour to use before running a build',
125126
},
127+
{
128+
name: '--dependency-check',
129+
description:
130+
'Check if there are any transitive dependencies containing native code that are not declared as a direct dependency in your package.json.',
131+
},
126132
];
127133

128134
export default {

packages/cli-platform-android/src/commands/runAndroid/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
logAlreadyRunningBundler,
2323
startServerInNewWindow,
2424
handlePortUnavailable,
25+
checkTransitiveDependencies,
2526
} from '@react-native-community/cli-tools';
2627
import {getAndroidProject} from '../../config/getAndroidProject';
2728
import listAndroidDevices from './listAndroidDevices';
@@ -56,6 +57,10 @@ async function runAndroid(_argv: Array<string>, config: Config, args: Flags) {
5657

5758
let {packager, port} = args;
5859

60+
if (args.dependencyCheck) {
61+
await checkTransitiveDependencies();
62+
}
63+
5964
const packagerStatus = await isPackagerRunning(port);
6065

6166
if (

packages/cli-platform-ios/src/commands/buildIOS/buildProject.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type BuildFlags = {
2020
interactive?: boolean;
2121
destination?: string;
2222
extraParams?: string[];
23+
dependencyCheck?: boolean;
2324
};
2425

2526
export function buildProject(

packages/cli-platform-ios/src/commands/buildIOS/index.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
import path from 'path';
1010
import chalk from 'chalk';
1111
import {Config} from '@react-native-community/cli-types';
12-
import {logger, CLIError} from '@react-native-community/cli-tools';
12+
import {
13+
logger,
14+
CLIError,
15+
checkTransitiveDependencies,
16+
} from '@react-native-community/cli-tools';
1317
import {Device} from '../../types';
1418
import {BuildFlags, buildProject} from './buildProject';
1519
import {getDestinationSimulator} from '../../tools/getDestinationSimulator';
@@ -41,6 +45,10 @@ async function buildIOS(_: Array<string>, ctx: Config, args: FlagsT) {
4145
);
4246
}
4347

48+
if (args.dependencyCheck) {
49+
await checkTransitiveDependencies();
50+
}
51+
4452
process.chdir(sourceDir);
4553

4654
const projectInfo = getProjectInfo();
@@ -236,6 +244,11 @@ export const iosBuildOptions = [
236244
name: '--target <string>',
237245
description: 'Explicitly set Xcode target to use.',
238246
},
247+
{
248+
name: '--dependency-check',
249+
description:
250+
'Check if there are any transitive dependencies containing native code that are not declared as a direct dependency in your package.json.',
251+
},
239252
];
240253

241254
export default {

packages/cli-platform-ios/src/commands/runIOS/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
isPackagerRunning,
2222
logAlreadyRunningBundler,
2323
handlePortUnavailable,
24+
checkTransitiveDependencies,
2425
} from '@react-native-community/cli-tools';
2526
import {BuildFlags, buildProject} from '../buildIOS/buildProject';
2627
import {iosBuildOptions} from '../buildIOS';
@@ -88,6 +89,10 @@ async function runIOS(_: Array<string>, ctx: Config, args: FlagsT) {
8889
);
8990
}
9091

92+
if (args.dependencyCheck) {
93+
await checkTransitiveDependencies();
94+
}
95+
9196
const {xcodeProject, sourceDir} = ctx.project.ios;
9297

9398
if (!xcodeProject) {

packages/cli-tools/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ export * as link from './doclink';
1717
export {default as startServerInNewWindow} from './startServerInNewWindow';
1818
export {default as handlePortUnavailable} from './handlePortUnavailable';
1919
export * from './port';
20-
export * as transitiveDeps from './resolveTransitiveDeps';
20+
export {default as checkTransitiveDependencies} from './resolveTransitiveDeps';
2121

2222
export * from './errors';

packages/cli-tools/src/resolveTransitiveDeps.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface DependencyData {
1717
duplicates?: DependencyData[];
1818
}
1919

20-
export function isUsingYarn(root: string) {
20+
function isUsingYarn(root: string) {
2121
return fs.existsSync(path.join(root, 'yarn.lock'));
2222
}
2323

@@ -62,7 +62,7 @@ function findDependencyPath(
6262
return dependencyPath;
6363
}
6464

65-
export function collectDependencies(root: string): Map<string, DependencyData> {
65+
function collectDependencies(root: string): Map<string, DependencyData> {
6666
const dependencies = new Map<string, DependencyData>();
6767

6868
const checkDependency = (dependencyPath: string) => {
@@ -242,7 +242,7 @@ async function yarnSilentInstallPeerDeps(root: string) {
242242
}
243243
}
244244

245-
export default async function findPeerDepsForAutolinking(root: string) {
245+
async function findPeerDepsForAutolinking(root: string) {
246246
const deps = collectDependencies(root);
247247
const nonEmptyPeers = filterNativeDependencies(root, deps);
248248
const nonInstalledPeers = filterInstalledPeers(root, nonEmptyPeers);
@@ -340,7 +340,7 @@ function installMissingPackages(
340340
}
341341
}
342342

343-
export async function resolveTransitiveDeps() {
343+
async function resolveTransitiveDeps() {
344344
const root = process.cwd();
345345
const isYarn = isUsingYarn(root);
346346

@@ -367,7 +367,7 @@ export async function resolveTransitiveDeps() {
367367
return false;
368368
}
369369

370-
export async function resolvePodsInstallation() {
370+
async function resolvePodsInstallation() {
371371
const {install} = await prompt({
372372
type: 'confirm',
373373
name: 'install',
@@ -383,7 +383,7 @@ export async function resolvePodsInstallation() {
383383
}
384384
}
385385

386-
export async function checkTransitiveDeps() {
386+
export default async function checkTransitiveDependencies() {
387387
const packageJsonPath = path.join(process.cwd(), 'package.json');
388388
const preInstallHash = generateFileHash(packageJsonPath);
389389
const areTransitiveDepsInstalled = await resolveTransitiveDeps();

packages/cli/src/index.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import loadConfig from '@react-native-community/cli-config';
2-
import {
3-
CLIError,
4-
logger,
5-
transitiveDeps,
6-
} from '@react-native-community/cli-tools';
2+
import {CLIError, logger} from '@react-native-community/cli-tools';
73
import type {
84
Command,
95
Config,
@@ -175,8 +171,6 @@ async function setupAndRun() {
175171
}
176172
}
177173

178-
await transitiveDeps.checkTransitiveDeps();
179-
180174
let config: Config | undefined;
181175

182176
try {

0 commit comments

Comments
 (0)