Skip to content

Commit

Permalink
fix(devkit): isIncomingVersionGreater should work with prerelease ver…
Browse files Browse the repository at this point in the history
…sions (#13805)

(cherry picked from commit 8f7feba)
  • Loading branch information
AgentEnder authored and FrozenPandaz committed Dec 19, 2022
1 parent 809df6a commit 014f999
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
@@ -1,6 +1,6 @@
import type { Tree } from '@nrwl/devkit';
import { readJson } from '@nrwl/devkit';
import { coerce, major } from 'semver';
import { coerce, clean, major } from 'semver';

export function getGeneratorDirectoryForInstalledAngularVersion(tree: Tree) {
const pkgJson = readJson(tree, 'package.json');
Expand All @@ -15,7 +15,9 @@ export function getGeneratorDirectoryForInstalledAngularVersion(tree: Tree) {
return null;
}

const majorAngularVersion = major(coerce(angularVersion));
const majorAngularVersion = major(
clean(angularVersion) ?? coerce(angularVersion)
);

const directoryDictionary = {
14: 'angular-v14',
Expand Down
8 changes: 6 additions & 2 deletions packages/devkit/src/utils/package-json.ts
Expand Up @@ -2,7 +2,7 @@ import { readJson, updateJson } from 'nx/src/generators/utils/json';
import { installPackagesTask } from '../tasks/install-packages-task';
import type { Tree } from 'nx/src/generators/tree';
import { GeneratorCallback } from 'nx/src/config/misc-interfaces';
import { coerce, gt, satisfies } from 'semver';
import { clean, coerce, gt, satisfies } from 'semver';
import { getPackageManagerCommand } from 'nx/src/utils/package-manager';
import { execSync } from 'child_process';

Expand All @@ -27,6 +27,10 @@ function filterExistingDependencies(
.reduce((acc, d) => ({ ...acc, [d]: dependencies[d] }), {});
}

function cleanSemver(version: string) {
return clean(version) ?? coerce(version);
}

function isIncomingVersionGreater(
incomingVersion: string,
existingVersion: string
Expand All @@ -45,7 +49,7 @@ function isIncomingVersionGreater(
return true;
}

return gt(coerce(incomingVersion), coerce(existingVersion));
return gt(cleanSemver(incomingVersion), cleanSemver(existingVersion));
}

function updateExistingDependenciesVersion(
Expand Down

0 comments on commit 014f999

Please sign in to comment.