feat(core): allow setting true for changelog config to enable with defaults (#20376)
This commit is contained in:
parent
d06a5e76d3
commit
74d438cd2c
@ -586,6 +586,88 @@ describe('createNxReleaseConfig()', () => {
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('should allow using true for group level changelog as an equivalent of an empty object (i.e. use the defaults)', async () => {
|
||||
const res = await createNxReleaseConfig(projectGraph, {
|
||||
groups: {
|
||||
'group-1': {
|
||||
projects: ['lib-a'],
|
||||
changelog: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(res).toMatchInlineSnapshot(`
|
||||
{
|
||||
"error": null,
|
||||
"nxReleaseConfig": {
|
||||
"changelog": {
|
||||
"git": {
|
||||
"commit": false,
|
||||
"commitArgs": "",
|
||||
"commitMessage": "",
|
||||
"tag": false,
|
||||
"tagArgs": "",
|
||||
"tagMessage": "",
|
||||
},
|
||||
"projectChangelogs": false,
|
||||
"workspaceChangelog": {
|
||||
"createRelease": false,
|
||||
"entryWhenNoChanges": "This was a version bump only, there were no code changes.",
|
||||
"file": "{workspaceRoot}/CHANGELOG.md",
|
||||
"renderOptions": {
|
||||
"includeAuthors": true,
|
||||
},
|
||||
"renderer": "nx/changelog-renderer",
|
||||
},
|
||||
},
|
||||
"git": {
|
||||
"commit": false,
|
||||
"commitArgs": "",
|
||||
"commitMessage": "",
|
||||
"tag": false,
|
||||
"tagArgs": "",
|
||||
"tagMessage": "",
|
||||
},
|
||||
"groups": {
|
||||
"group-1": {
|
||||
"changelog": {
|
||||
"createRelease": false,
|
||||
"entryWhenNoChanges": "This was a version bump only for {projectName} to align it with other projects, there were no code changes.",
|
||||
"file": "{projectRoot}/CHANGELOG.md",
|
||||
"renderOptions": {
|
||||
"includeAuthors": true,
|
||||
},
|
||||
"renderer": "nx/changelog-renderer",
|
||||
},
|
||||
"projects": [
|
||||
"lib-a",
|
||||
],
|
||||
"projectsRelationship": "fixed",
|
||||
"releaseTagPattern": "v{version}",
|
||||
"version": {
|
||||
"generator": "@nx/js:release-version",
|
||||
"generatorOptions": {},
|
||||
},
|
||||
},
|
||||
},
|
||||
"projectsRelationship": "fixed",
|
||||
"releaseTagPattern": "v{version}",
|
||||
"version": {
|
||||
"generator": "@nx/js:release-version",
|
||||
"generatorOptions": {},
|
||||
"git": {
|
||||
"commit": false,
|
||||
"commitArgs": "",
|
||||
"commitMessage": "",
|
||||
"tag": false,
|
||||
"tagArgs": "",
|
||||
"tagMessage": "",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('user config -> top level version', () => {
|
||||
@ -1062,6 +1144,96 @@ describe('createNxReleaseConfig()', () => {
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('should allow using true for workspaceChangelog and projectChangelogs as an equivalent of an empty object (i.e. use the defaults)', async () => {
|
||||
const res = await createNxReleaseConfig(projectGraph, {
|
||||
changelog: {
|
||||
projectChangelogs: true,
|
||||
workspaceChangelog: true,
|
||||
},
|
||||
});
|
||||
expect(res).toMatchInlineSnapshot(`
|
||||
{
|
||||
"error": null,
|
||||
"nxReleaseConfig": {
|
||||
"changelog": {
|
||||
"git": {
|
||||
"commit": false,
|
||||
"commitArgs": "",
|
||||
"commitMessage": "",
|
||||
"tag": false,
|
||||
"tagArgs": "",
|
||||
"tagMessage": "",
|
||||
},
|
||||
"projectChangelogs": {
|
||||
"createRelease": false,
|
||||
"entryWhenNoChanges": "This was a version bump only for {projectName} to align it with other projects, there were no code changes.",
|
||||
"file": "{projectRoot}/CHANGELOG.md",
|
||||
"renderOptions": {
|
||||
"includeAuthors": true,
|
||||
},
|
||||
"renderer": "nx/changelog-renderer",
|
||||
},
|
||||
"workspaceChangelog": {
|
||||
"createRelease": false,
|
||||
"entryWhenNoChanges": "This was a version bump only, there were no code changes.",
|
||||
"file": "{workspaceRoot}/CHANGELOG.md",
|
||||
"renderOptions": {
|
||||
"includeAuthors": true,
|
||||
},
|
||||
"renderer": "nx/changelog-renderer",
|
||||
},
|
||||
},
|
||||
"git": {
|
||||
"commit": false,
|
||||
"commitArgs": "",
|
||||
"commitMessage": "",
|
||||
"tag": false,
|
||||
"tagArgs": "",
|
||||
"tagMessage": "",
|
||||
},
|
||||
"groups": {
|
||||
"__default__": {
|
||||
"changelog": {
|
||||
"createRelease": false,
|
||||
"entryWhenNoChanges": "This was a version bump only for {projectName} to align it with other projects, there were no code changes.",
|
||||
"file": "{projectRoot}/CHANGELOG.md",
|
||||
"renderOptions": {
|
||||
"includeAuthors": true,
|
||||
},
|
||||
"renderer": "nx/changelog-renderer",
|
||||
},
|
||||
"projects": [
|
||||
"lib-a",
|
||||
"lib-b",
|
||||
"nx",
|
||||
],
|
||||
"projectsRelationship": "fixed",
|
||||
"releaseTagPattern": "v{version}",
|
||||
"version": {
|
||||
"generator": "@nx/js:release-version",
|
||||
"generatorOptions": {},
|
||||
},
|
||||
},
|
||||
},
|
||||
"projectsRelationship": "fixed",
|
||||
"releaseTagPattern": "v{version}",
|
||||
"version": {
|
||||
"generator": "@nx/js:release-version",
|
||||
"generatorOptions": {},
|
||||
"git": {
|
||||
"commit": false,
|
||||
"commitArgs": "",
|
||||
"commitMessage": "",
|
||||
"tag": false,
|
||||
"tagArgs": "",
|
||||
"tagMessage": "",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('user config -> top level and group level changelog combined', () => {
|
||||
|
||||
@ -11,7 +11,10 @@
|
||||
* defaults and user overrides, as well as handling common errors, up front to produce a single, consistent,
|
||||
* and easy to consume config object for all the `nx release` command implementations.
|
||||
*/
|
||||
import { NxJsonConfiguration } from '../../../config/nx-json';
|
||||
import {
|
||||
NxJsonConfiguration,
|
||||
NxReleaseChangelogConfiguration,
|
||||
} from '../../../config/nx-json';
|
||||
import { output, type ProjectGraph } from '../../../devkit-exports';
|
||||
import { findMatchingProjects } from '../../../utils/find-matching-projects';
|
||||
import { projectHasTarget } from '../../../utils/project-graph-utils';
|
||||
@ -27,6 +30,14 @@ type EnsureProjectsArray<T> = {
|
||||
: T[K];
|
||||
};
|
||||
|
||||
type RemoveTrueFromType<T> = T extends true ? never : T;
|
||||
type RemoveTrueFromProperties<T, K extends keyof T> = {
|
||||
[P in keyof T]: P extends K ? RemoveTrueFromType<T[P]> : T[P];
|
||||
};
|
||||
type RemoveTrueFromPropertiesOnEach<T, K extends keyof T[keyof T]> = {
|
||||
[U in keyof T]: RemoveTrueFromProperties<T[U], K>;
|
||||
};
|
||||
|
||||
export const CATCH_ALL_RELEASE_GROUP = '__default__';
|
||||
|
||||
/**
|
||||
@ -41,7 +52,15 @@ export const CATCH_ALL_RELEASE_GROUP = '__default__';
|
||||
export type NxReleaseConfig = DeepRequired<
|
||||
NxJsonConfiguration['release'] & {
|
||||
groups: DeepRequired<
|
||||
EnsureProjectsArray<NxJsonConfiguration['release']['groups']>
|
||||
RemoveTrueFromPropertiesOnEach<
|
||||
EnsureProjectsArray<NxJsonConfiguration['release']['groups']>,
|
||||
'changelog'
|
||||
>
|
||||
>;
|
||||
// Remove the true shorthand from the changelog config types, it will be normalized to a default object
|
||||
changelog: RemoveTrueFromProperties<
|
||||
DeepRequired<NxJsonConfiguration['release']['changelog']>,
|
||||
'workspaceChangelog' | 'projectChangelogs'
|
||||
>;
|
||||
}
|
||||
>;
|
||||
@ -166,13 +185,27 @@ export async function createNxReleaseConfig(
|
||||
],
|
||||
userConfig.version as Partial<NxReleaseConfig['version']>
|
||||
);
|
||||
|
||||
if (userConfig.changelog?.workspaceChangelog) {
|
||||
userConfig.changelog.workspaceChangelog = normalizeTrueToEmptyObject(
|
||||
userConfig.changelog.workspaceChangelog
|
||||
);
|
||||
}
|
||||
if (userConfig.changelog?.projectChangelogs) {
|
||||
userConfig.changelog.projectChangelogs = normalizeTrueToEmptyObject(
|
||||
userConfig.changelog.projectChangelogs
|
||||
);
|
||||
}
|
||||
|
||||
const rootChangelogConfig: NxReleaseConfig['changelog'] = deepMergeDefaults(
|
||||
[
|
||||
WORKSPACE_DEFAULTS.changelog,
|
||||
// Merge in the git defaults from the top level
|
||||
{ git: rootGitConfig } as NxReleaseConfig['changelog'],
|
||||
],
|
||||
userConfig.changelog as Partial<NxReleaseConfig['changelog']>
|
||||
normalizeTrueToEmptyObject(userConfig.changelog) as Partial<
|
||||
NxReleaseConfig['changelog']
|
||||
>
|
||||
);
|
||||
|
||||
// git configuration is not supported at the group level, only the root/command level
|
||||
@ -293,6 +326,12 @@ export async function createNxReleaseConfig(
|
||||
const projectsRelationship =
|
||||
releaseGroup.projectsRelationship || GROUP_DEFAULTS.projectsRelationship;
|
||||
|
||||
if (releaseGroup.changelog) {
|
||||
releaseGroup.changelog = normalizeTrueToEmptyObject(
|
||||
releaseGroup.changelog
|
||||
) as NxReleaseConfig['groups']['string']['changelog'];
|
||||
}
|
||||
|
||||
const groupDefaults: NxReleaseConfig['groups']['string'] = {
|
||||
projectsRelationship,
|
||||
projects: matchingProjects,
|
||||
@ -338,6 +377,15 @@ export async function createNxReleaseConfig(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* In some cases it is much cleaner and more intuitive for the user to be able to
|
||||
* specify `true` in their config when they want to use the default config for a
|
||||
* particular property, rather than having to specify an empty object.
|
||||
*/
|
||||
function normalizeTrueToEmptyObject<T>(value: T | boolean): T | {} {
|
||||
return value === true ? {} : value;
|
||||
}
|
||||
|
||||
export async function handleNxReleaseConfigError(
|
||||
error: CreateNxReleaseConfigError
|
||||
): Promise<never> {
|
||||
|
||||
@ -162,11 +162,17 @@ interface NxReleaseConfiguration {
|
||||
*/
|
||||
version?: NxReleaseVersionConfiguration;
|
||||
/**
|
||||
* Optionally override project changelog configuration for this group.
|
||||
* Project changelogs are disabled by default.
|
||||
*
|
||||
* Here you can optionally override project changelog configuration for this group.
|
||||
* Notes about boolean values:
|
||||
*
|
||||
* - true = enable project level changelogs using default configuration
|
||||
* - false = explicitly disable project level changelogs
|
||||
*
|
||||
* NOTE: git configuration is not supported at the group level, only the root/command level
|
||||
*/
|
||||
changelog?: NxReleaseChangelogConfiguration | false;
|
||||
changelog?: NxReleaseChangelogConfiguration | boolean;
|
||||
/**
|
||||
* Optionally override the git/release tag pattern to use for this group.
|
||||
*/
|
||||
@ -185,8 +191,20 @@ interface NxReleaseConfiguration {
|
||||
* Enable or override configuration for git operations as part of the changelog subcommand
|
||||
*/
|
||||
git?: NxReleaseGitConfiguration;
|
||||
workspaceChangelog?: NxReleaseChangelogConfiguration | false;
|
||||
projectChangelogs?: NxReleaseChangelogConfiguration | false;
|
||||
/**
|
||||
* Workspace changelog is enabled by default. Notes about boolean values:
|
||||
*
|
||||
* - true = explicitly enable workspace changelog using default configuration
|
||||
* - false = disable workspace changelog
|
||||
*/
|
||||
workspaceChangelog?: NxReleaseChangelogConfiguration | boolean;
|
||||
/**
|
||||
* Project changelogs are disabled by default. Notes about boolean values:
|
||||
*
|
||||
* - true = enable project level changelogs using default configuration
|
||||
* - false = explicitly disable project level changelogs
|
||||
*/
|
||||
projectChangelogs?: NxReleaseChangelogConfiguration | boolean;
|
||||
};
|
||||
/**
|
||||
* If no version config is provided, we will assume that @nx/js:release-version
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user