11// @ts -check
2+ import { resolveCommunityCLI } from "@rnx-kit/tools-react-native/context" ;
23import { XMLParser } from "fast-xml-parser" ;
34import * as nodefs from "node:fs" ;
45import * as path from "node:path" ;
@@ -10,13 +11,13 @@ import {
1011 memo ,
1112 readJSONFile ,
1213 readTextFile ,
13- requireTransitive ,
1414 toVersionNumber ,
1515 v ,
1616} from "../scripts/helpers.js" ;
1717import * as colors from "../scripts/utils/colors.mjs" ;
1818
1919/**
20+ * @import { Config } from "@react-native-community/cli-types"
2021 * @import {
2122 * AppManifest,
2223 * AppxBundle,
@@ -95,18 +96,20 @@ function generateCertificateItems(
9596
9697/**
9798 * Equivalent to invoking `react-native config`.
98- * @param { string } rnWindowsPath
99+ * @type { (rnWindowsPath: string) => Promise<Config> }
99100 */
100101export const loadReactNativeConfig = memo ( ( rnWindowsPath ) => {
101- /** @type {import("@react-native-community/cli") } */
102- const { loadConfig } = requireTransitive (
103- [ "@react-native-community/cli" ] ,
104- rnWindowsPath
105- ) ;
106- // The signature of `loadConfig` changed in 14.0.0:
107- // https://github.com/react-native-community/cli/commit/b787c89edb781bb788576cd615d2974fc81402fc
108- // @ts -expect-error TS2345: Argument of type X is not assignable to parameter of type Y
109- return loadConfig . length === 1 ? loadConfig ( { } ) : loadConfig ( ) ;
102+ const rncli = "file://" + resolveCommunityCLI ( rnWindowsPath ) ;
103+ return import ( rncli ) . then ( async ( cli ) => {
104+ const { loadConfig, loadConfigAsync } = cli ?. default ?? cli ;
105+ if ( ! loadConfigAsync ) {
106+ // The signature of `loadConfig` changed in 14.0.0:
107+ // https://github.com/react-native-community/cli/commit/b787c89edb781bb788576cd615d2974fc81402fc
108+ return loadConfig . length === 1 ? loadConfig ( { } ) : loadConfig ( ) ;
109+ }
110+
111+ return await loadConfigAsync ( { } ) ;
112+ } ) ;
110113} ) ;
111114
112115/**
@@ -207,17 +210,16 @@ function generateContentItems(
207210 *
208211 * @see {@link https://github.com/microsoft/react-native-windows/issues/9578 }
209212 * @param {string } rnWindowsPath
210- * @returns {[string, string][] }
213+ * @returns {Promise< [string, string][]> }
211214 */
212- function getNuGetDependencies ( rnWindowsPath , fs = nodefs ) {
215+ async function getNuGetDependencies ( rnWindowsPath , fs = nodefs ) {
213216 const pkgJson = findNearest ( "package.json" , undefined , fs ) ;
214217 if ( ! pkgJson ) {
215218 return [ ] ;
216219 }
217220
218- const dependencies = Object . values (
219- loadReactNativeConfig ( rnWindowsPath ) . dependencies
220- ) ;
221+ const config = await loadReactNativeConfig ( rnWindowsPath ) ;
222+ const dependencies = Object . values ( config . dependencies ) ;
221223
222224 const xml = new XMLParser ( {
223225 ignoreAttributes : false ,
@@ -402,9 +404,9 @@ export function getBundleResources(manifestFilePath, fs = nodefs) {
402404 * @param {MSBuildProjectOptions } options
403405 * @param {string } rnWindowsPath
404406 * @param {string } destPath
405- * @returns {ProjectInfo }
407+ * @returns {Promise< ProjectInfo> }
406408 */
407- export function projectInfo (
409+ export async function projectInfo (
408410 { useFabric, useNuGet } ,
409411 rnWindowsPath ,
410412 destPath ,
@@ -423,7 +425,7 @@ export function projectInfo(
423425 version,
424426 versionNumber,
425427 bundle : getBundleResources ( findNearest ( "app.json" , destPath , fs ) , fs ) ,
426- nugetDependencies : getNuGetDependencies ( rnWindowsPath ) ,
428+ nugetDependencies : await getNuGetDependencies ( rnWindowsPath ) ,
427429 useExperimentalNuGet : newArch || useNuGet ,
428430 useFabric : newArch ,
429431 } ;
0 commit comments