summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWyatt Preul <wpreul@gmail.com>2013-12-12 10:16:48 -0600
committerisaacs <i@izs.me>2013-12-12 09:38:47 -0800
commit1d5e7974451b04cd10afa29ca86641ad5cf68f46 (patch)
tree9761b151ac99f3db9b1c6a4330f68f742057a395
parent7dca8d714f47b40a6f0118a86ee167507648583a (diff)
downloadnode-1d5e7974451b04cd10afa29ca86641ad5cf68f46.tar.gz
module: only cache package main
-rw-r--r--lib/module.js12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/module.js b/lib/module.js
index 27bba73ac..77a2a8d18 100644
--- a/lib/module.js
+++ b/lib/module.js
@@ -94,11 +94,11 @@ function statPath(path) {
}
// 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');
@@ -110,7 +110,7 @@ function readPackage(requestPath) {
}
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;
@@ -122,9 +122,9 @@ function readPackage(requestPath) {
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);
}