Skip to content

Commit

Permalink
fix(semver): 🐞 add --tagPrefix + deprecate --versionTagPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
edbzn committed Feb 17, 2022
1 parent 03b743d commit 6c22e4c
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 39 deletions.
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,23 @@ nx run workspace:version [....options]

#### Available options

| name | type | default | description |
| ---------------------------- | ---------- | ----------- | ------------------------------------------------ |
| **`--dryRun`** | `boolean` | `false` | run with dry mode |
| **`--noVerify`** | `boolean` | `false` | skip git hooks |
| **`--push`** | `boolean` | `false` | push the release against git origin |
| **`--syncVersions`** | `boolean` | `false` | lock/sync versions between projects |
| **`--skipRootChangelog`** | `boolean` | `false` | skip generating root changelog |
| **`--skipProjectChangelog`** | `boolean` | `false` | skip generating project changelog |
| **`--origin`** | `string` | `'origin'` | push against git remote repository |
| **`--baseBranch`** | `string` | `'main'` | push against git base branch |
| **`--changelogHeader`** | `string` | `undefined` | custom Markdown header for changelogs |
| **`--releaseAs`** | `string` | `undefined` | specify the level of change |
| **`--preid`** | `string` | `undefined` | prerelease identifier |
| **`--versionTagPrefix`** | `string` | `undefined` | specify the tag prefix |
| **`--postTargets`** | `string[]` | `[]` | specify a list of target to execute post-release |
| **`--trackDeps`** | `boolean` | `false` | use dependencies when calculating a version bump |
| **`--commitMessageFormat`** | `string` | `undefined` | format the auto-generated message commit |
| name | type | default | description |
| ---------------------------- | --------------- | ----------- | ------------------------------------------------ |
| **`--dryRun`** | `boolean` | `false` | run with dry mode |
| **`--noVerify`** | `boolean` | `false` | skip git hooks |
| **`--push`** | `boolean` | `false` | push the release against git origin |
| **`--syncVersions`** | `boolean` | `false` | lock/sync versions between projects |
| **`--skipRootChangelog`** | `boolean` | `false` | skip generating root changelog |
| **`--skipProjectChangelog`** | `boolean` | `false` | skip generating project changelog |
| **`--origin`** | `string` | `'origin'` | push against git remote repository |
| **`--baseBranch`** | `string` | `'main'` | push against git base branch |
| **`--changelogHeader`** | `string` | `undefined` | custom Markdown header for changelogs |
| **`--releaseAs`** | `string` | `undefined` | specify the level of change |
| **`--preid`** | `string` | `undefined` | prerelease identifier |
| **`--tagPrefix`** | `string | null` | `undefined` | specify the tag prefix |
| **`--postTargets`** | `string[]` | `[]` | specify a list of target to execute post-release |
| **`--trackDeps`** | `boolean` | `false` | use dependencies when calculating a version bump |
| **`--commitMessageFormat`** | `string` | `undefined` | format the auto-generated message commit |

#### Configuration using the file

Expand All @@ -102,7 +102,7 @@ Note that you can define the options you want to customize using the `workspace.
"executor": "@jscutlery/semver:version",
"options": {
"baseBranch": "master",
"versionTagPrefix": "${target}@"
"tagPrefix": "${target}@"
}
}
```
Expand All @@ -123,7 +123,7 @@ nx run workspace:version --releaseAs=prerelease --preid=beta

#### Tag prefix customization

The **`--versionTagPrefix`** option allows you to customize the tag prefix.
The **`--tagPrefix`** option allows you to customize the tag prefix.

With the sync mode the tag prefix is set to `"v"` by default, which is resolved to `v0.0.1` for example. Note that only one tag is created for the whole workspace.

