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

feat(core): move checkAndCleanWithSemver to devkit #15505

Merged
merged 1 commit into from Mar 7, 2023
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 { GeneratorCallback, Tree } from '@nrwl/devkit';
import { addDependenciesToPackageJson, readJson } from '@nrwl/devkit';
import { checkAndCleanWithSemver } from '@nrwl/workspace/src/utilities/version-utils';
import { checkAndCleanWithSemver } from '@nrwl/devkit/src/utils/semver';
import { gte } from 'semver';
import { getPkgVersionForAngularMajorVersion } from '../../../utils/version-utils';
import { rxjsVersion as defaultRxjsVersion } from '../../../utils/versions';
Expand Down
@@ -1,5 +1,5 @@
import { readJson, Tree } from '@nrwl/devkit';
import { checkAndCleanWithSemver } from '@nrwl/workspace/src/utilities/version-utils';
import { checkAndCleanWithSemver } from '@nrwl/devkit/src/utils/semver';
import { lt } from 'semver';

export function detectTailwindInstalledVersion(
Expand Down
Expand Up @@ -6,7 +6,7 @@ import {
updateJson,
} from '@nrwl/devkit';
// don't import from root level to prevent issue where angular isn't installed.
import { checkAndCleanWithSemver } from '@nrwl/workspace/src/utilities/version-utils';
import { checkAndCleanWithSemver } from '@nrwl/devkit/src/utils/semver';
import { gte, lt } from 'semver';

export function updateCypressVersionIf10(tree: Tree): GeneratorCallback {
Expand Down
Expand Up @@ -12,7 +12,7 @@ import {
Tree,
visitNotIgnoredFiles,
} from '@nrwl/devkit';
import { checkAndCleanWithSemver } from '@nrwl/workspace/src/utilities/version-utils';
import { checkAndCleanWithSemver } from '@nrwl/devkit/src/utils/semver';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { tsquery } from '@phenomnomnominal/tsquery';
import { gte } from 'semver';
Expand Down
@@ -1,6 +1,9 @@
import { valid } from 'semver';

export function checkAndCleanWithSemver(pkgName: string, version: string) {
export function checkAndCleanWithSemver(
pkgName: string,
version: string
): string {
let newVersion = version;

if (valid(newVersion)) {
Expand Down
@@ -1,5 +1,5 @@
import { formatFiles, logger, readJson, Tree, updateJson } from '@nrwl/devkit';
import { checkAndCleanWithSemver } from '@nrwl/workspace';
import { checkAndCleanWithSemver } from '@nrwl/devkit/src/utils/semver';
import { satisfies } from 'semver';
import { sortObjectByKeys } from '@nrwl/workspace/src/utils/ast-utils';

Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/executors/build/build.impl.ts
Expand Up @@ -16,7 +16,7 @@ import {
calculateProjectDependencies,
DependentBuildableProjectNode,
} from '@nrwl/workspace/src/utilities/buildable-libs-utils';
import { checkAndCleanWithSemver } from '@nrwl/workspace/src/utilities/version-utils';
import { checkAndCleanWithSemver } from '@nrwl/devkit/src/utils/semver';

import { prepareConfig } from '../../utils/config';
import { updatePackageJson } from './lib/update-package-json';
Expand Down
Expand Up @@ -9,7 +9,7 @@ import {
visitNotIgnoredFiles,
} from '@nrwl/devkit';
import { lte } from 'semver';
import { checkAndCleanWithSemver } from '@nrwl/workspace/src/utilities/version-utils';
import { checkAndCleanWithSemver } from '@nrwl/devkit/src/utils/semver';
import { storybookVersion } from '../../../utils/versions';
import { createProjectStorybookDir } from '../../../generators/configuration/util-functions';
import { StorybookConfigureSchema } from '../../../generators/configuration/schema';
Expand Down
3 changes: 3 additions & 0 deletions packages/workspace/index.ts
Expand Up @@ -70,7 +70,10 @@ export * from './src/utils/rules/ng-add';
export { updateKarmaConf } from './src/utils/rules/update-karma-conf';
export { visitNotIgnoredFiles } from './src/utils/rules/visit-not-ignored-files';
import * as strings from './src/utils/strings';

// TODO(v17): Remove this export.
export { checkAndCleanWithSemver } from './src/utils/version-utils';

export { updatePackagesInPackageJson } from './src/utils/update-packages-in-package-json';

export { libraryGenerator } from './src/generators/library/library';
Expand Down
27 changes: 9 additions & 18 deletions packages/workspace/src/utilities/version-utils.ts
@@ -1,21 +1,12 @@
import { valid } from 'semver';
import { checkAndCleanWithSemver as _checkAndCleanWithSemver } from '@nrwl/devkit/src/utils/semver';
import { logger } from '@nrwl/devkit';

/** @deprecated Use checkAndCleanWithSemver from @nrwl/devkit/src/utils/semver instead.
* TODO(v17): Remove this function from workspace. Keep it for now since there are projects that use it (e.g. https://github.com/gperdomor/nx-tools).
*/
export function checkAndCleanWithSemver(pkgName: string, version: string) {
let newVersion = version;

if (valid(newVersion)) {
return newVersion;
}

if (version.startsWith('~') || version.startsWith('^')) {
newVersion = version.substring(1);
}

if (!valid(newVersion)) {
throw new Error(
`The package.json lists a version of ${pkgName} that Nx is unable to validate - (${version})`
);
}

return newVersion;
logger.warn(
`checkAndCleanWithSemver has been moved to @nrwl/devkit/src/utils/semver`
);
return _checkAndCleanWithSemver(pkgName, version);
}
@@ -1,7 +1,7 @@
import { chain, noop } from '@angular-devkit/schematics';
import { updateJsonInTree } from './ast-utils';
import { readFileSync } from 'fs';
import { checkAndCleanWithSemver } from './version-utils';
import { checkAndCleanWithSemver } from '@nrwl/devkit/src/utils/semver';
import { lt } from 'semver';
import { addInstallTask } from './rules/add-install-task';

Expand Down