lib/util/npm-utils.js
function check(packages, opt) {
    let deps = [];
    const pkgJson = (opt) ? findPackageJson(opt.startDir) : findPackageJson();
    let fileJson;

    if (!pkgJson) {
        throw new Error("Could not find a package.json file. Run 'npm init' to create one.");
    }

    try {
        fileJson = JSON.parse(fs.readFileSync(pkgJson, "utf8"));
    } catch (e) {
        const error = new Error(e);

        error.messageTemplate = "failed-to-read-json";
        error.messageData = {
            path: pkgJson,
            message: e.message
        };
        throw error;
    }

    if (opt.devDependencies && typeof fileJson.devDependencies === "object") {
        deps = deps.concat(Object.keys(fileJson.devDependencies));
    }
    if (opt.dependencies && typeof fileJson.dependencies === "object") {
        deps = deps.concat(Object.keys(fileJson.dependencies));
    }
    return packages.reduce((status, pkg) => {
        status[pkg] = deps.indexOf(pkg) !== -1;
        return status;
    }, {});
}
function check(packages, opt) {
    let deps = [];
    const pkgJson = (opt) ? findPackageJson(opt.startDir) : findPackageJson();
    let fileJson;

    if (!pkgJson) {
        throw new Error("Could not find a package.json file. Run 'npm init' to create one.");
    }

    try {
        fileJson = JSON.parse(fs.readFileSync(pkgJson, "utf8"));
    } catch (e) {
        const error = new Error(e);

        error.messageTemplate = "failed-to-read-json";
        error.messageData = {
            path: pkgJson,
            message: e.message
        };
        throw error;
    }

    if (opt.devDependencies && typeof fileJson.devDependencies === "object") {
        deps = deps.concat(Object.keys(fileJson.devDependencies));
    }
    if (opt.dependencies && typeof fileJson.dependencies === "object") {
        deps = deps.concat(Object.keys(fileJson.dependencies));
    }
    return packages.reduce((status, pkg) => {
        status[pkg] = deps.indexOf(pkg) !== -1;
        return status;
    }, {});
}
function check ( packages , opt ) { let deps = [ ] ; const pkgJson = ( opt ) ? findPackageJson ( opt . startDir ) : findPackageJson ( ) ; let fileJson ; if ( ! pkgJson ) { throw new Error ( "Could not find a package.json file. Run 'npm init' to create one." ) ; } try { fileJson = JSON . parse ( fs . readFileSync ( pkgJson , "utf8" ) ) ; } catch ( e ) { const error = new Error ( e ) ; error . messageTemplate = "failed-to-read-json" ; error . messageData = { path : pkgJson , message : e . message } ; throw error ; } if ( opt . devDependencies && typeof fileJson . devDependencies === "object" ) { deps = deps . concat ( Object . keys ( fileJson . devDependencies ) ) ; } if ( opt . dependencies && typeof fileJson . dependencies === "object" ) { deps = deps . concat ( Object . keys ( fileJson . dependencies ) ) ; } return packages . reduce ( ( status , pkg ) => { status [ pkg ] = deps . indexOf ( pkg ) !== - 1 ; return status ; } , { } ) ; }
Check whether node modules are include in a project's package.json.

@param   {string[]} packages           Array of node module names
@param   {Object}  opt                 Options Object
@param   {boolean} opt.dependencies    Set to true to check for direct dependencies
@param   {boolean} opt.devDependencies Set to true to check for development dependencies
@param   {boolean} opt.startdir        Directory to begin searching from
@returns {Object}                      An object whose keys are the module names
and values are booleans indicating installation.
Check whether node modules are include in a project s package . json .