Skip to content

Commit c215832

Browse files
authored
Merge pull request #450 from semantic-release/beta
2 parents d630b6e + 5932f0b commit c215832

20 files changed

+7355
-20587
lines changed

.git-blame-ignore-revs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# style: prettier
2+
6964913a3286531f1b3aa0a264feee9e84bb2329

.github/workflows/release.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ jobs:
2323
with:
2424
node-version: lts/*
2525
cache: npm
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

+10-5
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ jobs:
1313
strategy:
1414
matrix:
1515
node-version:
16-
- 14.17
17-
- 16
16+
- 18.0.0
17+
- 19
18+
- 20
1819
os:
1920
- ubuntu-latest
2021
- macos-latest
@@ -27,7 +28,7 @@ jobs:
2728
with:
2829
node-version: "${{ matrix.node-version }}"
2930
cache: npm
30-
- run: npm ci
31+
- run: npm clean-install
3132
- run: "npm run test:ci"
3233
test:
3334
runs-on: ubuntu-latest
@@ -36,9 +37,13 @@ jobs:
3637
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3
3738
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
3839
with:
39-
node-version: 16
40+
node-version: "lts/*"
4041
cache: npm
41-
- run: npm ci
42+
- run: npm clean-install
43+
- run: npm audit signatures
4244
- name: Ensure dependencies are compatible with the engines range
4345
run: npx ls-engines
4446
- run: npm run lint
47+
# https://github.com/lirantal/lockfile-lint#readme
48+
- name: Scan lockfile for security issues
49+
run: npx lockfile-lint --path package-lock.json

README.md

+59-36
Large diffs are not rendered by default.

index.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
const {isUndefined} = require('lodash');
2-
const parser = require('conventional-commits-parser').sync;
3-
const filter = require('conventional-commits-filter');
4-
const debug = require('debug')('semantic-release:commit-analyzer');
5-
const loadParserConfig = require('./lib/load-parser-config.js');
6-
const loadReleaseRules = require('./lib/load-release-rules.js');
7-
const analyzeCommit = require('./lib/analyze-commit.js');
8-
const compareReleaseTypes = require('./lib/compare-release-types.js');
9-
const RELEASE_TYPES = require('./lib/default-release-types.js');
10-
const DEFAULT_RELEASE_RULES = require('./lib/default-release-rules.js');
1+
import { isUndefined } from "lodash-es";
2+
import { sync as parser } from "conventional-commits-parser";
3+
import filter from "conventional-commits-filter";
4+
import debugFactory from "debug";
5+
import loadParserConfig from "./lib/load-parser-config.js";
6+
import loadReleaseRules from "./lib/load-release-rules.js";
7+
import analyzeCommit from "./lib/analyze-commit.js";
8+
import compareReleaseTypes from "./lib/compare-release-types.js";
9+
import RELEASE_TYPES from "./lib/default-release-types.js";
10+
import DEFAULT_RELEASE_RULES from "./lib/default-release-rules.js";
11+
12+
const debug = debugFactory("semantic-release:commit-analyzer");
1113

1214
/**
1315
* Determine the type of release to create based on a list of commits.
1416
*
1517
* @param {Object} pluginConfig The plugin configuration.
1618
* @param {String} pluginConfig.preset conventional-changelog preset ('angular', 'atom', 'codemirror', 'ember', 'eslint', 'express', 'jquery', 'jscs', 'jshint')
17-
* @param {String} pluginConfig.config Requirable npm package with a custom conventional-changelog preset
19+
* @param {String} pluginConfig.config Requireable npm package with a custom conventional-changelog preset
1820
* @param {String|Array} pluginConfig.releaseRules A `String` to load an external module or an `Array` of rules.
1921
* @param {Object} pluginConfig.parserOpts Additional `conventional-changelog-parser` options that will overwrite ones loaded by `preset` or `config`.
2022
* @param {Object} context The semantic-release context.
@@ -23,43 +25,43 @@ const DEFAULT_RELEASE_RULES = require('./lib/default-release-rules.js');
2325
*
2426
* @returns {String|null} the type of release to create based on the list of commits or `null` if no release has to be done.
2527
*/
26-
async function analyzeCommits(pluginConfig, context) {
27-
const {commits, logger} = context;
28+
export async function analyzeCommits(pluginConfig, context) {
29+
const { commits, logger } = context;
2830
const releaseRules = loadReleaseRules(pluginConfig, context);
2931
const config = await loadParserConfig(pluginConfig, context);
3032
let releaseType = null;
3133

3234
filter(
3335
commits
34-
.filter(({message, hash}) => {
36+
.filter(({ message, hash }) => {
3537
if (!message.trim()) {
36-
debug('Skip commit %s with empty message', hash);
38+
debug("Skip commit %s with empty message", hash);
3739
return false;
3840
}
3941

4042
return true;
4143
})
42-
.map(({message, ...commitProps}) => ({rawMsg: message, message, ...commitProps, ...parser(message, config)}))
43-
).every(({rawMsg, ...commit}) => {
44+
.map(({ message, ...commitProps }) => ({ rawMsg: message, message, ...commitProps, ...parser(message, config) }))
45+
).every(({ rawMsg, ...commit }) => {
4446
logger.log(`Analyzing commit: %s`, rawMsg);
4547
let commitReleaseType;
4648

4749
// Determine release type based on custom releaseRules
4850
if (releaseRules) {
49-
debug('Analyzing with custom rules');
51+
debug("Analyzing with custom rules");
5052
commitReleaseType = analyzeCommit(releaseRules, commit);
5153
}
5254

5355
// If no custom releaseRules or none matched the commit, try with default releaseRules
5456
if (isUndefined(commitReleaseType)) {
55-
debug('Analyzing with default rules');
57+
debug("Analyzing with default rules");
5658
commitReleaseType = analyzeCommit(DEFAULT_RELEASE_RULES, commit);
5759
}
5860

5961
if (commitReleaseType) {
60-
logger.log('The release type for the commit is %s', commitReleaseType);
62+
logger.log("The release type for the commit is %s", commitReleaseType);
6163
} else {
62-
logger.log('The commit should not trigger a release');
64+
logger.log("The commit should not trigger a release");
6365
}
6466

6567
// Set releaseType if commit's release type is higher
@@ -74,9 +76,7 @@ async function analyzeCommits(pluginConfig, context) {
7476

7577
return true;
7678
});
77-
logger.log('Analysis of %s commits complete: %s release', commits.length, releaseType || 'no');
79+
logger.log("Analysis of %s commits complete: %s release", commits.length, releaseType || "no");
7880

7981
return releaseType;
8082
}
81-
82-
module.exports = {analyzeCommits};

lib/analyze-commit.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
const {isMatchWith, isString} = require('lodash');
2-
const micromatch = require('micromatch');
3-
const debug = require('debug')('semantic-release:commit-analyzer');
4-
const RELEASE_TYPES = require('./default-release-types.js');
5-
const compareReleaseTypes = require('./compare-release-types.js');
1+
import { isMatchWith, isString } from "lodash-es";
2+
import micromatch from "micromatch";
3+
import debugFactory from "debug";
4+
import RELEASE_TYPES from "./default-release-types.js";
5+
import compareReleaseTypes from "./compare-release-types.js";
66

7+
const debug = debugFactory("semantic-release:commit-analyzer");
78
/**
89
* Find all the rules matching and return the highest release type of the matching rules.
910
*
1011
* @param {Array} releaseRules the rules to match the commit against.
1112
* @param {Commit} commit a parsed commit.
1213
* @return {string} the highest release type of the matching rules or `undefined` if no rule match the commit.
1314
*/
14-
module.exports = (releaseRules, commit) => {
15+
export default (releaseRules, commit) => {
1516
let releaseType;
1617

1718
releaseRules
1819
.filter(
19-
({breaking, revert, release, ...rule}) =>
20+
({ breaking, revert, release, ...rule }) =>
2021
// If the rule is not `breaking` or the commit doesn't have a breaking change note
2122
(!breaking || (commit.notes && commit.notes.length > 0)) &&
2223
// If the rule is not `revert` or the commit is not a revert
@@ -29,14 +30,14 @@ module.exports = (releaseRules, commit) => {
2930
.every((match) => {
3031
if (compareReleaseTypes(releaseType, match.release)) {
3132
releaseType = match.release;
32-
debug('The rule %o match commit with release type %o', match, releaseType);
33+
debug("The rule %o match commit with release type %o", match, releaseType);
3334
if (releaseType === RELEASE_TYPES[0]) {
34-
debug('Release type %o is the highest possible. Stop analysis.', releaseType);
35+
debug("Release type %o is the highest possible. Stop analysis.", releaseType);
3536
return false;
3637
}
3738
} else {
3839
debug(
39-
'The rule %o match commit with release type %o but the higher release type %o has already been found for this commit',
40+
"The rule %o match commit with release type %o but the higher release type %o has already been found for this commit",
4041
match,
4142
match.release,
4243
releaseType

lib/compare-release-types.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const RELEASE_TYPES = require('./default-release-types.js');
1+
import RELEASE_TYPES from "./default-release-types.js";
22

33
/**
44
* Test if a realease type is of higher level than a given one.
@@ -7,5 +7,5 @@ const RELEASE_TYPES = require('./default-release-types.js');
77
* @param {string} releaseType the release type to compare with.
88
* @return {Boolean} true if `releaseType` is higher than `currentReleaseType`.
99
*/
10-
module.exports = (currentReleaseType, releaseType) =>
10+
export default (currentReleaseType, releaseType) =>
1111
!currentReleaseType || RELEASE_TYPES.indexOf(releaseType) < RELEASE_TYPES.indexOf(currentReleaseType);

lib/default-release-rules.js

+22-22
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@
33
*
44
* @type {Array}
55
*/
6-
module.exports = [
7-
{breaking: true, release: 'major'},
8-
{revert: true, release: 'patch'},
6+
export default [
7+
{ breaking: true, release: "major" },
8+
{ revert: true, release: "patch" },
99
// Angular
10-
{type: 'feat', release: 'minor'},
11-
{type: 'fix', release: 'patch'},
12-
{type: 'perf', release: 'patch'},
10+
{ type: "feat", release: "minor" },
11+
{ type: "fix", release: "patch" },
12+
{ type: "perf", release: "patch" },
1313
// Atom
14-
{emoji: ':racehorse:', release: 'patch'},
15-
{emoji: ':bug:', release: 'patch'},
16-
{emoji: ':penguin:', release: 'patch'},
17-
{emoji: ':apple:', release: 'patch'},
18-
{emoji: ':checkered_flag:', release: 'patch'},
14+
{ emoji: ":racehorse:", release: "patch" },
15+
{ emoji: ":bug:", release: "patch" },
16+
{ emoji: ":penguin:", release: "patch" },
17+
{ emoji: ":apple:", release: "patch" },
18+
{ emoji: ":checkered_flag:", release: "patch" },
1919
// Ember
20-
{tag: 'BUGFIX', release: 'patch'},
21-
{tag: 'FEATURE', release: 'minor'},
22-
{tag: 'SECURITY', release: 'patch'},
20+
{ tag: "BUGFIX", release: "patch" },
21+
{ tag: "FEATURE", release: "minor" },
22+
{ tag: "SECURITY", release: "patch" },
2323
// ESLint
24-
{tag: 'Breaking', release: 'major'},
25-
{tag: 'Fix', release: 'patch'},
26-
{tag: 'Update', release: 'minor'},
27-
{tag: 'New', release: 'minor'},
24+
{ tag: "Breaking", release: "major" },
25+
{ tag: "Fix", release: "patch" },
26+
{ tag: "Update", release: "minor" },
27+
{ tag: "New", release: "minor" },
2828
// Express
29-
{component: 'perf', release: 'patch'},
30-
{component: 'deps', release: 'patch'},
29+
{ component: "perf", release: "patch" },
30+
{ component: "deps", release: "patch" },
3131
// JSHint
32-
{type: 'FEAT', release: 'minor'},
33-
{type: 'FIX', release: 'patch'},
32+
{ type: "FEAT", release: "minor" },
33+
{ type: "FIX", release: "patch" },
3434
];

lib/default-release-types.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
*
44
* @type {Array}
55
*/
6-
module.exports = ['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'];
6+
export default ["major", "premajor", "minor", "preminor", "patch", "prepatch", "prerelease"];

lib/load-parser-config.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
const {promisify} = require('util');
2-
const {isPlainObject} = require('lodash');
3-
const importFrom = require('import-from');
4-
const conventionalChangelogAngular = require('conventional-changelog-angular');
1+
import { dirname } from "node:path";
2+
import { fileURLToPath } from "node:url";
3+
import { promisify } from "node:util";
4+
import { isPlainObject } from "lodash-es";
5+
import importFrom from "import-from";
6+
import conventionalChangelogAngular from "conventional-changelog-angular";
57

68
/**
79
* Load `conventional-changelog-parser` options. Handle presets that return either a `Promise<Array>` or a `Promise<Function>`.
810
*
911
* @param {Object} pluginConfig The plugin configuration.
1012
* @param {Object} pluginConfig.preset conventional-changelog preset ('angular', 'atom', 'codemirror', 'ember', 'eslint', 'express', 'jquery', 'jscs', 'jshint')
11-
* @param {String} pluginConfig.config Requirable npm package with a custom conventional-changelog preset
12-
* @param {Object} pluginConfig.parserOpts Additionnal `conventional-changelog-parser` options that will overwrite ones loaded by `preset` or `config`.
13+
* @param {String} pluginConfig.config Requireable npm package with a custom conventional-changelog preset
14+
* @param {Object} pluginConfig.parserOpts Additional `conventional-changelog-parser` options that will overwrite ones loaded by `preset` or `config`.
1315
* @param {Object} context The semantic-release context.
1416
* @param {String} context.cwd The current working directory.
1517
* @return {Promise<Object>} a `Promise` that resolve to the `conventional-changelog-parser` options.
1618
*/
17-
module.exports = async ({preset, config, parserOpts, presetConfig}, {cwd}) => {
19+
export default async ({ preset, config, parserOpts, presetConfig }, { cwd }) => {
1820
let loadedConfig;
21+
const __dirname = dirname(fileURLToPath(import.meta.url));
1922

2023
if (preset) {
2124
const presetPackage = `conventional-changelog-${preset.toLowerCase()}`;
@@ -26,11 +29,11 @@ module.exports = async ({preset, config, parserOpts, presetConfig}, {cwd}) => {
2629
loadedConfig = conventionalChangelogAngular;
2730
}
2831

29-
loadedConfig = await (typeof loadedConfig === 'function'
32+
loadedConfig = await (typeof loadedConfig === "function"
3033
? isPlainObject(presetConfig)
3134
? loadedConfig(presetConfig)
3235
: promisify(loadedConfig)()
3336
: loadedConfig);
3437

35-
return {...loadedConfig.parserOpts, ...parserOpts};
38+
return { ...loadedConfig.parserOpts, ...parserOpts };
3639
};

lib/load-release-rules.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
const {isUndefined} = require('lodash');
2-
const importFrom = require('import-from');
3-
const RELEASE_TYPES = require('./default-release-types.js');
1+
import { dirname } from "node:path";
2+
import { fileURLToPath } from "node:url";
3+
import { isUndefined } from "lodash-es";
4+
import importFrom from "import-from";
5+
import RELEASE_TYPES from "./default-release-types.js";
46

57
/**
68
* Load and validate the `releaseRules` rules.
@@ -15,12 +17,13 @@ const RELEASE_TYPES = require('./default-release-types.js');
1517
*
1618
* @return {Array} the loaded and validated `releaseRules`.
1719
*/
18-
module.exports = ({releaseRules}, {cwd}) => {
20+
export default ({ releaseRules }, { cwd }) => {
1921
let loadedReleaseRules;
22+
const __dirname = dirname(fileURLToPath(import.meta.url));
2023

2124
if (releaseRules) {
2225
loadedReleaseRules =
23-
typeof releaseRules === 'string'
26+
typeof releaseRules === "string"
2427
? importFrom.silent(__dirname, releaseRules) || importFrom(cwd, releaseRules)
2528
: releaseRules;
2629

0 commit comments

Comments
 (0)