From edf1e86a5baa38be7b7fbe517c2fb7c34b491235 Mon Sep 17 00:00:00 2001 From: Adam Trzcinski Date: Thu, 4 Aug 2022 15:18:40 +0200 Subject: [PATCH 1/2] fix: pass projectRoot path to doctors fixers --- packages/cli-doctor/src/commands/doctor.ts | 12 ++++++++++-- .../cli-doctor/src/tools/healthchecks/xcodeEnv.ts | 8 +++----- packages/cli-doctor/src/tools/runAutomaticFix.ts | 3 +++ packages/cli-doctor/src/types.ts | 2 ++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/cli-doctor/src/commands/doctor.ts b/packages/cli-doctor/src/commands/doctor.ts index 5f19c1743..3ef1bec18 100644 --- a/packages/cli-doctor/src/commands/doctor.ts +++ b/packages/cli-doctor/src/commands/doctor.ts @@ -1,5 +1,9 @@ import chalk from 'chalk'; -import {logger, getLoader} from '@react-native-community/cli-tools'; +import { + logger, + getLoader, + findProjectRoot, +} from '@react-native-community/cli-tools'; import {getHealthchecks, HEALTHCHECK_TYPES} from '../tools/healthchecks'; import printFixOptions, {KEYS} from '../tools/printFixOptions'; import runAutomaticFix, {AUTOMATIC_FIX_LEVELS} from '../tools/runAutomaticFix'; @@ -116,6 +120,8 @@ const doctorCommand = (async (_, options) => { const environmentInfo = await getEnvironmentInfo(); + const projectRoot = findProjectRoot(); + const iterateOverHealthChecks = async ({ label, healthchecks, @@ -133,7 +139,7 @@ const doctorCommand = (async (_, options) => { version, versions, versionRange, - } = await healthcheck.getDiagnostics(environmentInfo); + } = await healthcheck.getDiagnostics(environmentInfo, projectRoot); // Assume that it's required unless specified otherwise const isRequired = healthcheck.isRequired !== false; @@ -213,6 +219,7 @@ const doctorCommand = (async (_, options) => { stats, loader, environmentInfo, + projectRoot, }); } @@ -248,6 +255,7 @@ const doctorCommand = (async (_, options) => { stats, loader, environmentInfo, + projectRoot, }); process.exit(0); diff --git a/packages/cli-doctor/src/tools/healthchecks/xcodeEnv.ts b/packages/cli-doctor/src/tools/healthchecks/xcodeEnv.ts index aab5e68ed..6f840e135 100644 --- a/packages/cli-doctor/src/tools/healthchecks/xcodeEnv.ts +++ b/packages/cli-doctor/src/tools/healthchecks/xcodeEnv.ts @@ -2,7 +2,6 @@ import {HealthCheckInterface} from '../../types'; import fs from 'fs'; import path from 'path'; import {promisify} from 'util'; -import {findProjectRoot} from '@react-native-community/cli-tools'; import {findPodfilePaths} from '@react-native-community/cli-platform-ios'; const xcodeEnvFile = '.xcode.env'; @@ -26,8 +25,8 @@ function pathDoesNotHaveXcodeEnvFile(pathString: string): boolean { export default { label: '.xcode.env', description: 'File to customize Xcode environment', - getDiagnostics: async () => { - const projectRoot = findProjectRoot(); + getDiagnostics: async (_, projectRoot) => { + console.log('projectRoot @ getDiagnostics', projectRoot); const allPathsHasXcodeEnvFile = findPodfilePaths(projectRoot) .map((pathString) => { const basePath = removeLastPathComponent(pathString); @@ -38,9 +37,8 @@ export default { needsToBeFixed: !allPathsHasXcodeEnvFile, }; }, - runAutomaticFix: async () => { + runAutomaticFix: async ({projectRoot}) => { const templateXcodeEnv = '_xcode.env'; - const projectRoot = findProjectRoot(); const templateIosPath = path.dirname( require.resolve('react-native/template/ios'), diff --git a/packages/cli-doctor/src/tools/runAutomaticFix.ts b/packages/cli-doctor/src/tools/runAutomaticFix.ts index 2bc109efd..8dee1e385 100644 --- a/packages/cli-doctor/src/tools/runAutomaticFix.ts +++ b/packages/cli-doctor/src/tools/runAutomaticFix.ts @@ -20,6 +20,7 @@ interface RunAutomaticFixArgs { }; loader: Loader; environmentInfo: EnvironmentInfo; + projectRoot: string; } export default async function ({ @@ -27,6 +28,7 @@ export default async function ({ automaticFixLevel, stats, environmentInfo, + projectRoot, }: RunAutomaticFixArgs) { // Remove the fix options from screen if (process.stdout.isTTY) { @@ -90,6 +92,7 @@ export default async function ({ loader: spinner, logManualInstallation, environmentInfo, + projectRoot, }); } catch (error) { // TODO: log the error in a meaningful way diff --git a/packages/cli-doctor/src/types.ts b/packages/cli-doctor/src/types.ts index bf1d14893..c08f572fa 100644 --- a/packages/cli-doctor/src/types.ts +++ b/packages/cli-doctor/src/types.ts @@ -75,6 +75,7 @@ export type RunAutomaticFix = (args: { message?: string; }) => void; environmentInfo: EnvironmentInfo; + projectRoot: string; }) => Promise | void; export type HealthCheckInterface = { @@ -84,6 +85,7 @@ export type HealthCheckInterface = { description?: string; getDiagnostics: ( environmentInfo: EnvironmentInfo, + projectRoot: string, ) => Promise<{ version?: string; versions?: [string]; From 64a7d07ec21b28341d131ad2d60a33cfd1412d29 Mon Sep 17 00:00:00 2001 From: Adam Trzcinski Date: Thu, 4 Aug 2022 15:19:38 +0200 Subject: [PATCH 2/2] fix: remove console.log call --- packages/cli-doctor/src/tools/healthchecks/xcodeEnv.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/cli-doctor/src/tools/healthchecks/xcodeEnv.ts b/packages/cli-doctor/src/tools/healthchecks/xcodeEnv.ts index 6f840e135..83daac313 100644 --- a/packages/cli-doctor/src/tools/healthchecks/xcodeEnv.ts +++ b/packages/cli-doctor/src/tools/healthchecks/xcodeEnv.ts @@ -26,7 +26,6 @@ export default { label: '.xcode.env', description: 'File to customize Xcode environment', getDiagnostics: async (_, projectRoot) => { - console.log('projectRoot @ getDiagnostics', projectRoot); const allPathsHasXcodeEnvFile = findPodfilePaths(projectRoot) .map((pathString) => { const basePath = removeLastPathComponent(pathString);