index.js
function(name) {
  // Walk up the module call tree until we find a module containing name in its peerOptionalDependencies
  var currentModule = module;
  var found = false;
  while (currentModule) {
    // Check currentModule has a package.json
    location = currentModule.filename;
    var location = find_package_json(location)
    if (!location) {
      currentModule = get_parent_module(currentModule);
      continue;
    }

    // Read the package.json file
    var object = JSON.parse(fs.readFileSync(f('%s/package.json', location)));
    // Is the name defined by interal file references
    var parts = name.split(/\//);

    // Check whether this package.json contains peerOptionalDependencies containing the name we're searching for
    if (!object.peerOptionalDependencies || (object.peerOptionalDependencies && !object.peerOptionalDependencies[parts[0]])) {
      currentModule = get_parent_module(currentModule);
      continue;
    }
    found = true;
    break;
  }

  // Check whether name has been found in currentModule's peerOptionalDependencies
  if (!found) {
    throw new Error(f('no optional dependency [%s] defined in peerOptionalDependencies in any package.json', parts[0]));
  }

  return {
    object: object,
    parts: parts
  }
}
function(name) {
  // Walk up the module call tree until we find a module containing name in its peerOptionalDependencies
  var currentModule = module;
  var found = false;
  while (currentModule) {
    // Check currentModule has a package.json
    location = currentModule.filename;
    var location = find_package_json(location)
    if (!location) {
      currentModule = get_parent_module(currentModule);
      continue;
    }

    // Read the package.json file
    var object = JSON.parse(fs.readFileSync(f('%s/package.json', location)));
    // Is the name defined by interal file references
    var parts = name.split(/\//);

    // Check whether this package.json contains peerOptionalDependencies containing the name we're searching for
    if (!object.peerOptionalDependencies || (object.peerOptionalDependencies && !object.peerOptionalDependencies[parts[0]])) {
      currentModule = get_parent_module(currentModule);
      continue;
    }
    found = true;
    break;
  }

  // Check whether name has been found in currentModule's peerOptionalDependencies
  if (!found) {
    throw new Error(f('no optional dependency [%s] defined in peerOptionalDependencies in any package.json', parts[0]));
  }

  return {
    object: object,
    parts: parts
  }
}
function ( name ) { // Walk up the module call tree until we find a module containing name in its peerOptionalDependencies var currentModule = module ; var found = false ; while ( currentModule ) { // Check currentModule has a package.json location = currentModule . filename ; var location = find_package_json ( location ) if ( ! location ) { currentModule = get_parent_module ( currentModule ) ; continue ; } // Read the package.json file var object = JSON . parse ( fs . readFileSync ( f ( '%s/package.json' , location ) ) ) ; // Is the name defined by interal file references var parts = name . split ( / \/ / ) ; // Check whether this package.json contains peerOptionalDependencies containing the name we're searching for if ( ! object . peerOptionalDependencies || ( object . peerOptionalDependencies && ! object . peerOptionalDependencies [ parts [ 0 ] ] ) ) { currentModule = get_parent_module ( currentModule ) ; continue ; } found = true ; break ; } // Check whether name has been found in currentModule's peerOptionalDependencies if ( ! found ) { throw new Error ( f ( 'no optional dependency [%s] defined in peerOptionalDependencies in any package.json' , parts [ 0 ] ) ) ; } return { object : object , parts : parts } }
Find the package.json object of the module closest up the module call tree that contains name in that module's peerOptionalDependencies
Find the package . json object of the module closest up the module call tree that contains name in that module s peerOptionalDependencies