Skip to content

Commit

Permalink
fix: update dependencies
Browse files Browse the repository at this point in the history
BREAKING CHANGE: drops node-fetch for the built-in fetch,
which means Node 18 or newer is required.
  • Loading branch information
wkillerud committed Jul 29, 2024
1 parent 68debd3 commit 4af25ea
Show file tree
Hide file tree
Showing 14 changed files with 272 additions and 222 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
package-lock=false
save-exact=true
13 changes: 13 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"singleQuote": true,
"trailingComma": "all",
"tabWidth": 4,
"overrides": [
{
"files": ["*.json", "*.yml"],
"options": {
"tabWidth": 2
}
}
]
}
22 changes: 22 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -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/*'],
},
];
102 changes: 51 additions & 51 deletions lib/analyze-commits.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
};
22 changes: 11 additions & 11 deletions lib/generate-notes.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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})`;
};
36 changes: 18 additions & 18 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -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),
};
20 changes: 10 additions & 10 deletions lib/prepare.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 },
);
}
};
52 changes: 29 additions & 23 deletions lib/publish.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
};
46 changes: 23 additions & 23 deletions lib/success.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
);
}
};
Loading

0 comments on commit 4af25ea

Please sign in to comment.