@@ -24,14 +24,18 @@ export function expandHome (p) {
24
24
25
25
export function fullPath ( p ) {
26
26
return new Promise ( ( resolve , reject ) => {
27
- if ( fs . existsSync ( p ) ) return resolve ( fs . realpathSync ( p ) )
27
+ if ( fs . existsSync ( p ) ) {
28
+ return resolve ( fs . realpathSync ( p ) )
29
+ }
28
30
const current_dir = process . cwd ( )
29
31
const exepath = path . dirname ( process . execPath )
30
-
32
+
31
33
try {
32
34
process . chdir ( exepath )
33
35
const realpath = fs . realpathSync ( p )
34
- fs . existsSync ( realpath ) && resolve ( realpath )
36
+ if ( fs . existsSync ( realpath ) ) {
37
+ resolve ( realpath )
38
+ }
35
39
} catch ( err ) {
36
40
console . log ( err )
37
41
} finally {
@@ -56,12 +60,16 @@ export function fullPath (p) {
56
60
57
61
export function getVersion ( path = jlpath ( ) ) {
58
62
return new Promise ( ( resolve , reject ) => {
59
- child_process . exec ( `"${ path } " --version` , ( err , stdout , stderr ) => {
60
- if ( err ) return reject ( stderr )
61
- const res = stdout . match ( / ( \d + ) \. ( \d + ) \. ( \d + ) / )
62
- if ( ! res ) return reject ( 'Couldn\'t resolve version.' )
63
- const [ _ , major , minor , patch ] = res
64
- return resolve ( { major, minor, patch } )
63
+ fullPath ( path ) . then ( path => {
64
+ child_process . exec ( `"${ path } " --version` , ( err , stdout , stderr ) => {
65
+ if ( err ) return reject ( stderr )
66
+ const res = stdout . match ( / ( \d + ) \. ( \d + ) \. ( \d + ) / )
67
+ if ( ! res ) return reject ( 'Couldn\'t resolve version.' )
68
+ const [ _ , major , minor , patch ] = res
69
+ return resolve ( { major, minor, patch } )
70
+ } )
71
+ } ) . catch ( e => {
72
+ reject ( 'Couldn\'t resolve version.' )
65
73
} )
66
74
} )
67
75
}
0 commit comments