Skip to content

Commit

Permalink
馃摝 NEW: Contraint version installs for peerDeps
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadawais committed Feb 20, 2020
1 parent 0d4ddc4 commit 659be15
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
29 changes: 28 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,33 @@ let npm;
);
process.exit(0);
}
const deps = Object.keys(data.data.peerDependencies).filter(dep => dep !== 'gatsby');
const peerDependencies = data.data.peerDependencies;
const deps = Object.keys(peerDependencies)
.filter(dep => dep !== 'gatsby')
.map(dep => {
let depVer = peerDependencies[dep];

// Check if there is whitespace.
if (depVer.indexOf(' ') >= 0) {
// Semver ranges can have a join of comparator sets.
// e.g. '^3.0.2 || ^4.0.0' or '>=1.2.7 <1.3.0'
const rangeSplit = depVer
.split(' ')
.map(v => coerce(v))
.filter(v => valid(v));

// Take each version in the range and find the maxSatisfying.
const verToInstall = maxSatisfying(rangeSplit, depVer);
if (verToInstall === null) {
return `${dep}`;
} else {
return `${dep}@${verToInstall}`;
}
} else {
return `${dep}@${depVer}`;
}
});
debug && spinner.warn(yellow(`Dependencies to be installed: ${deps}`));
spinner.succeed(`${green(`DEPENDENCIES`)} ${deps.length} found`);

// Installer.
Expand All @@ -128,6 +154,7 @@ let npm;
const [errInstall, installed] = await to(
Promise.all(
pkgs.map(async (pkg, i) => {
debug && spinner.warn(yellow(`INSTALLING ${pkg}`));
if (npm !== false) {
await execa(`npm`, [`install`, pkg, `--save`]);
} else {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"marked": "^0.8.0",
"marked-terminal": "^4.0.0",
"ora": "^4.0.3",
"semver": "^7.1.3",
"update-notifier": "^4.1.0"
},
"devDependencies": {
Expand Down

0 comments on commit 659be15

Please sign in to comment.