Skip to content

Commit

Permalink
module: only cache package main
Browse files Browse the repository at this point in the history
  • Loading branch information
geek authored and isaacs committed Dec 12, 2013
1 parent 7dca8d7 commit 1d5e797
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down

0 comments on commit 1d5e797

Please sign in to comment.