|
11 | 11 | * defaults and user overrides, as well as handling common errors, up front to produce a single, consistent,
|
12 | 12 | * and easy to consume config object for all the `nx release` command implementations.
|
13 | 13 | */
|
14 |
| -import { join } from 'path'; |
| 14 | +import { join, relative } from 'node:path'; |
15 | 15 | import { NxJsonConfiguration } from '../../../config/nx-json';
|
16 | 16 | import { ProjectFileMap, ProjectGraph } from '../../../config/project-graph';
|
17 | 17 | import { readJsonFile } from '../../../utils/fileutils';
|
18 | 18 | import { findMatchingProjects } from '../../../utils/find-matching-projects';
|
19 | 19 | import { output } from '../../../utils/output';
|
20 | 20 | import { PackageJson } from '../../../utils/package-json';
|
21 | 21 | import { workspaceRoot } from '../../../utils/workspace-root';
|
| 22 | +import { resolveChangelogRenderer } from '../utils/resolve-changelog-renderer'; |
22 | 23 | import { resolveNxJsonConfigErrorMessage } from '../utils/resolve-nx-json-error-message';
|
23 | 24 | import { DEFAULT_CONVENTIONAL_COMMITS_CONFIG } from './conventional-commits';
|
24 | 25 |
|
@@ -508,6 +509,8 @@ export async function createNxReleaseConfig(
|
508 | 509 | releaseGroups[releaseGroupName] = finalReleaseGroup;
|
509 | 510 | }
|
510 | 511 |
|
| 512 | + ensureChangelogRenderersAreResolvable(releaseGroups, rootChangelogConfig); |
| 513 | + |
511 | 514 | return {
|
512 | 515 | error: null,
|
513 | 516 | nxReleaseConfig: {
|
@@ -884,3 +887,55 @@ function isProjectPublic(
|
884 | 887 | return false;
|
885 | 888 | }
|
886 | 889 | }
|
| 890 | + |
| 891 | +function ensureChangelogRenderersAreResolvable( |
| 892 | + releaseGroups: NxReleaseConfig['groups'], |
| 893 | + rootChangelogConfig: NxReleaseConfig['changelog'] |
| 894 | +) { |
| 895 | + /** |
| 896 | + * If any form of changelog config is enabled, ensure that any provided changelog renderers are resolvable |
| 897 | + * up front so that we do not end up erroring only after the versioning step has been completed. |
| 898 | + */ |
| 899 | + const uniqueRendererPaths = new Set<string>(); |
| 900 | + |
| 901 | + if ( |
| 902 | + rootChangelogConfig.workspaceChangelog && |
| 903 | + typeof rootChangelogConfig.workspaceChangelog !== 'boolean' && |
| 904 | + rootChangelogConfig.workspaceChangelog.renderer?.length |
| 905 | + ) { |
| 906 | + uniqueRendererPaths.add(rootChangelogConfig.workspaceChangelog.renderer); |
| 907 | + } |
| 908 | + if ( |
| 909 | + rootChangelogConfig.projectChangelogs && |
| 910 | + typeof rootChangelogConfig.projectChangelogs !== 'boolean' && |
| 911 | + rootChangelogConfig.projectChangelogs.renderer?.length |
| 912 | + ) { |
| 913 | + uniqueRendererPaths.add(rootChangelogConfig.projectChangelogs.renderer); |
| 914 | + } |
| 915 | + |
| 916 | + for (const group of Object.values(releaseGroups)) { |
| 917 | + if ( |
| 918 | + group.changelog && |
| 919 | + typeof group.changelog !== 'boolean' && |
| 920 | + group.changelog.renderer?.length |
| 921 | + ) { |
| 922 | + uniqueRendererPaths.add(group.changelog.renderer); |
| 923 | + } |
| 924 | + } |
| 925 | + |
| 926 | + if (!uniqueRendererPaths.size) { |
| 927 | + return; |
| 928 | + } |
| 929 | + |
| 930 | + for (const rendererPath of uniqueRendererPaths) { |
| 931 | + try { |
| 932 | + resolveChangelogRenderer(rendererPath); |
| 933 | + } catch (e) { |
| 934 | + const workspaceRelativePath = relative(workspaceRoot, rendererPath); |
| 935 | + output.error({ |
| 936 | + title: `There was an error when resolving the configured changelog renderer at path: ${workspaceRelativePath}`, |
| 937 | + }); |
| 938 | + throw e; |
| 939 | + } |
| 940 | + } |
| 941 | +} |
0 commit comments