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

Commit

Permalink
Merge pull request #590 from thoop/master
Browse files Browse the repository at this point in the history
fix issue with tryPhantomjsInLib on Elastic Beanstalk
  • Loading branch information
nicks committed Aug 3, 2016
2 parents 08dd985 + a17cf74 commit 46af78b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
22 changes: 15 additions & 7 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var checkPhantomjsVersion = util.checkPhantomjsVersion
var getTargetPlatform = util.getTargetPlatform
var getTargetArch = util.getTargetArch
var getDownloadSpec = util.getDownloadSpec
var maybeLinkLibModule = util.maybeLinkLibModule
var findValidPhantomJsBinary = util.findValidPhantomJsBinary
var verifyChecksum = util.verifyChecksum
var writeLocationFile = util.writeLocationFile

Expand Down Expand Up @@ -322,9 +322,12 @@ function copyIntoPlace(extractedPath, targetPath) {
*/
function tryPhantomjsInLib() {
return kew.fcall(function () {
return maybeLinkLibModule(path.resolve(__dirname, './lib/location.js'))
}).then(function (success) {
if (success) exit(0)
return findValidPhantomJsBinary(path.resolve(__dirname, './lib/location.js'))
}).then(function (binaryLocation) {
if (binaryLocation) {
console.log('PhantomJS is previously installed at', binaryLocation)
exit(0)
}
}).fail(function () {
// silently swallow any errors
})
Expand Down Expand Up @@ -356,9 +359,14 @@ function tryPhantomjsOnPath() {
if (/NPM_INSTALL_MARKER/.test(contents)) {
console.log('Looks like an `npm install -g`')

return maybeLinkLibModule(path.resolve(fs.realpathSync(phantomPath), '../../lib/location'))
.then(function (success) {
if (success) exit(0)
var phantomLibPath = path.resolve(fs.realpathSync(phantomPath), '../../lib/location')
return findValidPhantomJsBinary(phantomLibPath)
.then(function (binaryLocation) {
if (binaryLocation) {
writeLocationFile(binaryLocation)
console.log('PhantomJS linked at', phantomLibPath)
exit(0)
}
console.log('Could not link global install, skipping...')
})
} else {
Expand Down
12 changes: 5 additions & 7 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ var libPath = __dirname

/**
* Given a lib/location file of a PhantomJS previously installed with NPM,
* try to link the binary to this lib/location.
* @return {Promise<boolean>} True on success
* is there a valid PhantomJS binary at this lib/location.
* @return {Promise<string>} resolved location of phantomjs binary on success
*/
function maybeLinkLibModule(libPath) {
function findValidPhantomJsBinary(libPath) {
return kew.fcall(function () {
var libModule = require(libPath)
if (libModule.location &&
Expand All @@ -29,9 +29,7 @@ function maybeLinkLibModule(libPath) {
if (fs.statSync(resolvedLocation)) {
return checkPhantomjsVersion(resolvedLocation).then(function (matches) {
if (matches) {
writeLocationFile(resolvedLocation)
console.log('PhantomJS linked at', resolvedLocation)
return kew.resolve(true)
return kew.resolve(resolvedLocation)
}
})
}
Expand Down Expand Up @@ -157,7 +155,7 @@ module.exports = {
getDownloadSpec: getDownloadSpec,
getTargetPlatform: getTargetPlatform,
getTargetArch: getTargetArch,
maybeLinkLibModule: maybeLinkLibModule,
findValidPhantomJsBinary: findValidPhantomJsBinary,
verifyChecksum: verifyChecksum,
writeLocationFile: writeLocationFile
}
12 changes: 6 additions & 6 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ exports.testCleanPath = function (test) {
}

exports.testBogusReinstallLocation = function (test) {
util.maybeLinkLibModule('./blargh')
.then(function (success) {
test.ok(!success, 'Expected link to fail')
util.findValidPhantomJsBinary('./blargh')
.then(function (binaryLocation) {
test.ok(!binaryLocation, 'Expected link to fail')
test.done()
})
}

exports.testSuccessfulReinstallLocation = function (test) {
util.maybeLinkLibModule(path.resolve(__dirname, '../lib/location'))
.then(function (success) {
test.ok(success, 'Expected link to succeed')
util.findValidPhantomJsBinary(path.resolve(__dirname, '../lib/location'))
.then(function (binaryLocation) {
test.ok(binaryLocation, 'Expected link to succeed')
test.done()
})
}
Expand Down

0 comments on commit 46af78b

Please sign in to comment.