Skip to content

Commit ce9fe3e

Browse files
feat: when recursively installing peer deps, don't re-process previously unmet peer deps
1 parent 3d656a6 commit ce9fe3e

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/checkPeerDependencies.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ export function checkPeerDependencies(packageManager: string, installMissingPeer
6161
});
6262

6363

64-
if (nosolution.length) {
64+
if (nosolution.length > 0) {
6565
console.error();
6666
}
6767

6868
const commandLines = getCommandLines(packageManager, installs, upgrades);
69-
if (installMissingPeerDependencies) {
69+
if (installMissingPeerDependencies && commandLines.length > 0) {
7070
console.log('Installing peerDependencies...');
7171
console.log();
7272
commandLines.forEach(command => {
@@ -75,7 +75,14 @@ export function checkPeerDependencies(packageManager: string, installMissingPeer
7575
console.log();
7676
});
7777

78-
const newUnsatisfiedDeps = getAllNestedPeerDependencies().filter(dep => !dep.semverSatisfies);
78+
const newUnsatisfiedDeps = getAllNestedPeerDependencies()
79+
.filter(dep => !dep.semverSatisfies)
80+
.filter(dep => !nosolution.some(x => isSameDep(x.problem, dep)));
81+
82+
if (nosolution.length === 0 && newUnsatisfiedDeps.length === 0) {
83+
console.log('All peer dependencies are met');
84+
}
85+
7986
if (newUnsatisfiedDeps.length > 0) {
8087
console.log(`Found ${newUnsatisfiedDeps.length} new unmet peerDependencies...`);
8188
if (++recursiveCount < 5) {
@@ -84,15 +91,28 @@ export function checkPeerDependencies(packageManager: string, installMissingPeer
8491
console.error('Recursion limit reached (5)');
8592
process.exit(5)
8693
}
87-
} else {
88-
console.log('All peer dependencies are met');
8994
}
9095

91-
} else {
96+
} else if (commandLines.length > 0) {
9297
console.log(`Install peerDependencies using ${commandLines.length > 1 ? 'these commands:' : 'this command'}:`);
9398
console.log();
9499
commandLines.forEach(command => console.log(command));
95100
console.log();
96101
}
97102
}
98103

104+
105+
function isSameDep(a: Dependency, b: Dependency) {
106+
const keys: Array<keyof Dependency> = [
107+
"name",
108+
"version",
109+
"depender",
110+
"dependerPath",
111+
"dependerVersion",
112+
"installedVersion",
113+
"semverSatisfies",
114+
"isYalc"
115+
];
116+
117+
return keys.every(key => a[key] === b[key]);
118+
}

0 commit comments

Comments
 (0)