Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): invalidate state if pod install was not run #3330

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/ninety-islands-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rnx-kit/tools-react-native": patch
"@rnx-kit/cli": patch
---

Fix context cache not taking `pod install` state into account
4 changes: 3 additions & 1 deletion packages/cli/src/build/android.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -12,8 +13,9 @@ export function buildAndroid(
): Promise<BuildResult> {
const { sourceDir } = config.project.android ?? {};
if (!sourceDir) {
logger.fail("No Android project was found");
invalidateState();
process.exitCode = 1;
logger.fail("No Android project was found");
return Promise.resolve(null);
}

Expand Down
7 changes: 5 additions & 2 deletions packages/cli/src/build/ios.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -13,20 +14,22 @@ export function buildIOS(
const { platform } = buildParams;
const { sourceDir, xcodeProject } = config.project[platform] ?? {};
if (!sourceDir || !xcodeProject) {
invalidateState();
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.exitCode = 1;
logger.fail(
"No Xcode workspaces were found; did you forget to run `pod install`?"
);
process.exitCode = 1;
return Promise.resolve(1);
}

Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/build/macos.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -24,10 +25,11 @@ export function buildMacOS(
const sourceDir = "macos";
const workspaces = findXcodeWorkspaces(sourceDir);
if (workspaces.length === 0) {
invalidateState();
process.exitCode = 1;
logger.fail(
"No Xcode workspaces were found; specify an Xcode workspace with `--workspace`"
);
process.exitCode = 1;
return Promise.resolve(1);
}

Expand Down
8 changes: 8 additions & 0 deletions packages/tools-react-native/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ export function getSavedState(
return fs.existsSync(stateFile) && fs.readFileSync(stateFile, UTF8);
}

export function invalidateState(
projectRoot = process.cwd(),
/** @internal */ fs = nodefs
) {
fs.rmSync(configCachePath(projectRoot));
fs.rmSync(cacheStatePath(projectRoot));
}

export function loadConfigFromCache(
projectRoot: string,
/** @internal */ fs = nodefs
Expand Down