<commit_before>import {autoinject} from 'aurelia-framework';
import {NPMAPI}     from '../../shared/npm-api';
import {FS, NPM}    from 'monterey-pal';
import * as semver  from 'semver';

@autoinject()
export class Analyzer {
  constructor(private npmAPI: NPMAPI) {
  }

  async analyze(project) {
    let packageJSON = JSON.parse(await FS.readFile(project.packageJSONPath));
    let deps = Object.assign({}, packageJSON.dependencies, packageJSON.devDependencies);
    let topLevelDependencies = [];

    // normalize data for the grid
    let keys = Object.keys(deps);
    for (let i = 0; i < keys.length; i++) {
      let key = keys[i];
      let dep = deps[key];

      topLevelDependencies.push({
        name: key,
        range: deps[key]
      });
    }

    return topLevelDependencies;
  }

  async lookupInstalledVersions(project, topLevelDependencies) {
    let tree: string = await NPM.ls({ workingDirectory: FS.getFolderPath(project.packageJSONPath) });
    let lines = tree.split('\n');
    let deps = [];
    // remove first line of tree (we already know what package it is)
    lines = lines.splice(1, lines.length);
    for (let i = 0; i < lines.length; i++) {
      let line = lines[i];
      line = line.replace('├── ', '');
      deps.push({
        name: line.split('@')[0],
        version: line.split('@')[1],
      });
    }

    deps.forEach(dep => {
      let tld = topLevelDependencies.find(x => x.name === dep.name);
      if (tld) {
        tld.version = dep.version;
      }
    });
  }

  getLatestVersions(dependencies) {
    dependencies.forEach(dep => {
      this.npmAPI.getLatest(dep.name)
      .then(version => dep.latest = version)
      .catch((e) => {});
    });
  }

  async checkIfUpToDate(m) {
    // can't determine whether a dep is out of date when
    // there is no version or latest version known<commit_msg>fix(npm): use json npm ls output<commit_after>import {autoinject} from 'aurelia-framework';
import {NPMAPI}     from '../../shared/npm-api';
import {FS, NPM}    from 'monterey-pal';
import * as semver  from 'semver';

@autoinject()
export class Analyzer {
  constructor(private npmAPI: NPMAPI) {
  }

  async analyze(project) {
    let packageJSON = JSON.parse(await FS.readFile(project.packageJSONPath));
    let deps = Object.assign({}, packageJSON.dependencies, packageJSON.devDependencies);
    let topLevelDependencies = [];

    // normalize data for the grid
    let keys = Object.keys(deps);
    for (let i = 0; i < keys.length; i++) {
      let key = keys[i];
      let dep = deps[key];

      topLevelDependencies.push({
        name: key,
        range: deps[key]
      });
    }

    return topLevelDependencies;
  }

  async lookupInstalledVersions(project, topLevelDependencies) {
    let deps = await NPM.ls({ workingDirectory: FS.getFolderPath(project.packageJSONPath) });

    let keys = Object.keys(deps.dependencies);
    for(let i = 0; i < keys.length; i++) {
      let key = keys[i];
      let dep = deps.dependencies[key];
      let tld = topLevelDependencies.find(x => x.name === key);
      if (tld) {
        tld.version = dep.version;
        tld.missing = dep.missing;
      }
    }
  }

  getLatestVersions(dependencies) {
    dependencies.forEach(dep => {
      this.npmAPI.getLatest(dep.name)
      .then(version => dep.latest = version)
      .catch((e) => {});
    });
  }

  async checkIfUpToDate(m) {
    // can't determine whether a dep is out of date when
    // there is no version or latest version known
{'fraction_non_alphanumeric': 0.14065180102915953, 'fraction_numerical': 0.002001143510577473, 'mean_word_length': 2.754291845493562, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, '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': '4127997', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1106, 'n_words': 282}