Skip to content

Instantly share code, notes, and snippets.

@tj
Created March 23, 2013 03:21
Show Gist options
  • Save tj/5226298 to your computer and use it in GitHub Desktop.
Save tj/5226298 to your computer and use it in GitHub Desktop.
require.resolve = function(path) {
if (path.charAt(0) === '/') path = path.slice(1);
var index = path + '/index.js';
var paths = [
path,
path + '.js',
path + '.json',
path + '/index.js',
path + '/index.json'
];
for (var i = 0; i < paths.length; i++) {
var path = paths[i];
if (has.call(require.modules, path)) return path;
}
if (has.call(require.aliases, index)) {
return require.aliases[index];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment