11// @ts -check
2- import * as crypto from "node:crypto" ;
2+ import { getCurrentState } from "@rnx-kit/tools-react-native/cache" ;
3+ import { loadContext } from "@rnx-kit/tools-react-native/context" ;
34import * as fs from "node:fs" ;
45import * as path from "node:path" ;
56import {
6- findFile ,
77 isMain ,
88 readJSONFile ,
99 readTextFile ,
10- requireTransitive ,
1110 writeTextFile ,
1211} from "../scripts/helpers.js" ;
1312
@@ -33,45 +32,6 @@ function ensureDirForFile(p) {
3332 fs . mkdirSync ( path . dirname ( p ) , { recursive : true , mode : 0o755 } ) ;
3433}
3534
36- /**
37- * @param {crypto.Hash } hash
38- * @param {string[] } files
39- * @param {string } projectRoot
40- * @param {"all" | "first-only" } mode
41- */
42- function updateHash ( hash , files , projectRoot , mode ) {
43- for ( const file of files ) {
44- const p = findFile ( file , projectRoot ) ;
45- if ( p ) {
46- hash . update ( fs . readFileSync ( p ) ) ;
47- if ( mode === "first-only" ) {
48- break ;
49- }
50- }
51- }
52- }
53-
54- /**
55- * @param {string } projectRoot
56- * @returns {string }
57- */
58- function getCurrentState ( projectRoot ) {
59- const sha2 = crypto . createHash ( "sha256" ) ;
60-
61- const configFiles = [ "package.json" , "react-native.config.js" ] ;
62- updateHash ( sha2 , configFiles , projectRoot , "all" ) ;
63-
64- const lockfiles = [
65- "yarn.lock" ,
66- "package-lock.json" ,
67- "pnpm-lock.yaml" ,
68- "bun.lockb" ,
69- ] ;
70- updateHash ( sha2 , lockfiles , projectRoot , "first-only" ) ;
71-
72- return sha2 . digest ( "hex" ) ;
73- }
74-
7535/**
7636 * @param {Config } config
7737 * @returns {AndroidDependencies }
@@ -132,19 +92,9 @@ function loadConfig(json, projectRoot) {
13292 return readJSONFile ( json ) ;
13393 }
13494
135- /** @type {import("@react-native-community/cli") } */
136- const { loadConfig } = requireTransitive (
137- [ "react-native" , "@react-native-community/cli" ] ,
138- projectRoot
139- ) ;
140-
141- // The signature of `loadConfig` changed in 14.0.0:
142- // https://github.com/react-native-community/cli/commit/b787c89edb781bb788576cd615d2974fc81402fc
143- const argc = loadConfig . length ;
144- // @ts -expect-error TS2345: Argument of type X is not assignable to parameter of type Y
145- const config = loadConfig ( argc === 1 ? { projectRoot } : projectRoot ) ;
146-
95+ const config = loadContext ( projectRoot ) ;
14796 const prunedConfig = pruneDependencies ( config ) ;
97+
14898 ensureDirForFile ( json ) ;
14999 writeTextFile ( json , JSON . stringify ( prunedConfig , undefined , 2 ) + "\n" ) ;
150100 writeTextFile ( stateFile , state ) ;
0 commit comments