Raise an error when a malformed package.json file is found.
The current behaviour will silently ignore any parsing errors that may occur when loading a package.json file. This makes debugging errors in the package.json file very difficult. This changes the behaviour that that errors opening and reading the file package.json file continue to be ignored, but errors in parsing will throw an exception.
This commit is contained in:
parent
94bedc60f4
commit
a4e10cdb07
@ -103,13 +103,20 @@ function readPackage(requestPath) {
|
||||
try {
|
||||
var jsonPath = path.resolve(requestPath, 'package.json');
|
||||
var json = fs.readFileSync(jsonPath, 'utf8');
|
||||
var pkg = packageCache[requestPath] = JSON.parse(json);
|
||||
return pkg;
|
||||
} catch (e) {}
|
||||
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
var pkg = packageCache[requestPath] = JSON.parse(json);
|
||||
} catch (e) {
|
||||
e.path = jsonPath;
|
||||
e.message = 'Error parsing ' + jsonPath + ': ' + e.message;
|
||||
throw e;
|
||||
}
|
||||
return pkg;
|
||||
}
|
||||
|
||||
function tryPackage(requestPath, exts) {
|
||||
var pkg = readPackage(requestPath);
|
||||
|
||||
@ -123,7 +130,7 @@ function tryPackage(requestPath, exts) {
|
||||
// In order to minimize unnecessary lstat() calls,
|
||||
// this cache is a list of known-real paths.
|
||||
// Set to an empty object to reset.
|
||||
Module._realpathCache = {}
|
||||
Module._realpathCache = {};
|
||||
|
||||
// check if the file exists and is not a directory
|
||||
function tryFile(requestPath) {
|
||||
@ -217,7 +224,7 @@ Module._nodeModulePaths = function(from) {
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Module._resolveLookupPaths = function(request, parent) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user