Example #1
0
 it('takes string and callback', () => {
   which('flow-typed', (err, val) => {
     (val: string);
   })
   // $ExpectError first param can't be anything but string
   which(123, (err, val) => {
     (val: string);
   })
 });
BrowserController.prototype._getDefaultBinary = function () {
  var platform = process.platform;
  
  // check default binary for linuy
  if (platform !== 'darwin' && platform !== 'win32' && this.defaultBinaries[platform]) {
     return which(this.defaultBinaries.linux);
  }

   // check to see if we are on Windows x64
  if (platform === 'win32' && process.arch === 'x64') {
    platform = 'win64';
  }

  return this.defaultBinaries[platform] ? this.defaultBinaries[platform] : which(this.defaultBinaries.default);
};
Example #3
0
  npm.load({ cache: cache, registry: common.registry }, function () {
    which('git', function (err, git) {
      t.ifError(err, 'git found on system')
      function tagExists (tag, _cb) {
        var child1 = spawn(git, ['tag', '-l', tag])
        var out = ''
        child1.stdout.on('data', function (d) {
          out += d.toString()
        })
        child1.on('exit', function () {
          return _cb(null, Boolean(~out.indexOf(tag)))
        })
      }

      var child2 = spawn(git, ['init'])
      child2.stdout.pipe(process.stdout)
      child2.on('exit', function () {
        npm.config.set('git-tag-version', false)
        npm.commands.version(['patch'], function (err) {
          if (err) return t.fail('Error perform version patch')
          var p = path.resolve(pkg, 'package')
          var testPkg = require(p)
          if (testPkg.version !== '0.0.1') t.fail(testPkg.version + ' !== \'0.0.1\'')
          t.equal('0.0.1', testPkg.version)
          tagExists('v0.0.1', function (err, exists) {
            t.ifError(err, 'tag found to exist')
            t.equal(exists, false, 'git tag DOES exist')
            t.pass('git tag does not exist')
            t.end()
          })
        })
      })
    })
  })
Example #4
0
// Split a command string into it's base components for strong-service-upstart
// command './bin/myapp.js --flag --two 2'
//  -> execPath: '/path/to/node'
//  -> script: ['/path/to/bin/myapp.js', '--flag', '--two', '2']
// command 'global-cmd sub-cmd --flag --two 2'
//  -> execPath: '/path/to/global-cmd' (resolved from $PATH)
//  -> script: ['sub-cmd', '--flag', '--two', '2']
function resolveCommand(opts, next) {

  // If opts.command is given by CLI it is most certainly a string
  if (!Array.isArray(opts.command)) {
    opts.command = shell.parse(opts.command);
  }

  which(opts.command[0], function(err, fromPath) {
    if (err)
      return maybeLocal();
    if (!opts.execPath) {
      // exec + script = command
      opts.execPath = fromPath;
      opts.script = opts.command.slice(1);
    }
    return next();
  });

  function maybeLocal() {
    var local = path.resolve(opts.command[0]);
    fs.exists(local, function(exists) {
      if (exists) {
        // exec + script = node + expanded path + args
        opts.execPath = opts.execPath || process.execPath;
        opts.script = [local].concat(opts.command.slice(1));
      } else {
        return next(new Error('Could not resolve command:', opts.command));
      }
    });
  }
}
Example #5
0
function load (npm, conf, cb) {
  which(process.argv[0], function (er, node) {
    //console.error("back from which")
    if (!er && node.toUpperCase() !== process.execPath.toUpperCase()) {
      log.verbose("node symlink", node)
      process.execPath = node
      process.installPrefix = path.resolve(node, "..", "..")
    }

    // look up configs
    //console.error("about to look up configs")

    ini.resolveConfigs(conf, function (er) {
      //console.error("back from config lookup", er && er.stack)
      if (er) return cb(er)

      var n = 2
        , errState

      loadPrefix(npm, conf, next)
      loadUid(npm, conf, next)

      function next (er) {
        //console.error("next", er && er.stack)
        if (errState) return
        if (er) return cb(errState = er)
        if (-- n <= 0) return cb()
      }
    })
  })
}
Example #6
0
 it('should match the actual path to the script file, with arguments', function (done) {
   which('node', function (err, path) {
     if (err) return done(err)
     testArgs(path.replace('Program Files (x86)', 'Progra~2')
                  .replace('Program Files', 'Progra~1') + ' bin.js', [ 'q', 'r' ], done)
   })
 })
