1
1
// @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" ;
3
4
import * as fs from "node:fs" ;
4
5
import * as path from "node:path" ;
5
6
import {
6
- findFile ,
7
7
isMain ,
8
8
readJSONFile ,
9
9
readTextFile ,
10
- requireTransitive ,
11
10
writeTextFile ,
12
11
} from "../scripts/helpers.js" ;
13
12
@@ -33,45 +32,6 @@ function ensureDirForFile(p) {
33
32
fs . mkdirSync ( path . dirname ( p ) , { recursive : true , mode : 0o755 } ) ;
34
33
}
35
34
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
-
75
35
/**
76
36
* @param {Config } config
77
37
* @returns {AndroidDependencies }
@@ -132,19 +92,9 @@ function loadConfig(json, projectRoot) {
132
92
return readJSONFile ( json ) ;
133
93
}
134
94
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 ) ;
147
96
const prunedConfig = pruneDependencies ( config ) ;
97
+
148
98
ensureDirForFile ( json ) ;
149
99
writeTextFile ( json , JSON . stringify ( prunedConfig , undefined , 2 ) + "\n" ) ;
150
100
writeTextFile ( stateFile , state ) ;
0 commit comments