mirror of
https://github.com/semantic-release/semantic-release.git
synced 2026-10-26 07:59:35 +00:00
db8ffaad90
* Revert "docs: update README to include information about the new core engine integration" This reverts commit4e476dee14. * Revert "fix(code-quality): add missing comma in context object for consistency" This reverts commit493d6cdaa1. * Revert "refactor: replace direct logger and env-ci replacements with a mockCore function for better test organization" This reverts commitd05e160668. * Revert "test: add tests for core delegation and dry-run policy handling" This reverts commit4f464a72ae. * Revert "refactor: integrate `core`; remove unused imports and restructuring the main export function" This reverts commit3f5d1b785b. * Revert "refactor: remove obsolete release type constants and notes separator" This reverts commit7d71f2eb14. * Revert "refactor: remove obsolete test files for logger, git, sensitive data handling, and utility functions" This reverts commit1ae1a19cdf. * Revert "refactor: remove obsolete Git-related utilities and logging functions" This reverts commitbedddc4091. * Revert "refactor(tests): remove obsolete tests for plugins and verification" This reverts commit7172195d12. * Revert "refactor: remove obsolete branch, error, and plugin definitions" This reverts commit51d1f5f9b2. * 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 commitbbfdc36be6.
70 lines
2.5 KiB
JavaScript
70 lines
2.5 KiB
JavaScript
import { cloneDeep, isFunction, isPlainObject, noop, omit } from "lodash-es";
|
|
import debugPlugins from "debug";
|
|
import getError from "../get-error.js";
|
|
import { extractErrors } from "../utils.js";
|
|
import PLUGINS_DEFINITIONS from "../definitions/plugins.js";
|
|
import { loadPlugin, parseConfig } from "./utils.js";
|
|
|
|
const debug = debugPlugins("semantic-release:plugins");
|
|
|
|
export default async (context, type, pluginOpt, pluginsPath) => {
|
|
const { stdout, stderr, options, logger } = context;
|
|
if (!pluginOpt) {
|
|
return noop;
|
|
}
|
|
|
|
const [name, config] = parseConfig(pluginOpt);
|
|
const pluginName = name.pluginName ? name.pluginName : isFunction(name) ? `[Function: ${name.name}]` : name;
|
|
const plugin = await loadPlugin(context, name, pluginsPath);
|
|
|
|
debug(`options for ${pluginName}/${type}: %O`, config);
|
|
|
|
let func;
|
|
if (isFunction(plugin)) {
|
|
func = plugin.bind(null, cloneDeep({ ...options, ...config }));
|
|
} else if (isPlainObject(plugin) && plugin[type] && isFunction(plugin[type])) {
|
|
func = plugin[type].bind(null, cloneDeep({ ...options, ...config }));
|
|
} else {
|
|
throw getError("EPLUGIN", { type, pluginName });
|
|
}
|
|
|
|
const validator = async (input) => {
|
|
const { dryRun, outputValidator } = PLUGINS_DEFINITIONS[type] || {};
|
|
try {
|
|
if (!input.options.dryRun || dryRun) {
|
|
logger.log(`Start step "${type}" of plugin "${pluginName}"`);
|
|
const result = await func({
|
|
...cloneDeep(omit(input, ["stdout", "stderr", "logger"])),
|
|
stdout,
|
|
stderr,
|
|
logger: logger.scope(logger.scopeName, pluginName),
|
|
});
|
|
if (outputValidator && !outputValidator(result)) {
|
|
throw getError(`E${type.toUpperCase()}OUTPUT`, { result, pluginName });
|
|
}
|
|
|
|
logger.success(`Completed step "${type}" of plugin "${pluginName}"`);
|
|
return result;
|
|
}
|
|
|
|
logger.warn(`Skip step "${type}" of plugin "${pluginName}" in dry-run mode`);
|
|
} catch (error) {
|
|
logger.error(`Failed step "${type}" of plugin "${pluginName}"`);
|
|
extractErrors(error).forEach((err) => Object.assign(err, { pluginName }));
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
Reflect.defineProperty(validator, "pluginName", { value: pluginName, writable: false, enumerable: true });
|
|
|
|
if (!isFunction(pluginOpt)) {
|
|
if (pluginsPath[name]) {
|
|
logger.success(`Loaded plugin "${type}" from "${pluginName}" in shareable config "${pluginsPath[name]}"`);
|
|
} else {
|
|
logger.success(`Loaded plugin "${type}" from "${pluginName}"`);
|
|
}
|
|
}
|
|
|
|
return validator;
|
|
};
|