11// @ts -check
22import { getCurrentState } from "@rnx-kit/tools-react-native/cache" ;
3- import { loadContext } from "@rnx-kit/tools-react-native/context " ;
3+ import { loadContextAsync } from "@rnx-kit/tools-react-native" ;
44import * as fs from "node:fs" ;
55import * as path from "node:path" ;
66import {
@@ -83,16 +83,16 @@ export function pruneDependencies(config) {
8383/**
8484 * @param {string } json
8585 * @param {string } projectRoot
86- * @returns {Config }
86+ * @returns {Promise< Config> }
8787 */
88- function loadConfig ( json , projectRoot ) {
88+ async function loadConfig ( json , projectRoot ) {
8989 const state = getCurrentState ( projectRoot ) ;
9090 const stateFile = json . substring ( 0 , json . length - "json" . length ) + "sha256" ;
9191 if ( fs . existsSync ( stateFile ) && readTextFile ( stateFile ) === state ) {
9292 return readJSONFile ( json ) ;
9393 }
9494
95- const config = loadContext ( projectRoot ) ;
95+ const config = await loadContextAsync ( projectRoot ) ;
9696 const prunedConfig = pruneDependencies ( config ) ;
9797
9898 ensureDirForFile ( json ) ;
@@ -101,10 +101,13 @@ function loadConfig(json, projectRoot) {
101101 return prunedConfig ;
102102}
103103
104- if ( isMain ( import . meta. url ) ) {
105- const [ , , projectRoot = process . cwd ( ) , output ] = process . argv ;
106-
107- const config = loadConfig (
104+ /**
105+ * @param {string } projectRoot
106+ * @param {string } output
107+ * @returns {Promise<void> }
108+ */
109+ async function main ( projectRoot , output ) {
110+ const config = await loadConfig (
108111 output . replace (
109112 / [ / \\ ] a p p [ / \\ ] b u i l d [ / \\ ] g e n e r a t e d [ / \\ ] r n t a [ / \\ ] / ,
110113 "/build/generated/autolinking/"
@@ -121,3 +124,8 @@ if (isMain(import.meta.url)) {
121124 writeTextFile ( output , json + "\n" ) ;
122125 }
123126}
127+
128+ if ( isMain ( import . meta. url ) ) {
129+ const [ , , projectRoot = process . cwd ( ) , output = "" ] = process . argv ;
130+ await main ( projectRoot , output ) ;
131+ }
0 commit comments