<commit_before>resourcePath = OSX.NSBundle.mainBundle.resourcePath

paths = [
  "/Users/chris/Code/Atomicity/src",
  "/Users/chris/Code/Atomicity/plugins",

  "#{resourcePath}/src",
  "#{resourcePath}/plugins",
  "#{resourcePath}/vendor"
]

require = (file) ->
  file  = resolve file
  parts = file.split '.'
  ext   = parts[parts.length-1]

  return __modules[file] if __modules[file]?

  __modules[file] = {} # Fix for circular references
  __modules[file] = (exts[ext] or (file) -> __read file) file
  __modules[file]

defines = []
define  = (cb) ->
  defines.push ->
    exports = {}
    module = exports: exports
    cb.call exports, require, exports, module
    module.exports or exports

exts =
  js: (file, code) ->
    code or= __read file

    if not /define\(/.test code
      code = """
        define(function(require, exports, module) {
          #{code};
        });
      """
    __jsc__.evalJSString_withScriptPath code, file
    defines.pop()?.call()
  coffee: (file) ->
    exts.js file, CoffeeScript.compile __read file

resolve = (file) ->
  if /!/.test file
    parts = file.split '!'
    file = parts[parts.length-1]

  if file[0] is '~'
    file = OSX.NSString.stringWithString(file)
      .stringByExpandingTildeInPath.toString()

  if file[0..1] is './'
    throw "require: ./ prefix not yet implemented"

  if file[0..2] is '../'
    throw "require: ../ prefix not yet implemented"

  if file[0] isnt '/'
    # I want to use _.detect, but we don't have that at this point
    # or break would do, but coffeescript doesn't have that
    expandedPath = null
    paths.forEach (path) ->
      if /\.(.+)$/.test(file) and __exists "#{path}/#{file}"
        expandedPath ?= "#{path}/#{file}"
      else
        expandedPath ?= expandPath("#{path}/#{file}")

      file = expandedPath if expandedPath?
  else
    file = expandPath(file) or file

  if file[0] isnt '/'
    throw "require: Can't find '#{file}'"

  return file

expandPath = (path) ->
  for ext, handler of exts<commit_msg>use Array.prototype.some where corey wanted to use _.detect<commit_after>resourcePath = OSX.NSBundle.mainBundle.resourcePath

paths = [
  "/Users/chris/Code/Atomicity/src",
  "/Users/chris/Code/Atomicity/plugins",

  "#{resourcePath}/src",
  "#{resourcePath}/plugins",
  "#{resourcePath}/vendor"
]

require = (file) ->
  file  = resolve file
  parts = file.split '.'
  ext   = parts[parts.length-1]

  return __modules[file] if __modules[file]?

  __modules[file] = {} # Fix for circular references
  __modules[file] = (exts[ext] or (file) -> __read file) file
  __modules[file]

defines = []
define  = (cb) ->
  defines.push ->
    exports = {}
    module = exports: exports
    cb.call exports, require, exports, module
    module.exports or exports

exts =
  js: (file, code) ->
    code or= __read file

    if not /define\(/.test code
      code = """
        define(function(require, exports, module) {
          #{code};
        });
      """
    __jsc__.evalJSString_withScriptPath code, file
    defines.pop()?.call()
  coffee: (file) ->
    exts.js file, CoffeeScript.compile __read file

resolve = (file) ->
  if /!/.test file
    parts = file.split '!'
    file = parts[parts.length-1]

  if file[0] is '~'
    file = OSX.NSString.stringWithString(file)
      .stringByExpandingTildeInPath.toString()

  if file[0..1] is './'
    throw "require: ./ prefix not yet implemented"

  if file[0..2] is '../'
    throw "require: ../ prefix not yet implemented"

  if file[0] isnt '/'
    paths.some (path) ->
      if /\.(.+)$/.test(file) and __exists "#{path}/#{file}"
        file = "#{path}/#{file}"
      else if expanded = expandPath "#{path}/#{file}"
        file = expanded
  else
    file = expandPath(file) or file

  if file[0] isnt '/'
    throw "require: Can't find '#{file}'"

  return file

expandPath = (path) ->
  for ext, handler of exts
{'fraction_non_alphanumeric': 0.15563598759048605, 'fraction_numerical': 0.004653567735263702, 'mean_word_length': 2.749031007751938, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '6467564', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1299, 'n_words': 334}