Expand Down
2 changes: 1 addition & 1 deletion packages/semver/src/executors/version/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe('@jscutlery/semver:version', () => {

it('should run standard-version with a custom tag', async () => {
const { success } = await version(
{ ...options, versionTagPrefix: 'custom-tag-prefix/${target}-' },
{ ...options, tagPrefix: 'custom-tag-prefix/${target}-' },
context
);

Expand Down
6 changes: 3 additions & 3 deletions packages/semver/src/executors/version/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from './utils/get-project-dependencies';
import { tryPushToGitRemote } from './utils/git';
import { runPostTargets } from './utils/post-target';
import { formatTag, resolveTagPrefix } from './utils/tag';
import { formatTag, formatTagPrefix } from './utils/tag';
import { tryBump } from './utils/try-bump';
import { getProjectRoot } from './utils/workspace';
import { versionProject, versionWorkspace } from './version';
Expand Down Expand Up @@ -48,7 +48,7 @@ export default async function version(
const projectName = context.projectName as string;
const preset = 'angular';

const tagPrefix = resolveTagPrefix({
const tagPrefix = formatTagPrefix({
versionTagPrefix,
projectName,
syncVersions,
Expand All @@ -75,7 +75,6 @@ export default async function version(
tagPrefix,
releaseType: releaseAs,
preid,
versionTagPrefix,
syncVersions,
});

Expand Down Expand Up @@ -199,5 +198,6 @@ function normalizeOptions(options: VersionBuilderSchema) {
skipProjectChangelog: options.skipProjectChangelog as boolean,
releaseAs: options.releaseAs ?? options.version,
changelogHeader: options.changelogHeader ?? defaultHeader,
versionTagPrefix: options.tagPrefix ?? options.versionTagPrefix,
};
}
7 changes: 6 additions & 1 deletion packages/semver/src/executors/version/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ export interface VersionBuilderSchema {
releaseAs?: ReleaseIdentifier;
preid?: string;
changelogHeader?: string;
versionTagPrefix?: string;
tagPrefix?: string | null;
/**
* @deprecated Use the alias tagPrefix (--tagPrefix) instead.
* @sunset 3.0.0
*/
versionTagPrefix?: string | null;
postTargets: string[];
commitMessageFormat?: string;
}
8 changes: 6 additions & 2 deletions packages/semver/src/executors/version/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"default": false
},
"version": {
"description": "Manually increment the version by that keyword.",
"description": "(Deprecated) Manually increment the version by that keyword.",
"type": "string"
},
"releaseAs": {
Expand All @@ -62,10 +62,14 @@
"description": "Use the next semantic prerelease version with a specific prerelease identifier.",
"type": "string"
},
"versionTagPrefix": {
"tagPrefix": {
"description": "Version tag prefix. Defaults are 'v' and '${target}-' for sync and independent modes. ${target} will be replaced with context target value for independent mode.",
"oneOf": [{ "type": "string" }, { "type": "null" }]
},
"versionTagPrefix": {
"description": "(Deprecated) Version tag prefix. Defaults are 'v' and '${target}-' for sync and independent modes. ${target} will be replaced with context target value for independent mode.",
"oneOf": [{ "type": "string" }, { "type": "null" }]
},
"postTargets": {
"description": "Specify the targets to run after a new version was successfully created.",
"type": "array",
Expand Down
14 changes: 7 additions & 7 deletions packages/semver/src/executors/version/utils/tag.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { resolveTagPrefix } from './tag';
import { formatTagPrefix } from './tag';

describe(resolveTagPrefix.name, () => {
describe(formatTagPrefix.name, () => {
it('should resolve interpolated string', () => {
expect(
resolveTagPrefix({
versionTagPrefix: 'testVersionTagPrefix',
formatTagPrefix({
versionTagPrefix: 'testtagPrefix',
projectName: 'testProjectName',
syncVersions: true,
})
).toBe('testVersionTagPrefix');
).toBe('testtagPrefix');
});

it('should resolve syncVersions', () => {
expect(
resolveTagPrefix({
formatTagPrefix({
versionTagPrefix: undefined,
projectName: 'testProjectName',
syncVersions: true,
Expand All @@ -23,7 +23,7 @@ describe(resolveTagPrefix.name, () => {

it('should resolve default tag', () => {
expect(
resolveTagPrefix({
formatTagPrefix({
versionTagPrefix: undefined,
projectName: 'testProjectName',
syncVersions: false,
Expand Down
9 changes: 5 additions & 4 deletions packages/semver/src/executors/version/utils/tag.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolveInterpolation } from './resolve-interpolation';

export function resolveTagPrefix({
export function formatTagPrefix({
versionTagPrefix,
projectName,
syncVersions,
Expand All @@ -10,15 +10,16 @@ export function resolveTagPrefix({
syncVersions: boolean;
}): string {
if (versionTagPrefix !== undefined) {
const resolvingContest = {
return resolveInterpolation(versionTagPrefix as string, {
target: projectName,
projectName: projectName,
};
return resolveInterpolation(versionTagPrefix as string, resolvingContest) as string;
}) as string;
}

if (syncVersions) {
return 'v';
}

return `${projectName}-`;
}

Expand Down
5 changes: 3 additions & 2 deletions packages/semver/src/executors/version/utils/try-bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { promisify } from 'util';

import { getLastVersion } from './get-last-version';
import { getCommits, getFirstCommitRef } from './git';
import { formatTag, resolveTagPrefix } from './tag';
import { formatTag, formatTagPrefix } from './tag';

import type { Observable } from 'rxjs';
import type { ReleaseIdentifier } from '../schema';
import type { DependencyRoot } from './get-project-dependencies';

export type Version =
| {
type: 'project';
Expand Down Expand Up @@ -248,7 +249,7 @@ export function _getDependencyVersions({
return forkJoin(
dependencyRoots.map(({ path: projectRoot, name: projectName }) => {
/* Get dependency version changes since last project version */
const tagPrefix = resolveTagPrefix({
const tagPrefix = formatTagPrefix({
versionTagPrefix,
projectName,
syncVersions: !!syncVersions,
Expand Down

0 comments on commit 6c22e4c

Please sign in to comment.