Skip to content

Commit

Permalink
feat(release)!: rewrite ChangelogRenderer to a class API and remove d…
Browse files Browse the repository at this point in the history
…eprecated config (#28229)

BREAKING CHANGE

In Nx v19, implementing a custom changelog renderer would involve a lot
of work on the user side. They would need to create an additional
function making every property available in its declaration and then
call the underlying default one and customize the final string (or
reimplement the whole thing).

E.g.

```js
const changelogRenderer = async ({
  projectGraph,
  commits,
  releaseVersion,
  project,
  entryWhenNoChanges,
  changelogRenderOptions,
  repoSlug,
  conventionalCommitsConfig,
  changes,
}) => {
  const defaultChangelog = await defaultChangelogRenderer({
    projectGraph,
    commits,
    releaseVersion,
    project,
    entryWhenNoChanges,
    changelogRenderOptions,
    repoSlug,
    conventionalCommitsConfig,
    changes,
  });

  // ...Do custom stuff and return final string...
};

module.exports = changelogRenderer;
```

In Nx v20, changelog renderer are classes. The DefaultChangelogRenderer
can therefore easily and granularly be extended and customized, and the
config does not need to be redeclared on the user side at all. We will
improve things even further in this area, but this breaking change is an
important stepping stone.

E.g. for manipulating the final string equivalent to the previous
example:

```js
module.exports = class CustomChangelogRenderer extends (
  DefaultChangelogRenderer
) {
  async render() {
    const defaultChangelogEntry = await super.render();
    // ...Do custom stuff and return final string...
  }
};
```

E.g. for customizing just how titles get rendered:

```js
class CustomChangelogRenderer extends DefaultChangelogRenderer {
  renderVersionTitle(): string {
    return 'Custom Version Title';
  }
}
```
  • Loading branch information
JamesHenry authored Oct 2, 2024
1 parent fe01c61 commit 2c0994a
Show file tree
Hide file tree
Showing 8 changed files with 1,017 additions and 1,086 deletions.
6 changes: 0 additions & 6 deletions e2e/release/src/circular-dependencies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,6 @@ describe('nx release circular dependencies', () => {
+ # 2.0.0 (YYYY-MM-DD)
+
+
+ ### 🧱 Updated Dependencies
+
+ - Updated {project-name} to 2.0.0
Expand All @@ -556,7 +555,6 @@ describe('nx release circular dependencies', () => {
+ # 2.0.0 (YYYY-MM-DD)
+
+
+ ### 🧱 Updated Dependencies
+
+ - Updated {project-name} to 2.0.0
Expand Down Expand Up @@ -867,7 +865,6 @@ describe('nx release circular dependencies', () => {
+ # 2.0.0 (YYYY-MM-DD)
+
+
+ ### 🧱 Updated Dependencies
+
+ - Updated {project-name} to 2.0.0
Expand All @@ -879,7 +876,6 @@ describe('nx release circular dependencies', () => {
+ # 2.0.0 (YYYY-MM-DD)
+
+
+ ### 🧱 Updated Dependencies
+
+ - Updated {project-name} to 2.0.0
Expand Down Expand Up @@ -1054,7 +1050,6 @@ describe('nx release circular dependencies', () => {
+ # 2.0.0 (YYYY-MM-DD)
+
+
+ ### 🧱 Updated Dependencies
+
+ - Updated {project-name} to 1.0.1
Expand All @@ -1066,7 +1061,6 @@ describe('nx release circular dependencies', () => {
+ ## 1.0.1 (YYYY-MM-DD)
+
+
+ ### 🧱 Updated Dependencies
+
+ - Updated {project-name} to 2.0.0
Expand Down
7 changes: 0 additions & 7 deletions e2e/release/src/conventional-commits-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,10 @@ describe('nx release conventional commits config', () => {
expect(pkg1Changelog).toMatchInlineSnapshot(`
# 1.0.0 (YYYY-MM-DD)
### Custom Type
- ⚠️ **{project-name}:** this is a breaking change
### ⚠️ Breaking Changes
- ⚠️ **{project-name}:** this is a breaking change
Expand All @@ -379,7 +377,6 @@ describe('nx release conventional commits config', () => {
expect(pkg2Changelog).toMatchInlineSnapshot(`
# 1.0.0 (YYYY-MM-DD)
### Custom Type
- **{project-name}:** this is a custom type
Expand All @@ -389,7 +386,6 @@ describe('nx release conventional commits config', () => {
expect(pkg3Changelog).toMatchInlineSnapshot(`
# 1.0.0 (YYYY-MM-DD)
### Custom Docs Header
- this is a doc
Expand All @@ -408,7 +404,6 @@ describe('nx release conventional commits config', () => {
expect(pkg5Changelog).toMatchInlineSnapshot(`
# 1.0.0 (YYYY-MM-DD)
### 🔥 Performance
- this is a performance improvement
Expand All @@ -418,12 +413,10 @@ describe('nx release conventional commits config', () => {
expect(pkg6Changelog).toMatchInlineSnapshot(`
# 1.0.0 (YYYY-MM-DD)
### 💅 Refactors
- this is refactor
### 📦 Build
- this is a build
Expand Down
4 changes: 1 addition & 3 deletions e2e/release/src/release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ describe('nx release', () => {
+ ## 999.9.9 (YYYY-MM-DD)
+
+
+ ### 🚀 Features
+
+ - an awesome new feature ([{COMMIT_SHA}](https://github.com/nrwl/fake-repo/commit/{COMMIT_SHA}))
Expand All @@ -150,7 +149,6 @@ describe('nx release', () => {
expect(readFile('CHANGELOG.md')).toMatchInlineSnapshot(`
## 999.9.9 (YYYY-MM-DD)
### 🚀 Features
- an awesome new feature ([{COMMIT_SHA}](https://github.com/nrwl/fake-repo/commit/{COMMIT_SHA}))
Expand Down Expand Up @@ -666,7 +664,7 @@ describe('nx release', () => {
+
## 999.9.9 (YYYY-MM-DD)
### 🚀 Features
NX Previewing an entry in {project-name}/CHANGELOG.md for v1000.0.0-next.0
Expand Down
Loading

0 comments on commit 2c0994a

Please sign in to comment.