async-resolve
v0.3.5
Published
An asynchronous and configurable implementation of require.resolve(), like node-resolve or enhanced-resolve.
Downloads
7
Maintainers
Readme
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:
- do
$ npm install
at root module folder - 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)