Files
semantic-release/lib/plugins/index.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

104 lines
3.4 KiB
JavaScript

import { castArray, identity, isNil, isPlainObject, isString, omit } from "lodash-es";
import AggregateError from "aggregate-error";
import getError from "../get-error.js";
import PLUGINS_DEFINITIONS from "../definitions/plugins.js";
import { loadPlugin, parseConfig, validatePlugin, validateStep } from "./utils.js";
import pipeline from "./pipeline.js";
import normalize from "./normalize.js";
export default async (context, pluginsPath) => {
let { options, logger } = context;
const errors = [];
const plugins = options.plugins
? await castArray(options.plugins).reduce(async (eventualPluginsList, plugin) => {
const pluginsList = await eventualPluginsList;
if (validatePlugin(plugin)) {
const [name, config] = parseConfig(plugin);
plugin = isString(name) ? await loadPlugin(context, name, pluginsPath) : name;
if (isPlainObject(plugin)) {
Object.entries(plugin).forEach(([type, func]) => {
if (PLUGINS_DEFINITIONS[type]) {
Reflect.defineProperty(func, "pluginName", {
value: isPlainObject(name) ? "Inline plugin" : name,
writable: false,
enumerable: true,
});
pluginsList[type] = [...(pluginsList[type] || []), [func, config]];
}
});
} else {
errors.push(getError("EPLUGINSCONF", { plugin }));
}
} else {
errors.push(getError("EPLUGINSCONF", { plugin }));
}
return pluginsList;
}, {})
: [];
if (errors.length > 0) {
throw new AggregateError(errors);
}
options = { ...plugins, ...options };
const pluginsConfig = await Object.entries(PLUGINS_DEFINITIONS).reduce(
async (
eventualPluginsConfigAccumulator,
[type, { required, default: def, pipelineConfig, postprocess = identity, preprocess = identity }]
) => {
let pluginOptions;
const pluginsConfigAccumulator = await eventualPluginsConfigAccumulator;
if (isNil(options[type]) && def) {
pluginOptions = def;
} else {
// If an object is passed and the path is missing, merge it with step options
if (isPlainObject(options[type]) && !options[type].path) {
options[type] = castArray(plugins[type]).map((plugin) =>
plugin ? [plugin[0], Object.assign(plugin[1], options[type])] : plugin
);
}
if (!validateStep({ required }, options[type])) {
errors.push(getError("EPLUGINCONF", { type, required, pluginConf: options[type] }));
return pluginsConfigAccumulator;
}
pluginOptions = options[type];
}
const steps = await Promise.all(
castArray(pluginOptions).map(async (pluginOpt) =>
normalize(
{ ...context, options: omit(options, Object.keys(PLUGINS_DEFINITIONS), "plugins") },
type,
pluginOpt,
pluginsPath
)
)
);
pluginsConfigAccumulator[type] = async (input) =>
postprocess(
await pipeline(
steps,
pipelineConfig && pipelineConfig(pluginsConfigAccumulator, logger)
)(await preprocess(input)),
input
);
return pluginsConfigAccumulator;
},
plugins
);
if (errors.length > 0) {
throw new AggregateError(errors);
}
return pluginsConfig;
};