module: only cache package main
This commit is contained in:
parent
7dca8d714f
commit
1d5e797445
@ -94,11 +94,11 @@ function statPath(path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if the directory is a package.json dir
|
// check if the directory is a package.json dir
|
||||||
var packageCache = {};
|
var packageMainCache = {};
|
||||||
|
|
||||||
function readPackage(requestPath) {
|
function readPackage(requestPath) {
|
||||||
if (hasOwnProperty(packageCache, requestPath)) {
|
if (hasOwnProperty(packageMainCache, requestPath)) {
|
||||||
return packageCache[requestPath];
|
return packageMainCache[requestPath];
|
||||||
}
|
}
|
||||||
|
|
||||||
var fs = NativeModule.require('fs');
|
var fs = NativeModule.require('fs');
|
||||||
@ -110,7 +110,7 @@ function readPackage(requestPath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var pkg = packageCache[requestPath] = JSON.parse(json);
|
var pkg = packageMainCache[requestPath] = JSON.parse(json).main;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
e.path = jsonPath;
|
e.path = jsonPath;
|
||||||
e.message = 'Error parsing ' + jsonPath + ': ' + e.message;
|
e.message = 'Error parsing ' + jsonPath + ': ' + e.message;
|
||||||
@ -122,9 +122,9 @@ function readPackage(requestPath) {
|
|||||||
function tryPackage(requestPath, exts) {
|
function tryPackage(requestPath, exts) {
|
||||||
var pkg = readPackage(requestPath);
|
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) ||
|
return tryFile(filename) || tryExtensions(filename, exts) ||
|
||||||
tryExtensions(path.resolve(filename, 'index'), exts);
|
tryExtensions(path.resolve(filename, 'index'), exts);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user