Skip to content

Commit

Permalink
fix(conventional-commits): Upgrade angular preset, ensure header is n…
Browse files Browse the repository at this point in the history
…ot duplicated

conventional-changelog-angular 5.0.0 removed the anchor, thus the insertion point logic was changed to detect the end of the header, not the beginning of entries.

References #1696
  • Loading branch information
evocateur committed Oct 1, 2018
1 parent 9752f3e commit 159a0b0
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 51 deletions.
Expand Up @@ -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.
+
+<a name="1.0.1-beta.4"></a>
+## [1.0.1-beta.4](/compare/v1.0.1-beta.3...v1.0.1-beta.4) (YYYY-MM-DD)
+
+
Expand All @@ -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.
+
+<a name="1.0.1-beta.4"></a>
+## [1.0.1-beta.4](/compare/v1.0.1-beta.3...v1.0.1-beta.4) (YYYY-MM-DD)
+
+
Expand Down
Expand Up @@ -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.
<a name="1.1.0"></a>
# 1.1.0 (YYYY-MM-DD)
Expand All @@ -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.
<a name="1.1.0"></a>
# 1.1.0 (YYYY-MM-DD)
Expand Down Expand Up @@ -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.
<a name="1.0.1"></a>
## [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
Expand All @@ -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.
<a name="1.0.1"></a>
## [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
Expand All @@ -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.
<a name="1.0.1"></a>
## [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
Expand All @@ -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.
<a name="1.1.0"></a>
# [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
Expand Down
18 changes: 18 additions & 0 deletions 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);
4 changes: 1 addition & 3 deletions 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.
Expand Down
10 changes: 5 additions & 5 deletions core/conventional-commits/lib/read-existing-changelog.js
Expand Up @@ -2,6 +2,7 @@

const fs = require("fs-extra");
const path = require("path");
const { BLANK_LINE, COMMIT_GUIDELINE } = require("./constants");

module.exports = readExistingChangelog;

Expand All @@ -14,12 +15,11 @@ function readExistingChangelog(pkg) {
chain = chain.then(() => fs.readFile(changelogFileLoc, "utf8").catch(() => ""));

chain = chain.then(changelogContents => {
// CHANGELOG entries start with <a name=, we remove
// the header if it exists by starting at the first entry.
const firstEntryIndex = changelogContents.indexOf("<a name=");
// Remove the header if it exists, thus starting at the first entry.
const headerIndex = changelogContents.indexOf(COMMIT_GUIDELINE);

if (firstEntryIndex !== -1) {
return changelogContents.substring(firstEntryIndex);
if (headerIndex !== -1) {
return changelogContents.substring(headerIndex + COMMIT_GUIDELINE.length + BLANK_LINE.length);
}

return changelogContents;
Expand Down
13 changes: 2 additions & 11 deletions core/conventional-commits/lib/update-changelog.js
@@ -1,25 +1,16 @@
"use strict";

const conventionalChangelogCore = require("conventional-changelog-core");
const dedent = require("dedent");
const fs = require("fs-extra");
const getStream = require("get-stream");
const log = require("npmlog");
const os = require("os");
const { BLANK_LINE, CHANGELOG_HEADER, EOL } = require("./constants");
const getChangelogConfig = require("./get-changelog-config");
const makeBumpOnlyFilter = require("./make-bump-only-filter");
const readExistingChangelog = require("./read-existing-changelog");

module.exports = updateChangelog;

const BLANK_LINE = os.EOL + os.EOL;
const CHANGELOG_HEADER = dedent`
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
`;

function updateChangelog(pkg, type, { changelogPreset, rootPath, tagPrefix, version }) {
log.silly(type, "for %s at %s", pkg.name, pkg.location);

Expand Down Expand Up @@ -65,7 +56,7 @@ function updateChangelog(pkg, type, { changelogPreset, rootPath, tagPrefix, vers

const content = [CHANGELOG_HEADER, newEntry, changelogContents].join(BLANK_LINE);

return fs.writeFile(changelogFileLoc, content.trim() + os.EOL).then(() => {
return fs.writeFile(changelogFileLoc, content.trim() + EOL).then(() => {
log.verbose(type, "wrote", changelogFileLoc);

return changelogFileLoc;
Expand Down
3 changes: 1 addition & 2 deletions core/conventional-commits/package.json
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions helpers/serialize-changelog/index.js
Expand Up @@ -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)");
},
Expand Down
48 changes: 42 additions & 6 deletions integration/lerna-publish-conventional-fixed.test.js
Expand Up @@ -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,
Expand All @@ -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.
<a name="2.0.0"></a>
## [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)
Expand Down Expand Up @@ -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.
<a name="2.0.0"></a>
# 2.0.0 (YYYY-MM-DD)
Expand All @@ -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.
<a name="2.0.0"></a>
## [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)
Expand All @@ -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.
<a name="2.0.0"></a>
## [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)
Expand All @@ -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.
<a name="2.0.0"></a>
# 2.0.0 (YYYY-MM-DD)
Expand All @@ -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.
<a name="2.0.0"></a>
## [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)
Expand Down
36 changes: 31 additions & 5 deletions integration/lerna-publish-conventional-independent.test.js
Expand Up @@ -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,
Expand All @@ -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.
<a name="1.1.0"></a>
# 1.1.0 (YYYY-MM-DD)
Expand All @@ -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.
<a name="2.1.0"></a>
## [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)
Expand All @@ -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.
<a name="4.0.0"></a>
## [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)
Expand All @@ -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.
<a name="4.1.0"></a>
# 4.1.0 (YYYY-MM-DD)
Expand All @@ -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.
<a name="5.1.0"></a>
## [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)
Expand Down
9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 159a0b0

Please sign in to comment.