@@ -24,13 +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 ( 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 )
32
+
30
33
try {
31
34
process . chdir ( exepath )
32
35
const realpath = fs . realpathSync ( p )
33
- fs . existsSync ( realpath ) && resolve ( realpath )
36
+ if ( fs . existsSync ( realpath ) ) {
37
+ resolve ( realpath )
38
+ }
34
39
} catch ( err ) {
35
40
console . log ( err )
36
41
} finally {
@@ -55,12 +60,16 @@ export function fullPath (p) {
55
60
56
61
export function getVersion ( path = jlpath ( ) ) {
57
62
return new Promise ( ( resolve , reject ) => {
58
- child_process . exec ( `"${ path } " --version` , ( err , stdout , stderr ) => {
59
- if ( err ) return reject ( stderr )
60
- const res = stdout . match ( / ( \d + ) \. ( \d + ) \. ( \d + ) / )
61
- if ( ! res ) return reject ( 'Couldn\'t resolve version.' )
62
- const [ _ , major , minor , patch ] = res
63
- 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.' )
64
73
} )
65
74
} )
66
75
}
0 commit comments