@@ -10,6 +10,7 @@ import { checkPlugins } from './check-plugin';
1010
1111import { read } from 'read' ;
1212import { tempDir } from './constants' ;
13+ import { depVersions } from './dep-versions' ;
1314
1415export async function question ( query : string , password ?: boolean ) {
1516 if ( NO_INTERACTIVE ) {
@@ -38,26 +39,6 @@ export function translateOptions(options: Record<string, string>) {
3839 return ret ;
3940}
4041
41- export function getRNVersion ( ) {
42- const version = JSON . parse (
43- fs
44- . readFileSync (
45- require . resolve ( 'react-native/package.json' , {
46- paths : [ process . cwd ( ) ] ,
47- } ) ,
48- )
49- . toString ( ) ,
50- ) . version ;
51-
52- const [ , major , minor ] = / ^ ( \d + ) \. ( \d + ) \. / . exec ( version ) || [ ] ;
53-
54- return {
55- version,
56- major : Number ( major ) ,
57- minor : Number ( minor ) ,
58- } ;
59- }
60-
6142export async function getApkInfo ( fn : string ) {
6243 const appInfoParser = new AppInfoParser ( fn ) ;
6344 const bundleFile = await appInfoParser . parser . getEntry (
@@ -198,21 +179,11 @@ export async function printVersionCommand() {
198179 `react-native-update-cli: ${ pkg . version } ${ latestPushyCliVersion } ` ,
199180 ) ;
200181 let pushyVersion = '' ;
201- try {
202- const PACKAGE_JSON_PATH = require . resolve (
203- 'react-native-update/package.json' ,
204- {
205- paths : [ process . cwd ( ) ] ,
206- } ,
207- ) ;
208- pushyVersion = require ( PACKAGE_JSON_PATH ) . version ;
209- latestPushyVersion = latestPushyVersion
210- ? ` (最新:${ chalk . green ( latestPushyVersion ) } )`
211- : '' ;
212- console . log ( `react-native-update: ${ pushyVersion } ${ latestPushyVersion } ` ) ;
213- } catch ( e ) {
214- console . log ( 'react-native-update: 无法获取版本号,请在项目目录中运行命令' ) ;
215- }
182+ pushyVersion = depVersions [ 'react-native-update' ] ;
183+ latestPushyVersion = latestPushyVersion
184+ ? ` (最新:${ chalk . green ( latestPushyVersion ) } )`
185+ : '' ;
186+ console . log ( `react-native-update: ${ pushyVersion } ${ latestPushyVersion } ` ) ;
216187 if ( pushyVersion ) {
217188 if ( semverSatisfies ( pushyVersion , '<8.5.2' ) ) {
218189 console . warn (
@@ -229,6 +200,8 @@ export async function printVersionCommand() {
229200 '当前版本已不再支持,请升级到 v10 的最新小版本(代码无需改动,可直接热更): npm i react-native-update@10' ,
230201 ) ;
231202 }
203+ } else {
204+ console . log ( 'react-native-update: 无法获取版本号,请在项目目录中运行命令' ) ;
232205 }
233206}
234207
0 commit comments