Skip to content

Commit 3bd491b

Browse files
committed
feat: migrate to semantic-release 24
1 parent a57ef3b commit 3bd491b

19 files changed

+6746
-2396
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ module.exports = {
77
},
88
"extends": "eslint:recommended",
99
"parserOptions": {
10-
"ecmaVersion": "latest"
10+
"ecmaVersion": "latest",
11+
"sourceType": "module"
1112
},
1213
"rules": {
1314
}

.husky/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

.husky/commit-msg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
# . "$(dirname "$0")/_/husky.sh"
3+
4+
npx --no -- commitlint --edit "$1"

.npmrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# require meeting the Node version restriction strictly
2+
# defined in package.json -> engines section
3+
engine-strict=true

analyzeCommits.js

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
const analyzeCommits = require('@semantic-release/commit-analyzer')
2-
const SemanticReleaseError = require('@semantic-release/error')
3-
const execSync = require('child_process').execSync;
4-
const lastTag = require('./lastTag');
5-
const utils = require('./utils');
1+
import SemanticReleaseError from '@semantic-release/error';
2+
import { execSync } from 'child_process';
3+
import { lastTag } from './lastTag.js';
4+
import { ghActionsBranch } from './utils.js';
65

76
const until = f => array => {
87
const first = array[0];
@@ -11,7 +10,7 @@ const until = f => array => {
1110
return [];
1211
}
1312

14-
return [ first, ...until(f)(array.slice(1)) ];
13+
return [first, ...until(f)(array.slice(1))];
1514
};
1615

