install.js
function tryPhantomjsOnPath() {
  if (getTargetPlatform() != process.platform || getTargetArch() != process.arch) {
    console.log('Building for target platform ' + getTargetPlatform() + '/' + getTargetArch() +
                '. Skipping PATH search')
    return Q.resolve(false)
  }

  return Q.nfcall(which, 'phantomjs')
  .then(function (result) {
    phantomPath = result
    console.log('Considering PhantomJS found at', phantomPath)

    // Horrible hack to avoid problems during global install. We check to see if
    // the file `which` found is our own bin script.
    if (phantomPath.indexOf(path.join('npm', 'phantomjs')) !== -1) {
      console.log('Looks like an `npm install -g` on windows; skipping installed version.')
      return
    }

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

      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 {
      return checkPhantomjsVersion(phantomPath).then(function (matches) {
        if (matches) {
          writeLocationFile(phantomPath)
          console.log('PhantomJS is already installed on PATH at', phantomPath)
          exit(0)
        }
      })
    }
  }, function () {
    console.log('PhantomJS not found on PATH')
  })
  .fail(function (err) {
    console.error('Error checking path, continuing', err)
    return false
  })
}
function tryPhantomjsOnPath() {
  if (getTargetPlatform() != process.platform || getTargetArch() != process.arch) {
    console.log('Building for target platform ' + getTargetPlatform() + '/' + getTargetArch() +
                '. Skipping PATH search')
    return Q.resolve(false)
  }

  return Q.nfcall(which, 'phantomjs')
  .then(function (result) {
    phantomPath = result
    console.log('Considering PhantomJS found at', phantomPath)

    // Horrible hack to avoid problems during global install. We check to see if
    // the file `which` found is our own bin script.
    if (phantomPath.indexOf(path.join('npm', 'phantomjs')) !== -1) {
      console.log('Looks like an `npm install -g` on windows; skipping installed version.')
      return
    }

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

      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 {
      return checkPhantomjsVersion(phantomPath).then(function (matches) {
        if (matches) {
          writeLocationFile(phantomPath)
          console.log('PhantomJS is already installed on PATH at', phantomPath)
          exit(0)
        }
      })
    }
  }, function () {
    console.log('PhantomJS not found on PATH')
  })
  .fail(function (err) {
    console.error('Error checking path, continuing', err)
    return false
  })
}
function tryPhantomjsOnPath ( ) { if ( getTargetPlatform ( ) != process . platform || getTargetArch ( ) != process . arch ) { console . log ( 'Building for target platform ' + getTargetPlatform ( ) + '/' + getTargetArch ( ) + '. Skipping PATH search' ) return Q . resolve ( false ) } return Q . nfcall ( which , 'phantomjs' ) . then ( function ( result ) { phantomPath = result console . log ( 'Considering PhantomJS found at' , phantomPath ) // Horrible hack to avoid problems during global install. We check to see if // the file `which` found is our own bin script. if ( phantomPath . indexOf ( path . join ( 'npm' , 'phantomjs' ) ) !== - 1 ) { console . log ( 'Looks like an `npm install -g` on windows; skipping installed version.' ) return } var contents = fs . readFileSync ( phantomPath , 'utf8' ) if ( / NPM_INSTALL_MARKER / . test ( contents ) ) { console . log ( 'Looks like an `npm install -g`' ) 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 { return checkPhantomjsVersion ( phantomPath ) . then ( function ( matches ) { if ( matches ) { writeLocationFile ( phantomPath ) console . log ( 'PhantomJS is already installed on PATH at' , phantomPath ) exit ( 0 ) } } ) } } , function ( ) { console . log ( 'PhantomJS not found on PATH' ) } ) . fail ( function ( err ) { console . error ( 'Error checking path, continuing' , err ) return false } ) }
Check to see if the binary on PATH is OK to use. If successful, exit the process.
Check to see if the binary on PATH is OK to use . If successful exit the process .