diff --git a/commands/version/__tests__/__snapshots__/version-bump-prerelease.test.js.snap b/commands/version/__tests__/__snapshots__/version-bump-prerelease.test.js.snap index 7e67e25bfc..73a294ddfc 100644 --- a/commands/version/__tests__/__snapshots__/version-bump-prerelease.test.js.snap +++ b/commands/version/__tests__/__snapshots__/version-bump-prerelease.test.js.snap @@ -158,13 +158,12 @@ new file mode 100644 index SHA..SHA --- /dev/null +++ b/CHANGELOG.md -@@ -0,0 +1,12 @@ +@@ -0,0 +1,11 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + -+ +## [1.0.1-beta.4](/compare/v1.0.1-beta.3...v1.0.1-beta.4) (YYYY-MM-DD) + + @@ -183,13 +182,12 @@ new file mode 100644 index SHA..SHA --- /dev/null +++ b/packages/package-3/CHANGELOG.md -@@ -0,0 +1,12 @@ +@@ -0,0 +1,11 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + -+ +## [1.0.1-beta.4](/compare/v1.0.1-beta.3...v1.0.1-beta.4) (YYYY-MM-DD) + + diff --git a/core/conventional-commits/__tests__/__snapshots__/conventional-commits.test.js.snap b/core/conventional-commits/__tests__/__snapshots__/conventional-commits.test.js.snap index 0d5cbb3298..41745d19d9 100644 --- a/core/conventional-commits/__tests__/__snapshots__/conventional-commits.test.js.snap +++ b/core/conventional-commits/__tests__/__snapshots__/conventional-commits.test.js.snap @@ -31,7 +31,6 @@ exports[`conventional-commits updateChangelog() creates files if they do not exi All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - # 1.1.0 (YYYY-MM-DD) @@ -47,7 +46,6 @@ exports[`conventional-commits updateChangelog() creates files if they do not exi All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - # 1.1.0 (YYYY-MM-DD) @@ -84,8 +82,7 @@ exports[`conventional-commits updateChangelog() updates fixed changelogs: leaf 1 All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [1.0.1](https://github.com/lerna/conventional-commits-fixed/compare/v1.0.0...v1.0.1) (YYYY-MM-DD) +## [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD) ### Bug Fixes @@ -112,8 +109,7 @@ exports[`conventional-commits updateChangelog() updates fixed changelogs: root 1 All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [1.0.1](https://github.com/lerna/conventional-commits-fixed/compare/v1.0.0...v1.0.1) (YYYY-MM-DD) +## [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD) ### Bug Fixes @@ -140,8 +136,7 @@ exports[`conventional-commits updateChangelog() updates independent changelogs 1 All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [1.0.1](https://github.com/lerna/conventional-commits-independent/compare/package-1@1.0.0...package-1@1.0.1) (YYYY-MM-DD) +## [1.0.1](/compare/package-1@1.0.0...package-1@1.0.1) (YYYY-MM-DD) ### Bug Fixes @@ -156,8 +151,7 @@ exports[`conventional-commits updateChangelog() updates independent changelogs 2 All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -# [1.1.0](https://github.com/lerna/conventional-commits-independent/compare/package-2@1.0.0...package-2@1.1.0) (YYYY-MM-DD) +# [1.1.0](/compare/package-2@1.0.0...package-2@1.1.0) (YYYY-MM-DD) ### Features diff --git a/core/conventional-commits/lib/constants.js b/core/conventional-commits/lib/constants.js new file mode 100644 index 0000000000..30d177d8fb --- /dev/null +++ b/core/conventional-commits/lib/constants.js @@ -0,0 +1,18 @@ +"use strict"; + +// changelogs are always written with LF line endings +const EOL = "\n"; + +exports.EOL = EOL; + +exports.BLANK_LINE = EOL + EOL; + +exports.COMMIT_GUIDELINE = + "See [Conventional Commits](https://conventionalcommits.org) for commit guidelines."; + +exports.CHANGELOG_HEADER = [ + "# Change Log", + "", + "All notable changes to this project will be documented in this file.", + exports.COMMIT_GUIDELINE, +].join(EOL); diff --git a/core/conventional-commits/lib/make-bump-only-filter.js b/core/conventional-commits/lib/make-bump-only-filter.js index f7aad766fc..32d582a5cb 100644 --- a/core/conventional-commits/lib/make-bump-only-filter.js +++ b/core/conventional-commits/lib/make-bump-only-filter.js @@ -1,11 +1,9 @@ "use strict"; -const os = require("os"); +const { BLANK_LINE } = require("./constants"); module.exports = makeBumpOnlyFilter; -const BLANK_LINE = os.EOL + os.EOL; - function makeBumpOnlyFilter(pkg) { return newEntry => { // When force publishing, it is possible that there will be no actual changes, only a version bump. diff --git a/core/conventional-commits/lib/read-existing-changelog.js b/core/conventional-commits/lib/read-existing-changelog.js index 74a968a608..6ad764a2cc 100644 --- a/core/conventional-commits/lib/read-existing-changelog.js +++ b/core/conventional-commits/lib/read-existing-changelog.js @@ -2,6 +2,7 @@ const fs = require("fs-extra"); const path = require("path"); +const { BLANK_LINE, COMMIT_GUIDELINE } = require("./constants"); module.exports = readExistingChangelog; @@ -14,12 +15,11 @@ function readExistingChangelog(pkg) { chain = chain.then(() => fs.readFile(changelogFileLoc, "utf8").catch(() => "")); chain = chain.then(changelogContents => { - // CHANGELOG entries start with { + return fs.writeFile(changelogFileLoc, content.trim() + EOL).then(() => { log.verbose(type, "wrote", changelogFileLoc); return changelogFileLoc; diff --git a/core/conventional-commits/package.json b/core/conventional-commits/package.json index f3e2f26544..2ddbaff7f6 100644 --- a/core/conventional-commits/package.json +++ b/core/conventional-commits/package.json @@ -32,10 +32,9 @@ }, "dependencies": { "@lerna/validation-error": "file:../validation-error", - "conventional-changelog-angular": "^3.0.7", + "conventional-changelog-angular": "^5.0.1", "conventional-changelog-core": "^3.1.0", "conventional-recommended-bump": "^4.0.1", - "dedent": "^0.7.0", "fs-extra": "^7.0.0", "get-stream": "^4.0.0", "npm-package-arg": "^6.0.0", diff --git a/helpers/serialize-changelog/index.js b/helpers/serialize-changelog/index.js index e8eba11672..63e158d5a0 100644 --- a/helpers/serialize-changelog/index.js +++ b/helpers/serialize-changelog/index.js @@ -8,6 +8,7 @@ module.exports = { serialize(str) { return gitSHA .serialize(normalizeNewline(str)) + .replace(/(\[.*?\])\(.*\/compare\/(.*?)\)/g, "$1(/compare/$2)") .replace(/(\[.*?\])\(.*\/commits\/SHA\)/g, "$1(COMMIT_URL)") .replace(/\(\d{4}-\d{2}-\d{2}\)/g, "(YYYY-MM-DD)"); }, diff --git a/integration/lerna-publish-conventional-fixed.test.js b/integration/lerna-publish-conventional-fixed.test.js index aba90bb989..d7e2168c4d 100644 --- a/integration/lerna-publish-conventional-fixed.test.js +++ b/integration/lerna-publish-conventional-fixed.test.js @@ -52,6 +52,10 @@ Successfully published: - package-4@2.0.0 `); + // ensure changelog header is not duplicated + await commitChangeToPackage(cwd, "package-2", "fix(package-2): And another thing", { thing: true }); + await cliRunner(cwd, env)(...args); + const changelogFilePaths = await globby(["**/CHANGELOG.md"], { cwd, absolute: true, @@ -75,7 +79,17 @@ Successfully published: All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - +## [2.0.1](/compare/v2.0.0...v2.0.1) (YYYY-MM-DD) + + +### Bug Fixes + +* **package-2:** And another thing ([SHA](COMMIT_URL)) + + + + + # 2.0.0 (YYYY-MM-DD) @@ -107,7 +121,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - # 2.0.0 (YYYY-MM-DD) @@ -132,7 +145,17 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - +## [2.0.1](/compare/v2.0.0...v2.0.1) (YYYY-MM-DD) + + +### Bug Fixes + +* **package-2:** And another thing ([SHA](COMMIT_URL)) + + + + + # 2.0.0 (YYYY-MM-DD) @@ -156,7 +179,14 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - +## [2.0.1](/compare/v2.0.0...v2.0.1) (YYYY-MM-DD) + +**Note:** Version bump only for package package-3 + + + + + # 2.0.0 (YYYY-MM-DD) @@ -181,7 +211,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - # 2.0.0 (YYYY-MM-DD) @@ -200,7 +229,14 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - +## [2.0.1](/compare/v2.0.0...v2.0.1) (YYYY-MM-DD) + +**Note:** Version bump only for package package-5 + + + + + # 2.0.0 (YYYY-MM-DD) diff --git a/integration/lerna-publish-conventional-independent.test.js b/integration/lerna-publish-conventional-independent.test.js index 9ccef79219..861848d56e 100644 --- a/integration/lerna-publish-conventional-independent.test.js +++ b/integration/lerna-publish-conventional-independent.test.js @@ -52,6 +52,10 @@ Successfully published: - package-4@4.1.0 `); + // ensure changelog header is not duplicated + await commitChangeToPackage(cwd, "package-2", "fix(package-2): And another thing", { thing: true }); + await cliRunner(cwd, env)(...args); + const changelogFilePaths = await globby(["**/CHANGELOG.md"], { cwd, absolute: true, @@ -75,7 +79,6 @@ Successfully published: All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - # 1.1.0 (YYYY-MM-DD) @@ -100,7 +103,17 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - +## [2.1.1](/compare/package-2@2.1.0...package-2@2.1.1) (YYYY-MM-DD) + + +### Bug Fixes + +* **package-2:** And another thing ([SHA](COMMIT_URL)) + + + + + # 2.1.0 (YYYY-MM-DD) @@ -124,7 +137,14 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - +## [4.0.1](/compare/package-3@4.0.0...package-3@4.0.1) (YYYY-MM-DD) + +**Note:** Version bump only for package package-3 + + + + + # 4.0.0 (YYYY-MM-DD) @@ -149,7 +169,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - # 4.1.0 (YYYY-MM-DD) @@ -168,7 +187,14 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - +## [5.1.1](/compare/package-5@5.1.0...package-5@5.1.1) (YYYY-MM-DD) + +**Note:** Version bump only for package package-5 + + + + + # 5.1.0 (YYYY-MM-DD) diff --git a/package-lock.json b/package-lock.json index 34fd0ef477..47266cad52 100644 --- a/package-lock.json +++ b/package-lock.json @@ -359,10 +359,9 @@ "version": "file:core/conventional-commits", "requires": { "@lerna/validation-error": "file:core/validation-error", - "conventional-changelog-angular": "^3.0.7", + "conventional-changelog-angular": "^5.0.1", "conventional-changelog-core": "^3.1.0", "conventional-recommended-bump": "^4.0.1", - "dedent": "^0.7.0", "fs-extra": "^7.0.0", "get-stream": "^4.0.0", "npm-package-arg": "^6.0.0", @@ -1789,9 +1788,9 @@ "dev": true }, "conventional-changelog-angular": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/conventional-changelog-angular/-/conventional-changelog-angular-3.0.7.tgz", - "integrity": "sha512-I1W7Vr/2AFlwhrjvjhp8Tz61qsRWc/dL96kgMmAwkJw/eVLLTokbuYnyYQ8k+/Loy2na8C18yD0SOkE/1AmIsw==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/conventional-changelog-angular/-/conventional-changelog-angular-5.0.1.tgz", + "integrity": "sha512-q4ylJ68fWZDdrFC9z4zKcf97HW6hp7Mo2YlqD4owfXhecFKy/PJCU/1oVFF4TqochchChqmZ0Vb0e0g8/MKNlA==", "requires": { "compare-func": "^1.3.1", "q": "^1.5.1"