<commit_before>import objectAssign from "object-assign";
import path from "path";
import semver from "semver";
import NpmUtilities from "./NpmUtilities";
import logger from "./logger";

export default class Package {
  constructor(pkg, location) {
    this._package = pkg;
    this._location = location;
  }

  get name() {
    return this._package.name;
  }

  get location() {
    return this._location;
  }

  get nodeModulesLocation() {
    return path.join(this._location, "node_modules");
  }

  get version() {
    return this._package.version;
  }

  set version(version) {
    this._package.version = version;
  }

  get bin() {
    return this._package.bin;
  }

  get dependencies() {
    return this._package.dependencies;
  }

  get devDependencies() {
    return this._package.devDependencies;
  }

  get peerDependencies() {
    return this._package.peerDependencies;
  }

  get allDependencies() {
    return objectAssign(
      {},
      this.devDependencies,
      this.dependencies
    );
  }

  get scripts() {
    return this._package.scripts || {};
  }

  isPrivate() {
    return !!this._package.private;
  }

  toJsonString() {
    return JSON.stringify(this._package, null, 2) + "\n";
  }

  /**
   * Run a NPM script in this package's directory
   * @param {String} script NPM script to run
   * @param {Function} callback
   */
  runScript(script, callback) {
    if (this.scripts[script]) {
      NpmUtilities.runScriptInDir(script, [], this.location, callback);
    } else {
      callback();
    }
  }

  /**
   * Determine if a dependency version satisfies the requirements of this package
   * @param {Package} dependency
   * @param {Boolean} showWarning
   * @returns {Boolean}
   */
  hasMatchingDependency(dependency, showWarning = false) {
    const expectedVersion = this.allDependencies[dependency.name];
    const actualVersion = dependency.version;

    if (!expectedVersion) {
      return false;
    }

    // check if semantic versions are compatible
    if (semver.satisfies(actualVersion, expectedVersion)) {
      return true;
    }

    if (showWarning) {
      logger.warning(
        `Version mismatch inside "${this.name}". ` +
        `Depends on "${dependency.name}@${expectedVersion}" ` +
        `instead of "${dependency.name}@${actualVersion}".`
      );
    }

    return false;
  }

  /**
   * Determine if a dependency has already been installed for this package
   * @param {String} dependency Name of the dependency
   * @returns {Boolean}
   */
  hasDependencyInstalled(dependency) {<commit_msg>Remove unused logging parameter<commit_after>import objectAssign from "object-assign";
import path from "path";
import semver from "semver";
import NpmUtilities from "./NpmUtilities";

export default class Package {
  constructor(pkg, location) {
    this._package = pkg;
    this._location = location;
  }

  get name() {
    return this._package.name;
  }

  get location() {
    return this._location;
  }

  get nodeModulesLocation() {
    return path.join(this._location, "node_modules");
  }

  get version() {
    return this._package.version;
  }

  set version(version) {
    this._package.version = version;
  }

  get bin() {
    return this._package.bin;
  }

  get dependencies() {
    return this._package.dependencies;
  }

  get devDependencies() {
    return this._package.devDependencies;
  }

  get peerDependencies() {
    return this._package.peerDependencies;
  }

  get allDependencies() {
    return objectAssign(
      {},
      this.devDependencies,
      this.dependencies
    );
  }

  get scripts() {
    return this._package.scripts || {};
  }

  isPrivate() {
    return !!this._package.private;
  }

  toJsonString() {
    return JSON.stringify(this._package, null, 2) + "\n";
  }

  /**
   * Run a NPM script in this package's directory
   * @param {String} script NPM script to run
   * @param {Function} callback
   */
  runScript(script, callback) {
    if (this.scripts[script]) {
      NpmUtilities.runScriptInDir(script, [], this.location, callback);
    } else {
      callback();
    }
  }

  /**
   * Determine if a dependency version satisfies the requirements of this package
   * @param {Package} dependency
   * @returns {Boolean}
   */
  hasMatchingDependency(dependency) {
    const expectedVersion = this.allDependencies[dependency.name];
    const actualVersion = dependency.version;

    if (!expectedVersion) {
      return false;
    }

    // check if semantic versions are compatible
    if (semver.satisfies(actualVersion, expectedVersion)) {
      return true;
    }

    return false;
  }

  /**
   * Determine if a dependency has already been installed for this package
   * @param {String} dependency Name of the dependency
   * @returns {Boolean}
   */
  hasDependencyInstalled(dependency) {
{'fraction_non_alphanumeric': 0.11538461538461539, 'fraction_numerical': 0.0004158004158004158, 'mean_word_length': 2.959670781893004, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5850460', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1374, 'n_words': 365}