<commit_before>'use strict'

import majorVersions from 'major-versions'
import array from 'ensure-array'
import npm from 'npm'
import npmSpawn from 'spawn-npm-install'
import {promisify, promisifyAll} from 'bluebird'
import {resolve} from 'path'
import assert from 'assert'
import {partial} from 'ap'
import {EventEmitter} from 'events'
import defaults from 'defaults'

promisifyAll(npmSpawn)

export class Runner extends EventEmitter {
  constructor (name, range, options = {}) {
    super()
    assert(name, 'Peer name must be defined')
    assert(range, 'Peer range must be defined')
    defaults(options, {
      script: 'test-main',
      bail: true
    })
    Object.assign(this, {name, range, options})
  }
  versions () {
    return promisify(npm.commands.view)([this.name, 'dist-tags.latest'], true)
      .then(v => majorVersions(this.range, v))
      .tap((versions) => this.emit('versions', versions))
  }
  install (version = '') {
    this.emit('preinstall', version)
    return npmSpawn.installAsync([`${this.name}@${version}`], {
      stdio: 'inherit'
    })
    .then(() => this.emit('postinstall', version))
    .return(version)
  }
  uninstall (version) {
    this.emit('preuninstall', version)
    return promisify(npm.commands.uninstall)(this.name)
      .then(() => this.emit('postuninstall', version))
  }
  runScript (version) {<commit_msg>Resolve first object key from npm.view result<commit_after>'use strict'

import majorVersions from 'major-versions'
import array from 'ensure-array'
import npm from 'npm'
import npmSpawn from 'spawn-npm-install'
import {promisify, promisifyAll} from 'bluebird'
import {resolve} from 'path'
import assert from 'assert'
import {partial} from 'ap'
import {EventEmitter} from 'events'
import defaults from 'defaults'

promisifyAll(npmSpawn)

export class Runner extends EventEmitter {
  constructor (name, range, options = {}) {
    super()
    assert(name, 'Peer name must be defined')
    assert(range, 'Peer range must be defined')
    defaults(options, {
      script: 'test-main',
      bail: true
    })
    Object.assign(this, {name, range, options})
  }
  versions () {
    return promisify(npm.commands.view)([this.name, 'dist-tags.latest'], true)
      .then(Object.keys)
      .get(0)
      .then(v => majorVersions(this.range, v))
      .tap((versions) => this.emit('versions', versions))
  }
  install (version = '') {
    this.emit('preinstall', version)
    return npmSpawn.installAsync([`${this.name}@${version}`], {
      stdio: 'inherit'
    })
    .then(() => this.emit('postinstall', version))
    .return(version)
  }
  uninstall (version) {
    this.emit('preuninstall', version)
    return promisify(npm.commands.uninstall)(this.name)
      .then(() => this.emit('postuninstall', version))
  }
  runScript (version) {
{'fraction_non_alphanumeric': 0.14923241699393075, 'fraction_numerical': 0.0003570153516601214, 'mean_word_length': 3.941798941798942, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5848140', 'n_tokens_mistral': 898, 'n_tokens_neox': 893, 'n_words': 226}