From 3083a1c27b164b7ce7b7b0be110cdf4dfe025dc0 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Fri, 24 Apr 2020 10:43:12 -0400 Subject: [PATCH] Ensure `CHANGELOG.md` has correct version when `git.tagName` is not present Previously we would call `format(null, { version })` which returns `''`. --- index.js | 10 +++------- test.js | 6 +++++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 706ba36..a538da9 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,9 @@ module.exports = class LernaChangelogGeneratorPlugin extends Plugin { get nextVersion() { let { version } = this.config.getContext(); - let nextVersion = this.getTagNameFromVersion(version); + + let tagName = this.config.getContext('git.tagName'); + let nextVersion = tagName ? format(tagName, { version }) : version; return nextVersion; } @@ -33,12 +35,6 @@ module.exports = class LernaChangelogGeneratorPlugin extends Plugin { return this.changelog; } - getTagNameFromVersion(version) { - let tagName = this.config.getContext('git.tagName'); - - return format(tagName, { version }); - } - async getTagForHEAD() { try { return await this.exec('git describe --tags --abbrev=0', { options: { write: false } }); diff --git a/test.js b/test.js index 824b369..d3849ef 100644 --- a/test.js +++ b/test.js @@ -95,7 +95,8 @@ test('it invokes lerna-changelog', async (t) => { }); test('it honors custom git.tagName formatting', async (t) => { - let plugin = buildPlugin(); + let infile = tmp.fileSync().name; + let plugin = buildPlugin({ infile }); plugin.config.setContext({ git: { tagName: 'v${version}' } }); @@ -105,6 +106,9 @@ test('it honors custom git.tagName formatting', async (t) => { ['git describe --tags --abbrev=0', { write: false }], [`${LERNA_PATH} --next-version=Unreleased --from=v1.0.0`, { write: false }], ]); + + const changelog = fs.readFileSync(infile, { encoding: 'utf8' }); + t.is(changelog, `### v1.0.1 (2020-03-18)\n\nThe changelog\n\n`); }); test('it sets the changelog without version information onto the config', async (t) => {