Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

Try to find phantomjs binary in .bin #191

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 19 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@ var fs = require('fs')
var path = require('path')
var _ = require('lodash')

var phantomSource = require('phantomjs-prebuilt').path

if (phantomSource === null) {
var which = require('npm-which')(process.cwd())

try {
phantomSource = which.sync('phantomjs')
} catch (e) {}
}

if (phantomSource == null) {
var installScriptLocation = require.resolve('phantomjs-prebuilt/install')
var installScriptCmd = '`node ' + installScriptLocation + '`'

throw new Error("PhantomJS binary not found, make sure `phantomjs-prebuilt`'s `postinstall` is run, or manually run " + installScriptCmd)
}

function serializeOption (value) {
if (typeof value === 'function') {
return value.toString()
Expand All @@ -13,8 +30,6 @@ var phantomJSExePath = function () {
// If the path we're given by phantomjs is to a .cmd, it is pointing to a global copy.
// Using the cmd as the process to execute causes problems cleaning up the processes
// so we walk from the cmd to the phantomjs.exe and use that instead.
var phantomSource = require('phantomjs-prebuilt').path

if (path.extname(phantomSource).toLowerCase() === '.cmd') {
var phantomPackage = require('phantomjs-prebuilt/package.json')
return path.join(
Expand Down Expand Up @@ -102,8 +117,8 @@ PhantomJSBrowser.prototype = {
name: 'PhantomJS',

DEFAULT_CMD: {
linux: require('phantomjs-prebuilt').path,
darwin: require('phantomjs-prebuilt').path,
linux: phantomSource,
darwin: phantomSource,
win32: phantomJSExePath()
},
ENV_CMD: 'PHANTOMJS_BIN'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"author": "Vojta Jina <[email protected]>",
"dependencies": {
"lodash": "^4.0.1",
"npm-which": "^3.0.1",
"phantomjs-prebuilt": "^2.1.7"
},
"peerDependencies": {
Expand Down
28 changes: 21 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2045,6 +2045,20 @@ normalize-path@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-2.0.1.tgz#47886ac1662760d4261b7d979d241709d3ce3f7a"

npm-path@^2.0.2:
version "2.0.3"
resolved "https://registry.yarnpkg.com/npm-path/-/npm-path-2.0.3.tgz#15cff4e1c89a38da77f56f6055b24f975dfb2bbe"
dependencies:
which "^1.2.10"

npm-which@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/npm-which/-/npm-which-3.0.1.tgz#9225f26ec3a285c209cae67c3b11a6b4ab7140aa"
dependencies:
commander "^2.9.0"
npm-path "^2.0.2"
which "^1.2.10"

npmlog@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-4.0.2.tgz#d03950e0e78ce1527ba26d2a7592e9348ac3e75f"
Expand Down Expand Up @@ -2480,11 +2494,11 @@ safe-buffer@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.0.1.tgz#d263ca54696cd8a306b5ca6551e92de57918fbe7"

"semver@2 || 3 || 4", "semver@2 || 3 || 4 || 5", semver@^4.3.3, semver@~4.3.3:
"semver@2 || 3 || 4", semver@^4.3.3, semver@~4.3.3:
version "4.3.6"
resolved "https://registry.yarnpkg.com/semver/-/semver-4.3.6.tgz#300bc6e0e86374f7ba61068b5b1ecd57fc6532da"

semver@~5.3.0:
"semver@2 || 3 || 4 || 5", semver@~5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"

Expand Down Expand Up @@ -2831,16 +2845,16 @@ void-elements@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-2.0.1.tgz#c066afb582bb1cb4128d60ea92392e94d5e9dbec"

which@~1.0.5:
version "1.0.9"
resolved "https://registry.yarnpkg.com/which/-/which-1.0.9.tgz#460c1da0f810103d0321a9b633af9e575e64486f"

which@~1.2.10:
which@^1.2.10, which@~1.2.10:
version "1.2.12"
resolved "https://registry.yarnpkg.com/which/-/which-1.2.12.tgz#de67b5e450269f194909ef23ece4ebe416fa1192"
dependencies:
isexe "^1.1.1"

which@~1.0.5:
version "1.0.9"
resolved "https://registry.yarnpkg.com/which/-/which-1.0.9.tgz#460c1da0f810103d0321a9b633af9e575e64486f"

wide-align@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.0.tgz#40edde802a71fea1f070da3e62dcda2e7add96ad"
Expand Down