function perform_require(reqfunc, plugin_desc, builtin, level) {
  var search_list = plugin_desc.search
  var initfunc, search

  next_search_entry: for (var i = 0; i < search_list.length; i++) {
    search = search_list[i]

    // only load builtins if builtin flag true
    if (!builtin && 'builtin' == search.type) continue

    if (0 === level && 'builtin' != search.type && search.name.match(/^[./]/))
      continue

    try {
      // NOTE: Unfortunately module.require does not expose require.resolve
      if (reqfunc.resolve) {
        search.path = reqfunc.resolve(search.name)
      }

      var history_entry = {
        module: reqfunc.module,
        path: search.path,
        name: search.name,
      }
      plugin_desc.history.push(history_entry)

      initfunc = reqfunc(search.name)

      // Found it!
      break
    } catch (e) {
      if ('MODULE_NOT_FOUND' == e.code) {
        // TODO: this fails if a sub file of the plugin module fails,
        // as the module name is within the file path
        // E.g. seneca-entity/lib/common.js

        // A require failed inside the plugin.
        if (-1 == e.message.indexOf(search.name)) {
          return { error: e, found: search }
        }

        // Plain old not found, so continue searching.
        continue next_search_entry
      } else {
        // The require failed for some other reason.
        return { error: e, found: search }
      }
    }
  }

  // Return the init function, and a description of where we found it.
  return {
    initfunc: initfunc,
    module: reqfunc.module,
    require: search.name,
    path: search.path,
    found: search,
  }
}
// #### Iterate over all the search items using the provided require function
Iterate over all the search items using the provided require function
Iterate over all the search items using the provided require function
function perform_require(reqfunc, plugin_desc, builtin, level) {
  var search_list = plugin_desc.search
  var initfunc, search
  next_search_entry: for (var i = 0; i < search_list.length; i++) {
    search = search_list[i]
    if (!builtin && 'builtin' == search.type) continue
    if (0 === level && 'builtin' != search.type && search.name.match(/^[./]/))
      continue
    try {
      if (reqfunc.resolve) {
        search.path = reqfunc.resolve(search.name)
      }
      var history_entry = {
        module: reqfunc.module,
        path: search.path,
        name: search.name,
      }
      plugin_desc.history.push(history_entry)
      initfunc = reqfunc(search.name)
      break
    } catch (e) {
      if ('MODULE_NOT_FOUND' == e.code) {
        if (-1 == e.message.indexOf(search.name)) {
          return { error: e, found: search }
        }
        continue next_search_entry
      } else {
        return { error: e, found: search }
      }
    }
  }
  return {
    initfunc: initfunc,
    module: reqfunc.module,
    require: search.name,
    path: search.path,
    found: search,
  }
}
function perform_require ( reqfunc , plugin_desc , builtin , level ) { var search_list = plugin_desc . search var initfunc , search next_search_entry : for ( var i = 0 ; i < search_list . length ; i ++ ) { search = search_list [ i ] if ( ! builtin && 'builtin' == search . type ) continue if ( 0 === level && 'builtin' != search . type && search . name . match ( / ^[./] / ) ) continue try { if ( reqfunc . resolve ) { search . path = reqfunc . resolve ( search . name ) } var history_entry = { module : reqfunc . module , path : search . path , name : search . name , } plugin_desc . history . push ( history_entry ) initfunc = reqfunc ( search . name ) break } catch ( e ) { if ( 'MODULE_NOT_FOUND' == e . code ) { if ( - 1 == e . message . indexOf ( search . name ) ) { return { error : e , found : search } } continue next_search_entry } else { return { error : e , found : search } } } } return { initfunc : initfunc , module : reqfunc . module , require : search . name , path : search . path , found : search , } }
Iterate over all the search items using the provided require function
Iterate over all the search items using the provided require function
// only load builtins if builtin flag true // NOTE: Unfortunately module.require does not expose require.resolve // Found it! // TODO: this fails if a sub file of the plugin module fails, // as the module name is within the file path // E.g. seneca-entity/lib/common.js // A require failed inside the plugin. // Plain old not found, so continue searching. // The require failed for some other reason. // Return the init function, and a description of where we found it.