}
// check if the directory is a package.json dir
-var packageCache = {};
+var packageMainCache = {};
function readPackage(requestPath) {
- if (hasOwnProperty(packageCache, requestPath)) {
- return packageCache[requestPath];
+ if (hasOwnProperty(packageMainCache, requestPath)) {
+ return packageMainCache[requestPath];
}
var fs = NativeModule.require('fs');
}
try {
- var pkg = packageCache[requestPath] = JSON.parse(json);
+ var pkg = packageMainCache[requestPath] = JSON.parse(json).main;
} catch (e) {
e.path = jsonPath;
e.message = 'Error parsing ' + jsonPath + ': ' + e.message;
function tryPackage(requestPath, exts) {
var pkg = readPackage(requestPath);
- if (!pkg || !pkg.main) return false;
+ if (!pkg) return false;
- var filename = path.resolve(requestPath, pkg.main);
+ var filename = path.resolve(requestPath, pkg);
return tryFile(filename) || tryExtensions(filename, exts) ||
tryExtensions(path.resolve(filename, 'index'), exts);
}