Skip to content

Commit

Permalink
Chore: refactor code (#12113)
Browse files Browse the repository at this point in the history
* Chore: refactor code

* Fix: minor tweak

* Minor tweak

* Fix: lint

* Fix: minor tweak

have deps as a Set rather than an array

* Fix: tweak

* fix: typo
  • Loading branch information
jamesgeorge007 authored and kaicataldo committed Aug 30, 2019
1 parent 52e2cf5 commit 0acdefb
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/init/npm-utils.js
Expand Up @@ -98,7 +98,7 @@ function fetchPeerDependencies(packageName) {
* and values are booleans indicating installation.
*/
function check(packages, opt) {
let deps = [];
const deps = new Set();
const pkgJson = (opt) ? findPackageJson(opt.startDir) : findPackageJson();
let fileJson;

Expand All @@ -119,14 +119,14 @@ function check(packages, opt) {
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));
}
["dependencies", "devDependencies"].forEach(key => {
if (opt[key] && typeof fileJson[key] === "object") {
Object.keys(fileJson[key]).forEach(dep => deps.add(dep));
}
});

return packages.reduce((status, pkg) => {
status[pkg] = deps.indexOf(pkg) !== -1;
status[pkg] = deps.has(pkg);
return status;
}, {});
}
Expand Down

0 comments on commit 0acdefb

Please sign in to comment.