Skip to content
This repository was archived by the owner on Jul 24, 2019. It is now read-only.

Commit ee20e6d

Browse files
author
Nick Santos
committedMar 25, 2016
try to link to the global phantomjs npm install if we can
1 parent 00c6258 commit ee20e6d

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed
 

‎install.js

+31-7
Original file line numberDiff line numberDiff line change
@@ -327,17 +327,31 @@ function copyIntoPlace(extractedPath, targetPath) {
327327
})
328328
}
329329

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+
330347
/**
331348
* Check to see if the binary in lib is OK to use. If successful, exit the process.
332349
*/
333350
function tryPhantomjsInLib() {
334351
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)
341355
exit(0)
342356
}
343357
}).fail(function () {
@@ -369,7 +383,17 @@ function tryPhantomjsOnPath() {
369383

370384
var contents = fs.readFileSync(phantomPath, 'utf8')
371385
if (/NPM_INSTALL_MARKER/.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...')
373397
} else {
374398
return checkPhantomjsVersion(phantomPath).then(function (matches) {
375399
if (matches) {

‎lib/phantomjs.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77

88
var fs = require('fs')
99
var path = require('path')
10-
var which = require('which')
1110

1211

1312
/**
1413
* Where the phantom binary can be found.
1514
* @type {string}
1615
*/
1716
try {
18-
exports.path = path.resolve(__dirname, require('./location').location)
17+
var location = require('./location')
18+
exports.path = path.resolve(__dirname, location.location)
19+
exports.platform = location.platform
20+
exports.arch = location.arch
1921
} catch(e) {
2022
// Must be running inside install script.
2123
exports.path = null

0 commit comments

Comments
 (0)
This repository has been archived.