Example #7
0
 checkSass: function () {
   var d = Q.defer();
   var name = 'sass';
   if (!this.rubyInstalled) {
     this.log(name, 'skipped', 'Skip Sass installation test.');
     return;
   }
   which('sass', function (error, p) {
     if (error) {
       this.log(
         name,
         'ng',
         'Sass is not found on your computer.',
         '1. Install Sass using gem:\n' +
         '     $ gem install sass\n' +
         '2. Set the installation directory to PATH if you haven\'t.',
         error
       );
       d.resolve();
       return;
     }
     this.log(name, 'ok', 'Sass is installed.');
     d.resolve();
   }.bind(this));
   return d.promise;
 }
Example #8
0
 return function installed(done) {
   var ctx = this;
   which(command, function(err) {
     ctx[command] = !err;
     done();
   });
 };
Example #9
0
File: cache.js Project: InfInt/npm
  fs.stat(p, function (er, s) {
    if (er) return cloneGitRemote(p, u, co, origUrl, silent, cb)
    if (!s.isDirectory()) return rm(p, function (er){
      if (er) return cb(er)
      cloneGitRemote(p, u, co, origUrl, silent, cb)
    })

    var git = npm.config.get("git")
    var args = [ "config", "--get", "remote.origin.url" ]
    var env = gitEnv()

    // check for git
    which(git, function (err) {
      if (err) {
        err.code = "ENOGIT"
        return cb(err)
      }
      exec(git, args, {cwd: p, env: env}, function (er, stdout, stderr) {
        stdoutTrimmed = (stdout + "\n" + stderr).trim()
        if (er || u !== stdout.trim()) {
          log.warn( "`git config --get remote.origin.url` returned "
                  + "wrong result ("+u+")", stdoutTrimmed )
          return rm(p, function (er){
            if (er) return cb(er)
            cloneGitRemote(p, u, co, origUrl, silent, cb)
          })
        }
        log.verbose("git remote.origin.url", stdoutTrimmed)
        archiveGitRemote(p, u, co, origUrl, cb)
      })
    })
  })
