From 4af25ea824f17a11ac145d41e8a9d8c45ee73ff6 Mon Sep 17 00:00:00 2001 From: William Killerud Date: Mon, 29 Jul 2024 15:32:26 +0200 Subject: [PATCH] fix: update dependencies BREAKING CHANGE: drops node-fetch for the built-in fetch, which means Node 18 or newer is required. --- .gitattributes | 1 + .npmrc | 1 + .prettierrc.json | 13 +++++ eslint.config.js | 22 +++++++++ lib/analyze-commits.js | 102 +++++++++++++++++++-------------------- lib/generate-notes.js | 22 ++++----- lib/main.js | 36 +++++++------- lib/prepare.js | 20 ++++---- lib/publish.js | 52 +++++++++++--------- lib/success.js | 46 +++++++++--------- lib/verify-conditions.js | 60 +++++++++++------------ lib/verify-release.js | 52 ++++++++++---------- package.json | 19 +++++--- release.config.js | 48 +++++++++--------- 14 files changed, 272 insertions(+), 222 deletions(-) create mode 100644 .gitattributes create mode 100644 .prettierrc.json create mode 100644 eslint.config.js diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.npmrc b/.npmrc index 43c97e7..0ca8d2a 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1,2 @@ package-lock=false +save-exact=true diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..649f132 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,13 @@ +{ + "singleQuote": true, + "trailingComma": "all", + "tabWidth": 4, + "overrides": [ + { + "files": ["*.json", "*.yml"], + "options": { + "tabWidth": 2 + } + } + ] +} diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..2d5b982 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,22 @@ +import prettierConfig from 'eslint-config-prettier'; +import prettierPlugin from 'eslint-plugin-prettier/recommended'; +import globals from 'globals'; +import js from '@eslint/js'; + +export default [ + js.configs.recommended, + prettierConfig, + prettierPlugin, + { + languageOptions: { + globals: { + ...globals.node, + ...globals.browser, + global: true, + }, + }, + }, + { + ignores: ['tap-snapshots/*', 'node_modules/*'], + }, +]; diff --git a/lib/analyze-commits.js b/lib/analyze-commits.js index 7089577..ba63155 100644 --- a/lib/analyze-commits.js +++ b/lib/analyze-commits.js @@ -1,16 +1,16 @@ -const eik = require("@eik/cli"); +const eik = require('@eik/cli'); -const I_VERSION_UPDATE = "Version: ✅ Updated Eik version from v%s to v%s."; +const I_VERSION_UPDATE = 'Version: ✅ Updated Eik version from v%s to v%s.'; const I_VERSION_NOT_NEEDED = - "Version: ✅ Not needed as the current version of this package already contains these files."; + 'Version: ✅ Not needed as the current version of this package already contains these files.'; const I_PUBLISH_NOT_NEEDED = - "Publish: ✅ Not needed as the current version of this package is already published."; + 'Publish: ✅ Not needed as the current version of this package is already published.'; const I_PUBLISH_NEEDED = - "Version: ✅ Not needed as the current Eik version not yet published."; + 'Version: ✅ Not needed as the current Eik version not yet published.'; const E_SERVER_CONNECTION_ERROR = - "Version: ❌ Unable to connect with Eik server."; + 'Version: ❌ Unable to connect with Eik server.'; const E_VERSIONING_ERROR = - "Version: ❌ Unable to perform versioning operation."; + 'Version: ❌ Unable to perform versioning operation.'; /** * Semantic Release "Analyze Commits" hook @@ -22,55 +22,55 @@ const E_VERSIONING_ERROR = * @param {object} state */ module.exports = async function analyzeCommits(options, context, state) { - const { version: currentVersion, server, type, name } = state.eikJSON; + const { version: currentVersion, server, type, name } = state.eikJSON; - // attempt to version Eik assets - try { - state.versionToPublish = await eik.version({ - name, - version: currentVersion, - type, - files: state.eikJSON.files, - server, - cwd: context.cwd, - level: options.level, - map: state.eikJSON.map, - out: state.eikJSON.out, - }); + // attempt to version Eik assets + try { + state.versionToPublish = await eik.version({ + name, + version: currentVersion, + type, + files: state.eikJSON.files, + server, + cwd: context.cwd, + level: options.level, + map: state.eikJSON.map, + out: state.eikJSON.out, + }); - // successful versioning, publish is now needed - context.logger.log( - I_VERSION_UPDATE, - currentVersion, - state.versionToPublish - ); - state.publishNeeded = true; - return options.level || "patch"; - } catch (err) { - // unsuccessful versioning, handle reason individually + // successful versioning, publish is now needed + context.logger.log( + I_VERSION_UPDATE, + currentVersion, + state.versionToPublish, + ); + state.publishNeeded = true; + return options.level || 'patch'; + } catch (err) { + // unsuccessful versioning, handle reason individually - if (err.message.includes("Unable to fetch package metadata")) { - context.logger.log(E_SERVER_CONNECTION_ERROR); - } + if (err.message.includes('Unable to fetch package metadata')) { + context.logger.log(E_SERVER_CONNECTION_ERROR); + } - if (err.message.includes("Unable to hash local files for comparison")) { - context.logger.log(E_VERSIONING_ERROR); - } + if (err.message.includes('Unable to hash local files for comparison')) { + context.logger.log(E_VERSIONING_ERROR); + } - if (err.message.includes("package has not yet been published")) { - state.publishNeeded = true; - state.versionToPublish = currentVersion; - context.logger.log(I_PUBLISH_NEEDED); - return options.level || "patch"; - } + if (err.message.includes('package has not yet been published')) { + state.publishNeeded = true; + state.versionToPublish = currentVersion; + context.logger.log(I_PUBLISH_NEEDED); + return options.level || 'patch'; + } - if (err.message.includes("package already contains these files")) { - context.logger.log(I_VERSION_NOT_NEEDED); - state.publishNeeded = false; - context.logger.log(I_PUBLISH_NOT_NEEDED); - return null; - } + if (err.message.includes('package already contains these files')) { + context.logger.log(I_VERSION_NOT_NEEDED); + state.publishNeeded = false; + context.logger.log(I_PUBLISH_NOT_NEEDED); + return null; + } - throw err; - } + throw err; + } }; diff --git a/lib/generate-notes.js b/lib/generate-notes.js index 14c5ed1..f823778 100644 --- a/lib/generate-notes.js +++ b/lib/generate-notes.js @@ -1,5 +1,5 @@ -const { join } = require("path"); -const { typeSlug } = require("@eik/common-utils"); +const { join } = require('path'); +const { typeSlug } = require('@eik/common-utils'); /** * Semantic Release "generate notes" hook @@ -11,15 +11,15 @@ const { typeSlug } = require("@eik/common-utils"); * @param {object} state */ module.exports = async function generateNotes(options, context, state) { - if (!state.publishNeeded) return; + if (!state.publishNeeded) return; - const { name, server, type } = state.eikJSON; - const version = state.versionToPublish; - const date = new Date(); - const dateString = `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`; - const slug = typeSlug(type); - const versionURL = new URL(join(slug, name, version), server).href; - const nameURL = new URL(join(slug, name), server).href; + const { name, server, type } = state.eikJSON; + const version = state.versionToPublish; + const date = new Date(); + const dateString = `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`; + const slug = typeSlug(type); + const versionURL = new URL(join(slug, name, version), server).href; + const nameURL = new URL(join(slug, name), server).href; - return `(${dateString}) Version [${version}](${versionURL}) of Eik package [${name}](${nameURL}) published to [${server}](${server})`; + return `(${dateString}) Version [${version}](${versionURL}) of Eik package [${name}](${nameURL}) published to [${server}](${server})`; }; diff --git a/lib/main.js b/lib/main.js index 54b7916..efee3ad 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,26 +1,26 @@ -const verifyConditions = require("./verify-conditions"); -const analyzeCommits = require("./analyze-commits"); -const verifyRelease = require("./verify-release"); -const generateNotes = require("./generate-notes"); -const prepare = require("./prepare"); -const publish = require("./publish"); -const success = require("./success"); +const verifyConditions = require('./verify-conditions'); +const analyzeCommits = require('./analyze-commits'); +const verifyRelease = require('./verify-release'); +const generateNotes = require('./generate-notes'); +const prepare = require('./prepare'); +const publish = require('./publish'); +const success = require('./success'); class State { - eikToken = ""; - eikJSON = {}; - versionToPublish = null; - publishNeeded = null; + eikToken = ''; + eikJSON = {}; + versionToPublish = null; + publishNeeded = null; } const state = new State(); module.exports = { - verifyConditions: (options, ctx) => verifyConditions(options, ctx, state), - analyzeCommits: (options, ctx) => analyzeCommits(options, ctx, state), - verifyRelease: (options, ctx) => verifyRelease(options, ctx, state), - generateNotes: (options, ctx) => generateNotes(options, ctx, state), - prepare: (options, ctx) => prepare(options, ctx, state), - publish: (options, ctx) => publish(options, ctx, state), - success: (options, ctx) => success(options, ctx, state), + verifyConditions: (options, ctx) => verifyConditions(options, ctx, state), + analyzeCommits: (options, ctx) => analyzeCommits(options, ctx, state), + verifyRelease: (options, ctx) => verifyRelease(options, ctx, state), + generateNotes: (options, ctx) => generateNotes(options, ctx, state), + prepare: (options, ctx) => prepare(options, ctx, state), + publish: (options, ctx) => publish(options, ctx, state), + success: (options, ctx) => success(options, ctx, state), }; diff --git a/lib/prepare.js b/lib/prepare.js index b010217..dac98d2 100644 --- a/lib/prepare.js +++ b/lib/prepare.js @@ -1,6 +1,6 @@ -const json = require("@eik/cli/utils/json"); +const json = require('@eik/cli/utils/json'); -const VERSION_WRITTEN = "Version: ✅ v%s written back to eik.json file."; +const VERSION_WRITTEN = 'Version: ✅ v%s written back to eik.json file.'; /** * Semantic Release "prepare" hook @@ -12,13 +12,13 @@ const VERSION_WRITTEN = "Version: ✅ v%s written back to eik.json file."; * @param {object} state */ module.exports = async function prepare(options, context, state) { - if (!state.publishNeeded) return; + if (!state.publishNeeded) return; - if (state.eikJSON.version !== state.versionToPublish) { - context.logger.log(VERSION_WRITTEN, state.versionToPublish); - await json.writeEik( - { version: state.versionToPublish }, - { cwd: context.cwd } - ); - } + if (state.eikJSON.version !== state.versionToPublish) { + context.logger.log(VERSION_WRITTEN, state.versionToPublish); + await json.writeEik( + { version: state.versionToPublish }, + { cwd: context.cwd }, + ); + } }; diff --git a/lib/publish.js b/lib/publish.js index 9204b18..91b99de 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -1,8 +1,8 @@ -const eik = require("@eik/cli"); +const eik = require('@eik/cli'); -const PUBLISHED = "Publish: ✅ Published %s file(s) to Eik server %s"; +const PUBLISHED = 'Publish: ✅ Published %s file(s) to Eik server %s'; const E_PUBLISH_FAILED = - "Publish: ❌ Failed, this may leave your build in a broken state. If retrying the build fails, try pushing a new commit."; + 'Publish: ❌ Failed, this may leave your build in a broken state. If retrying the build fails, try pushing a new commit.'; /** * Semantic Release "publish" hook @@ -14,25 +14,31 @@ const E_PUBLISH_FAILED = * @param {object} state */ module.exports = async function publish(options, context, state) { - if (!state.publishNeeded) return; + if (!state.publishNeeded) return; - try { - const result = await eik.publish({ - name: state.eikJSON.name, - type: state.eikJSON.type, - server: state.eikJSON.server, - files: state.eikJSON.files, - cwd: context.cwd, - token: state.eikToken, - dryRun: false, - version: state.versionToPublish, - map: state.eikJSON.map, - out: state.eikJSON.out, - }); - const filesPublished = result.files.filter((file) => file.type === "pkg"); - context.logger.log(PUBLISHED, filesPublished.length, state.eikJSON.server); - } catch (err) { - context.logger.log(E_PUBLISH_FAILED); - throw err; - } + try { + const result = await eik.publish({ + name: state.eikJSON.name, + type: state.eikJSON.type, + server: state.eikJSON.server, + files: state.eikJSON.files, + cwd: context.cwd, + token: state.eikToken, + dryRun: false, + version: state.versionToPublish, + map: state.eikJSON.map, + out: state.eikJSON.out, + }); + const filesPublished = result.files.filter( + (file) => file.type === 'pkg', + ); + context.logger.log( + PUBLISHED, + filesPublished.length, + state.eikJSON.server, + ); + } catch (err) { + context.logger.log(E_PUBLISH_FAILED); + throw err; + } }; diff --git a/lib/success.js b/lib/success.js index 5549e30..0f69e21 100644 --- a/lib/success.js +++ b/lib/success.js @@ -1,11 +1,11 @@ -const { join } = require("path"); -const { default: fetch } = require("node-fetch"); -const { typeSlug } = require("@eik/common-utils"); +const { join } = require('path'); +const { default: fetch } = require('node-fetch'); +const { typeSlug } = require('@eik/common-utils'); const PUBLISH_SUCCESS = - "Publish: ✅ Successfully published package %s (v%s) to %s."; + 'Publish: ✅ Successfully published package %s (v%s) to %s.'; const PUBLISH_FAILURE = - "Publish: ❌ Unable to locate package %s (v%s) at %s. Received HTTP status code %s."; + 'Publish: ❌ Unable to locate package %s (v%s) at %s. Received HTTP status code %s.'; /** * Semantic Release "success" hook @@ -17,22 +17,22 @@ const PUBLISH_FAILURE = * @param {object} state */ module.exports = async function success(options, context, state) { - if (!state.publishNeeded) return; - const { logger } = context; - const { server, name, type } = state.eikJSON; - const slug = typeSlug(type); - const url = new URL(join(slug, name, state.versionToPublish), server); - url.searchParams.set("ts", `${Date.now()}`); - const result = await fetch(url); - if (result.ok) { - logger.log(PUBLISH_SUCCESS, name, state.versionToPublish, url.href); - } else { - logger.log( - PUBLISH_FAILURE, - name, - state.versionToPublish, - url.href, - result.status - ); - } + if (!state.publishNeeded) return; + const { logger } = context; + const { server, name, type } = state.eikJSON; + const slug = typeSlug(type); + const url = new URL(join(slug, name, state.versionToPublish), server); + url.searchParams.set('ts', `${Date.now()}`); + const result = await fetch(url); + if (result.ok) { + logger.log(PUBLISH_SUCCESS, name, state.versionToPublish, url.href); + } else { + logger.log( + PUBLISH_FAILURE, + name, + state.versionToPublish, + url.href, + result.status, + ); + } }; diff --git a/lib/verify-conditions.js b/lib/verify-conditions.js index 8b014f3..ce42c2b 100644 --- a/lib/verify-conditions.js +++ b/lib/verify-conditions.js @@ -1,12 +1,12 @@ -const AggregateError = require("aggregate-error"); -const eik = require("@eik/cli"); -const { configStore } = require("@eik/common-config-loader"); +const AggregateError = require('aggregate-error'); +const eik = require('@eik/cli'); +const { configStore } = require('@eik/common-config-loader'); -const E_TOKEN_MISSING = "Verify: ❌ EIK_TOKEN environment variable not found"; +const E_TOKEN_MISSING = 'Verify: ❌ EIK_TOKEN environment variable not found'; const E_LEVEL_INVALID = - 'Verify: ❌ Plugin option "level" must be one of "major", "minor" or "patch", "%s" given.'; -const E_LOGIN_FAIL = "Verify: ❌ Unable to log in to Eik server"; -const LEVELS = ["major", "minor", "patch"]; + 'Verify: ❌ Plugin option "level" must be one of "major", "minor" or "patch", "%s" given.'; +const E_LOGIN_FAIL = 'Verify: ❌ Unable to log in to Eik server'; +const LEVELS = ['major', 'minor', 'patch']; /** * Semantic Release "verify conditions" hook @@ -18,32 +18,32 @@ const LEVELS = ["major", "minor", "patch"]; * @param {object} state */ module.exports = async function verifyConditions(options, context, state) { - const errors = []; + const errors = []; - // verify EIK_TOKEN present in the environment - if (!context.env.EIK_TOKEN) errors.push(new Error(E_TOKEN_MISSING)); + // verify EIK_TOKEN present in the environment + if (!context.env.EIK_TOKEN) errors.push(new Error(E_TOKEN_MISSING)); - // verify options.level is one of "major", "minor" or "patch" if set - if (!LEVELS.includes(options.level || "patch")) { - errors.push(new Error(E_LEVEL_INVALID.replace("%s", options.level))); - } + // verify options.level is one of "major", "minor" or "patch" if set + if (!LEVELS.includes(options.level || 'patch')) { + errors.push(new Error(E_LEVEL_INVALID.replace('%s', options.level))); + } - // verify existance of and validity of eik.json file AND read contents - try { - state.eikJSON = configStore.findInDirectory(context.cwd); - } catch (err) { - errors.push(err); - } + // verify existance of and validity of eik.json file AND read contents + try { + state.eikJSON = configStore.findInDirectory(context.cwd); + } catch (err) { + errors.push(err); + } - // login to Eik server and save resulting token in state for later hooks - state.eikToken = await eik.login({ - server: state.eikJSON.server, - key: context.env.EIK_TOKEN, - }); - // verify login succeeded - if (!state.eikToken) errors.push(new Error(E_LOGIN_FAIL)); + // login to Eik server and save resulting token in state for later hooks + state.eikToken = await eik.login({ + server: state.eikJSON.server, + key: context.env.EIK_TOKEN, + }); + // verify login succeeded + if (!state.eikToken) errors.push(new Error(E_LOGIN_FAIL)); - if (errors.length > 0) { - throw new AggregateError(errors); - } + if (errors.length > 0) { + throw new AggregateError(errors); + } }; diff --git a/lib/verify-release.js b/lib/verify-release.js index ef34b15..df8642a 100644 --- a/lib/verify-release.js +++ b/lib/verify-release.js @@ -1,8 +1,8 @@ -const eik = require("@eik/cli"); +const eik = require('@eik/cli'); const E_NO_FILES = `Verify: ❌ No files detected for upload. Did you run bundling first (if needed)? Is the "files" field of eik.json correct?`; -const E_VERIFY_FAIL = "Verify: ❌ Verification checks failed to complete"; -const FOUND_FILES = "Verify: ✅ Found %d file(s) to publish"; +const E_VERIFY_FAIL = 'Verify: ❌ Verification checks failed to complete'; +const FOUND_FILES = 'Verify: ✅ Found %d file(s) to publish'; /** * Semantic Release "verify release" hook @@ -14,30 +14,30 @@ const FOUND_FILES = "Verify: ✅ Found %d file(s) to publish"; * @param {object} state */ module.exports = async function verifyRelease(options, context, state) { - if (!state.publishNeeded) return; + if (!state.publishNeeded) return; - try { - const result = await eik.publish({ - name: state.eikJSON.name, - type: state.eikJSON.type, - server: state.eikJSON.server, - files: state.eikJSON.files, - cwd: context.cwd, - token: state.eikToken, - dryRun: true, - version: state.versionToPublish, - map: state.eikJSON.map, - out: state.eikJSON.out, - }); + try { + const result = await eik.publish({ + name: state.eikJSON.name, + type: state.eikJSON.type, + server: state.eikJSON.server, + files: state.eikJSON.files, + cwd: context.cwd, + token: state.eikToken, + dryRun: true, + version: state.versionToPublish, + map: state.eikJSON.map, + out: state.eikJSON.out, + }); - const filesToBePublished = result.files.filter( - (file) => file.type === "package file" - ); - if (!filesToBePublished.length) throw new Error(E_NO_FILES); + const filesToBePublished = result.files.filter( + (file) => file.type === 'package file', + ); + if (!filesToBePublished.length) throw new Error(E_NO_FILES); - context.logger.log(FOUND_FILES, filesToBePublished.length); - } catch (err) { - context.logger.log(E_VERIFY_FAIL); - throw err; - } + context.logger.log(FOUND_FILES, filesToBePublished.length); + } catch (err) { + context.logger.log(E_VERIFY_FAIL); + throw err; + } }; diff --git a/package.json b/package.json index 851f294..9155909 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,10 @@ "version": "1.0.7", "description": "Semantic release plugin for Eik", "main": "lib/main.js", + "type": "module", "scripts": { + "lint": "eslint .", + "lint:fix": "eslint . --fix", "test": "tap --disable-coverage --allow-empty-coverage" }, "publishConfig": { @@ -13,16 +16,20 @@ "author": "", "license": "MIT", "dependencies": { - "@eik/cli": "^2.0.35", - "@eik/common-config-loader": "^4.0.0-next.12", - "@eik/common-utils": "^4.0.0-next.12", - "aggregate-error": "3.1.0", - "node-fetch": "^2.6.1" + "@eik/cli": "2.0.39", + "@eik/common-config-loader": "4.0.0-next.12", + "@eik/common-utils": "4.0.0-next.12", + "aggregate-error": "5.0.0" }, "devDependencies": { "@semantic-release/changelog": "6.0.3", "@semantic-release/git": "10.0.1", + "eslint": "9.8.0", + "eslint-config-prettier": "9.1.0", + "eslint-plugin-prettier": "5.2.1", + "globals": "15.8.0", "semantic-release": "24.0.0", - "tap": "20.0.3" + "prettier": "3.3.3", + "tap": "21.0.0" } } diff --git a/release.config.js b/release.config.js index 7880574..2e85148 100644 --- a/release.config.js +++ b/release.config.js @@ -1,27 +1,27 @@ -module.exports = { - plugins: [ - "@semantic-release/commit-analyzer", - "@semantic-release/release-notes-generator", - "@semantic-release/changelog", - [ - "@semantic-release/npm", - { - tarballDir: "release", - }, +export default { + plugins: [ + '@semantic-release/commit-analyzer', + '@semantic-release/release-notes-generator', + '@semantic-release/changelog', + [ + '@semantic-release/npm', + { + tarballDir: 'release', + }, + ], + [ + '@semantic-release/github', + { + assets: 'release/*.tgz', + }, + ], + '@semantic-release/git', ], - [ - "@semantic-release/github", - { - assets: "release/*.tgz", - }, + preset: 'angular', + branches: [ + { name: 'main' }, + { name: 'alpha', prerelease: true }, + { name: 'beta', prerelease: true }, + { name: 'next', prerelease: true }, ], - "@semantic-release/git", - ], - preset: "angular", - branches: [ - { name: "main" }, - { name: "alpha", prerelease: true }, - { name: "beta", prerelease: true }, - { name: "next", prerelease: true }, - ], };