function listModulesInDirectory(modulesDir) {
  const log = debug("phantomas:modules");
  log("Getting the list of all modules in " + modulesDir);

  // https://nodejs.org/api/fs.html#fs_fs_readdirsync_path_options
  var ls = fs.readdirSync(modulesDir),
    modules = [];

  ls.forEach(function (entry) {
    // First check whether an entry is a directory, than check if it contains a module file
    // https://nodejs.org/api/fs.html#fs_fs_existssync_path
    if (fs.existsSync(modulesDir + "/" + entry + "/" + entry + ".js")) {
      modules.push(entry);
    }
  });

  return modules.sort();
}
Lists all modules / extensions in a given directory

@param {string} modulesDir
@returns {Array<string}