An asynchronous and configurable implementation of require.resolve(), like node-resolve or enhanced-resolve.
CoffeeScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bench
lib
src
test
.gitignore
.npmignore
.travis.yml
Benchmarking.md
Cakefile
History.md
LICENSE
README.md
package.json

README.md

Build Status Dependency Status

async-resolve

This module a fastest async and configurable requre.resolve() implementation.

Installation

$ npm install async-resolve

Usage

Resolve absolute path for given [file|directory|module] in given basedir in asynchronous manner.

var Resolver = require('async-resolve');
var resolver_obj = new Resolver();
resolver_obj.resolve('module', __dirname, function(err, filename) {
  return console.log(filename);
});

Methods

var Resolver = require('async-resolve');

new Resolver(opts)

The resolver object may be configured on creation time:

options = {
  // default: ['.js', '.json', '.node'] - specify allowed filetypes, note that the
  // order matters. in this example index.js is prioritized over index.coffee
  extensions: ['.js', '.coffee', '.eco'],
  // default : false - make searching verbose for debug and tests
  log: true
  // default : 'node_modules' - its 'node_modules' directory names, may be changed
  modules : 'other_modules'
};
resolver_obj = new Resolver(options);

resolve(pkg, basedir, cb)

Resolve pkg in basedir on node.js-based algorithm

resolver_obj.resolve('module', __dirname, function(err, filename) {
  return console.log(filename);
});

addExtensions(exts)

also resolver object may be configured after creation:

resolver_obj.addExtensions('.jade');

getState()

All options may be inspected (for testing and debug):

resolver_obj.getState();
/*
{
  log: true,
  modules : 'other_modules',
  extensions: [ '.js', '.coffee', '.eco', '.jade' ],
  dir_load_steps: [
   'package.json',
   'index.js',
   'index.coffee',
   'index.eco',
   'index.jade' 
   ] 
}
*/

isCoreModule()

Return true if filename is node.js core module or false otherwise.

resolver_obj.isCoreModule('util'); // -> true

This method use internal module names table for fast lookup, not IO.

Similar modules

Test

$ cake test

Benchmark

In short async-resolve 2.4 times as fast as enhanced-resolve.

My benchmark results.

Build you own in 2 steps:

  1. do $ npm install at root module folder
  2. run $ coffee ./bench/async-resolve_vs_other.coffee from root module folder

License

Copyright (c) 2013 Dmitrii Karpich

MIT (https://raw.github.com/Meettya/async-resolve/master/LICENSE)