Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(esm): converted the package to esm #297

Merged
merged 13 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# style: prettier
833e2127a843ed33f9da1b945e28933afe25a5aa
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ jobs:
with:
cache: npm
node-version: lts/*
- run: npm ci
- run: npm clean-install
- run: npm audit signatures
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
15 changes: 8 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
strategy:
matrix:
node-version:
- 14.17
- 16
- 18.0.0
- 19
os:
- ubuntu-latest
runs-on: "${{ matrix.os }}"
Expand All @@ -25,7 +25,9 @@ jobs:
with:
node-version: "${{ matrix.node-version }}"
cache: npm
- run: npm ci
- run: npm clean-install
- name: Ensure dependencies are compatible with the engines range
run: npx ls-engines
- run: "npm run test:ci"
test:
runs-on: ubuntu-latest
Expand All @@ -34,9 +36,8 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: lts/*
cache: npm
- run: npm ci
- name: Ensure dependencies are compatible with the engines range
run: npx ls-engines
- run: npm clean-install
- run: npm audit signatures
- run: npm run lint
37 changes: 22 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![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)

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

## Install
Expand All @@ -22,26 +22,33 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
```json
{
"plugins": [
["@semantic-release/commit-analyzer", {
"preset": "angular",
"parserOpts": {
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
[
"@semantic-release/commit-analyzer",
{
"preset": "angular",
"parserOpts": {
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
}
}
}],
["@semantic-release/release-notes-generator", {
"preset": "angular",
"parserOpts": {
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
},
"writerOpts": {
"commitsSort": ["subject", "scope"]
],
[
"@semantic-release/release-notes-generator",
{
"preset": "angular",
"parserOpts": {
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
},
"writerOpts": {
"commitsSort": ["subject", "scope"]
}
}
}]
]
]
}
```

With this example:

- 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`)
- 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`)

Expand All @@ -50,7 +57,7 @@ With this example:
### Options

| Option | Description | Default |
|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `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) |
| `config` | NPM package name of a custom [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) preset. | - |
| `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. | - |
Expand Down
80 changes: 40 additions & 40 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
const {format} = require('url');
const {find, merge} = require('lodash');
const getStream = require('get-stream');
const intoStream = require('into-stream');
const parser = require('conventional-commits-parser').sync;
const writer = require('conventional-changelog-writer');
const filter = require('conventional-commits-filter');
const readPkgUp = require('read-pkg-up');
const debug = require('debug')('semantic-release:release-notes-generator');
const loadChangelogConfig = require('./lib/load-changelog-config.js');
const HOSTS_CONFIG = require('./lib/hosts-config.js');
import { format } from "url";
import { find, merge } from "lodash-es";
import getStream from "get-stream";
import intoStream from "into-stream";
import { sync as parser } from "conventional-commits-parser";
import writer from "./wrappers/conventional-changelog-writer.js";
import filter from "conventional-commits-filter";
import { readPackageUp } from "read-pkg-up";
import debugFactory from "debug";
import loadChangelogConfig from "./lib/load-changelog-config.js";
import HOSTS_CONFIG from "./lib/hosts-config.js";

const debug = debugFactory("semantic-release:release-notes-generator");

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

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

const {issue, commit, referenceActions, issuePrefixes} =
const { issue, commit, referenceActions, issuePrefixes } =
find(HOSTS_CONFIG, (conf) => conf.hostname === hostname) || HOSTS_CONFIG.default;
const parsedCommits = filter(
commits
.filter(({message, hash}) => {
.filter(({ message, hash }) => {
if (!message.trim()) {
debug('Skip commit %s with empty message', hash);
debug("Skip commit %s with empty message", hash);
return false;
}

return true;
})
.map((rawCommit) => ({
...rawCommit,
...parser(rawCommit.message, {referenceActions, issuePrefixes, ...parserOpts}),
...parser(rawCommit.message, { referenceActions, issuePrefixes, ...parserOpts }),
}))
);
const previousTag = lastRelease.gitTag || lastRelease.gitHead;
const currentTag = nextRelease.gitTag || nextRelease.gitHead;
const {host: hostConfig, linkCompare, linkReferences, commit: commitConfig, issue: issueConfig} = pluginConfig;
const { host: hostConfig, linkCompare, linkReferences, commit: commitConfig, issue: issueConfig } = pluginConfig;
const changelogContext = merge(
{
version: nextRelease.version,
host: format({protocol, hostname, port}),
host: format({ protocol, hostname, port }),
owner,
repository,
previousTag,
currentTag,
linkCompare: currentTag && previousTag,
issue,
commit,
packageData: ((await readPkgUp({normalize: false, cwd})) || {}).packageJson,
packageData: ((await readPackageUp({ normalize: false, cwd })) || {}).packageJson,
},
{host: hostConfig, linkCompare, linkReferences, commit: commitConfig, issue: issueConfig}
{ host: hostConfig, linkCompare, linkReferences, commit: commitConfig, issue: issueConfig }
);

debug('version: %o', changelogContext.version);
debug('host: %o', changelogContext.hostname);
debug('owner: %o', changelogContext.owner);
debug('repository: %o', changelogContext.repository);
debug('previousTag: %o', changelogContext.previousTag);
debug('currentTag: %o', changelogContext.currentTag);
debug('host: %o', changelogContext.host);
debug('linkReferences: %o', changelogContext.linkReferences);
debug('issue: %o', changelogContext.issue);
debug('commit: %o', changelogContext.commit);
debug("version: %o", changelogContext.version);
debug("host: %o", changelogContext.hostname);
debug("owner: %o", changelogContext.owner);
debug("repository: %o", changelogContext.repository);
debug("previousTag: %o", changelogContext.previousTag);
debug("currentTag: %o", changelogContext.currentTag);
debug("host: %o", changelogContext.host);
debug("linkReferences: %o", changelogContext.linkReferences);
debug("issue: %o", changelogContext.issue);
debug("commit: %o", changelogContext.commit);

return getStream(intoStream.object(parsedCommits).pipe(writer(changelogContext, writerOpts)));
}

module.exports = {generateNotes};
Loading