Skip to content

Commit 3b11f00

Browse files
committed
feat: convert package to ESM (#464)
BREAKING CHANGE: This package is now ESM-only and cannot be used by CJS packages. BREAKING CHANGE: The minimum supported Node version has been changed to 18.0.0.
1 parent e029ca8 commit 3b11f00

26 files changed

+7962
-12204
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 3 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
- macos-latest
@@ -30,7 +30,7 @@ jobs:
3030
- run: npm ci
3131
- name: Ensure dependencies are compatible with the version of node
3232
run: npx ls-engines
33-
- run: "npm run test:ci"
33+
- run: npm run test
3434
test:
3535
runs-on: ubuntu-latest
3636
needs: test_matrix

README.md

Lines changed: 48 additions & 44 deletions
Large diffs are not rendered by default.

index.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/* eslint require-atomic-updates: off */
22

3-
const verifyGitLab = require('./lib/verify');
4-
const publishGitLab = require('./lib/publish');
5-
const successGitLab = require('./lib/success');
6-
const failGitLab = require('./lib/fail');
3+
import verifyGitLab from "./lib/verify.js";
4+
import publishGitLab from "./lib/publish.js";
5+
import successGitLab from "./lib/success.js";
6+
import failGitLab from "./lib/fail.js";
77

88
let verified;
99

10-
async function verifyConditions(pluginConfig, context) {
10+
export async function verifyConditions(pluginConfig, context) {
1111
await verifyGitLab(pluginConfig, context);
1212
verified = true;
1313
}
1414

15-
async function publish(pluginConfig, context) {
15+
export async function publish(pluginConfig, context) {
1616
if (!verified) {
1717
await verifyGitLab(pluginConfig, context);
1818
verified = true;
@@ -21,7 +21,7 @@ async function publish(pluginConfig, context) {
2121
return publishGitLab(pluginConfig, context);
2222
}
2323

24-
async function success(pluginConfig, context) {
24+
export async function success(pluginConfig, context) {
2525
if (!verified) {
2626
await verifyGitLab(pluginConfig, context);
2727
verified = true;
@@ -30,13 +30,11 @@ async function success(pluginConfig, context) {
3030
return successGitLab(pluginConfig, context);
3131
}
3232

33-
async function fail(pluginConfig, context) {
33+
export async function fail(pluginConfig, context) {
3434
if (!verified) {
3535
await verifyGitLab(pluginConfig, context);
3636
verified = true;
3737
}
3838

3939
return failGitLab(pluginConfig, context);
4040
}
41-
42-
module.exports = {verifyConditions, publish, success, fail};

lib/definitions/constants.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const HOME_URL = 'https://github.com/semantic-release/semantic-release';
1+
export const HOME_URL = 'https://github.com/semantic-release/semantic-release';
22

3-
const RELEASE_NAME = 'GitLab release';
4-
5-
module.exports = {HOME_URL, RELEASE_NAME};
3+
export const RELEASE_NAME = 'GitLab release';

lib/definitions/errors.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const {inspect} = require('util');
2-
const pkg = require('../../package.json');
1+
import {inspect} from 'util';
2+
import pkg from '../../package.json' assert {type: 'json'};
33

44
const [homepage] = pkg.homepage.split('#');
55
const linkify = (file) => `${homepage}/blob/master/${file}`;
66
const stringify = (object) => inspect(object, {breakLength: Number.POSITIVE_INFINITY, depth: 2, maxArrayLength: 5});
77

8-
module.exports = {
8+
export default {
99
EINVALIDASSETS: ({assets}) => ({
1010
message: 'Invalid `assets` option.',
1111
details: `The [assets option](${linkify(

lib/fail.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,63 @@
1-
const {template} = require('lodash');
2-
const urlJoin = require('url-join');
3-
const got = require('got');
4-
const debug = require('debug')('semantic-release:gitlab');
5-
const resolveConfig = require('./resolve-config');
6-
const getRepoId = require('./get-repo-id');
7-
const getFailComment = require('./get-fail-comment');
8-
9-
module.exports = async (pluginConfig, context) => {
1+
import { template } from "lodash-es";
2+
import urlJoin from "url-join";
3+
import got from "got";
4+
import _debug from "debug";
5+
const debug = _debug("semantic-release:gitlab");
6+
import resolveConfig from "./resolve-config.js";
7+
import getRepoId from "./get-repo-id.js";
8+
import getFailComment from "./get-fail-comment.js";
9+
10+
export default async (pluginConfig, context) => {
1011
const {
11-
options: {repositoryUrl},
12+
options: { repositoryUrl },
1213
branch,
1314
errors,
1415
logger,
1516
} = context;
16-
const {gitlabToken, gitlabUrl, gitlabApiUrl, failComment, failTitle, labels, assignee} = resolveConfig(
17+
const { gitlabToken, gitlabUrl, gitlabApiUrl, failComment, failTitle, labels, assignee } = resolveConfig(
1718
pluginConfig,
1819
context
1920
);
2021
const repoId = getRepoId(context, gitlabUrl, repositoryUrl);
2122
const encodedRepoId = encodeURIComponent(repoId);
22-
const apiOptions = {headers: {'PRIVATE-TOKEN': gitlabToken}};
23+
const apiOptions = { headers: { "PRIVATE-TOKEN": gitlabToken } };
2324

2425
if (failComment === false || failTitle === false) {
25-
logger.log('Skip issue creation.');
26+
logger.log("Skip issue creation.");
2627
} else {
2728
const encodedFailTitle = encodeURIComponent(failTitle);
28-
const description = failComment ? template(failComment)({branch, errors}) : getFailComment(branch, errors);
29+
const description = failComment ? template(failComment)({ branch, errors }) : getFailComment(branch, errors);
2930

3031
const issuesEndpoint = urlJoin(gitlabApiUrl, `/projects/${encodedRepoId}/issues`);
3132
const openFailTitleIssueEndpoint = urlJoin(issuesEndpoint, `?state=opened&search=${encodedFailTitle}`);
3233

33-
const openFailTitleIssues = await got(openFailTitleIssueEndpoint, {...apiOptions}).json();
34+
const openFailTitleIssues = await got(openFailTitleIssueEndpoint, { ...apiOptions }).json();
3435
const existingIssue = openFailTitleIssues.find((openFailTitleIssue) => openFailTitleIssue.title === failTitle);
3536

3637
if (existingIssue) {
37-
debug('comment on issue: %O', existingIssue);
38+
debug("comment on issue: %O", existingIssue);
3839

3940
const issueNotesEndpoint = urlJoin(
4041
gitlabApiUrl,
4142
`/projects/${existingIssue.project_id}/issues/${existingIssue.iid}/notes`
4243
);
4344
await got.post(issueNotesEndpoint, {
4445
...apiOptions,
45-
json: {body: description},
46+
json: { body: description },
4647
});
4748

48-
const {id, web_url} = existingIssue;
49-
logger.log('Commented on issue #%d: %s.', id, web_url);
49+
const { id, web_url } = existingIssue;
50+
logger.log("Commented on issue #%d: %s.", id, web_url);
5051
} else {
51-
const newIssue = {id: encodedRepoId, description, labels, title: failTitle, assignee_id: assignee};
52-
debug('create issue: %O', newIssue);
52+
const newIssue = { id: encodedRepoId, description, labels, title: failTitle, assignee_id: assignee };
53+
debug("create issue: %O", newIssue);
5354

5455
/* eslint camelcase: off */
55-
const {id, web_url} = await got.post(issuesEndpoint, {
56+
const { id, web_url } = await got.post(issuesEndpoint, {
5657
...apiOptions,
5758
json: newIssue,
5859
});
59-
logger.log('Created issue #%d: %s.', id, web_url);
60+
logger.log("Created issue #%d: %s.", id, web_url);
6061
}
6162
}
6263
};

lib/get-error.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const SemanticReleaseError = require('@semantic-release/error');
2-
const ERROR_DEFINITIONS = require('./definitions/errors');
1+
import SemanticReleaseError from "@semantic-release/error";
2+
import ERROR_DEFINITIONS from "./definitions/errors.js";
33

4-
module.exports = (code, ctx = {}) => {
5-
const {message, details} = ERROR_DEFINITIONS[code](ctx);
4+
export default (code, ctx = {}) => {
5+
const { message, details } = ERROR_DEFINITIONS[code](ctx);
66
return new SemanticReleaseError(message, code, details);
77
};

lib/get-fail-comment.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {HOME_URL} = require('./definitions/constants');
1+
import { HOME_URL } from "./definitions/constants.js";
22

33
const FAQ_URL = `${HOME_URL}/blob/master/docs/support/FAQ.md`;
44
const GET_HELP_URL = `${HOME_URL}#get-help`;
@@ -12,11 +12,11 @@ ${
1212
`Unfortunately this error doesn't have any additional information.${
1313
error.pluginName
1414
? ` Feel free to kindly ask the author of the \`${error.pluginName}\` plugin to add more helpful information.`
15-
: ''
15+
: ""
1616
}`
1717
}`;
1818

19-
module.exports = (branch, errors) => `## :rotating_light: The automated release from the \`${
19+
export default (branch, errors) => `## :rotating_light: The automated release from the \`${
2020
branch.name
2121
}\` branch failed. :rotating_light:
2222
@@ -39,7 +39,7 @@ If those don't help, or if this issue is reporting something you think isn't rig
3939
4040
---
4141
42-
${errors.map((error) => formatError(error)).join('\n\n---\n\n')}
42+
${errors.map((error) => formatError(error)).join("\n\n---\n\n")}
4343
4444
---
4545

lib/get-repo-id.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const parseUrl = require('parse-url');
2-
const escapeStringRegexp = require('escape-string-regexp');
1+
import parseUrl from "parse-url";
2+
import escapeStringRegexp from "escape-string-regexp";
33

4-
module.exports = ({envCi: {service} = {}, env: {CI_PROJECT_PATH}}, gitlabUrl, repositoryUrl) =>
5-
service === 'gitlab' && CI_PROJECT_PATH
4+
export default ({ envCi: { service } = {}, env: { CI_PROJECT_PATH } }, gitlabUrl, repositoryUrl) =>
5+
service === "gitlab" && CI_PROJECT_PATH
66
? CI_PROJECT_PATH
77
: parseUrl(repositoryUrl)
8-
.pathname.replace(new RegExp(`^${escapeStringRegexp(parseUrl(gitlabUrl).pathname)}`), '')
9-
.replace(/^\//, '')
10-
.replace(/\/$/, '')
11-
.replace(/\.git$/, '');
8+
.pathname.replace(new RegExp(`^${escapeStringRegexp(parseUrl(gitlabUrl).pathname)}`), "")
9+
.replace(/^\//, "")
10+
.replace(/\/$/, "")
11+
.replace(/\.git$/, "");

lib/get-success-comment.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
const {HOME_URL} = require('./definitions/constants');
1+
import { HOME_URL } from "./definitions/constants.js";
22

33
const linkify = (releaseInfo) =>
44
`${releaseInfo.url ? `[${releaseInfo.name}](${releaseInfo.url})` : `\`${releaseInfo.name}\``}`;
55

6-
module.exports = (issueOrMergeRequest, releaseInfos, nextRelease) =>
7-
`:tada: This ${issueOrMergeRequest.isMergeRequest ? 'MR is included' : 'issue has been resolved'} in version ${
6+
export default (issueOrMergeRequest, releaseInfos, nextRelease) =>
7+
`:tada: This ${issueOrMergeRequest.isMergeRequest ? "MR is included" : "issue has been resolved"} in version ${
88
nextRelease.version
99
} :tada:${
1010
releaseInfos.length > 0
1111
? `\n\nThe release is available on${
1212
releaseInfos.length === 1
1313
? ` ${linkify(releaseInfos[0])}.`
14-
: `:\n${releaseInfos.map((releaseInfo) => `- ${linkify(releaseInfo)}`).join('\n')}`
14+
: `:\n${releaseInfos.map((releaseInfo) => `- ${linkify(releaseInfo)}`).join("\n")}`
1515
}`
16-
: ''
16+
: ""
1717
}
1818
\nYour **[semantic-release](${HOME_URL})** bot :package: :rocket:`;

0 commit comments

Comments
 (0)