<commit_before>/**
 * Installs and caches modules from npm.
 *
 * @copyright
 * Copyright (c) 2015 by Appcelerator, Inc. All Rights Reserved.
 *
 * @license
 * Licensed under the terms of the Apache Public License.
 * Please see the LICENSE included with this distribution for details.
 */

'use strict';

module.exports.install = install;

var async = require('async');
var fs = require('fs-extra');
var npm = require('npm');
var path = require('path');
var pluralize = require('pluralize');
var Promise = Promise || require('q').Promise;
var semver = require('semver');
var tmp = require('tmp');

/**
 * Installs a module from npm and caches it.
 *
 * @param {object} [opts] - Various options.
 * @param {boolean} [opts.allowShrinkwrap] - When true, tells npm to honor shrinkwrap settings.
 * @param {string} [opts.cacheDir=~/.npm-fast-install] - The directory to cache modules.
 * @param {string} [opts.dir=`cwd`] - The directory containing the package.json.
 * @param {stream} [opts.logger] - A logger to use such as `console`.
 * @param {number} [opts.maxTasks=5] - The maximum number of npm install jobs to run simultaneously.
 * @param {boolean} [opts.production] - When true, installs only dependencies, not dev dependencies.
 *
 * @returns {Promise} A promise object
 */
function install(opts) {
	return (new Promise(function (fulfill, reject) {
		if (!opts || typeof opts !== 'object') {
			opts = {};
		}

		// check directory
		var dir = resolvePath(opts.dir || process.cwd());
		if (!fs.existsSync(dir)) {
			return reject(new Error('Invalid directory: ' + dir));
		}

		// init logger
		var logger = opts.logger && typeof opts.logger === 'object' ? opts.logger : {};
		['log', 'debug', 'info', 'warn', 'error'].forEach(function (lvl) { typeof logger[lvl] === 'function' || (logger[lvl] = function () {}); });

		var modulesAPI = parseInt(process.versions.modules) || (function (m) {
			return !m || m[1] === '0.8' ? 1 : m[1] === '0.10' ? 11 : m[1] === '0.11' && m[2] < 8 ? 12 : 13;
		}(process.version.match(/^v(\d+\.\d+)\.(\d+)$/)));

		logger.info('Node.js version: %s', process.version);
		logger.info('Architecture:    %s', process.arch);
		logger.info('Module version:  %s', modulesAPI);
		logger.info('npm version:     %s', npm.version + '\n');

		// load the package.json
		var pkgJsonFile = path.join(dir, 'package.json');
		if (!fs.existsSync(pkgJsonFile)) {
			return reject(new Error('No package.json found'));
		}
		logger.info('Loading package.json: %s', pkgJsonFile);

		var pkgJson = require(pkgJsonFile);
		var deps = pkgJson.dependencies && typeof pkgJson.dependencies === 'object' ? Object.keys(pkgJson.dependencies).map(function (dep) {
			return { name: dep, ver: pkgJson.dependencies[dep] };
		}) : [];
		var results = {<commit_msg>New options.dependencies field.<commit_after>/**
 * Installs and caches modules from npm.
 *
 * @copyright
 * Copyright (c) 2015 by Appcelerator, Inc. All Rights Reserved.
 *
 * @license
 * Licensed under the terms of the Apache Public License.
 * Please see the LICENSE included with this distribution for details.
 */

'use strict';

module.exports.install = install;

var async = require('async');
var fs = require('fs-extra');
var npm = require('npm');
var path = require('path');
var pluralize = require('pluralize');
var Promise = Promise || require('q').Promise;
var semver = require('semver');
var tmp = require('tmp');

/**
 * Installs a module from npm and caches it.
 *
 * @param {object} [opts] - Various options.
 * @param {boolean} [opts.allowShrinkwrap] - When true, tells npm to honor shrinkwrap settings.
 * @param {string} [opts.cacheDir=~/.npm-fast-install] - The directory to cache modules.
 * @param {string} [opts.dir=`cwd`] - The directory containing the package.json.
 * @param {stream} [opts.logger] - A logger to use such as `console`.
 * @param {number} [opts.maxTasks=5] - The maximum number of npm install jobs to run simultaneously.
 * @param {boolean} [opts.production] - When true, installs only dependencies, not dev dependencies.
 *
 * @returns {Promise} A promise object
 */
function install(opts) {
	return (new Promise(function (fulfill, reject) {
		if (!opts || typeof opts !== 'object') {
			opts = {};
		}

		// check directory
		var dir = resolvePath(opts.dir || process.cwd());
		if (!fs.existsSync(dir)) {
			return reject(new Error('Invalid directory: ' + dir));
		}

		// init logger
		var logger = opts.logger && typeof opts.logger === 'object' ? opts.logger : {};
		['log', 'debug', 'info', 'warn', 'error'].forEach(function (lvl) { typeof logger[lvl] === 'function' || (logger[lvl] = function () {}); });

		var modulesAPI = parseInt(process.versions.modules) || (function (m) {
			return !m || m[1] === '0.8' ? 1 : m[1] === '0.10' ? 11 : m[1] === '0.11' && m[2] < 8 ? 12 : 13;
		}(process.version.match(/^v(\d+\.\d+)\.(\d+)$/)));

		logger.info('Node.js version: %s', process.version);
		logger.info('Architecture:    %s', process.arch);
		logger.info('Module version:  %s', modulesAPI);
		logger.info('npm version:     %s', npm.version + '\n');

		var deps = [];
		
		if (opts.dependencies) {
			deps = Object.keys(opts.dependencies).map(function (dep) {
				return { name: dep, ver: opts.dependencies[dep] };
			});
		} else {
			// load the package.json
			var pkgJsonFile = path.join(dir, 'package.json');
			if (!opts.dependencies) {
				if (!fs.existsSync(pkgJsonFile)) {
					return reject(new Error('No package.json found'));
				}
				logger.info('Loading package.json: %s', pkgJsonFile);
			}
			var pkgJson = require(pkgJsonFile);
			if (pkgJson.dependencies && typeof pkgJson.dependencies === 'object') {
				deps = Object.keys(pkgJson.dependencies).map(function (dep) {
					return { name: dep, ver: pkgJson.dependencies[dep] };
				});
			}
		}
		var results = {
{'fraction_non_alphanumeric': 0.1766229281767956, 'fraction_numerical': 0.008632596685082873, 'mean_word_length': 3.8315262718932446, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3531936', 'n_tokens_mistral': 2013, 'n_tokens_neox': 1818, 'n_words': 543}