Skip to content

Commit

Permalink
fix(@schematics/update): only update peer dependency if out of range
Browse files Browse the repository at this point in the history
  • Loading branch information
clydin authored and Keen Yee Liau committed Sep 11, 2019
1 parent 8cc0a11 commit a87f42a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/schematics/update/update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ function _addPeerDependencies(
packages: Map<string, VersionRange>,
allDependencies: ReadonlyMap<string, VersionRange>,
npmPackageJson: NpmRepositoryPackageJson,
npmPackageJsonMap: Map<string, NpmRepositoryPackageJson>,
logger: logging.LoggerApi,
): void {
const maybePackage = packages.get(npmPackageJson.name);
Expand All @@ -737,9 +738,19 @@ function _addPeerDependencies(
const error = false;

for (const [peer, range] of Object.entries(packageJson.peerDependencies || {})) {
if (!packages.has(peer)) {
packages.set(peer, range as VersionRange);
if (packages.has(peer)) {
continue;
}

const peerPackageJson = npmPackageJsonMap.get(peer);
if (peerPackageJson) {
const peerInfo = _buildPackageInfo(tree, packages, allDependencies, peerPackageJson, logger);
if (semver.satisfies(peerInfo.installed.version, range)) {
continue;
}
}

packages.set(peer, range as VersionRange);
}

if (error) {
Expand Down Expand Up @@ -860,7 +871,7 @@ export default function(options: UpdateSchema): Rule {
lastPackagesSize = packages.size;
npmPackageJsonMap.forEach((npmPackageJson) => {
_addPackageGroup(tree, packages, allDependencies, npmPackageJson, logger);
_addPeerDependencies(tree, packages, allDependencies, npmPackageJson, logger);
_addPeerDependencies(tree, packages, allDependencies, npmPackageJson, npmPackageJsonMap, logger);
});
} while (packages.size > lastPackagesSize);

Expand Down

0 comments on commit a87f42a

Please sign in to comment.