pax_global_header00006660000000000000000000000064121253443760014521gustar00rootroot0000000000000052 comment=790cdf5ab7c92bb146e8ace05ba0b26c5f51ffb3 node-resolve-0.3.1/000077500000000000000000000000001212534437600141245ustar00rootroot00000000000000node-resolve-0.3.1/.travis.yml000066400000000000000000000000531212534437600162330ustar00rootroot00000000000000language: node_js node_js: - 0.6 - 0.8 node-resolve-0.3.1/LICENSE000066400000000000000000000020611212534437600151300ustar00rootroot00000000000000This software is released under the MIT license: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. node-resolve-0.3.1/example/000077500000000000000000000000001212534437600155575ustar00rootroot00000000000000node-resolve-0.3.1/example/async.js000066400000000000000000000002311212534437600172260ustar00rootroot00000000000000var resolve = require('../'); resolve('tap', { basedir: __dirname }, function (err, res) { if (err) console.error(err) else console.log(res) }); node-resolve-0.3.1/example/sync.js000066400000000000000000000001471212534437600170730ustar00rootroot00000000000000var resolve = require('../'); var res = resolve.sync('tap', { basedir: __dirname }); console.log(res); node-resolve-0.3.1/index.js000066400000000000000000000003021212534437600155640ustar00rootroot00000000000000var core = require('./lib/core'); exports = module.exports = require('./lib/async'); exports.core = core; exports.isCore = function (x) { return core[x] }; exports.sync = require('./lib/sync'); node-resolve-0.3.1/lib/000077500000000000000000000000001212534437600146725ustar00rootroot00000000000000node-resolve-0.3.1/lib/async.js000066400000000000000000000105051212534437600163460ustar00rootroot00000000000000var core = require('./core'); var fs = require('fs'); var path = require('path'); module.exports = function resolve (x, opts, cb) { if (core[x]) return cb(null, x); if (typeof opts === 'function') { cb = opts; opts = {}; } if (!opts) opts = {}; var isFile = opts.isFile || function (file, cb) { fs.stat(file, function (err, stat) { if (err && err.code === 'ENOENT') cb(null, false) else if (err) cb(err) else cb(null, stat.isFile() || stat.isFIFO()) }); }; var readFile = opts.readFile || fs.readFile; var extensions = opts.extensions || [ '.js' ]; var y = opts.basedir || path.dirname(require.cache[__filename].parent.filename) ; opts.paths = opts.paths || []; if (x.match(/^(?:\.\.?\/|\/|([A-Za-z]:)?\\)/)) { loadAsFile(path.resolve(y, x), function (err, m) { if (err) cb(err) else if (m) cb(null, m) else loadAsDirectory(path.resolve(y, x), function (err, d) { if (err) cb(err) else if (d) cb(null, d) else cb(new Error("Cannot find module '" + x + "'")) }) }); } else loadNodeModules(x, y, function (err, n) { if (err) cb(err) else if (n) cb(null, n) else cb(new Error("Cannot find module '" + x + "'")) }); function loadAsFile (x, cb) { (function load (exts) { if (exts.length === 0) return cb(null, undefined); var file = x + exts[0]; isFile(file, function (err, ex) { if (err) cb(err) else if (ex) cb(null, file) else load(exts.slice(1)) }); })([''].concat(extensions)); } function loadAsDirectory (x, cb) { var pkgfile = path.join(x, '/package.json'); isFile(pkgfile, function (err, ex) { if (err) return cb(err); if (!ex) return loadAsFile(path.join(x, '/index'), cb); readFile(pkgfile, function (err, body) { if (err) return cb(err); try { var pkg = JSON.parse(body); } catch (err) {} if (opts.packageFilter) { pkg = opts.packageFilter(pkg, x); } if (pkg.main) { loadAsFile(path.resolve(x, pkg.main), function (err, m) { if (err) return cb(err); if (m) return cb(null, m); var dir = path.resolve(x, pkg.main); loadAsDirectory(dir, function (err, n) { if (err) return cb(err); if (n) return cb(null, n); loadAsFile(path.join(x, '/index'), cb); }); }); return; } loadAsFile(path.join(x, '/index'), cb); }); }); } function loadNodeModules (x, start, cb) { (function process (dirs) { if (dirs.length === 0) return cb(null, undefined); var dir = dirs[0]; loadAsFile(path.join(dir, '/', x), function (err, m) { if (err) return cb(err); if (m) return cb(null, m); loadAsDirectory(path.join(dir, '/', x), function (err, n) { if (err) return cb(err); if (n) return cb(null, n); process(dirs.slice(1)); }); }); })(nodeModulesPaths(start)); } function nodeModulesPaths (start, cb) { var splitRe = process.platform === 'win32' ? /[\/\\]/ : /\/+/; var parts = start.split(splitRe); var dirs = []; for (var i = parts.length - 1; i >= 0; i--) { if (parts[i] === 'node_modules') continue; var dir = path.join( path.join.apply(path, parts.slice(0, i + 1)), 'node_modules' ); if (!parts[0].match(/([A-Za-z]:)/)) { dir = '/' + dir; } dirs.push(dir); } return dirs.concat(opts.paths); } }; node-resolve-0.3.1/lib/core.js000066400000000000000000000001561212534437600161620ustar00rootroot00000000000000module.exports = require('./core.json').reduce(function (acc, x) { acc[x] = true; return acc; }, {}); node-resolve-0.3.1/lib/core.json000066400000000000000000000007761212534437600165270ustar00rootroot00000000000000[ "assert", "buffer_ieee754", "buffer", "child_process", "cluster", "console", "constants", "crypto", "_debugger", "dgram", "dns", "domain", "events", "freelist", "fs", "http", "https", "_linklist", "module", "net", "os", "path", "punycode", "querystring", "readline", "repl", "stream", "string_decoder", "sys", "timers", "tls", "tty", "url", "util", "vm", "zlib" ] node-resolve-0.3.1/lib/sync.js000066400000000000000000000057571212534437600162220ustar00rootroot00000000000000var core = require('./core'); var fs = require('fs'); var path = require('path'); module.exports = function (x, opts) { if (core[x]) return x; if (!opts) opts = {}; var isFile = opts.isFile || function (file) { try { var stat = fs.statSync(file) } catch (err) { if (err && err.code === 'ENOENT') return false } return stat.isFile() || stat.isFIFO(); }; var readFileSync = opts.readFileSync || fs.readFileSync; var extensions = opts.extensions || [ '.js' ]; var y = opts.basedir || path.dirname(require.cache[__filename].parent.filename) ; opts.paths = opts.paths || []; if (x.match(/^(?:\.\.?\/|\/|([A-Za-z]:)?\\)/)) { var m = loadAsFileSync(path.resolve(y, x)) || loadAsDirectorySync(path.resolve(y, x)); if (m) return m; } else { var n = loadNodeModulesSync(x, y); if (n) return n; } throw new Error("Cannot find module '" + x + "'"); function loadAsFileSync (x) { if (isFile(x)) { return x; } for (var i = 0; i < extensions.length; i++) { var file = x + extensions[i]; if (isFile(file)) { return file; } } } function loadAsDirectorySync (x) { var pkgfile = path.join(x, '/package.json'); if (isFile(pkgfile)) { var body = readFileSync(pkgfile, 'utf8'); try { var pkg = JSON.parse(body); if (opts.packageFilter) { pkg = opts.packageFilter(pkg, x); } if (pkg.main) { var m = loadAsFileSync(path.resolve(x, pkg.main)); if (m) return m; var n = loadAsDirectorySync(path.resolve(x, pkg.main)); if (n) return n; } } catch (err) {} } return loadAsFileSync(path.join( x, '/index')); } function loadNodeModulesSync (x, start) { var dirs = nodeModulesPathsSync(start); for (var i = 0; i < dirs.length; i++) { var dir = dirs[i]; var m = loadAsFileSync(path.join( dir, '/', x)); if (m) return m; var n = loadAsDirectorySync(path.join( dir, '/', x )); if (n) return n; } } function nodeModulesPathsSync (start) { var splitRe = process.platform === 'win32' ? /[\/\\]/ : /\/+/; var parts = start.split(splitRe); var dirs = []; for (var i = parts.length - 1; i >= 0; i--) { if (parts[i] === 'node_modules') continue; var dir = path.join( path.join.apply(path, parts.slice(0, i + 1)), 'node_modules' ); if (!parts[0].match(/([A-Za-z]:)/)) { dir = '/' + dir; } dirs.push(dir); } return dirs.concat(opts.paths); } }; node-resolve-0.3.1/package.json000066400000000000000000000012341212534437600164120ustar00rootroot00000000000000{ "name" : "resolve", "description" : "resolve like require.resolve() on behalf of files asynchronously and synchronously", "version" : "0.3.1", "repository" : { "type" : "git", "url" : "git://github.com/substack/node-resolve.git" }, "main" : "index.js", "keywords" : [ "resolve", "require", "node", "module" ], "scripts" : { "test" : "tap test/*.js" }, "devDependencies" : { "tap" : "~0.4.0" }, "license" : "MIT", "author" : { "name" : "James Halliday", "email" : "mail@substack.net", "url" : "http://substack.net" } } node-resolve-0.3.1/readme.markdown000066400000000000000000000056231212534437600171330ustar00rootroot00000000000000# resolve implements the [node `require.resolve()` algorithm](http://nodejs.org/docs/v0.4.8/api/all.html#all_Together...) such that you can `require.resolve()` on behalf of a file asynchronously and synchronously [![build status](https://secure.travis-ci.org/substack/node-resolve.png)](http://travis-ci.org/substack/node-resolve) # example asynchronously resolve: ``` js var resolve = require('resolve'); resolve('tap', { basedir: __dirname }, function (err, res) { if (err) console.error(err) else console.log(res) }); ``` ``` $ node example/async.js /home/substack/projects/node-resolve/node_modules/tap/lib/main.js ``` synchronously resolve: ``` js var resolve = require('resolve'); var res = resolve.sync('tap', { basedir: __dirname }); console.log(res); ``` ``` $ node example/sync.js /home/substack/projects/node-resolve/node_modules/tap/lib/main.js ``` # methods ``` js var resolve = require('resolve') ``` ## resolve(pkg, opts={}, cb) Asynchronously resolve the module path string `pkg` into `cb(err, res)`. options are: * opts.basedir - directory to begin resolving from * opts.extensions - array of file extensions to search in order * opts.readFile - how to read files asynchronously * opts.isFile - function to asynchronously test whether a file exists * opts.packageFilter - transform the parsed package.json contents before looking at the "main" field * opts.paths - require.paths array to use if nothing is found on the normal node_modules recursive walk (probably don't use this) default `opts` values: ``` javascript { paths: [], basedir: __dirname, extensions: [ '.js' ], readFile: fs.readFile, isFile: function (file, cb) { fs.stat(file, function (err, stat) { if (err && err.code === 'ENOENT') cb(null, false) else if (err) cb(err) else cb(null, stat.isFile()) }); } } ``` ## resolve.sync(pkg, opts) Synchronously resolve the module path string `pkg`, returning the result and throwing an error when `pkg` can't be resolved. options are: * opts.basedir - directory to begin resolving from * opts.extensions - array of file extensions to search in order * opts.readFile - how to read files synchronously * opts.isFile - function to synchronously test whether a file exists * opts.packageFilter - transform the parsed package.json contents before looking at the "main" field * opts.paths - require.paths array to use if nothing is found on the normal node_modules recursive walk (probably don't use this) default `opts` values: ``` javascript { paths: [], basedir: __dirname, extensions: [ '.js' ], readFileSync: fs.readFileSync, isFile: function (file) { try { return fs.statSync(file).isFile() } catch (e) { return false } } } ```` ## resolve.isCore(pkg) Return whether a package is in core. # install With [npm](https://npmjs.org) do: ``` npm install resolve ``` # license MIT node-resolve-0.3.1/test/000077500000000000000000000000001212534437600151035ustar00rootroot00000000000000node-resolve-0.3.1/test/core.js000066400000000000000000000004401212534437600163670ustar00rootroot00000000000000var test = require('tap').test; var resolve = require('../'); test('core modules', function (t) { t.ok(resolve.isCore('fs')); t.ok(resolve.isCore('net')); t.ok(resolve.isCore('http')); t.ok(!resolve.isCore('seq')); t.ok(!resolve.isCore('../')); t.end(); }); node-resolve-0.3.1/test/filter.js000066400000000000000000000006361212534437600167330ustar00rootroot00000000000000var test = require('tap').test; var resolve = require('../'); test('filter', function (t) { t.plan(1); var dir = __dirname + '/resolver'; resolve('./baz', { basedir : dir, packageFilter : function (pkg) { pkg.main = 'doom'; return pkg; } }, function (err, res) { if (err) t.fail(err); t.equal(res, dir + '/baz/doom.js'); }); }); node-resolve-0.3.1/test/filter_sync.js000066400000000000000000000005531212534437600177650ustar00rootroot00000000000000var test = require('tap').test; var resolve = require('../'); test('filter', function (t) { var dir = __dirname + '/resolver'; var res = resolve.sync('./baz', { basedir : dir, packageFilter : function (pkg) { pkg.main = 'doom' return pkg; } }); t.equal(res, dir + '/baz/doom.js'); t.end(); }); node-resolve-0.3.1/test/mock.js000066400000000000000000000033201212534437600163700ustar00rootroot00000000000000var test = require('tap').test; var resolve = require('../'); test('mock', function (t) { t.plan(4); var files = { '/foo/bar/baz.js' : 'beep' }; function opts (basedir) { return { basedir : basedir, isFile : function (file, cb) { cb(null, files.hasOwnProperty(file)); }, readFile : function (file, cb) { cb(null, files[file]); } } } resolve('./baz', opts('/foo/bar'), function (err, res) { if (err) t.fail(err); t.equal(res, '/foo/bar/baz.js'); }); resolve('./baz.js', opts('/foo/bar'), function (err, res) { if (err) t.fail(err); t.equal(res, '/foo/bar/baz.js'); }); resolve('baz', opts('/foo/bar'), function (err, res) { t.equal(err.message, "Cannot find module 'baz'"); }); resolve('../baz', opts('/foo/bar'), function (err, res) { t.equal(err.message, "Cannot find module '../baz'"); }); }); test('mock package', function (t) { t.plan(1); var files = { '/foo/node_modules/bar/baz.js' : 'beep', '/foo/node_modules/bar/package.json' : JSON.stringify({ main : './baz.js' }) }; function opts (basedir) { return { basedir : basedir, isFile : function (file, cb) { cb(null, files.hasOwnProperty(file)); }, readFile : function (file, cb) { cb(null, files[file]); } } } resolve('bar', opts('/foo'), function (err, res) { if (err) t.fail(err); t.equal(res, '/foo/node_modules/bar/baz.js'); }); }); node-resolve-0.3.1/test/mock_sync.js000066400000000000000000000027241212534437600174330ustar00rootroot00000000000000var test = require('tap').test; var resolve = require('../'); test('mock', function (t) { t.plan(4); var files = { '/foo/bar/baz.js' : 'beep' }; function opts (basedir) { return { basedir : basedir, isFile : function (file) { return files.hasOwnProperty(file) }, readFileSync : function (file) { return files[file] } } } t.equal( resolve.sync('./baz', opts('/foo/bar')), '/foo/bar/baz.js' ); t.equal( resolve.sync('./baz.js', opts('/foo/bar')), '/foo/bar/baz.js' ); t.throws(function () { resolve.sync('baz', opts('/foo/bar')); }); t.throws(function () { resolve.sync('../baz', opts('/foo/bar')); }); }); test('mock package', function (t) { t.plan(1); var files = { '/foo/node_modules/bar/baz.js' : 'beep', '/foo/node_modules/bar/package.json' : JSON.stringify({ main : './baz.js' }) }; function opts (basedir) { return { basedir : basedir, isFile : function (file) { return files.hasOwnProperty(file) }, readFileSync : function (file) { return files[file] } } } t.equal( resolve.sync('bar', opts('/foo')), '/foo/node_modules/bar/baz.js' ); }); node-resolve-0.3.1/test/resolver.js000066400000000000000000000077721212534437600173170ustar00rootroot00000000000000var test = require('tap').test; var resolve = require('../'); test('async foo', function (t) { t.plan(3); var dir = __dirname + '/resolver'; resolve('./foo', { basedir : dir }, function (err, res) { if (err) t.fail(err); t.equal(res, dir + '/foo.js'); }); resolve('./foo.js', { basedir : dir }, function (err, res) { if (err) t.fail(err); t.equal(res, dir + '/foo.js'); }); resolve('foo', { basedir : dir }, function (err) { t.equal(err.message, "Cannot find module 'foo'"); }); }); test('bar', function (t) { t.plan(2); var dir = __dirname + '/resolver'; resolve('foo', { basedir : dir + '/bar' }, function (err, res) { if (err) t.fail(err); t.equal(res, dir + '/bar/node_modules/foo/index.js'); }); resolve('foo', { basedir : dir + '/bar' }, function (err, res) { if (err) t.fail(err); t.equal(res, dir + '/bar/node_modules/foo/index.js'); }); }); test('baz', function (t) { t.plan(1); var dir = __dirname + '/resolver'; resolve('./baz', { basedir : dir }, function (err, res) { if (err) t.fail(err); t.equal(res, dir + '/baz/quux.js'); }); }); test('biz', function (t) { t.plan(3); var dir = __dirname + '/resolver/biz/node_modules'; resolve('./grux', { basedir : dir }, function (err, res) { if (err) t.fail(err); t.equal(res, dir + '/grux/index.js'); }); resolve('tiv', { basedir : dir + '/grux' }, function (err, res) { if (err) t.fail(err); t.equal(res, dir + '/tiv/index.js'); }); resolve('grux', { basedir : dir + '/tiv' }, function (err, res) { if (err) t.fail(err); t.equal(res, dir + '/grux/index.js'); }); }); test('normalize', function (t) { t.plan(1); var dir = __dirname + '/resolver/biz/node_modules/grux'; resolve('../grux', { basedir : dir }, function (err, res) { if (err) t.fail(err); t.equal(res, dir + '/index.js'); }); }); test('cup', function (t) { t.plan(3); var dir = __dirname + '/resolver'; resolve('./cup', { basedir : dir, extensions : [ '.js', '.coffee' ] }, function (err, res) { if (err) t.fail(err); t.equal(res, dir + '/cup.coffee'); }); resolve('./cup.coffee', { basedir : dir }, function (err, res) { if (err) t.fail(err); t.equal(res, dir + '/cup.coffee'); }); resolve('./cup', { basedir : dir, extensions : [ '.js' ] }, function (err, res) { t.equal(err.message, "Cannot find module './cup'"); }); }); test('mug', function (t) { t.plan(3); var dir = __dirname + '/resolver'; resolve('./mug', { basedir : dir }, function (err, res) { if (err) t.fail(err); t.equal(res, dir + '/mug.js'); }); resolve('./mug', { basedir : dir, extensions : [ '.coffee', '.js' ] }, function (err, res) { if (err) t.fail(err); t.equal(res, dir + '/mug.coffee'); }); resolve('./mug', { basedir : dir, extensions : [ '.js', '.coffee' ] }, function (err, res) { t.equal(res, dir + '/mug.js'); }); }); test('other path', function (t) { t.plan(4); var resolverDir = __dirname + '/resolver'; var dir = resolverDir + '/bar'; var otherDir = resolverDir + '/other_path'; resolve('root', { basedir : dir, paths: [otherDir] }, function (err, res) { if (err) t.fail(err); t.equal(res, resolverDir + '/other_path/root.js'); }); resolve('lib/other-lib', { basedir : dir, paths: [otherDir] }, function (err, res) { if (err) t.fail(err); t.equal(res, resolverDir + '/other_path/lib/other-lib.js'); }); resolve('root', { basedir : dir, }, function (err, res) { t.equal(err.message, "Cannot find module 'root'"); }); resolve('zzz', { basedir : dir, paths: [otherDir] }, function (err, res) { t.equal(err.message, "Cannot find module 'zzz'"); }); }); node-resolve-0.3.1/test/resolver/000077500000000000000000000000001212534437600167445ustar00rootroot00000000000000node-resolve-0.3.1/test/resolver/bar/000077500000000000000000000000001212534437600175105ustar00rootroot00000000000000node-resolve-0.3.1/test/resolver/bar/node_modules/000077500000000000000000000000001212534437600221655ustar00rootroot00000000000000node-resolve-0.3.1/test/resolver/bar/node_modules/foo/000077500000000000000000000000001212534437600227505ustar00rootroot00000000000000node-resolve-0.3.1/test/resolver/bar/node_modules/foo/index.js000066400000000000000000000000241212534437600244110ustar00rootroot00000000000000module.exports = 1; node-resolve-0.3.1/test/resolver/baz/000077500000000000000000000000001212534437600175205ustar00rootroot00000000000000node-resolve-0.3.1/test/resolver/baz/doom.js000066400000000000000000000000001212534437600210020ustar00rootroot00000000000000node-resolve-0.3.1/test/resolver/baz/package.json000066400000000000000000000000331212534437600220020ustar00rootroot00000000000000{ "main" : "quux.js" } node-resolve-0.3.1/test/resolver/baz/quux.js000066400000000000000000000000241212534437600210540ustar00rootroot00000000000000module.exports = 1; node-resolve-0.3.1/test/resolver/biz/000077500000000000000000000000001212534437600175305ustar00rootroot00000000000000node-resolve-0.3.1/test/resolver/biz/node_modules/000077500000000000000000000000001212534437600222055ustar00rootroot00000000000000node-resolve-0.3.1/test/resolver/biz/node_modules/grux/000077500000000000000000000000001212534437600231725ustar00rootroot00000000000000node-resolve-0.3.1/test/resolver/biz/node_modules/grux/index.js000066400000000000000000000000471212534437600246400ustar00rootroot00000000000000module.exports = require('tiv') * 100; node-resolve-0.3.1/test/resolver/biz/node_modules/tiv/000077500000000000000000000000001212534437600230075ustar00rootroot00000000000000node-resolve-0.3.1/test/resolver/biz/node_modules/tiv/index.js000066400000000000000000000000241212534437600244500ustar00rootroot00000000000000module.exports = 3; node-resolve-0.3.1/test/resolver/cup.coffee000066400000000000000000000000011212534437600206730ustar00rootroot00000000000000 node-resolve-0.3.1/test/resolver/foo.js000066400000000000000000000000241212534437600200610ustar00rootroot00000000000000module.exports = 1; node-resolve-0.3.1/test/resolver/mug.coffee000066400000000000000000000000001212534437600206730ustar00rootroot00000000000000node-resolve-0.3.1/test/resolver/mug.js000066400000000000000000000000001212534437600200600ustar00rootroot00000000000000node-resolve-0.3.1/test/resolver/other_path/000077500000000000000000000000001212534437600211015ustar00rootroot00000000000000node-resolve-0.3.1/test/resolver/other_path/lib/000077500000000000000000000000001212534437600216475ustar00rootroot00000000000000node-resolve-0.3.1/test/resolver/other_path/lib/other-lib.js000066400000000000000000000000001212534437600240600ustar00rootroot00000000000000node-resolve-0.3.1/test/resolver/other_path/root.js000066400000000000000000000000001212534437600224100ustar00rootroot00000000000000node-resolve-0.3.1/test/resolver_sync.js000066400000000000000000000063531212534437600203450ustar00rootroot00000000000000var test = require('tap').test; var resolve = require('../'); test('foo', function (t) { var dir = __dirname + '/resolver'; t.equal( resolve.sync('./foo', { basedir : dir }), dir + '/foo.js' ); t.equal( resolve.sync('./foo.js', { basedir : dir }), dir + '/foo.js' ); t.throws(function () { resolve.sync('foo', { basedir : dir }); }); t.end(); }); test('bar', function (t) { var dir = __dirname + '/resolver'; t.equal( resolve.sync('foo', { basedir : dir + '/bar' }), dir + '/bar/node_modules/foo/index.js' ); t.end(); }); test('baz', function (t) { var dir = __dirname + '/resolver'; t.equal( resolve.sync('./baz', { basedir : dir }), dir + '/baz/quux.js' ); t.end(); }); test('biz', function (t) { var dir = __dirname + '/resolver/biz/node_modules'; t.equal( resolve.sync('./grux', { basedir : dir }), dir + '/grux/index.js' ); t.equal( resolve.sync('tiv', { basedir : dir + '/grux' }), dir + '/tiv/index.js' ); t.equal( resolve.sync('grux', { basedir : dir + '/tiv' }), dir + '/grux/index.js' ); t.end(); }); test('normalize', function (t) { var dir = __dirname + '/resolver/biz/node_modules/grux'; t.equal( resolve.sync('../grux', { basedir : dir }), dir + '/index.js' ); t.end(); }); test('cup', function (t) { var dir = __dirname + '/resolver'; t.equal( resolve.sync('./cup', { basedir : dir, extensions : [ '.js', '.coffee' ] }), dir + '/cup.coffee' ); t.equal( resolve.sync('./cup.coffee', { basedir : dir }), dir + '/cup.coffee' ); t.throws(function () { resolve.sync('./cup', { basedir : dir, extensions : [ '.js' ] }) }); t.end(); }); test('mug', function (t) { var dir = __dirname + '/resolver'; t.equal( resolve.sync('./mug', { basedir : dir }), dir + '/mug.js' ); t.equal( resolve.sync('./mug', { basedir : dir, extensions : [ '.coffee', '.js' ] }), dir + '/mug.coffee' ); t.equal( resolve.sync('./mug', { basedir : dir, extensions : [ '.js', '.coffee' ] }), dir + '/mug.js' ); t.end(); }); test('other path', function (t) { var resolverDir = __dirname + '/resolver'; var dir = resolverDir + '/bar'; var otherDir = resolverDir + '/other_path'; var path = require('path'); t.equal( resolve.sync('root', { basedir : dir, paths: [otherDir] }), resolverDir + '/other_path/root.js' ); t.equal( resolve.sync('lib/other-lib', { basedir : dir, paths: [otherDir] }), resolverDir + '/other_path/lib/other-lib.js' ); t.throws(function () { resolve.sync('root', { basedir : dir, }); }); t.throws(function () { resolve.sync('zzz', { basedir : dir, paths: [otherDir] }); }); t.end(); });