@@ -24,13 +24,18 @@ export function expandHome (p) {
2424
2525export function fullPath ( p ) {
2626 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+ }
2830 const current_dir = process . cwd ( )
2931 const exepath = path . dirname ( process . execPath )
32+
3033 try {
3134 process . chdir ( exepath )
3235 const realpath = fs . realpathSync ( p )
33- fs . existsSync ( realpath ) && resolve ( realpath )
36+ if ( fs . existsSync ( realpath ) ) {
37+ resolve ( realpath )
38+ }
3439 } catch ( err ) {
3540 console . log ( err )
3641 } finally {
@@ -55,12 +60,16 @@ export function fullPath (p) {
5560
5661export function getVersion ( path = jlpath ( ) ) {
5762 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.' )
6473 } )
6574 } )
6675}
0 commit comments