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

This commit is contained in:
Tommy Nguyen 2024-09-04 21:07:12 +02:00 коммит произвёл GitHub
Родитель 4ec3a23a28
Коммит 29859abdef
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
5 изменённых файлов: 25 добавлений и 4 удалений

Просмотреть файл

@ -0,0 +1,6 @@
---
"@rnx-kit/tools-react-native": patch
"@rnx-kit/cli": patch
---
Fix context cache not taking `pod install` state into account

Просмотреть файл

@ -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<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);
}

Просмотреть файл

@ -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.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);
}

Просмотреть файл

@ -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.exitCode = 1;
logger.fail(
"No Xcode workspaces were found; specify an Xcode workspace with `--workspace`"
);
process.exitCode = 1;
return Promise.resolve(1);
}

Просмотреть файл

@ -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