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)
  • Loading branch information
AgentEnder committed Dec 13, 2022
1 parent 75c34c3 commit 8f7feba
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

1 comment on commit 8f7feba

@vercel
Copy link

@vercel vercel bot commented on 8f7feba Dec 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx.dev
nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app

Please sign in to comment.