From ecf5903676deb120dfac5a762b627091b1a90ddd Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Wed, 4 Sep 2024 12:29:45 +0200 Subject: [PATCH 1/2] fix(cli): invalidate state if `pod install` was not run --- .changeset/ninety-islands-shop.md | 6 ++++++ packages/cli/src/build/android.ts | 4 +++- packages/cli/src/build/ios.ts | 7 +++++-- packages/cli/src/build/macos.ts | 4 +++- packages/tools-react-native/src/cache.ts | 8 ++++++++ 5 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 .changeset/ninety-islands-shop.md diff --git a/.changeset/ninety-islands-shop.md b/.changeset/ninety-islands-shop.md new file mode 100644 index 000000000..78e38f1bc --- /dev/null +++ b/.changeset/ninety-islands-shop.md @@ -0,0 +1,6 @@ +--- +"@rnx-kit/tools-react-native": patch +"@rnx-kit/cli": patch +--- + +Fix context cache not taking `pod install` state into account diff --git a/packages/cli/src/build/android.ts b/packages/cli/src/build/android.ts index 57460de22..89a845273 100644 --- a/packages/cli/src/build/android.ts +++ b/packages/cli/src/build/android.ts @@ -1,4 +1,5 @@ import type { Config } from "@react-native-community/cli-types"; +import { invalidateState } from "@rnx-kit/tools-react-native/cache"; import ora from "ora"; import type { AndroidBuildParams } from "./types"; import { watch } from "./watcher"; @@ -12,8 +13,9 @@ export function buildAndroid( ): Promise { const { sourceDir } = config.project.android ?? {}; if (!sourceDir) { - logger.fail("No Android project was found"); + invalidateState(process.cwd()); process.exitCode = 1; + logger.fail("No Android project was found"); return Promise.resolve(null); } diff --git a/packages/cli/src/build/ios.ts b/packages/cli/src/build/ios.ts index 983dd22e0..b4e245cd7 100644 --- a/packages/cli/src/build/ios.ts +++ b/packages/cli/src/build/ios.ts @@ -1,4 +1,5 @@ import type { Config } from "@react-native-community/cli-types"; +import { invalidateState } from "@rnx-kit/tools-react-native/cache"; import * as path from "node:path"; import ora from "ora"; import type { BuildResult } from "./apple"; @@ -13,20 +14,22 @@ export function buildIOS( const { platform } = buildParams; const { sourceDir, xcodeProject } = config.project[platform] ?? {}; if (!sourceDir || !xcodeProject) { + invalidateState(process.cwd()); + process.exitCode = 1; const root = platform.substring(0, platform.length - 2); logger.fail( `No ${root}OS project was found; did you forget to run 'pod install'?` ); - process.exitCode = 1; return Promise.resolve(1); } const { name, path: projectDir } = xcodeProject; if (!name?.endsWith(".xcworkspace")) { + invalidateState(process.cwd()); + process.exitCode = 1; logger.fail( "No Xcode workspaces were found; did you forget to run `pod install`?" ); - process.exitCode = 1; return Promise.resolve(1); } diff --git a/packages/cli/src/build/macos.ts b/packages/cli/src/build/macos.ts index 7b10bf61b..aede60957 100644 --- a/packages/cli/src/build/macos.ts +++ b/packages/cli/src/build/macos.ts @@ -1,4 +1,5 @@ import type { Config } from "@react-native-community/cli-types"; +import { invalidateState } from "@rnx-kit/tools-react-native/cache"; import * as fs from "node:fs"; import * as path from "node:path"; import ora from "ora"; @@ -24,10 +25,11 @@ export function buildMacOS( const sourceDir = "macos"; const workspaces = findXcodeWorkspaces(sourceDir); if (workspaces.length === 0) { + invalidateState(process.cwd()); + process.exitCode = 1; logger.fail( "No Xcode workspaces were found; specify an Xcode workspace with `--workspace`" ); - process.exitCode = 1; return Promise.resolve(1); } diff --git a/packages/tools-react-native/src/cache.ts b/packages/tools-react-native/src/cache.ts index 373cc794b..98ab6a3b6 100644 --- a/packages/tools-react-native/src/cache.ts +++ b/packages/tools-react-native/src/cache.ts @@ -67,6 +67,14 @@ export function getSavedState( return fs.existsSync(stateFile) && fs.readFileSync(stateFile, UTF8); } +export function invalidateState( + projectRoot: string, + /** @internal */ fs = nodefs +) { + fs.rmSync(configCachePath(projectRoot)); + fs.rmSync(cacheStatePath(projectRoot)); +} + export function loadConfigFromCache( projectRoot: string, /** @internal */ fs = nodefs From 3fc1954f09d551663f3dcd68d1ad1a302ac49452 Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Wed, 4 Sep 2024 16:12:09 +0200 Subject: [PATCH 2/2] fixup! fix(cli): invalidate state if `pod install` was not run --- packages/cli/src/build/android.ts | 2 +- packages/cli/src/build/ios.ts | 4 ++-- packages/cli/src/build/macos.ts | 2 +- packages/tools-react-native/src/cache.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/build/android.ts b/packages/cli/src/build/android.ts index 89a845273..ca76fb2f9 100644 --- a/packages/cli/src/build/android.ts +++ b/packages/cli/src/build/android.ts @@ -13,7 +13,7 @@ export function buildAndroid( ): Promise { const { sourceDir } = config.project.android ?? {}; if (!sourceDir) { - invalidateState(process.cwd()); + invalidateState(); process.exitCode = 1; logger.fail("No Android project was found"); return Promise.resolve(null); diff --git a/packages/cli/src/build/ios.ts b/packages/cli/src/build/ios.ts index b4e245cd7..a3229b3c0 100644 --- a/packages/cli/src/build/ios.ts +++ b/packages/cli/src/build/ios.ts @@ -14,7 +14,7 @@ export function buildIOS( const { platform } = buildParams; const { sourceDir, xcodeProject } = config.project[platform] ?? {}; if (!sourceDir || !xcodeProject) { - invalidateState(process.cwd()); + invalidateState(); process.exitCode = 1; const root = platform.substring(0, platform.length - 2); logger.fail( @@ -25,7 +25,7 @@ export function buildIOS( const { name, path: projectDir } = xcodeProject; if (!name?.endsWith(".xcworkspace")) { - invalidateState(process.cwd()); + invalidateState(); process.exitCode = 1; logger.fail( "No Xcode workspaces were found; did you forget to run `pod install`?" diff --git a/packages/cli/src/build/macos.ts b/packages/cli/src/build/macos.ts index aede60957..1c68e9bb0 100644 --- a/packages/cli/src/build/macos.ts +++ b/packages/cli/src/build/macos.ts @@ -25,7 +25,7 @@ export function buildMacOS( const sourceDir = "macos"; const workspaces = findXcodeWorkspaces(sourceDir); if (workspaces.length === 0) { - invalidateState(process.cwd()); + invalidateState(); process.exitCode = 1; logger.fail( "No Xcode workspaces were found; specify an Xcode workspace with `--workspace`" diff --git a/packages/tools-react-native/src/cache.ts b/packages/tools-react-native/src/cache.ts index 98ab6a3b6..a5c074186 100644 --- a/packages/tools-react-native/src/cache.ts +++ b/packages/tools-react-native/src/cache.ts @@ -68,7 +68,7 @@ export function getSavedState( } export function invalidateState( - projectRoot: string, + projectRoot = process.cwd(), /** @internal */ fs = nodefs ) { fs.rmSync(configCachePath(projectRoot));