Skip to content

Commit 38a10fe

Browse files
authored
Merge pull request #297 from semantic-release/esm
2 parents 997768e + 6bf3262 commit 38a10fe

12 files changed

+7172
-21050
lines changed

.git-blame-ignore-revs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# style: prettier
2+
833e2127a843ed33f9da1b945e28933afe25a5aa

.github/workflows/release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ jobs:
2323
with:
2424
cache: npm
2525
node-version: lts/*
26-
- run: npm ci
26+
- run: npm clean-install
27+
- run: npm audit signatures
2728
- run: npx semantic-release
2829
env:
2930
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ jobs:
1313
strategy:
1414
matrix:
1515
node-version:
16-
- 14.17
17-
- 16
16+
- 18.0.0
17+
- 19
1818
os:
1919
- ubuntu-latest
2020
runs-on: "${{ matrix.os }}"
@@ -25,7 +25,9 @@ jobs:
2525
with:
2626
node-version: "${{ matrix.node-version }}"
2727
cache: npm
28-
- run: npm ci
28+
- run: npm clean-install
29+
- name: Ensure dependencies are compatible with the engines range
30+
run: npx ls-engines
2931
- run: "npm run test:ci"
3032
test:
3133
runs-on: ubuntu-latest
@@ -34,9 +36,8 @@ jobs:
3436
- uses: actions/checkout@v3
3537
- uses: actions/setup-node@v3
3638
with:
37-
node-version: 16
39+
node-version: lts/*
3840
cache: npm
39-
- run: npm ci
40-
- name: Ensure dependencies are compatible with the engines range
41-
run: npx ls-engines
41+
- run: npm clean-install
42+
- run: npm audit signatures
4243
- run: npm run lint

README.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![npm next version](https://img.shields.io/npm/v/@semantic-release/release-notes-generator/next.svg)](https://www.npmjs.com/package/@semantic-release/release-notes-generator)
77

88
| Step | Description |
9-
|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
9+
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1010
| `generateNotes` | Generate release notes for the commits added since the last release with [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog). |
1111

1212
## Install
@@ -22,26 +22,33 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
2222
```json
2323
{
2424
"plugins": [
25-
["@semantic-release/commit-analyzer", {
26-
"preset": "angular",
27-
"parserOpts": {
28-
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
25+
[
26+
"@semantic-release/commit-analyzer",
27+
{
28+
"preset": "angular",
29+
"parserOpts": {
30+
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
31+
}
2932
}
30-
}],
31-
["@semantic-release/release-notes-generator", {
32-
"preset": "angular",
33-
"parserOpts": {
34-
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
35-
},
36-
"writerOpts": {
37-
"commitsSort": ["subject", "scope"]
33+
],
34+
[
35+
"@semantic-release/release-notes-generator",
36+
{
37+
"preset": "angular",
38+
"parserOpts": {
39+
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
40+
},
41+
"writerOpts": {
42+
"commitsSort": ["subject", "scope"]
43+
}
3844
}
39-
}]
45+
]
4046
]
4147
}
4248
```
4349

4450
With this example:
51+
4552
- the commits that contains `BREAKING CHANGE`, `BREAKING CHANGES` or `BREAKING` in their body will be considered breaking changes (by default the [angular preset](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-angular/index.js#L14) checks only for `BREAKING CHANGE` and `BREAKING CHANGES`)
4653
- the commits will be sorted in the changelog by `subject` then `scope` (by default the [angular preset](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-angular/index.js#L90) sort the commits in the changelog by `scope` then `subject`)
4754

@@ -50,7 +57,7 @@ With this example:
5057
### Options
5158

5259
| Option | Description | Default |
53-
|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
60+
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
5461
| `preset` | [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) preset (possible values: [`angular`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular), [`atom`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-atom), [`codemirror`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-codemirror), [`ember`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-ember), [`eslint`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-eslint), [`express`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-express), [`jquery`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-jquery), [`jshint`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-jshint), [`conventionalcommits`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-conventionalcommits)). | [`angular`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular) |
5562
| `config` | NPM package name of a custom [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) preset. | - |
5663
| `parserOpts` | Additional [conventional-commits-parser](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser#conventionalcommitsparseroptions) options that will extends the ones loaded by `preset` or `config`. This is convenient to use a [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) preset with some customizations without having to create a new module. | - |

index.js

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
const {format} = require('url');
2-
const {find, merge} = require('lodash');
3-
const getStream = require('get-stream');
4-
const intoStream = require('into-stream');
5-
const parser = require('conventional-commits-parser').sync;
6-
const writer = require('conventional-changelog-writer');
7-
const filter = require('conventional-commits-filter');
8-
const readPkgUp = require('read-pkg-up');
9-
const debug = require('debug')('semantic-release:release-notes-generator');
10-
const loadChangelogConfig = require('./lib/load-changelog-config.js');
11-
const HOSTS_CONFIG = require('./lib/hosts-config.js');
1+
import { format } from "url";
2+
import { find, merge } from "lodash-es";
3+
import getStream from "get-stream";
4+
import intoStream from "into-stream";
5+
import { sync as parser } from "conventional-commits-parser";
6+
import writer from "./wrappers/conventional-changelog-writer.js";
7+
import filter from "conventional-commits-filter";
8+
import { readPackageUp } from "read-pkg-up";
9+
import debugFactory from "debug";
10+
import loadChangelogConfig from "./lib/load-changelog-config.js";
11+
import HOSTS_CONFIG from "./lib/hosts-config.js";
12+
13+
const debug = debugFactory("semantic-release:release-notes-generator");
1214

1315
/**
1416
* Generate the changelog for all the commits in `options.commits`.
1517
*
1618
* @param {Object} pluginConfig The plugin configuration.
1719
* @param {String} pluginConfig.preset conventional-changelog preset ('angular', 'atom', 'codemirror', 'ember', 'eslint', 'express', 'jquery', 'jscs', 'jshint').
18-
* @param {String} pluginConfig.config Requierable npm package with a custom conventional-changelog preset
20+
* @param {String} pluginConfig.config Requireable npm package with a custom conventional-changelog preset
1921
* @param {Object} pluginConfig.parserOpts Additional `conventional-changelog-parser` options that will overwrite ones loaded by `preset` or `config`.
2022
* @param {Object} pluginConfig.writerOpts Additional `conventional-changelog-writer` options that will overwrite ones loaded by `preset` or `config`.
2123
* @param {Object} context The semantic-release context.
@@ -26,67 +28,65 @@ const HOSTS_CONFIG = require('./lib/hosts-config.js');
2628
*
2729
* @returns {String} The changelog for all the commits in `context.commits`.
2830
*/
29-
async function generateNotes(pluginConfig, context) {
30-
const {commits, lastRelease, nextRelease, options, cwd} = context;
31-
const repositoryUrl = options.repositoryUrl.replace(/\.git$/i, '');
32-
const {parserOpts, writerOpts} = await loadChangelogConfig(pluginConfig, context);
31+
export async function generateNotes(pluginConfig, context) {
32+
const { commits, lastRelease, nextRelease, options, cwd } = context;
33+
const repositoryUrl = options.repositoryUrl.replace(/\.git$/i, "");
34+
const { parserOpts, writerOpts } = await loadChangelogConfig(pluginConfig, context);
3335

3436
const [match, auth, host, path] = /^(?!.+:\/\/)(?:(?<auth>.*)@)?(?<host>.*?):(?<path>.*)$/.exec(repositoryUrl) || [];
35-
let {hostname, port, pathname, protocol} = new URL(
36-
match ? `ssh://${auth ? `${auth}@` : ''}${host}/${path}` : repositoryUrl
37+
let { hostname, port, pathname, protocol } = new URL(
38+
match ? `ssh://${auth ? `${auth}@` : ""}${host}/${path}` : repositoryUrl
3739
);
38-
port = protocol.includes('ssh') ? '' : port;
39-
protocol = protocol && /http[^s]/.test(protocol) ? 'http' : 'https';
40+
port = protocol.includes("ssh") ? "" : port;
41+
protocol = protocol && /http[^s]/.test(protocol) ? "http" : "https";
4042
const [, owner, repository] = /^\/(?<owner>[^/]+)?\/?(?<repository>.+)?$/.exec(pathname);
4143

42-
const {issue, commit, referenceActions, issuePrefixes} =
44+
const { issue, commit, referenceActions, issuePrefixes } =
4345
find(HOSTS_CONFIG, (conf) => conf.hostname === hostname) || HOSTS_CONFIG.default;
4446
const parsedCommits = filter(
4547
commits
46-
.filter(({message, hash}) => {
48+
.filter(({ message, hash }) => {
4749
if (!message.trim()) {
48-
debug('Skip commit %s with empty message', hash);
50+
debug("Skip commit %s with empty message", hash);
4951
return false;
5052
}
5153

5254
return true;
5355
})
5456
.map((rawCommit) => ({
5557
...rawCommit,
56-
...parser(rawCommit.message, {referenceActions, issuePrefixes, ...parserOpts}),
58+
...parser(rawCommit.message, { referenceActions, issuePrefixes, ...parserOpts }),
5759
}))
5860
);
5961
const previousTag = lastRelease.gitTag || lastRelease.gitHead;
6062
const currentTag = nextRelease.gitTag || nextRelease.gitHead;
61-
const {host: hostConfig, linkCompare, linkReferences, commit: commitConfig, issue: issueConfig} = pluginConfig;
63+
const { host: hostConfig, linkCompare, linkReferences, commit: commitConfig, issue: issueConfig } = pluginConfig;
6264
const changelogContext = merge(
6365
{
6466
version: nextRelease.version,
65-
host: format({protocol, hostname, port}),
67+
host: format({ protocol, hostname, port }),
6668
owner,
6769
repository,
6870
previousTag,
6971
currentTag,
7072
linkCompare: currentTag && previousTag,
7173
issue,
7274
commit,
73-
packageData: ((await readPkgUp({normalize: false, cwd})) || {}).packageJson,
75+
packageData: ((await readPackageUp({ normalize: false, cwd })) || {}).packageJson,
7476
},
75-
{host: hostConfig, linkCompare, linkReferences, commit: commitConfig, issue: issueConfig}
77+
{ host: hostConfig, linkCompare, linkReferences, commit: commitConfig, issue: issueConfig }
7678
);
7779

78-
debug('version: %o', changelogContext.version);
79-
debug('host: %o', changelogContext.hostname);
80-
debug('owner: %o', changelogContext.owner);
81-
debug('repository: %o', changelogContext.repository);
82-
debug('previousTag: %o', changelogContext.previousTag);
83-
debug('currentTag: %o', changelogContext.currentTag);
84-
debug('host: %o', changelogContext.host);
85-
debug('linkReferences: %o', changelogContext.linkReferences);
86-
debug('issue: %o', changelogContext.issue);
87-
debug('commit: %o', changelogContext.commit);
80+
debug("version: %o", changelogContext.version);
81+
debug("host: %o", changelogContext.hostname);
82+
debug("owner: %o", changelogContext.owner);
83+
debug("repository: %o", changelogContext.repository);
84+
debug("previousTag: %o", changelogContext.previousTag);
85+
debug("currentTag: %o", changelogContext.currentTag);
86+
debug("host: %o", changelogContext.host);
87+
debug("linkReferences: %o", changelogContext.linkReferences);
88+
debug("issue: %o", changelogContext.issue);
89+
debug("commit: %o", changelogContext.commit);
8890

8991
return getStream(intoStream.object(parsedCommits).pipe(writer(changelogContext, writerOpts)));
9092
}
91-
92-
module.exports = {generateNotes};

0 commit comments

Comments
 (0)