1716
const lastTaggedRelease = () => {
@@ -21,47 +20,49 @@ const lastTaggedRelease = () => {
2120
return execSync(`git rev-list ${args}`, { encoding: 'utf8' }).trim();
2221
};
2322

24-
module.exports = function (pluginConfig, config, cb) {
23+
export default async function (pluginConfig, config) {
24+
let commitAnalyzer = (await import('@semantic-release/commit-analyzer'));
2525
// run standard commit analysis
26-
return analyzeCommits(pluginConfig, config, function(error, type) {
27-
const branch = config.env.TRAVIS_BRANCH || config.env.GIT_LOCAL_BRANCH || utils.ghActionsBranch(config.env);
28-
const branchTags = config.options.branchTags;
29-
const distTag = branchTags && branchTags[branch];
26+
const analyzeCommitsResult = await commitAnalyzer.analyzeCommits(pluginConfig, config);
27+
const type = analyzeCommitsResult;
3028

31-
// use default behavior if not publishing a custom dist-tag
32-
if (!distTag) {
33-
return cb(error, type);
34-
}
29+
const branch = config.env.TRAVIS_BRANCH || config.env.GIT_LOCAL_BRANCH || ghActionsBranch(config.env);
30+
const branchTags = config.options.branchTags;
31+
const distTag = branchTags && branchTags[branch];
3532

36-
let releaseType = type;
37-
if (type) {
38-
// map all types of releases to prereleases
39-
releaseType = {
40-
'major': 'premajor',
41-
'minor': 'preminor',
42-
'patch': 'prepatch'
43-
}[type] || type;
33+
// use default behavior if not publishing a custom dist-tag
34+
if (!distTag) {
35+
return type;
36+
}
4437

45-
console.log("Publishing a " + releaseType + " release.");
46-
}
38+
let releaseType = type;
39+
if (type) {
40+
// map all types of releases to prereleases
41+
releaseType = {
42+
'major': 'premajor',
43+
'minor': 'preminor',
44+
'patch': 'prepatch'
45+
}[type] || type;
4746

48-
// suppress NPM releases of non-feature commits (chore/docs/etc)
49-
const lastReleaseHash = lastTaggedRelease();
50-
const untilLastRelease = until(commit => commit.hash === lastReleaseHash);
51-
const commits = untilLastRelease(config.commits);
52-
const commitSubset = Object.assign({}, config, { commits });
47+
console.log("Publishing a " + releaseType + " release.");
48+
}
5349

54-
analyzeCommits(pluginConfig, commitSubset, function(_, type) {
55-
if (!type) {
56-
// commits since last dist-tag release are empty, suppress release
57-
return cb(new SemanticReleaseError(
58-
'There are no relevant changes, so no new version is released.',
59-
'ENOCHANGE'
60-
));
61-
}
50+
// suppress NPM releases of non-feature commits (chore/docs/etc)
51+
const lastReleaseHash = lastTaggedRelease();
52+
const untilLastRelease = until(commit => commit.hash === lastReleaseHash);
53+
const commits = untilLastRelease(config.commits);
54+
const commitSubset = Object.assign({}, config, { commits });
6255

63-
cb(error, releaseType);
64-
});
65-
});
66-
};
56+
const result = await commitAnalyzer.analyzeCommits(pluginConfig, commitSubset)
57+
58+
if (!type) {
59+
// commits since last dist-tag release are empty, suppress release
60+
return new SemanticReleaseError(
61+
'There are no relevant changes, so no new version is released.',
62+
'ENOCHANGE'
63+
);
64+
}
65+
66+
return result;
67+
}
6768

bin/find-dev-deps.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

3-
const fs = require('fs');
4-
const json = fs.readFileSync('package.json', { encoding: 'utf-8' });
3+
import { readFileSync } from 'fs';
4+
const json = readFileSync('package.json', { encoding: 'utf-8' });
55
const meta = JSON.parse(json);
66
const deps = Object.assign({}, meta.dependencies, meta.peerDependencies);
77

bin/semantic-prerelease.js

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
11
#!/usr/bin/env node
22

3-
const utils = require('../utils');
4-
const path = require('path');
5-
const validateConfig = require('../validateConfig');
6-
const config = require(path.resolve('package.json'));
7-
const branch = process.env.TRAVIS_BRANCH || process.env.GIT_LOCAL_BRANCH || utils.ghActionsBranch(process.env);
3+
import { ghActionsBranch } from '../utils.js';
4+
import validateConfig from '../validateConfig.js';
5+
import config from 'package.json';
6+
import { exec } from 'child_process';
7+
const branch = process.env.TRAVIS_BRANCH || process.env.GIT_LOCAL_BRANCH || ghActionsBranch(process.env);
88
const branchTags = config.release && config.release.branchTags;
99
const tag = branchTags && branchTags[branch];
1010
const dryRun = process.argv.find(arg => /^(--dry-run|-n)$/.test(arg));
1111
const publicPackage = process.argv.find(arg => /^(--public)$/.test(arg));
1212
const validate = process.argv.find(arg => /^(--validate|-v)$/.test(arg));
13-
const command = [ 'npm', 'publish' ];
13+
const command = ['npm', 'publish'];
1414

15-
if (validate) {
15+
function semanticRelease() {
16+
if (validate) {
1617
validateConfig(config);
1718
return;
18-
}
19-
20-
if (tag) {
21-
command.push('--tag', tag);
22-
}
19+
}
20+
// } else {
21+
if (tag) {
22+
command.push('--tag', tag);
23+
}
2324

24-
if (publicPackage) {
25-
command.push('--access=public');
26-
}
25+
if (publicPackage) {
26+
command.push('--access=public');
27+
}
2728

28-
if (!branchTags) {
29-
console.warn('[WARN] No branch tag configuration');
30-
}
29+
if (!branchTags) {
30+
console.warn('[WARN] No branch tag configuration');
31+
}
3132

32-
if (dryRun) {
33-
console.log(command.join(' '));
34-
} else {
35-
const exec = require('child_process').exec;
36-
exec(command.join(' '), function(error, stdout, stderr) {
37-
console.log(stdout);
33+
if (dryRun) {
34+
console.log(command.join(' '));
35+
} else {
36+
exec(command.join(' '), function (error, stdout, stderr) {
37+
console.log(stdout);
3838

39-
if (error) {
40-
console.error(`[ERROR] npm publish: ${stderr}`);
41-
process.exit(1);
42-
}
43-
});
39+
if (error) {
40+
console.error(`[ERROR] npm publish: ${stderr}`);
41+
process.exit(1);
42+
}
43+
});
44+
}
4445
}
46+
47+
semanticRelease();

commitlint.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
extends: ["@commitlint/config-conventional"],
3+
};

condition-github-actions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
var SRError = require('@semantic-release/error')
1+
import SRError from '@semantic-release/error'
22

3-
module.exports = function (pluginConfig, config, cb) {
3+
export function verifyConditions(pluginConfig, config, cb) {
44
var env = config.env
55

66
if (!Object.hasOwnProperty.call(env, 'GITHUB_ACTION')) {

generateNotes.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
const changelog = require('conventional-changelog')
2-
const parseUrl = require('github-url-from-git')
3-
const lastTag = require('./lastTag');
1+
import conventionalChangelog from 'conventional-changelog';
2+
import parseUrl from 'github-url-from-git';
3+
import { lastTag } from './lastTag.js';
44

5-
module.exports = function (pluginConfig, {pkg}, cb) {
5+
export default function (pluginConfig, {pkg}, cb) {
6+
console.log("============================= generate notes");
67
const repository = pkg.repository ? parseUrl(pkg.repository.url) : null
78
const from = lastTag();
89

9-
changelog({
10+
conventionalChangelog({
1011
version: pkg.version,
1112
repository: repository,
1213
from: from,
1314
file: false
1415
}, cb)
15-
};
16-
16+
}

0 commit comments

Comments
 (0)