From 3e8301d37bbb4ef89947f0504d7f92cd1f2fb9f0 Mon Sep 17 00:00:00 2001 From: David Losert Date: Fri, 23 Aug 2024 17:52:21 +0000 Subject: [PATCH] fix: Converting packages to type: module to fix error with semantic-release/error package being esm only --- index.js | 6 +++--- lib/errors/GitError.js | 4 ++-- lib/git.js | 10 ++++++---- lib/publish.js | 4 ++-- lib/resolveTags.js | 2 +- package.json | 3 ++- vitest.config.mjs | 1 + 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 9151fdf..214929b 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,11 @@ -const { createPublish } = require('./lib/publish'); -const { git } = require('./lib/git'); +import { createPublish } from './lib/publish'; +import { git } from './lib/git'; const publishTags = createPublish(git); async function publish(pluginConfig, context) { await publishTags(pluginConfig, context); } -module.exports = { +export { publish }; diff --git a/lib/errors/GitError.js b/lib/errors/GitError.js index cf4ede1..c7afe31 100644 --- a/lib/errors/GitError.js +++ b/lib/errors/GitError.js @@ -1,4 +1,4 @@ -const SemanticReleaseError = require("@semantic-release/error"); +import SemanticReleaseError from "@semantic-release/error"; class GitError extends SemanticReleaseError { constructor(originalError) { @@ -9,6 +9,6 @@ class GitError extends SemanticReleaseError { } } -module.exports = { +export { GitError }; diff --git a/lib/git.js b/lib/git.js index e143d1c..3a0c8e3 100644 --- a/lib/git.js +++ b/lib/git.js @@ -1,6 +1,8 @@ -const util = require('util'); -const exec = util.promisify(require('child_process').exec); -const { GitError } = require('./errors/GitError'); +import { promisify } from 'util'; +import { exec as pureExec } from 'child_process'; +import { GitError } from './errors/GitError'; + +const exec = promisify(pureExec); const git = { forcePushTags: async ({sourceTag, targetTags, repositoryUrl}) => { @@ -19,6 +21,6 @@ const git = { } } -module.exports = { +export { git }; diff --git a/lib/publish.js b/lib/publish.js index 2ae6ce1..b7c5196 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -1,4 +1,4 @@ -const { resolveTags } = require('./resolveTags'); +import { resolveTags } from './resolveTags'; function createPublish(git) { return async (pluginConfig, context) => { @@ -16,6 +16,6 @@ function createPublish(git) { } } -module.exports = { +export { createPublish }; diff --git a/lib/resolveTags.js b/lib/resolveTags.js index 1ac8190..9ee63fc 100644 --- a/lib/resolveTags.js +++ b/lib/resolveTags.js @@ -4,6 +4,6 @@ function resolveTags(givenTag) { return [major, `${major}.${minor}`]; } -module.exports = { +export { resolveTags }; diff --git a/package.json b/package.json index b23aa97..cf04f82 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,13 @@ "version": "2.0.0", "description": "Semantic Release Plugin to update all version Tags for a GitHub Action during a release", "main": "index.js", + "type": "module", "contributors": [ "David Losert " ], "scripts": { "test": "vitest", - "test:ci": "vitest" + "test:ci": "vitest --coverage.enabled" }, "repository": { "type": "git", diff --git a/vitest.config.mjs b/vitest.config.mjs index 575ed9c..ea17234 100644 --- a/vitest.config.mjs +++ b/vitest.config.mjs @@ -4,6 +4,7 @@ export default defineConfig({ test: { coverage: { + include: ['lib/**/*.js'], // you can include other reporters, but 'json-summary' is required, json is recommended reporter: ['text', 'json-summary', 'json'], }