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

try to link to the global phantomjs npm install if we can #510

Merged
merged 1 commit into from
Mar 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,17 +327,31 @@ function copyIntoPlace(extractedPath, targetPath) {
})
}

function getLocationInLibModuleIfMatching(libPath) {
var libModule = require(libPath)
if (libModule.location &&
getTargetPlatform() == libModule.platform &&
getTargetArch() == libModule.arch) {
try {
var resolvedLocation = path.resolve(path.dirname(libPath), libModule.location)
if (fs.statSync(resolvedLocation)) {
return resolvedLocation
}
} catch (e) {
// fall through
}
}
return false
}

/**
* Check to see if the binary in lib is OK to use. If successful, exit the process.
*/
function tryPhantomjsInLib() {
return kew.fcall(function () {
var libModule = require('./lib/location.js')
if (libModule.location &&
getTargetPlatform() == libModule.platform &&
getTargetArch() == libModule.arch &&
fs.statSync(path.join('./lib', libModule.location))) {
console.log('PhantomJS is previously installed at ' + libModule.location)
var location = getLocationInLibModuleIfMatching('./lib/location.js')
if (location) {
console.log('PhantomJS is previously installed at', location)
exit(0)
}
}).fail(function () {
Expand Down Expand Up @@ -369,7 +383,17 @@ function tryPhantomjsOnPath() {

var contents = fs.readFileSync(phantomPath, 'utf8')
if (/NPM_INSTALL_MARKER/.test(contents)) {
console.log('Looks like an `npm install -g`; skipping installed version.')
console.log('Looks like an `npm install -g`')

var globalLocation = getLocationInLibModuleIfMatching(
path.resolve(fs.realpathSync(phantomPath), '../../lib/location'))
if (globalLocation) {
console.log('Linking to global install at', globalLocation)
writeLocationFile(globalLocation)
exit(0)
}

console.log('Could not link global install, skipping...')
} else {
return checkPhantomjsVersion(phantomPath).then(function (matches) {
if (matches) {
Expand Down
6 changes: 4 additions & 2 deletions lib/phantomjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@

var fs = require('fs')
var path = require('path')
var which = require('which')


/**
* Where the phantom binary can be found.
* @type {string}
*/
try {
exports.path = path.resolve(__dirname, require('./location').location)
var location = require('./location')
exports.path = path.resolve(__dirname, location.location)
exports.platform = location.platform
exports.arch = location.arch
} catch(e) {
// Must be running inside install script.
exports.path = null
Expand Down