@@ -327,17 +327,31 @@ function copyIntoPlace(extractedPath, targetPath) {
327
327
} )
328
328
}
329
329
330
+ function getLocationInLibModuleIfMatching ( libPath ) {
331
+ var libModule = require ( libPath )
332
+ if ( libModule . location &&
333
+ getTargetPlatform ( ) == libModule . platform &&
334
+ getTargetArch ( ) == libModule . arch ) {
335
+ try {
336
+ var resolvedLocation = path . resolve ( path . dirname ( libPath ) , libModule . location )
337
+ if ( fs . statSync ( resolvedLocation ) ) {
338
+ return resolvedLocation
339
+ }
340
+ } catch ( e ) {
341
+ // fall through
342
+ }
343
+ }
344
+ return false
345
+ }
346
+
330
347
/**
331
348
* Check to see if the binary in lib is OK to use. If successful, exit the process.
332
349
*/
333
350
function tryPhantomjsInLib ( ) {
334
351
return kew . fcall ( function ( ) {
335
- var libModule = require ( './lib/location.js' )
336
- if ( libModule . location &&
337
- getTargetPlatform ( ) == libModule . platform &&
338
- getTargetArch ( ) == libModule . arch &&
339
- fs . statSync ( path . join ( './lib' , libModule . location ) ) ) {
340
- console . log ( 'PhantomJS is previously installed at ' + libModule . location )
352
+ var location = getLocationInLibModuleIfMatching ( './lib/location.js' )
353
+ if ( location ) {
354
+ console . log ( 'PhantomJS is previously installed at' , location )
341
355
exit ( 0 )
342
356
}
343
357
} ) . fail ( function ( ) {
@@ -369,7 +383,17 @@ function tryPhantomjsOnPath() {
369
383
370
384
var contents = fs . readFileSync ( phantomPath , 'utf8' )
371
385
if ( / N P M _ I N S T A L L _ M A R K E R / . test ( contents ) ) {
372
- console . log ( 'Looks like an `npm install -g`; skipping installed version.' )
386
+ console . log ( 'Looks like an `npm install -g`' )
387
+
388
+ var globalLocation = getLocationInLibModuleIfMatching (
389
+ path . resolve ( fs . realpathSync ( phantomPath ) , '../../lib/location' ) )
390
+ if ( globalLocation ) {
391
+ console . log ( 'Linking to global install at' , globalLocation )
392
+ writeLocationFile ( globalLocation )
393
+ exit ( 0 )
394
+ }
395
+
396
+ console . log ( 'Could not link global install, skipping...' )
373
397
} else {
374
398
return checkPhantomjsVersion ( phantomPath ) . then ( function ( matches ) {
375
399
if ( matches ) {
0 commit comments