UNPKG

542 BJavaScriptView Raw
1'use strict';
2
3const extend = require('xtend');
4
5function readPackageJson(filename) {
6 let pkg;
7 let error;
8 try {
9 pkg = require(filename);
10 } catch (e) {
11 if (e.code === 'MODULE_NOT_FOUND') {
12 error = new Error(`A package.json was not found at ${filename}`);
13 } else {
14 error = new Error(`A package.json was found at ${filename}, but it is not valid.`);
15 }
16 }
17 return extend({devDependencies: {}, dependencies: {}, error: error}, pkg)
18}
19
20module.exports = readPackageJson;