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

fix issue with tryPhantomjsInLib on Elastic Beanstalk #590

Merged
merged 2 commits into from
Aug 3, 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
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