Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(devkit): isIncomingVersionGreater should work with prerelease versions #13805

Merged
merged 1 commit into from Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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