Skip to content

Commit d26ca87

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

18 files changed

+6684
-2344
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"

analyzeCommits.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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 { analyzeCommits } from '@semantic-release/commit-analyzer';
2+
import SemanticReleaseError from '@semantic-release/error';
3+
import { execSync } from 'child_process';
4+
import { lastTag } from './lastTag.js';
5+
import { ghActionsBranch } from './utils.js';
66

77
const until = f => array => {
88
const first = array[0];
@@ -21,10 +21,10 @@ const lastTaggedRelease = () => {
2121
return execSync(`git rev-list ${args}`, { encoding: 'utf8' }).trim();
2222
};
2323

24-
module.exports = function (pluginConfig, config, cb) {
24+
export default function (pluginConfig, config, cb) {
2525
// run standard commit analysis
2626
return analyzeCommits(pluginConfig, config, function(error, type) {
27-
const branch = config.env.TRAVIS_BRANCH || config.env.GIT_LOCAL_BRANCH || utils.ghActionsBranch(config.env);
27+
const branch = config.env.TRAVIS_BRANCH || config.env.GIT_LOCAL_BRANCH || ghActionsBranch(config.env);
2828
const branchTags = config.options.branchTags;
2929
const distTag = branchTags && branchTags[branch];
3030

@@ -63,5 +63,5 @@ module.exports = function (pluginConfig, config, cb) {
6363
cb(error, releaseType);
6464
});
6565
});
66-
};
66+
}
6767

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: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
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 { resolve } from 'path';
5+
import validateConfig from '../validateConfig.js';
6+
const config = require(resolve('package.json'));
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

1515
if (validate) {
16-
validateConfig(config);
17-
return;
18-
}
16+
validateConfig(config);
17+
// return;
18+
} else {
19+
if (tag) {
20+
command.push('--tag', tag);
21+
}
1922

20-
if (tag) {
21-
command.push('--tag', tag);
22-
}
23+
if (publicPackage) {
24+
command.push('--access=public');
25+
}
2326

24-
if (publicPackage) {
25-
command.push('--access=public');
26-
}
27+
if (!branchTags) {
28+
console.warn('[WARN] No branch tag configuration');
29+
}
2730

28-
if (!branchTags) {
29-
console.warn('[WARN] No branch tag configuration');
30-
}
31-
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);
31+
if (dryRun) {
32+
console.log(command.join(' '));
33+
} else {
34+
const exec = require('child_process').exec;
35+
exec(command.join(' '), function (error, stdout, stderr) {
36+
console.log(stdout);
3837

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

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: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const changelog = require('conventional-changelog')
2-
const parseUrl = require('github-url-from-git')
3-
const lastTag = require('./lastTag');
1+
import changelog 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) {
66
const repository = pkg.repository ? parseUrl(pkg.repository.url) : null
77
const from = lastTag();
88

@@ -12,5 +12,4 @@ module.exports = function (pluginConfig, {pkg}, cb) {
1212
from: from,
1313
file: false
1414
}, cb)
15-
};
16-
15+
}

getLastRelease.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
const defaultLastRelease = require('@semantic-release/last-release-npm');
2-
const lastTag = require('./lastTag');
3-
const utils = require('./utils');
4-
module.exports = function (pluginConfig, config, cb) {
1+
import defaultLastRelease from '@semantic-release/last-release-npm';
2+
import lastTag from './lastTag';
3+
import { ghActionsBranch } from './utils';
4+
5+
export default function (pluginConfig, config, cb) {
56
let branch;
67
let oldTag;
78

@@ -10,7 +11,7 @@ module.exports = function (pluginConfig, config, cb) {
1011
} else if (config.env.GIT_LOCAL_BRANCH) {
1112
branch = config.env.GIT_LOCAL_BRANCH;
1213
} else if (config.env.GITHUB_REF) {
13-
branch = utils.ghActionsBranch(config.env);
14+
branch = ghActionsBranch(config.env);
1415
} else {
1516
throw new Error('Unable to determine Git branch. Tried TRAVIS_BRANCH, GIT_LOCAL_BRANCH and GITHUB_REF');
1617
}
@@ -34,5 +35,4 @@ module.exports = function (pluginConfig, config, cb) {
3435
}
3536
cb(err, res);
3637
});
37-
};
38-
38+
}

lastTag.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
const execSync = require('child_process').execSync;
1+
import { execSync } from 'child_process';
22

3-
const lastTag = ({ branch = 'origin/master', dev = true } = {}) => {
3+
export const lastTag = ({ branch = 'origin/master', dev = true } = {}) => {
44
const exclude = dev ? ' --exclude="*dev*"' : '';
55
return execSync(`git describe --tags --match "v[0-9]*" ${exclude} --abbrev=0 ${branch} || true`,
66
{ encoding: 'utf8' }
77
).trim();
8-
};
9-
10-
module.exports = lastTag;
8+
}

0 commit comments

Comments
 (0)