@@ -23,7 +23,7 @@ export async function question(query: string, password?: boolean) {
2323}
2424
2525export function translateOptions ( options : Record < string , string > ) {
26- const ret = { } ;
26+ const ret : Record < string , string > = { } ;
2727 for ( const key in options ) {
2828 const v = options [ key ] ;
2929 if ( typeof v === 'string' ) {
@@ -40,19 +40,21 @@ export function translateOptions(options: Record<string, string>) {
4040
4141export function getRNVersion ( ) {
4242 const version = JSON . parse (
43- fs . readFileSync (
44- require . resolve ( 'react-native/package.json' , {
45- paths : [ process . cwd ( ) ] ,
46- } ) ,
47- ) ,
43+ fs
44+ . readFileSync (
45+ require . resolve ( 'react-native/package.json' , {
46+ paths : [ process . cwd ( ) ] ,
47+ } ) ,
48+ )
49+ . toString ( ) ,
4850 ) . version ;
4951
50- // We only care about major and minor version.
51- const match = / ^ ( \d + ) \. ( \d + ) \. / . exec ( version ) ;
52+ const [ , major , minor ] = / ^ ( \d + ) \. ( \d + ) \. / . exec ( version ) || [ ] ;
53+
5254 return {
5355 version,
54- major : match [ 1 ] | 0 ,
55- minor : match [ 2 ] | 0 ,
56+ major : Number ( major ) ,
57+ minor : Number ( minor ) ,
5658 } ;
5759}
5860
@@ -173,17 +175,22 @@ export function saveToLocal(originPath: string, destName: string) {
173175 // fs.copyFileSync(originPath, destPath);
174176}
175177
176- async function getLatestVersion ( pkgName : string ) {
177- return Promise . race ( [
178- latestVersion ( pkgName )
179- . then ( ( p ) => p . latest )
180- . catch ( ( ) => '' ) ,
181- new Promise ( ( resolve ) => setTimeout ( ( ) => resolve ( '' ) , 2000 ) ) ,
182- ] ) ;
178+ async function getLatestVersion ( pkgNames : string [ ] ) {
179+ return latestVersion ( pkgNames , {
180+ useCache : true ,
181+ requestOptions : {
182+ timeout : 2000 ,
183+ } ,
184+ } )
185+ . then ( ( pkgs ) => pkgs . map ( ( pkg ) => pkg . latest ) )
186+ . catch ( ( ) => [ ] ) ;
183187}
184188
185189export async function printVersionCommand ( ) {
186- let latestPushyCliVersion = await getLatestVersion ( 'react-native-update-cli' ) ;
190+ let [ latestPushyCliVersion , latestPushyVersion ] = await getLatestVersion ( [
191+ 'react-native-update-cli' ,
192+ 'react-native-update' ,
193+ ] ) ;
187194 latestPushyCliVersion = latestPushyCliVersion
188195 ? ` (最新:${ chalk . green ( latestPushyCliVersion ) } )`
189196 : '' ;
@@ -199,7 +206,6 @@ export async function printVersionCommand() {
199206 } ,
200207 ) ;
201208 pushyVersion = require ( PACKAGE_JSON_PATH ) . version ;
202- let latestPushyVersion = await getLatestVersion ( 'react-native-update' ) ;
203209 latestPushyVersion = latestPushyVersion
204210 ? ` (最新:${ chalk . green ( latestPushyVersion ) } )`
205211 : '' ;
@@ -226,6 +232,4 @@ export async function printVersionCommand() {
226232 }
227233}
228234
229-
230-
231235export { checkPlugins } ;
0 commit comments