<commit_before>fs = require 'fs'

module.exports =
class Package
  @resolve: (name) ->
    path = require.resolve(name, verifyExistence: false)
    return path if path
    throw new Error("No package found named '#{name}'")

  @build: (name) ->
    TextMatePackage = require 'text-mate-package'
    AtomPackage = require 'atom-package'
    if TextMatePackage.testName(name)
      new TextMatePackage(name)
    else
      if fs.isDirectory(@resolve(name))
        new AtomPackage(name)
      else
        try
          PackageClass = require name
          new PackageClass(name) if typeof PackageClass is 'function'
        catch e
          console.warn "Failed to load package named '#{name}'", e.stack

  name: null
  path: null
  isDirectory: false
  module: null<commit_msg>Don't directly require packages with manifests<commit_after>fs = require 'fs'
_ = require 'underscore'

module.exports =
class Package
  @resolve: (name) ->
    path = require.resolve(name, verifyExistence: false)
    return path if path
    throw new Error("No package found named '#{name}'")

  @build: (name) ->
    TextMatePackage = require 'text-mate-package'
    AtomPackage = require 'atom-package'

    path = @resolve(name)
    newStylePackage = _.find fs.list(path), (filePath) =>
      /package\.[cj]son$/.test filePath

    if TextMatePackage.testName(name)
      new TextMatePackage(name)
    else
      if newStylePackage or fs.isDirectory(path)
        new AtomPackage(name)
      else
        try
          PackageClass = require name
          new PackageClass(name) if typeof PackageClass is 'function'
        catch e
          console.warn "Failed to load package named '#{name}'", e.stack

  name: null
  path: null
  isDirectory: false
  module: null
{'fraction_non_alphanumeric': 0.09994288977727013, 'fraction_numerical': 0.0, 'mean_word_length': 2.8761061946902653, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '884210', 'n_tokens_mistral': 519, 'n_tokens_neox': 508, 'n_words': 156}