Files
semantic-release/lib/plugins/utils.js
T
Olabode Lawal-Shittabey db8ffaad90 fix(revert): next (#4200)
* Revert "docs: update README to include information about the new core engine integration"

This reverts commit 4e476dee14.

* Revert "fix(code-quality): add missing comma in context object for consistency"

This reverts commit 493d6cdaa1.

* Revert "refactor: replace direct logger and env-ci replacements with a mockCore function for better test organization"

This reverts commit d05e160668.

* Revert "test: add tests for core delegation and dry-run policy handling"

This reverts commit 4f464a72ae.

* Revert "refactor: integrate `core`; remove unused imports and restructuring the main export function"

This reverts commit 3f5d1b785b.

* Revert "refactor: remove obsolete release type constants and notes separator"

This reverts commit 7d71f2eb14.

* Revert "refactor: remove obsolete test files for logger, git, sensitive data handling, and utility functions"

This reverts commit 1ae1a19cdf.

* Revert "refactor: remove obsolete Git-related utilities and logging functions"

This reverts commit bedddc4091.

* Revert "refactor(tests): remove obsolete tests for plugins and verification"

This reverts commit 7172195d12.

* Revert "refactor: remove obsolete branch, error, and plugin definitions"

This reverts commit 51d1f5f9b2.

* Merge branch 'master' of https://github.com/semantic-release/semantic-release into fix(revert)/next

* Revert "Merge branch 'master' of https://github.com/semantic-release/semantic-release into fix(revert)/next"

This reverts commit bbfdc36be6.
2026-06-09 16:08:49 -07:00

82 lines
2.1 KiB
JavaScript

import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { castArray, isArray, isFunction, isNil, isPlainObject, isString } from "lodash-es";
import resolveFrom from "resolve-from";
const __dirname = dirname(fileURLToPath(import.meta.url));
const validateSteps = (conf) => {
return conf.every((conf) => {
if (
isArray(conf) &&
(conf.length === 1 || conf.length === 2) &&
(isString(conf[0]) || isFunction(conf[0])) &&
(isNil(conf[1]) || isPlainObject(conf[1]))
) {
return true;
}
conf = castArray(conf);
if (conf.length !== 1) {
return false;
}
const [name, config] = parseConfig(conf[0]);
return (isString(name) || isFunction(name)) && isPlainObject(config);
});
};
export function validatePlugin(conf) {
return (
isString(conf) ||
(isArray(conf) &&
(conf.length === 1 || conf.length === 2) &&
(isString(conf[0]) || isPlainObject(conf[0])) &&
(isNil(conf[1]) || isPlainObject(conf[1]))) ||
(isPlainObject(conf) && (isNil(conf.path) || isString(conf.path) || isPlainObject(conf.path)))
);
}
export function validateStep({ required }, conf) {
conf = castArray(conf).filter(Boolean);
if (required) {
return conf.length >= 1 && validateSteps(conf);
}
return conf.length === 0 || validateSteps(conf);
}
export async function loadPlugin({ cwd }, name, pluginsPath) {
const basePath = pluginsPath[name]
? dirname(resolveFrom.silent(__dirname, pluginsPath[name]) || resolveFrom(cwd, pluginsPath[name]))
: __dirname;
if (isFunction(name)) {
return name;
}
const file = resolveFrom.silent(basePath, name) || resolveFrom(cwd, name);
const { default: cjsExport, ...esmNamedExports } = await import(`file://${file}`);
if (cjsExport) {
return cjsExport;
}
return esmNamedExports;
}
export function parseConfig(plugin) {
let path;
let config;
if (isArray(plugin)) {
[path, config] = plugin;
} else if (isPlainObject(plugin) && !isNil(plugin.path)) {
({ path, ...config } = plugin);
} else {
path = plugin;
}
return [path, config || {}];
}