<commit_before>/*
 *   Copyright 2014-2015 <NAME> (http://guybedford.com)
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

require('core-js/es6/string');

var config = require('./config');
var Promise = require('rsvp').Promise;
var asp = require('rsvp').denodeify;
var pkg = require('./package');
var semver = require('./semver');
var PackageName = require('./config/package-name');
var ui = require('./ui');
var path = require('path');
var link = require('./link');
var globalConfig = require('./global-config');

var rimraf = require('rimraf');

var readJSON = require('./common').readJSON;
var alphabetize = require('./common').alphabetize;
var hasProperties = require('./common').hasProperties;

var fs = require('graceful-fs');

var primaryRanges = {};
var secondaryRanges = {};

var installedResolves = {};
var installingResolves = {};

var installed;
var installing = {
  baseMap: {},
  depMap: {}
};

var errorMessages = {
  'implicit-install': 'Update does not support implicit installs.',
  'update-with-version': 'Update does not support explicit version ranges.'
};

// NB remove assertions for release
// function assert(statement, name) {
//  if (!statement)
//    throw new TypeError('Assertion Failed: ' + name);
// }

/*
 * Main install API wrapper
 *
 * install('jquery')
 * install('jquery', {options})
 * install('jquery', 'github:components/jquery')
 * install('jquery', 'github:components/jquery', {options})
 * install(true) - from package.json
 * install(true, {options}) - from package.json
 *
 * options.force - skip cache
 * options.inject
 * options.link means symlink linked versions in ranges to jspm_packages where available
 * options.lock - lock existing tree dependencies
 * options.latest - new install tree has all deps installed to latest - no rollback deduping
 * options.unlink
 * options.quick - lock and skip hash checks
 * options.dev - store in devDependencies
 *
 * options.summary - show fork and resolution summary
 */
exports.install = function(targets, options) {
  if (typeof targets === 'string') {
    var name = targets;
    targets = {};
    targets[name] = typeof options === 'string' ? options : '';
    options = typeof options === 'object' ? options : arguments[2];
  }
  options = options || {};

  return config.load()
  .then(function() {
    var error;
    installed = installed || config.loader;

    if (options.force)
      config.force = true;

    if (options.link || options.quick)
      options.lock = true;

    var k, defaultTargets = {};
    for (k in config.pjson.devDependencies)
      defaultTargets[k] = config.pjson.devDependencies[k];
    for (k in config.pjson.dependencies)
      defaultTargets[k] = config.pjson.dependencies[k];

    if (targets === true)
      targets = defaultTargets;
    else if (targets && options.doUpdate)
      Object.keys(targets).forEach(function(module) {
        var target = targets[module];
        var configured = defaultTargets[module];
        if (!configured || target) {
          var moduleExpr = target ? module + '@' + target : module;
          error = configured ? 'update-with-version' : 'implicit-install';
          ui.log('warn', 'Did you mean `jspm install ' + moduleExpr + '`?');
        }
        targets[module] = configured || '';
      });

    if (error) {
      ui.log('err', errorMessages[error]);<commit_msg>Avoid generating nonsensical "did you mean" suggestions<commit_after>/*
 *   Copyright 2014-2015 <NAME> (http://guybedford.com)
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

require('core-js/es6/string');

var config = require('./config');
var Promise = require('rsvp').Promise;
var asp = require('rsvp').denodeify;
var pkg = require('./package');
var semver = require('./semver');
var PackageName = require('./config/package-name');
var ui = require('./ui');
var path = require('path');
var link = require('./link');
var globalConfig = require('./global-config');

var rimraf = require('rimraf');

var readJSON = require('./common').readJSON;
var alphabetize = require('./common').alphabetize;
var hasProperties = require('./common').hasProperties;

var fs = require('graceful-fs');

var primaryRanges = {};
var secondaryRanges = {};

var installedResolves = {};
var installingResolves = {};

var installed;
var installing = {
  baseMap: {},
  depMap: {}
};

var errorMessages = {
  'implicit-install': 'Update does not support implicit installs.',
  'update-with-version': 'Update does not support explicit version ranges.'
};

// NB remove assertions for release
// function assert(statement, name) {
//  if (!statement)
//    throw new TypeError('Assertion Failed: ' + name);
// }

/*
 * Main install API wrapper
 *
 * install('jquery')
 * install('jquery', {options})
 * install('jquery', 'github:components/jquery')
 * install('jquery', 'github:components/jquery', {options})
 * install(true) - from package.json
 * install(true, {options}) - from package.json
 *
 * options.force - skip cache
 * options.inject
 * options.link means symlink linked versions in ranges to jspm_packages where available
 * options.lock - lock existing tree dependencies
 * options.latest - new install tree has all deps installed to latest - no rollback deduping
 * options.unlink
 * options.quick - lock and skip hash checks
 * options.dev - store in devDependencies
 *
 * options.summary - show fork and resolution summary
 */
exports.install = function(targets, options) {
  if (typeof targets === 'string') {
    var name = targets;
    targets = {};
    targets[name] = typeof options === 'string' ? options : '';
    options = typeof options === 'object' ? options : arguments[2];
  }
  options = options || {};

  return config.load()
  .then(function() {
    var error;
    installed = installed || config.loader;

    if (options.force)
      config.force = true;

    if (options.link || options.quick)
      options.lock = true;

    var k, defaultTargets = {};
    for (k in config.pjson.devDependencies)
      defaultTargets[k] = config.pjson.devDependencies[k];
    for (k in config.pjson.dependencies)
      defaultTargets[k] = config.pjson.dependencies[k];

    if (targets === true)
      targets = defaultTargets;
    else if (targets && options.doUpdate)
      Object.keys(targets).forEach(function(module) {
        var target = targets[module];
        var targetIsVersion = target.indexOf(':') === -1;
        var configured = defaultTargets[module];
        if (!configured || targetIsVersion) {
          var moduleExpr = targetIsVersion ? module + '@' + target : module;
          error = configured ? 'update-with-version' : 'implicit-install';
          ui.log('warn', 'Did you mean `jspm install ' + moduleExpr + '`?');
        }
        targets[module] = configured || '';
      });

    if (error) {
      ui.log('err', errorMessages[error]);
{'fraction_non_alphanumeric': 0.13850063532401524, 'fraction_numerical': 0.003684879288437103, 'mean_word_length': 3.479795105293113, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4067410', 'n_tokens_mistral': 2225, 'n_tokens_neox': 2170, 'n_words': 693}