Example #10
0
module.exports = function () {

  which('electron', function (err, resolvedPath) {
    if (!resolvedPath && !process.env.ELECTRON_PATH) {
      console.error('')
      console.error('  Can not find `electron` in the $PATH and $ELECTRON_PATH is not set.')
      console.error('  Please either set $ELECTRON_PATH or run `npm i -g electron-prebuilt`.')
      console.error('')
      process.exit(1)
    }

    if (!resolvedPath) return runElectron(process.env.ELECTRON_PATH)
    if (resolvedPath) return runElectron(resolvedPath)
    if (err) console.error(err)
  })

  function runElectron(resolvedPath) {
    var args = process.argv.slice(2)
    args.unshift(path.resolve(path.join(__dirname, '../index.js')))
    var electron = spawn(resolvedPath, args, {stdio: [process.stdin, process.stdout, 'pipe']})
    electron.stderr.on('data', function (data) {
      var str = data.toString('utf8')
      // it's Chromium, STFU
      if (str.match(/^\[\d+\:\d+/)) return
      process.stderr.write(data)
    })
    electron.on('exit', function (code) {
      process.exit(code)
    })
  }


}
Example #11
0
module.exports = function (svg, opts, next, done) {
  debug('checking for convert binary')
  which('convert', function (err, path) {
    if (err) {
      debug('imagemagick is not installed')
      next()
      done()
      return
    }

    var dir = opts.dir || '.'
    debug('writing svg')
    fs.writeFileSync(dir + '/flamegraph.svg', svg)
    var background = 'black'
    var args = ['-background', background, '-trim', '-resize',
      'x460', dir + '/flamegraph.svg', dir + '/flamegraph-small.png']

    spawn('convert', args)
      .on('close', function () {
        next()
        spawn('bash', [__dirname + '/imgcat', dir + '/flamegraph-small.png'], {stdio: 'inherit'})
          .on('exit', function (code) {
            done()
          })
      })
  })
}
Example #12
0
File: cache.js Project: InfInt/npm
  mkdir(p, function (er) {
    if (er) return cb(er)

    var git = npm.config.get("git")
    var args = [ "clone", "--mirror", u, p ]
    var env = gitEnv()

    // check for git
    which(git, function (err) {
      if (err) {
        err.code = "ENOGIT"
        return cb(err)
      }
      exec(git, args, {cwd: p, env: env}, function (er, stdout, stderr) {
        stdout = (stdout + "\n" + stderr).trim()
        if (er) {
          if (silent) {
            log.verbose("git clone " + u, stdout)
          } else {
            log.error("git clone " + u, stdout)
          }
          return cb(er)
        }
        log.verbose("git clone " + u, stdout)
        archiveGitRemote(p, u, co, origUrl, cb)
      })
    })
  })
Example #13
0
NotifySend.prototype.notify = function (options, callback) {
  options = options || {};

  if (!options.message) {
    callback(new Error('Message is required.'));
    return this;
  }

  if (os.type() !== 'Linux') {
    callback(new Error('Only supported on Linux systems'));
    return this;
  }

  if (hasNotifier === false) {
    callback(new Error('notify-send must be installed on the system.'));
    return this;
  }

  if (hasNotifier || !!this.options.suppressOsdCheck) {
    doNotification(options, callback);
    return this;
  }

  which(notifier, function (err) {
    hasNotifier = !err;

    if (err) {
      return callback(err);
    }

    doNotification(options, callback);
  });
  return this;
};
Example #14
0
// PRIVATE FUNCTIONS
/**
 * Attempts to discover mysql binary and set services:mysql:binaryPath
 * @param {Function} callback
 * @return {Boolean} success
 */
function _discoverBinary(kernel, callback) {
	var which = require('which');
	
	kernel.log.info('Searching for mysqld...'.yellow);
	
	// try to detect from PATH with which
	which('mysqld', function(error, binaryPath) {
		if(binaryPath) {
			kernel.log.info('discovered mysql via which:'.green, binaryPath)
			callback(null, binaryPath);
		}
		else {
			// search common locations
			flatiron.common.async.detectSeries([
				'/usr/sbin/mysqld'
				,'/usr/local/bin/mysqld'
			], fs.exists, function(binaryPath) {
				if(binaryPath) {
					kernel.log.info('discovered mysql via scan:'.green, binaryPath)
					callback(null, binaryPath);
				}
				else {
					callback(new Error('failed to discover binary'));
				}
			});
		}
	});
}
Example #15
0
var getSubmodules = function (cb) {
  var git = npm.config.get("git")
  var args = [ "submodule", "status" ]

  // check for git
  which(git, function (err) {
    if (err) {
      err.code = "ENOGIT"
      return cb(err)
    }
    exec(git, args, function (er, stdout) {
      if (er) return cb(er)
      var res = stdout.trim().split(/\n/).map(function (line) {
        return line.trim().split(/\s+/)[1]
      }).filter(function (line) {
        // only care about submodules in the node_modules folder.
        return line && line.match(/^node_modules\//)
      }).map(function (line) {
        return line.replace(/^node_modules\//g, "")
      })

      // memoize.
      getSubmodules = function (cb) { return cb(null, res) }

      cb(null, res)
    })
  })
}
  npm.load({ cache: cache, registry: common.registry}, function () {
    which("git", function (err, git) {
      t.ifError(err, "git found on system")
      function tagExists(tag, _cb) {
        var child1 = spawn(git, ["tag", "-l", tag])
        var out = ""
        child1.stdout.on("data", function (d) {
          out += d.toString()
        })
        child1.on("exit", function () {
          return _cb(null, Boolean(~out.indexOf(tag)))
        })
      }

      var child2 = spawn(git, ["init"])
      child2.stdout.pipe(process.stdout)
      child2.on("exit", function () {
        npm.config.set("git-tag-version", false)
        npm.commands.version(["patch"], function (err) {
          if (err) return t.fail("Error perform version patch")
          var p = path.resolve(pkg, "package")
          var testPkg = require(p)
          if (testPkg.version !== "0.0.1") t.fail(testPkg.version+" !== \"0.0.1\"")
          t.equal("0.0.1", testPkg.version)
          tagExists("v0.0.1", function (err, exists) {
            t.ifError(err, "tag found to exist")
            t.equal(exists, false, "git tag DOES exist")
            t.pass("git tag does not exist")
            t.end()
          })
        })
      })
    })
  })
Example #17
0
/**
 * Use callback-style signature but toggle sync execution if `isSync` is true.
 * If options.npm is supplied, this will simply provide npm/bin/npm-cli.
 */
function whichNpm (options, fn) {
  const npmCli = options.npm && path.join(options.npm, 'bin', 'npm-cli.js')

  if (options.isSync) {
    let npmPath = null

    try {
      npmPath = fs.realpathSync(npmCli || which.sync('npm'))
    } catch (err) {
      return fn(err)
    }

    fn(null, npmPath)
    return
  }

  if (options.npm) {
    fs.realpath(npmCli, fn)
    return
  }

  which('npm', function (err, npmPath) {
    if (err) return fn(err)
    fs.realpath(npmPath, fn)
  })
}
Example #18
0
 resolveBin(moduleName, {executable:cmd}, function (error, path) {
   if (error) { // failed to find in [global/local] node_modules - fallback to PATH
     which(cmd, cb);
   } else {
     cb(null, path);
   }
 });
Example #19
0
Finder.prototype.inPath = function () {
  const done = this.plan()

  which(this.bin, (err, path) => {
    if (err) return done()
    this.found(path, 'PATH', done)
  })
}
Example #20
0
File: jest.js Project: CoericK/jest
function getWatcher(config, packageRoot, callback) {
  which(WATCHMAN_BIN, (err, resolvedPath) => {
    const watchman = !err && resolvedPath;
    const glob = config.moduleFileExtensions.map(ext => '**/*' + ext);
    const watcher = sane(packageRoot, {glob, watchman});
    callback(watcher);
  });
}
Example #21
0
    var which_helper = function(cmd, cb) {
        if(!win32 || !/optipng|jpegtran/.test(cmd)) return which(cmd, cb);

        var cmdpath = cmd === 'optipng' ? '../vendor/optipng-0.7.1-win32/optipng.exe' :
          '../vendor/jpegtran-8d/jpegtran.exe';

        cb(null, path.join(__dirname, cmdpath));
    };
Example #22
0
function getGitPath (cb) {
  var tracker = log.newItem('getGitPath', 1)
  tracker.info('getGitPath', 'Finding git in your PATH')
  which('git', function (err, path) {
    tracker.finish()
    cb(err, path)
  })
}
Example #23
0
/**
 * Validates the pathBin for the openssl command
 *
 * @private
 * @param {String} pathBin The path to OpenSSL Bin
 * @param {Function} callback Callback function with an error object
 */
function testOpenSSLPath (pathBin, callback) {
  which(pathBin, function (error) {
    if (error) {
      return callback(new Error('Could not find openssl on your system on this path: ' + pathBin))
    }
    callback()
  })
}
 problem.verify = function (args, cb) {
   which('electron', function (err, resolvedPath) {
     if (err) {
       return cb(null, false, chalk.green('{{ee.fail}}') + ' {{exercise.installing.fail}}')
     }
     cb(null, true, chalk.green('{{ee.success}}') + ' {{exercise.installing.success}}')
   })
 }
Example #25
0
 return new Promise((res, rej) => {
   whichCb(executable, (err, resolvedPath) => {
     if (err) {
       rej(err);
     } else {
       res(resolvedPath);
     }
   });
 });
Example #26
0
function checkEnv (cb) {
  which("git", function (err) {
    if (err) {
      cb(new Error("git command not found in PATH"));
    }

    cb();
  });
}
Example #27
0
 installing: function () {
   which('cnpm', (err, resolvedPath) => {
     if (err) {
       this.npmInstall()
     } else {
       this.runInstall('cnpm')
     }
   })
 }
Example #28
0
	return new Promise( function( reject, resolve ){
		which( cmd, function( err, res ){
			if( err ){ reject( err ); }

			config.set( 'cmd:' + cmd, res );

			resolve();
		} );
	} );
Example #29
0
 function (next) {
   which(opts.start.bin, function (err, p) {
     if (err) return next(err);
     service.plist.ProgramArguments.push(p)
     opts.start.args.forEach(function (arg) {
       service.plist.ProgramArguments.push(arg)
     });
     next();
   })
 },
Example #30
0
  grunt.registerHelper('which', function(cmd, cb) {
    if ( !win32 || !/optipng|jpegtran/.test( cmd ) ) {
      return which( cmd, cb );
    }

    var cmdpath = cmd === 'optipng' ? '../vendor/optipng-0.7.1-win32/optipng.exe' :
      '../vendor/jpegtran-8d/jpegtran.exe';

    cb(null, path.join(__dirname, cmdpath));
  });