1
1
// @ts -check
2
2
import { 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" ;
4
4
import * as fs from "node:fs" ;
5
5
import * as path from "node:path" ;
6
6
import {
@@ -83,16 +83,16 @@ export function pruneDependencies(config) {
83
83
/**
84
84
* @param {string } json
85
85
* @param {string } projectRoot
86
- * @returns {Config }
86
+ * @returns {Promise< Config> }
87
87
*/
88
- function loadConfig ( json , projectRoot ) {
88
+ async function loadConfig ( json , projectRoot ) {
89
89
const state = getCurrentState ( projectRoot ) ;
90
90
const stateFile = json . substring ( 0 , json . length - "json" . length ) + "sha256" ;
91
91
if ( fs . existsSync ( stateFile ) && readTextFile ( stateFile ) === state ) {
92
92
return readJSONFile ( json ) ;
93
93
}
94
94
95
- const config = loadContext ( projectRoot ) ;
95
+ const config = await loadContextAsync ( projectRoot ) ;
96
96
const prunedConfig = pruneDependencies ( config ) ;
97
97
98
98
ensureDirForFile ( json ) ;
@@ -101,10 +101,13 @@ function loadConfig(json, projectRoot) {
101
101
return prunedConfig ;
102
102
}
103
103
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 (
108
111
output . replace (
109
112
/ [ / \\ ] a p p [ / \\ ] b u i l d [ / \\ ] g e n e r a t e d [ / \\ ] r n t a [ / \\ ] / ,
110
113
"/build/generated/autolinking/"
@@ -121,3 +124,8 @@ if (isMain(import.meta.url)) {
121
124
writeTextFile ( output , json + "\n" ) ;
122
125
}
123
126
}
127
+
128
+ if ( isMain ( import . meta. url ) ) {
129
+ const [ , , projectRoot = process . cwd ( ) , output = "" ] = process . argv ;
130
+ await main ( projectRoot , output ) ;
131
+ }
0 commit comments