commit-and-tag-version 13.2.1 → 13.3.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/CHANGELOG.md +15 -0
- package/MIGRATION.md +7 -1
- package/README.md +39 -2
- package/lib/lifecycles/bump.js +2 -2
- package/lib/lifecycles/changelog.js +61 -15
- package/lib/preset-loader.js +21 -0
- package/package.json +17 -8
- package/template.d.ts +6 -0
- package/template.js +9 -0
- package/test/esm-config.integration-test.js +37 -0
- package/test/package-exports.integration-test.js +51 -0
- package/test/prerelease-window.integration-test.js +42 -3
- package/vitest.config.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [13.3.0](https://github.com/absolute-version/commit-and-tag-version/compare/v13.2.2...v13.3.0) (2026-10-15)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **template:** expose the template helpers as a subpath export ([#357](https://github.com/absolute-version/commit-and-tag-version/issues/357)) ([0990f12](https://github.com/absolute-version/commit-and-tag-version/commit/0990f126f8dd3b6fa2a08b0feabc53a44dda12a3)), closes [#323](https://github.com/absolute-version/commit-and-tag-version/issues/323)
|
|
11
|
+
|
|
12
|
+
## [13.2.2](https://github.com/absolute-version/commit-and-tag-version/compare/v13.2.1...v13.2.2) (2026-10-13)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* accept parser and writer options from conventional-changelog 7+ presets ([#351](https://github.com/absolute-version/commit-and-tag-version/issues/351)) ([18b7416](https://github.com/absolute-version/commit-and-tag-version/commit/18b7416bd86651b1b0a62af212165baba0e771a7)), closes [#328](https://github.com/absolute-version/commit-and-tag-version/issues/328)
|
|
18
|
+
* list only the changes since the previous prerelease with the same name in each prerelease changelog section, instead of repeating everything since the last stable release. Stable releases, and the first prerelease with a new name, still list everything since the last stable release. (fixes [#349](https://github.com/absolute-version/commit-and-tag-version/issues/349)) ([#350](https://github.com/absolute-version/commit-and-tag-version/issues/350)) ([a95edce](https://github.com/absolute-version/commit-and-tag-version/commit/a95edce7b350bb31376a1fd9553d2a81b43fcbfc))
|
|
19
|
+
|
|
5
20
|
## [13.2.1](https://github.com/absolute-version/commit-and-tag-version/compare/v13.2.0...v13.2.1) (2026-09-14)
|
|
6
21
|
|
|
7
22
|
|
package/MIGRATION.md
CHANGED
|
@@ -82,7 +82,13 @@ export default {
|
|
|
82
82
|
|
|
83
83
|
If you customized the main template, implement `template(context)` as well instead of continuing to use `mainTemplate`.
|
|
84
84
|
|
|
85
|
-
ESM `.versionrc.js` and `.versionrc.mjs` configurations require [`commit-and-tag-version` 13.1.0](https://github.com/absolute-version/commit-and-tag-version/releases/tag/v13.1.0) or newer.
|
|
85
|
+
ESM `.versionrc.js` and `.versionrc.mjs` configurations require [`commit-and-tag-version` 13.1.0](https://github.com/absolute-version/commit-and-tag-version/releases/tag/v13.1.0) or newer. From 13.3.0 the same helpers are re-exported as `commit-and-tag-version/template`, so a configuration file can import them without adding another dependency:
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
import { words } from 'commit-and-tag-version/template';
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
If you import `@conventional-changelog/template` directly instead, declare it as a direct dependency of the user project. Strict dependency managers such as pnpm require it.
|
|
86
92
|
|
|
87
93
|
### Behaviour that is intentionally preserved
|
|
88
94
|
|
package/README.md
CHANGED
|
@@ -225,6 +225,20 @@ You can override both [parser](https://github.com/conventional-changelog/convent
|
|
|
225
225
|
}
|
|
226
226
|
```
|
|
227
227
|
|
|
228
|
+
`parser` and `writer` are accepted as aliases of `parserOpts` and `writerOpts`, matching the shape of presets built on conventional-changelog 7+, so such a preset can be used directly as the configuration (e.g. `commit-and-tag-version --config ./my-preset.js`). If both are set, `parserOpts`/`writerOpts` take precedence.
|
|
229
|
+
|
|
230
|
+
Custom writer templates must be render functions rather than Handlebars strings; see the [v13 migration guide](MIGRATION.md#custom-writer-templates-use-render-functions). The official [`@conventional-changelog/template`](https://conventional-changelog.js.org/template/) helpers are re-exported from this package, so they can be imported without installing anything else — including under strict package managers such as pnpm:
|
|
231
|
+
|
|
232
|
+
```js
|
|
233
|
+
import { words } from 'commit-and-tag-version/template';
|
|
234
|
+
|
|
235
|
+
function commitPartial(_context, commit) {
|
|
236
|
+
return words(commit.subject || commit.header, commit.shortHash);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export default { writerOpts: { commitPartial } };
|
|
240
|
+
```
|
|
241
|
+
|
|
228
242
|
## CLI Usage
|
|
229
243
|
|
|
230
244
|
> **NOTE:** To pass nested configurations to the CLI without defining them in the `package.json` use dot notation as the parameters `e.g. --skip.changelog`.
|
|
@@ -242,7 +256,7 @@ commit-and-tag-version --first-release
|
|
|
242
256
|
npx commit-and-tag-version --first-release
|
|
243
257
|
```
|
|
244
258
|
|
|
245
|
-
This will tag a release **without bumping the version `bumpFiles`[1]()**.
|
|
259
|
+
This will tag a release **without bumping the version `bumpFiles`[1](<>)**.
|
|
246
260
|
|
|
247
261
|
When you are ready, push the git tag and `npm publish` your first release. \o/
|
|
248
262
|
|
|
@@ -299,6 +313,29 @@ commit-and-tag-version --prerelease xyz # Creates v1.4.3-xyz.1 (auto-incremente
|
|
|
299
313
|
|
|
300
314
|
This behavior applies to both named prereleases (e.g., `-alpha.0`, `-beta.1`) and unnamed prereleases (e.g., `-0`, `-1`), ensuring that you can safely cut multiple prerelease versions without encountering git tag conflicts.
|
|
301
315
|
|
|
316
|
+
#### What Each Changelog Section Covers
|
|
317
|
+
|
|
318
|
+
Each release's changelog section starts where the previous release ended, and which earlier release counts as "previous" depends on what you are releasing:
|
|
319
|
+
|
|
320
|
+
- A stable release covers everything since the last stable release, including changes that already appeared in prereleases.
|
|
321
|
+
- A prerelease covers everything since the most recent tag that is either a stable release or a prerelease with the same name. Prereleases with other names are ignored.
|
|
322
|
+
|
|
323
|
+
For example, starting from `v1.0.0`:
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
# feat: add a
|
|
327
|
+
commit-and-tag-version --prerelease alpha # v1.1.0-alpha.0 lists "add a"
|
|
328
|
+
# feat: add b
|
|
329
|
+
commit-and-tag-version --prerelease alpha # v1.1.0-alpha.1 lists "add b" only
|
|
330
|
+
# fix: correct c
|
|
331
|
+
commit-and-tag-version --prerelease beta # v1.1.0-beta.0 lists a, b and c: it is the first beta
|
|
332
|
+
commit-and-tag-version # v1.1.0 lists a, b and c
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
The compare link in each heading starts from the same tag, so `v1.1.0-alpha.1` links to `v1.1.0-alpha.0...v1.1.0-alpha.1` and `v1.1.0` links to `v1.0.0...v1.1.0`.
|
|
336
|
+
|
|
337
|
+
Unnamed prereleases (e.g., `-0`, `-1`) are treated as sharing one name.
|
|
338
|
+
|
|
302
339
|
#### Keeping Prereleases out of a Final Changelog
|
|
303
340
|
|
|
304
341
|
`commit-and-tag-version` does not currently provide a general-purpose option to
|
|
@@ -663,7 +700,7 @@ module.exports.writeVersion = function (contents, version) {
|
|
|
663
700
|
### Why do breaking changes before 1.0.0 not trigger a 1.0.0 release?
|
|
664
701
|
|
|
665
702
|
Below 1.0.0, the semver specification doesn't give any guarantees about the
|
|
666
|
-
meaning of version numbers.
|
|
703
|
+
meaning of version numbers.
|
|
667
704
|
|
|
668
705
|
However, with npm there is a community convention,
|
|
669
706
|
and implementation-defined behaviour: If your version is between 0.1.0 and
|
package/lib/lifecycles/bump.js
CHANGED
|
@@ -7,7 +7,7 @@ import path from 'path';
|
|
|
7
7
|
import semver from 'semver';
|
|
8
8
|
import { ConventionalGitClient } from '@conventional-changelog/git-client';
|
|
9
9
|
import checkpoint from '../checkpoint.js';
|
|
10
|
-
import presetLoader from '../preset-loader.js';
|
|
10
|
+
import presetLoader, { getParserOpts } from '../preset-loader.js';
|
|
11
11
|
import runLifecycleScript from '../run-lifecycle-script.js';
|
|
12
12
|
import writeFile from '../write-file.js';
|
|
13
13
|
import { resolveUpdaterObjectFromArgument } from '../updaters/index.js';
|
|
@@ -296,7 +296,7 @@ async function bumpVersion(releaseAs, currentVersion, args) {
|
|
|
296
296
|
// towards the next version (#310).
|
|
297
297
|
skipUnstable: true,
|
|
298
298
|
})
|
|
299
|
-
.commits({ path: args.path }, args
|
|
299
|
+
.commits({ path: args.path }, getParserOpts(args));
|
|
300
300
|
|
|
301
301
|
if (args.verbose) {
|
|
302
302
|
bumper.options({
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { ConventionalGitClient } from '@conventional-changelog/git-client';
|
|
1
2
|
import chalk from 'chalk';
|
|
2
3
|
import { ConventionalChangelog } from 'conventional-changelog';
|
|
3
4
|
import fs from 'fs';
|
|
4
5
|
import semver from 'semver';
|
|
5
6
|
import checkpoint from '../checkpoint.js';
|
|
6
|
-
import presetLoader
|
|
7
|
+
import presetLoader, {
|
|
8
|
+
getParserOpts,
|
|
9
|
+
getWriterOpts,
|
|
10
|
+
} from '../preset-loader.js';
|
|
7
11
|
import runLifecycleScript from '../run-lifecycle-script.js';
|
|
8
12
|
import writeFile from '../write-file.js';
|
|
9
13
|
|
|
@@ -42,6 +46,52 @@ function extractChangelogBody(oldContent) {
|
|
|
42
46
|
: oldContent;
|
|
43
47
|
}
|
|
44
48
|
|
|
49
|
+
/**
|
|
50
|
+
* The prerelease identifier of a version: 'alpha' for 1.0.0-alpha.1, '' for an
|
|
51
|
+
* unnamed prerelease such as 1.0.0-0, and null for a stable version.
|
|
52
|
+
*/
|
|
53
|
+
function prereleaseChannel(version) {
|
|
54
|
+
const prerelease = semver.prerelease(version);
|
|
55
|
+
if (!prerelease) return null;
|
|
56
|
+
return typeof prerelease[0] === 'string' ? prerelease[0] : '';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Whether an earlier release ends the changelog section of the version being
|
|
61
|
+
* released. Stable releases always do. Prereleases only do for a later
|
|
62
|
+
* prerelease with the same identifier, so that:
|
|
63
|
+
* - a stable release, or the first prerelease with a new identifier, covers
|
|
64
|
+
* everything since the last stable release, including changes that only
|
|
65
|
+
* appeared in other prereleases (#310)
|
|
66
|
+
* - a continued prerelease only covers changes since the previous prerelease
|
|
67
|
+
* with that identifier, rather than repeating them every time (#349)
|
|
68
|
+
*/
|
|
69
|
+
function isReleaseBoundary(version, newVersion) {
|
|
70
|
+
if (!semver.valid(version)) return false;
|
|
71
|
+
const channel = prereleaseChannel(version);
|
|
72
|
+
return channel === null || channel === prereleaseChannel(newVersion);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Git client that only reports the tags which are release boundaries for the
|
|
77
|
+
* version being released, so the changelog's commit range, section splits
|
|
78
|
+
* and compare links all agree on where the previous release was.
|
|
79
|
+
*/
|
|
80
|
+
class ReleaseBoundaryGitClient extends ConventionalGitClient {
|
|
81
|
+
constructor(cwd, newVersion) {
|
|
82
|
+
super(cwd);
|
|
83
|
+
this.newVersion = newVersion;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async *getSemverTags(params = {}) {
|
|
87
|
+
for await (const tag of super.getSemverTags(params)) {
|
|
88
|
+
if (isReleaseBoundary(tag.replace(params.prefix, ''), this.newVersion)) {
|
|
89
|
+
yield tag;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
45
95
|
async function outputChangelog(args, newVersion) {
|
|
46
96
|
createIfMissing(args);
|
|
47
97
|
const header = args.header;
|
|
@@ -55,13 +105,12 @@ async function outputChangelog(args, newVersion) {
|
|
|
55
105
|
|
|
56
106
|
const changelogFrontMatter = extractFrontMatter(oldContent);
|
|
57
107
|
|
|
58
|
-
const generator = new ConventionalChangelog(
|
|
108
|
+
const generator = new ConventionalChangelog(
|
|
109
|
+
new ReleaseBoundaryGitClient(process.cwd(), newVersion),
|
|
110
|
+
)
|
|
59
111
|
.readPackage()
|
|
60
112
|
.loadPreset(presetLoader(args))
|
|
61
|
-
|
|
62
|
-
// both cover all commits since the last stable release, so changes that
|
|
63
|
-
// only appeared in prereleases are not dropped from the release (#310).
|
|
64
|
-
.tags({ prefix: args.tagPrefix, skipUnstable: true })
|
|
113
|
+
.tags({ prefix: args.tagPrefix })
|
|
65
114
|
.options({
|
|
66
115
|
releaseCount: args.releaseCount,
|
|
67
116
|
...(args.verbose
|
|
@@ -71,16 +120,13 @@ async function outputChangelog(args, newVersion) {
|
|
|
71
120
|
: {}),
|
|
72
121
|
})
|
|
73
122
|
.context({ version: newVersion })
|
|
74
|
-
.commits({ merges: null, path: args.path }, args
|
|
123
|
+
.commits({ merges: null, path: args.path }, getParserOpts(args))
|
|
75
124
|
.writer({
|
|
76
|
-
// Split sections at
|
|
77
|
-
// released in
|
|
78
|
-
// rather than being regenerated under
|
|
79
|
-
generateOn: (commit) =>
|
|
80
|
-
|
|
81
|
-
semver.valid(commit.version) && !semver.prerelease(commit.version),
|
|
82
|
-
),
|
|
83
|
-
...(args.writerOpts || {}),
|
|
125
|
+
// Split sections at the same tags the commit range is built from, so
|
|
126
|
+
// commits released in other prereleases stay in this release's section
|
|
127
|
+
// rather than being regenerated under that prerelease's heading.
|
|
128
|
+
generateOn: (commit) => isReleaseBoundary(commit.version, newVersion),
|
|
129
|
+
...(getWriterOpts(args) || {}),
|
|
84
130
|
});
|
|
85
131
|
|
|
86
132
|
let content = '';
|
package/lib/preset-loader.js
CHANGED
|
@@ -66,6 +66,27 @@ function translateSpecOptionsToPresetConfig(preset) {
|
|
|
66
66
|
return preset;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Presets built on conventional-changelog >= 7 return their parser and writer
|
|
71
|
+
* options under `parser` and `writer` (older presets used `parserOpts` and
|
|
72
|
+
* `writerOpts`). Accept both shapes so a preset object can be used directly as
|
|
73
|
+
* the configuration (e.g. `--config ./my-preset.js`). When both are present,
|
|
74
|
+
* the `*Opts` keys take precedence.
|
|
75
|
+
*/
|
|
76
|
+
function mergeOptions(newStyle, legacy) {
|
|
77
|
+
if (newStyle === undefined) return legacy;
|
|
78
|
+
if (legacy === undefined) return newStyle;
|
|
79
|
+
return { ...newStyle, ...legacy };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function getParserOpts(args) {
|
|
83
|
+
return mergeOptions(args.parser, args.parserOpts);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function getWriterOpts(args) {
|
|
87
|
+
return mergeOptions(args.writer, args.writerOpts);
|
|
88
|
+
}
|
|
89
|
+
|
|
69
90
|
export default (args) => {
|
|
70
91
|
let preset = args.preset || DEFAULT_PRESET;
|
|
71
92
|
if (preset === DEFAULT_PRESET) {
|
package/package.json
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commit-and-tag-version",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.3.0",
|
|
4
4
|
"description": "replacement for `npm version` with automatic CHANGELOG generation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.js",
|
|
9
|
+
"./template": {
|
|
10
|
+
"types": "./template.d.ts",
|
|
11
|
+
"default": "./template.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json",
|
|
14
|
+
"./*": "./*"
|
|
15
|
+
},
|
|
7
16
|
"bin": {
|
|
8
17
|
"commit-and-tag-version": "bin/cli.js"
|
|
9
18
|
},
|
|
@@ -47,17 +56,17 @@
|
|
|
47
56
|
"homepage": "https://github.com/absolute-version/commit-and-tag-version#readme",
|
|
48
57
|
"dependencies": {
|
|
49
58
|
"@conventional-changelog/git-client": "3.1.0",
|
|
50
|
-
"@conventional-changelog/template": "1.
|
|
51
|
-
"chalk": "^6.0.
|
|
59
|
+
"@conventional-changelog/template": "1.4.0",
|
|
60
|
+
"chalk": "^6.0.1",
|
|
52
61
|
"conventional-changelog": "8.1.0",
|
|
53
62
|
"conventional-changelog-config-spec": "2.1.0",
|
|
54
|
-
"conventional-changelog-conventionalcommits": "10.
|
|
63
|
+
"conventional-changelog-conventionalcommits": "10.4.0",
|
|
55
64
|
"conventional-recommended-bump": "12.1.0",
|
|
56
65
|
"detect-indent": "^7.0.2",
|
|
57
66
|
"detect-newline": "^3.1.0",
|
|
58
67
|
"dotgitignore": "^2.1.0",
|
|
59
68
|
"fast-xml-parser": "^5.10.1",
|
|
60
|
-
"figures": "^
|
|
69
|
+
"figures": "^6.1.0",
|
|
61
70
|
"find-up": "^5.0.0",
|
|
62
71
|
"semver": "^7.7.2",
|
|
63
72
|
"yaml": "^2.9.0",
|
|
@@ -66,11 +75,11 @@
|
|
|
66
75
|
"devDependencies": {
|
|
67
76
|
"@eslint/js": "^10.0.1",
|
|
68
77
|
"@vitest/coverage-istanbul": "^4.1.11",
|
|
69
|
-
"@vitest/eslint-plugin": "^1.6.
|
|
70
|
-
"conventional-changelog-angular": "^9.
|
|
78
|
+
"@vitest/eslint-plugin": "^1.6.27",
|
|
79
|
+
"conventional-changelog-angular": "^9.4.0",
|
|
71
80
|
"eslint": "^10.8.1",
|
|
72
81
|
"eslint-config-prettier": "^10.1.8",
|
|
73
|
-
"globals": "^17.
|
|
82
|
+
"globals": "^17.12.0",
|
|
74
83
|
"istanbul-lib-instrument": "^6.0.3",
|
|
75
84
|
"pirates": "^4.0.7",
|
|
76
85
|
"prettier": "^3.9.6",
|
package/template.d.ts
ADDED
package/template.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public re-export of the conventional-changelog template helpers, so custom
|
|
3
|
+
* writer render functions can import them without having to resolve
|
|
4
|
+
* `@conventional-changelog/template` from their own project, which strict
|
|
5
|
+
* package managers such as pnpm refuse to do.
|
|
6
|
+
*
|
|
7
|
+
* @see https://conventional-changelog.js.org/template/
|
|
8
|
+
*/
|
|
9
|
+
export * from '@conventional-changelog/template';
|
|
@@ -90,6 +90,43 @@ export default {
|
|
|
90
90
|
expect(output).not.toContain('commitPartial is not a function');
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
+
it('uses the parser and writer options of a preset used as the config', function () {
|
|
94
|
+
// conventional-changelog >= 7 presets return `parser` and `writer`
|
|
95
|
+
// instead of `parserOpts` and `writerOpts` (#328).
|
|
96
|
+
fs.writeFileSync(
|
|
97
|
+
'.versionrc.js',
|
|
98
|
+
`import createPreset from 'conventional-changelog-conventionalcommits'
|
|
99
|
+
|
|
100
|
+
export default function () {
|
|
101
|
+
return createPreset({
|
|
102
|
+
types: [{ type: 'feat', section: 'Shiny Features' }],
|
|
103
|
+
})
|
|
104
|
+
}`,
|
|
105
|
+
'utf-8',
|
|
106
|
+
);
|
|
107
|
+
shell.exec('git commit --allow-empty -m"feat: add a shiny thing"');
|
|
108
|
+
|
|
109
|
+
const output = runCli();
|
|
110
|
+
expect(output).toContain('Shiny Features');
|
|
111
|
+
expect(output).toContain('add a shiny thing');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('accepts `parser` options in place of `parserOpts`', function () {
|
|
115
|
+
fs.writeFileSync(
|
|
116
|
+
'.versionrc.js',
|
|
117
|
+
"export default { parser: { noteKeywords: ['HEADS-UP'] } }",
|
|
118
|
+
'utf-8',
|
|
119
|
+
);
|
|
120
|
+
shell.exec(
|
|
121
|
+
'git commit --allow-empty -m"fix: rename an option" -m"HEADS-UP: the old name is gone"',
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const output = runCli();
|
|
125
|
+
expect(output).toContain(
|
|
126
|
+
'bumping version in package.json from 1.0.0 to 2.0.0',
|
|
127
|
+
);
|
|
128
|
+
});
|
|
129
|
+
|
|
93
130
|
it('reads an ES module config from .versionrc.mjs', function () {
|
|
94
131
|
fs.writeFileSync(
|
|
95
132
|
'.versionrc.mjs',
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { execFileSync } from 'child_process';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
|
|
5
|
+
const PACKAGE_ROOT = path.resolve(
|
|
6
|
+
fileURLToPath(new URL('..', import.meta.url)),
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* These tests use a child process rather than the in-process harness: `exports`
|
|
11
|
+
* subpath resolution and package self-referencing are Node resolver behaviour,
|
|
12
|
+
* which the vitest module runner does not reproduce.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
function resolveEntryPoints() {
|
|
16
|
+
const script = `
|
|
17
|
+
const template = await import('commit-and-tag-version/template')
|
|
18
|
+
const main = await import('commit-and-tag-version')
|
|
19
|
+
const legacy = await import('commit-and-tag-version/defaults.js')
|
|
20
|
+
console.log(JSON.stringify({
|
|
21
|
+
words: typeof template.words,
|
|
22
|
+
template: typeof template.template,
|
|
23
|
+
main: typeof main.default,
|
|
24
|
+
legacy: typeof legacy.default,
|
|
25
|
+
}))
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
const output = execFileSync(
|
|
29
|
+
process.execPath,
|
|
30
|
+
['--input-type=module', '-e', script],
|
|
31
|
+
{ cwd: PACKAGE_ROOT, encoding: 'utf-8' },
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return JSON.parse(output.trim());
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe('package exports', function () {
|
|
38
|
+
it('exposes the template helpers as a subpath export', function () {
|
|
39
|
+
expect(resolveEntryPoints()).toMatchObject({
|
|
40
|
+
words: 'function',
|
|
41
|
+
template: 'function',
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('keeps the entry points that existed before `exports`', function () {
|
|
46
|
+
expect(resolveEntryPoints()).toMatchObject({
|
|
47
|
+
main: 'function',
|
|
48
|
+
legacy: 'object',
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -118,11 +118,50 @@ describe('prerelease bump and changelog windows (#310)', function () {
|
|
|
118
118
|
runCli('--prerelease', 'dev');
|
|
119
119
|
expect(tags()).toContain('v1.1.0-dev.1');
|
|
120
120
|
|
|
121
|
-
//
|
|
122
|
-
// the
|
|
121
|
+
// Only the changes since the previous prerelease with this identifier
|
|
122
|
+
// are listed; the feat is already in the dev.0 section (#349).
|
|
123
123
|
const devSection = changelogSection('1.1.0-dev.1');
|
|
124
|
-
expect(devSection).toContain('add feat');
|
|
124
|
+
expect(devSection).not.toContain('add feat');
|
|
125
125
|
expect(devSection).toContain('add fix');
|
|
126
|
+
expect(devSection).toContain('v1.1.0-dev.0...v1.1.0-dev.1');
|
|
127
|
+
expect(changelogSection('1.1.0-dev.0')).toContain('add feat');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('lists each change once across continued prereleases and again in the stable release', function () {
|
|
131
|
+
commit('feat: add a');
|
|
132
|
+
runCli('--prerelease', 'alpha');
|
|
133
|
+
commit('feat: add b');
|
|
134
|
+
runCli('--prerelease', 'alpha');
|
|
135
|
+
commit('fix: correct c');
|
|
136
|
+
runCli('--prerelease', 'alpha');
|
|
137
|
+
|
|
138
|
+
const prereleases = fs
|
|
139
|
+
.readFileSync('CHANGELOG.md', 'utf-8')
|
|
140
|
+
.split(/^#+ \[?1\.0\.0[\] ]/m)[0];
|
|
141
|
+
expect(prereleases.match(/add a/g)).toHaveLength(1);
|
|
142
|
+
expect(prereleases.match(/add b/g)).toHaveLength(1);
|
|
143
|
+
expect(prereleases.match(/correct c/g)).toHaveLength(1);
|
|
144
|
+
|
|
145
|
+
runCli();
|
|
146
|
+
const stableSection = changelogSection('1.1.0');
|
|
147
|
+
expect(stableSection).toContain('add a');
|
|
148
|
+
expect(stableSection).toContain('add b');
|
|
149
|
+
expect(stableSection).toContain('correct c');
|
|
150
|
+
expect(stableSection).toContain('v1.0.0...v1.1.0');
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('covers other prereleases when returning to an earlier identifier', function () {
|
|
154
|
+
commit('feat: add feat');
|
|
155
|
+
runCli('--prerelease', 'dev');
|
|
156
|
+
commit('fix: add fix');
|
|
157
|
+
runCli('--prerelease', 'rc');
|
|
158
|
+
commit('fix: second fix');
|
|
159
|
+
runCli('--prerelease', 'dev');
|
|
160
|
+
|
|
161
|
+
const devSection = changelogSection('1.1.0-dev.1');
|
|
162
|
+
expect(devSection).not.toContain('add feat');
|
|
163
|
+
expect(devSection).toContain('add fix');
|
|
164
|
+
expect(devSection).toContain('second fix');
|
|
126
165
|
});
|
|
127
166
|
|
|
128
167
|
it('escalates a continued prerelease when a bigger change lands', function () {
|