Files
Olabode Lawal-Shittabey 1beed123fa feat: integrate @semantic-release/core engine (#4256)
This pull request refactors the core logic of the package to use the
`@semantic-release/core` engine directly, removes legacy and duplicated
code, and centralizes configuration. The changes simplify the codebase
by delegating most of the release logic to the upstream core package,
making the CLI wrapper thinner and easier to maintain. Several internal
utility files for branch and tag handling are also removed, as their
logic is now handled by `@semantic-release/core`.

### Migration to Core Engine

* The CLI now delegates release logic to `@semantic-release/core`, using
its `resolveConfig`, `getLogger`, and other helpers, instead of
maintaining a custom implementation. This reduces maintenance overhead
and ensures alignment with the core release logic.
* The documentation is updated to explain that `semantic-release` uses
`@semantic-release/core` as its engine, and provides guidance for
advanced use cases.

### Configuration and Defaults

* A new `SEMANTIC_RELEASE_DEFAULT_CONFIG` constant is introduced,
centralizing the default plugin stack for releases.

### Codebase Simplification

* Removes internal implementations for branch expansion, tag retrieval,
and normalization, as well as related validation and error handling
logic. These are now handled by the core engine.
2026-10-06 06:42:49 +01:00

61 lines
2.0 KiB
JavaScript

import semanticReleaseCore, { resolveConfig, getLogger, resolveEnvCi } from "@semantic-release/core";
import * as marked from "marked";
import { SEMANTIC_RELEASE_DEFAULT_CONFIG } from "./lib/definitions/constants.js";
import pkg from "./package.json" with { type: "json" };
let markedOptionsSet = false;
async function terminalOutput(text) {
if (!markedOptionsSet) {
const { default: TerminalRenderer } = await import("marked-terminal"); // eslint-disable-line node/no-unsupported-features/es-syntax
marked.setOptions({ renderer: new TerminalRenderer() });
markedOptionsSet = true;
}
return marked.parse(text);
}
export default async (
cliOptions = {},
{ cwd = process.cwd(), env = process.env, stdout = process.stdout, stderr = process.stderr } = {}
) => {
const envCiResult = resolveEnvCi({ env, cwd });
const { isCi, branch, prBranch, isPr } = envCiResult;
const ciBranch = isPr ? prBranch : branch;
const noCi = Boolean(cliOptions.noCi || cliOptions.ci === false);
const shouldAutoDryRun = !isCi && !cliOptions.dryRun && !noCi;
const effectiveCliOptions = shouldAutoDryRun ? { ...cliOptions, dryRun: true } : cliOptions;
const shouldSkipRelease = isCi && isPr && !noCi;
const context = {
cwd,
env,
stdout,
stderr,
envCi: envCiResult,
};
context.logger = getLogger(context);
context.logger.log(`Running ${pkg.name} version ${pkg.version}`);
if (shouldAutoDryRun) {
context.logger.warn("This run was not triggered in a known CI environment, running in dry-run mode.");
}
if (shouldSkipRelease) {
context.logger.log("This run was triggered by a pull request and therefore a new version won't be published.");
return false;
}
const { options: resolvedOptions, plugins } = await resolveConfig(context, effectiveCliOptions, {
baseConfig: SEMANTIC_RELEASE_DEFAULT_CONFIG,
buildPlugins: true,
});
context.options = resolvedOptions;
const result = await semanticReleaseCore({ context, plugins, formatOutput: terminalOutput });
return result;
};