<commit_before>(function () {
  "use strict";

  var fs = require('fs')
    , getFile = require('./get-file').getFile
    , endsWithJs = /\.js$/
    ;

  function getScript(pkg, pathname, callback) {
    var paths
      , name
      , moduleRoot = pkg.moduleRoot
      , main = 'index.js' // can't use package.json.main for everything
      ;

    function onFileRead(err, data) {
      if (err) {
        console.error('[ERROR (getScript)] :', pathname);
        callback(err);
        return;
      }

      callback(null, paths.join('/'), name, data.toString('utf8'));
    }

    function onDirRead(err, nodes) {
      if (err) {
        callback(new Error("Couldn't find \"" + moduleRoot + '/' + paths.join('/') + "\""));
        return;
      }

      if (-1 !== nodes.indexOf(name)) {
        if (endsWithJs.exec(name)) {
          // probably a file
          getFile(moduleRoot + '/' + pathname, onFileRead);
        } else {
          // probably a directory
          paths.push(name);
          name = main;
          getFile(moduleRoot + '/' + pathname + '/' + main, onFileRead);
        }
      } else if (-1 !== nodes.indexOf(name + '.js')) {
        // probably a file
        name += '.js';
        getFile(moduleRoot + '/' + pathname + '.js', onFileRead);
      } else {
        // not a directory nor a file
        // probably doesn't exist
        callback(new Error("Couldn't find \"" + pathname + "\""));
      }
    }

    paths = pathname.split('/');
    name = paths.pop();
    
    fs.readdir(moduleRoot + '/' + paths.join('/'), onDirRead);
  }

  module.exports.getScript = getScript;
}());<commit_msg>Fixed bug where directory foo was preferred over file foo.js in the same directory<commit_after>(function () {
  "use strict";

  var fs = require('fs')
    , getFile = require('./get-file').getFile
    , endsWithJs = /\.js$/
    ;

  function getScript(pkg, pathname, callback) {
    var paths
      , name
      , moduleRoot = pkg.moduleRoot
      , main = 'index.js' // can't use package.json.main for everything
      ;

    function onFileRead(err, data) {
      if (err) {
        console.error('[ERROR (getScript)] :', pathname);
        callback(err);
        return;
      }

      callback(null, paths.join('/'), name, data.toString('utf8'));
    }

    function onDirRead(err, nodes) {
      if (err) {
        callback(new Error("Couldn't find \"" + moduleRoot + '/' + paths.join('/') + "\""));
        return;
      }

      if (-1 !== nodes.indexOf(name + '.js')) {
        // probably a file
        name += '.js';
        getFile(moduleRoot + '/' + pathname + '.js', onFileRead);
      } else if (-1 !== nodes.indexOf(name)) {
        if (endsWithJs.exec(name)) {
          // probably a file
          getFile(moduleRoot + '/' + pathname, onFileRead);
        } else {
          // probably a directory
          paths.push(name);
          name = main;
          getFile(moduleRoot + '/' + pathname + '/' + main, onFileRead);
        }
      } else {
        // not a directory nor a file
        // probably doesn't exist
        callback(new Error("Couldn't find \"" + pathname + "\""));
      }
    }

    paths = pathname.split('/');
    name = paths.pop();
    
    fs.readdir(moduleRoot + '/' + paths.join('/'), onDirRead);
  }

  module.exports.getScript = getScript;
}());
{'fraction_non_alphanumeric': 0.1704238052299369, 'fraction_numerical': 0.0018034265103697023, 'mean_word_length': 1.93215859030837, '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': '3346226', 'n_tokens_mistral': 1040, 'n_tokens_neox': 1009, 'n_words': 233}