Skip to content
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/tidy-sides-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rnx-kit/cli": patch
"@rnx-kit/tools-react-native": patch
---

As of 0.89, we need to manually include Android/iOS configs
9 changes: 6 additions & 3 deletions packages/cli/src/bin/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
getSavedState,
saveConfigToCache,
} from "@rnx-kit/tools-react-native/cache";
import { resolveCommunityCLI } from "@rnx-kit/tools-react-native/context";
import {
makeLoadConfigOptions,
resolveCommunityCLI,
} from "@rnx-kit/tools-react-native/context";
import { reactNativeConfig } from "../index.ts";
import { RNX_FAST_PATH, RNX_PREFIX } from "./constants.ts";

Expand Down Expand Up @@ -70,12 +73,12 @@ async function loadContextWithCLI(root: string) {
const rncli = resolveCommunityCLI(root);
const { loadConfig, loadConfigAsync } = require(rncli);

const options = makeLoadConfigOptions(loadConfig, root, rncli);
if (!loadConfigAsync) {
const options = loadConfig.length === 1 ? { projectRoot: root } : root;
return loadConfig(options);
}

return await loadConfigAsync({ projectRoot: root });
return await loadConfigAsync(options);
}

export async function loadContextForCommand(
Expand Down
1 change: 1 addition & 0 deletions packages/jest-preset/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/__fixtures__/*/node_modules/.cache

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions packages/tools-react-native/context.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export {
loadContext,
loadContextAsync,
makeLoadConfigOptions,
readReactNativeConfig,
resolveCommunityCLI,
} from "./lib/context.js";
44 changes: 38 additions & 6 deletions packages/tools-react-native/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import {
saveConfigToCache,
} from "./cache.ts";

type LoadConfigOptions = {
projectRoot: string;
platforms: Record<string, unknown>;
};

// As of 0.76, `@react-native-community/cli` is no longer a dependency of
// `react-native`. Consumers have to take a direct dependency on CLI instead.
const RN_CLI_DECOUPLED = 76;
Expand Down Expand Up @@ -61,10 +66,37 @@ function getConfigOrState<T = Config>(
return state;
}

function makeLoadConfigOptions(fn: typeof loadConfig, projectRoot: string) {
return fn.length === 1
? { projectRoot }
: (projectRoot as unknown as { projectRoot: string });
export function makeLoadConfigOptions(
fn: typeof loadConfig,
projectRoot: string,
rncli?: string
) {
if (fn.length !== 1) {
return projectRoot as unknown as { projectRoot: string };
}

// As of 0.89, we have to manually include Android and iOS
const opts: LoadConfigOptions = { projectRoot, platforms: {} };

const paths = { paths: rncli ? [rncli, projectRoot] : [projectRoot] };
const platforms = [
["android", "@react-native-community/cli-platform-android"],
["ios", "@react-native-community/cli-platform-ios"],
];

for (const [platform, pkg] of platforms) {
try {
const p = require(require.resolve(pkg, paths));
opts.platforms[platform] = {
projectConfig: p.projectConfig,
dependencyConfig: p.dependencyConfig,
};
} catch (_) {
// Ignore
}
}

return opts;
}

/**
Expand Down Expand Up @@ -94,7 +126,7 @@ export function loadContext(projectRoot = process.cwd()): Config {
const rncli = resolveCommunityCLI(projectRoot);
const { loadConfig } = require(rncli);

const options = makeLoadConfigOptions(loadConfig, projectRoot);
const options = makeLoadConfigOptions(loadConfig, projectRoot, rncli);
const config = loadConfig(options);
saveConfigToCache(projectRoot, state, config);
return config;
Expand All @@ -117,7 +149,7 @@ export async function loadContextAsync(
const rncli = resolveCommunityCLI(projectRoot);
const { loadConfig, loadConfigAsync } = require(rncli);

const options = makeLoadConfigOptions(loadConfig, projectRoot);
const options = makeLoadConfigOptions(loadConfig, projectRoot, rncli);

if (!loadConfigAsync) {
const config = loadConfig(options);
Expand Down
Loading