@release-it/keep-a-changelog 2.5.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +35 -24
- package/package.json +10 -9
- package/test.js +29 -10
package/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Plugin } from 'release-it';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { detectNewline } from 'detect-newline';
|
|
5
|
+
import format from 'string-template';
|
|
6
6
|
|
|
7
7
|
const pad = num => ('0' + num).slice(-2);
|
|
8
8
|
|
|
@@ -53,37 +53,48 @@ class KeepAChangelog extends Plugin {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
getChangelog(latestVersion) {
|
|
56
|
-
const { isIncrement } = this.config;
|
|
57
|
-
// Return the unchanged changelog content when no increment is made
|
|
58
|
-
if (!isIncrement) {
|
|
59
|
-
return this.changelogContent;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
56
|
const { changelog } = this.getContext();
|
|
63
57
|
if (changelog) return changelog;
|
|
64
58
|
|
|
65
59
|
const { filename, strictLatest } = this;
|
|
66
|
-
|
|
67
60
|
const previousReleaseTitle = strictLatest ? `## [${latestVersion}]` : `## [`;
|
|
68
61
|
const hasPreviousReleaseSection = this.changelogContent.includes(previousReleaseTitle);
|
|
69
|
-
|
|
70
62
|
if (strictLatest && !hasPreviousReleaseSection) {
|
|
71
63
|
throw Error(`Missing section for previous release ("${latestVersion}") in ${filename}.`);
|
|
72
64
|
}
|
|
73
65
|
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
66
|
+
const { isIncrement } = this.config;
|
|
67
|
+
const titleToFind = isIncrement ? this.unreleasedTitleRaw : latestVersion;
|
|
68
|
+
const changelogContent = this.getChangelogEntryContent(titleToFind);
|
|
69
|
+
|
|
70
|
+
this.setContext({ changelog: changelogContent });
|
|
71
|
+
return changelogContent;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getChangelogEntryContent(releaseTitleRaw) {
|
|
75
|
+
const { filename, changelogContent, EOL } = this;
|
|
76
|
+
|
|
77
|
+
const releaseTitleMarkdown = `## [${releaseTitleRaw}]`;
|
|
78
|
+
const previousReleaseTitle = `## [`;
|
|
79
|
+
|
|
80
|
+
const indexOfReleaseTitle = changelogContent.indexOf(releaseTitleMarkdown);
|
|
81
|
+
|
|
82
|
+
if (indexOfReleaseTitle === -1) {
|
|
83
|
+
throw Error(`Missing section for previous release ("${releaseTitleRaw}") in ${filename}.`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const entryContentStartIndex = changelogContent.indexOf(EOL, indexOfReleaseTitle);
|
|
87
|
+
let entryContentEndIndex = changelogContent.indexOf(previousReleaseTitle, entryContentStartIndex);
|
|
88
|
+
if (entryContentEndIndex === -1) {
|
|
89
|
+
entryContentEndIndex = changelogContent.length;
|
|
78
90
|
}
|
|
79
91
|
|
|
80
|
-
const
|
|
81
|
-
if (!
|
|
82
|
-
throw Error(`There are no entries under "${
|
|
92
|
+
const changelogEntryContent = changelogContent.substring(entryContentStartIndex, entryContentEndIndex).trim();
|
|
93
|
+
if (!changelogEntryContent) {
|
|
94
|
+
throw Error(`There are no entries under "${releaseTitleRaw}" section in ${filename}.`);
|
|
83
95
|
}
|
|
84
96
|
|
|
85
|
-
|
|
86
|
-
return changelogContent;
|
|
97
|
+
return changelogEntryContent;
|
|
87
98
|
}
|
|
88
99
|
|
|
89
100
|
bump(version) {
|
|
@@ -107,7 +118,7 @@ class KeepAChangelog extends Plugin {
|
|
|
107
118
|
}
|
|
108
119
|
|
|
109
120
|
// Add a link for the first tagged version
|
|
110
|
-
if (!latestTag) {
|
|
121
|
+
if (!latestTag || latestTag === '0.0.0') {
|
|
111
122
|
const firstVersionUrl = format(this.versionUrlFormats.firstVersionUrl, { repositoryUrl, tagName });
|
|
112
123
|
const firstVersionLink = `[${version}]: ${firstVersionUrl}`;
|
|
113
124
|
return `${updatedChangelog}${this.EOL}${firstVersionLink}`;
|
|
@@ -142,4 +153,4 @@ class KeepAChangelog extends Plugin {
|
|
|
142
153
|
}
|
|
143
154
|
}
|
|
144
155
|
|
|
145
|
-
|
|
156
|
+
export default KeepAChangelog;
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@release-it/keep-a-changelog",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Keep-a-changelog plugin for release-it",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": "./index.js",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"test": "bron test.js",
|
|
8
9
|
"release": "release-it"
|
|
@@ -29,20 +30,20 @@
|
|
|
29
30
|
"url": "https://webpro.nl"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
|
-
"detect-newline": "^
|
|
33
|
+
"detect-newline": "^4.0.0",
|
|
33
34
|
"string-template": "^1.0.0"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
|
-
"bron": "^
|
|
37
|
-
"mock-fs": "^5.
|
|
38
|
-
"release-it": "^
|
|
39
|
-
"sinon": "^
|
|
37
|
+
"bron": "^2.0.3",
|
|
38
|
+
"mock-fs": "^5.1.4",
|
|
39
|
+
"release-it": "^15.3.0",
|
|
40
|
+
"sinon": "^14.0.0"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
42
|
-
"release-it": "^
|
|
43
|
+
"release-it": "^15.0.0-esm.4"
|
|
43
44
|
},
|
|
44
45
|
"engines": {
|
|
45
|
-
"node": ">=
|
|
46
|
+
"node": ">=14"
|
|
46
47
|
},
|
|
47
48
|
"release-it": {
|
|
48
49
|
"github": {
|
package/test.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { strict as assert } from 'assert';
|
|
2
|
+
import test from 'bron';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import mock from 'mock-fs';
|
|
5
|
+
import { factory, runTasks } from 'release-it/test/util/index.js';
|
|
6
|
+
import sinon from 'sinon';
|
|
7
|
+
import Plugin from './index.js';
|
|
8
8
|
|
|
9
9
|
const initialDryRunFileContents =
|
|
10
10
|
'\n\n## [Unreleased]\n\n* Item A\n* Item B\n\n## [1.0.0] - 2020-05-02\n\n* Item C\n* Item D';
|
|
@@ -56,11 +56,30 @@ test('should throw for empty "unreleased" section', async t => {
|
|
|
56
56
|
await assert.rejects(runTasks(plugin), /There are no entries under "Unreleased" section in CHANGELOG-EMPTY\.md/);
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
test('should
|
|
59
|
+
test('should throw for missing "unreleased" section when no-increment flag is set if changelog is misformatted', async t => {
|
|
60
|
+
const options = { increment: false, [namespace]: { filename: 'CHANGELOG-FOO.md' } };
|
|
61
|
+
const plugin = factory(Plugin, { namespace, options });
|
|
62
|
+
await assert.rejects(runTasks(plugin), /Missing "Unreleased" section in CHANGELOG-FOO.md/);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('should throw for missing "1.0.0" section when no-increment flag is set', async t => {
|
|
66
|
+
const options = { increment: false, [namespace]: { filename: 'CHANGELOG-MISSING.md' } };
|
|
67
|
+
const plugin = factory(Plugin, { namespace, options });
|
|
68
|
+
await assert.rejects(runTasks(plugin), /Missing section for previous release \("1\.0\.0"\) in CHANGELOG-MISSING\.md/);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('should find "1.0.0" section when no-increment flag is set when items under version', async t => {
|
|
60
72
|
const options = { increment: false, [namespace]: { filename: 'CHANGELOG-EMPTY.md' } };
|
|
61
73
|
const plugin = factory(Plugin, { namespace, options });
|
|
62
74
|
await runTasks(plugin);
|
|
63
|
-
assert.equal(plugin.getChangelog(),
|
|
75
|
+
assert.equal(plugin.getChangelog('1.0.0'), '* Item A\n* Item B');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('should find "1.0.0" section when no-increment flag is set when items under unreleased and version', async t => {
|
|
79
|
+
const options = { increment: false, [namespace]: { filename: 'CHANGELOG-FULL.md' } };
|
|
80
|
+
const plugin = factory(Plugin, { namespace, options });
|
|
81
|
+
await runTasks(plugin);
|
|
82
|
+
assert.equal(plugin.getChangelog('1.0.0'), '* Item C\n* Item D');
|
|
64
83
|
});
|
|
65
84
|
|
|
66
85
|
test('should throw for missing section for previous release', async t => {
|
|
@@ -263,6 +282,6 @@ test('should add links to the end of a new changelog', async t => {
|
|
|
263
282
|
assert.equal(plugin.getChangelog(), '* Item A\n* Item B');
|
|
264
283
|
assert.match(
|
|
265
284
|
readFile('./CHANGELOG-VERSION_URL_NEW.md'),
|
|
266
|
-
/^## \[1\.0\.0] - [0-9]{4}-[0-9]{2}-[0-9]{2}\n\n\* Item A\n\* Item B\n\n\[unreleased]: https:\/\/github\.com\/user\/project\/compare\/1\.0\.0\.\.\.HEAD\n\[1
|
|
285
|
+
/^## \[1\.0\.0] - [0-9]{4}-[0-9]{2}-[0-9]{2}\n\n\* Item A\n\* Item B\n\n\[unreleased]: https:\/\/github\.com\/user\/project\/compare\/1\.0\.0\.\.\.HEAD\n\[1\.0\.0]: https:\/\/github\.com\/user\/project\/releases\/tag\/1\.0\.0\n$/
|
|
267
286
|
);
|
|
268
287
|
});
|