lib/modules.js
function getFilename(id, options, next) {
	var Path = require('path'),
		root = options.root || exports.defaults.root,
		map = options.map || {},
		forbid = (options.forbid || []).map(function(forbid) {
			return forbid.test ? forbid : Path.resolve(root, forbid);
		}),
		filename;

	function test(forbid) {
		return forbid.test ? forbid.test(filename) :
			(filename.slice(0, forbid.length) === forbid); // filename starts with forbid
	}

	// mapped modules can be in forbidden places. (define and define.shim should be mapped)
	map.define = map.define || Path.resolve(__dirname, 'define');
	map['define.min'] = map['define.min'] || Path.resolve(__dirname, 'define.min');
	map['define.shim'] = map['define.shim'] || Path.resolve(__dirname, 'define.shim');

	// get a filename from the id
	filename = map[id] || id; // look for the file in the id map
	if ('function' === typeof filename) { filename = filename(id, options); } // if function use result
	filename = Path.resolve(root, filename); // relative to root

	if (!map[id]) {
		// anything below options.root is forbidden
		if ('..' === Path.relative(root, filename).slice(0, 2) || forbid.some(test)) {
			return next(new Error('Forbidden'), '');
		}
	}

	fs.stat(filename, function(err, stats) {
		if (err) { // not found without .js, try with
			return fs.exists(filename + '.js', function(exists) {
				return next(null, filename + (exists ? '.js' : ''));
			});
		}

		if (stats.isDirectory()) { // directories look for /index.js
			return fs.exists(filename + '/index.js', function(exists) {
				return next(null, filename + (exists ? '/index.js' : ''));
			});
		}

		return next(null, filename);
	});
}
function getFilename(id, options, next) {
	var Path = require('path'),
		root = options.root || exports.defaults.root,
		map = options.map || {},
		forbid = (options.forbid || []).map(function(forbid) {
			return forbid.test ? forbid : Path.resolve(root, forbid);
		}),
		filename;

	function test(forbid) {
		return forbid.test ? forbid.test(filename) :
			(filename.slice(0, forbid.length) === forbid); // filename starts with forbid
	}

	// mapped modules can be in forbidden places. (define and define.shim should be mapped)
	map.define = map.define || Path.resolve(__dirname, 'define');
	map['define.min'] = map['define.min'] || Path.resolve(__dirname, 'define.min');
	map['define.shim'] = map['define.shim'] || Path.resolve(__dirname, 'define.shim');

	// get a filename from the id
	filename = map[id] || id; // look for the file in the id map
	if ('function' === typeof filename) { filename = filename(id, options); } // if function use result
	filename = Path.resolve(root, filename); // relative to root

	if (!map[id]) {
		// anything below options.root is forbidden
		if ('..' === Path.relative(root, filename).slice(0, 2) || forbid.some(test)) {
			return next(new Error('Forbidden'), '');
		}
	}

	fs.stat(filename, function(err, stats) {
		if (err) { // not found without .js, try with
			return fs.exists(filename + '.js', function(exists) {
				return next(null, filename + (exists ? '.js' : ''));
			});
		}

		if (stats.isDirectory()) { // directories look for /index.js
			return fs.exists(filename + '/index.js', function(exists) {
				return next(null, filename + (exists ? '/index.js' : ''));
			});
		}

		return next(null, filename);
	});
}
function getFilename ( id , options , next ) { var Path = require ( 'path' ) , root = options . root || exports . defaults . root , map = options . map || { } , forbid = ( options . forbid || [ ] ) . map ( function ( forbid ) { return forbid . test ? forbid : Path . resolve ( root , forbid ) ; } ) , filename ; function test ( forbid ) { return forbid . test ? forbid . test ( filename ) : ( filename . slice ( 0 , forbid . length ) === forbid ) ; // filename starts with forbid } // mapped modules can be in forbidden places. (define and define.shim should be mapped) map . define = map . define || Path . resolve ( __dirname , 'define' ) ; map [ 'define.min' ] = map [ 'define.min' ] || Path . resolve ( __dirname , 'define.min' ) ; map [ 'define.shim' ] = map [ 'define.shim' ] || Path . resolve ( __dirname , 'define.shim' ) ; // get a filename from the id filename = map [ id ] || id ; // look for the file in the id map if ( 'function' === typeof filename ) { filename = filename ( id , options ) ; } // if function use result filename = Path . resolve ( root , filename ) ; // relative to root if ( ! map [ id ] ) { // anything below options.root is forbidden if ( '..' === Path . relative ( root , filename ) . slice ( 0 , 2 ) || forbid . some ( test ) ) { return next ( new Error ( 'Forbidden' ) , '' ) ; } } fs . stat ( filename , function ( err , stats ) { if ( err ) { // not found without .js, try with return fs . exists ( filename + '.js' , function ( exists ) { return next ( null , filename + ( exists ? '.js' : '' ) ) ; } ) ; } if ( stats . isDirectory ( ) ) { // directories look for /index.js return fs . exists ( filename + '/index.js' , function ( exists ) { return next ( null , filename + ( exists ? '/index.js' : '' ) ) ; } ) ; } return next ( null , filename ) ; } ) ; }
convert module id to filename
convert module id to filename