Skip to content

Core SDK Reference

@pubm/core is the programmatic API for the pubm CLI. This page lists the public exports from the package root:

import { ... } from "@pubm/core";

The package includes type declarations and both ESM/CJS entry points. Package metadata currently requires node >= 24.

Terminal window
npm install @pubm/core
pnpm add @pubm/core
bun add @pubm/core

Runs the same release pipeline that powers the CLI.

import { pubm } from "@pubm/core";
await pubm({
version: "patch",
dryRun: true,
tag: "next",
});

pubm() accepts an Options object. The key fields are:

FieldTypePurpose
versionstringRequired release target such as patch, minor, major, or an explicit semver.
dryRunbooleanShow the task plan without mutating Git state or publishing.
mode"local" | "ci"Execution mode: local (interactive) or ci (non-interactive, tag-based).
preparebooleanRun the preparation phase only (validate and dry-run publish checks).
publishbooleanRun the publish phase only (publish from the latest tag).
releaseDraftbooleanCreate a draft GitHub Release instead of a published one.
branchstringRequire a specific branch before publishing.
anyBranchbooleanDisable branch enforcement for one run.
tagstringPublish under a dist-tag like latest, next, or beta.
packagesPackageConfig[]Override auto-discovered packages.

For config-driven releases, pubm() loads pubm.config.*, resolves package discovery, and wires plugins before it runs the task graph.

Use these helpers to read or validate pubm.config.*.

ExportKindPurpose
defineConfigfunctionTyped helper for authoring pubm.config.ts.
loadConfigfunctionLoad pubm.config.* from disk and return PubmConfig | null.
resolveConfigfunctionApply defaults, auto-discover packages, and normalize private registries.
PubmConfigtypeUser-authored config shape.
ResolvedPubmConfigtypeFully-resolved config returned by resolveConfig().
PackageConfigtypePer-package config entry used by discovery and publish planning.
import { defineConfig, loadConfig, resolveConfig } from "@pubm/core";
export default defineConfig({
packages: [{ path: "packages/core" }],
});
const config = await loadConfig(process.cwd());
const resolved = config ? await resolveConfig(config, process.cwd()) : null;

Use PackageConfig to override per-package registries, ecosystem, build command, or test command:

type PackageConfig = {
path: string;
registries?: Array<"npm" | "jsr" | "crates" | string | PrivateRegistryConfig>;
ecosystem?: "js" | "rust";
buildCommand?: string;
testCommand?: string;
};

Use the plugin exports to extend the publish pipeline with custom registries, ecosystems, lifecycle hooks, or CLI commands.

ExportKindPurpose
PubmPlugintypeTop-level plugin contract.
PluginHookstypeLifecycle hooks such as beforeBuild, afterPublish, onError, afterRelease, and asset pipeline hooks.
HookFn / ErrorHookFn / AfterReleaseHookFntypeHook signatures.
PluginCommand / PluginSubcommand / PluginCommandOptiontypeCustom CLI command model for plugins.
PluginRunnerclassUtility that executes hooks and collects registries/ecosystems from loaded plugins. Also exposes collectCredentials() and collectChecks() to gather credential descriptors and preflight checks from all registered plugins.
PluginCredentialtypeDeclarative descriptor for a token or secret required by a plugin. See Plugins API Reference.
PluginChecktypeDescriptor for a preflight check contributed by a plugin. See Plugins API Reference.
PluginTaskContexttypeListr2-agnostic wrapper passed to PluginCheck.task. Exposes output, title, and prompt().
GhSecretEntrytypeOne entry returned by the GitHub Secrets sync helpers: { secretName: string; token: string }.
collectPluginCredentialsfunctionGather PluginCredential[] from all plugins registered in the config and resolve their values.
injectPluginTokensToEnvfunctionWrite resolved plugin token values into process.env so subsequent publish steps can read them as plain env vars.
ReleaseContexttypeRelease metadata passed to afterRelease hooks. Includes packageName, version, tag, releaseUrl, and assets.
ReleaseAssettypeOne uploaded asset: name, url, sha256, and structured platform.
ParsedPlatformtypeStructured platform info: raw, os, arch, vendor, abi, variant.
PreparedAssettypeAsset after compression and hashing, ready for upload.
TransformedAssettypeAsset after transformAsset hook, before compression.
CompressedAssettypeAsset after compressAsset step, before naming.
UploadedAssettypeAsset after upload with url and target.
ResolvedAssettypeAsset after glob matching with parsed platform info.
import { defineConfig, type PubmPlugin } from "@pubm/core";
const plugin: PubmPlugin = {
name: "announce",
hooks: {
afterPublish(ctx) {
console.log("published", ctx.version);
},
},
};
export default defineConfig({
plugins: [plugin],
});

These exports support the release asset pipeline and are useful for plugin authors and custom tooling.

ExportKindPurpose
parsePlatformfunctionParse OS, arch, ABI, variant, and vendor from a path segment string using the built-in tables.
runAssetPipelinefunctionRun the full asset pipeline (resolve, transform, compress, name, hash, checksums) given a resolved config and hook set.
import { parsePlatform, runAssetPipeline } from "@pubm/core";
// Parse a path segment or capture string
const platform = parsePlatform("darwin-arm64");
// { raw: "darwin-arm64", os: "darwin", arch: "arm64" }
const platform2 = parsePlatform("x86_64-unknown-linux-gnu");
// { raw: "x86_64-unknown-linux-gnu", os: "linux", arch: "x64", vendor: "unknown", abi: "gnu" }

Asset pipeline types:

import type {
ParsedPlatform,
ReleaseContext,
ReleaseAsset,
ResolvedAsset,
TransformedAsset,
CompressedAsset,
PreparedAsset,
UploadedAsset,
} from "@pubm/core";

See Release Assets and Asset Pipeline Hooks for usage guides.

These exports help you build custom tooling around .pubm/changesets.

ExportKindPurpose
readChangesets / parseChangesetfunctionsRead and parse .pubm/changesets/*.md.
getStatusfunctionAggregate pending changesets by package.
discoverCurrentVersions / discoverPackageInfosfunctionsRead current package names and versions from the workspace.
calculateVersionBumpsfunctionCompute next versions from current versions plus pending changesets.
generateChangesetId / generateChangesetContent / writeChangesetfunctionsCreate new changeset files.
buildChangelogEntries / generateChangelog / writeChangelogToFilefunctionsBuild changelog output from changesets.
migrateFromChangesetsfunctionCopy legacy .changeset/ data into .pubm/.
deleteChangesetFilesfunctionRemove consumed changeset files.
parseChangelogSectionfunctionParse a changelog section back into structured data.

Important related types:

TypePurpose
ChangesetParsed .md file with id, summary, and package releases.
ReleaseOne package bump entry inside a changeset.
BumpType"patch" | "minor" | "major".
Status / PackageStatusAggregated pending state from getStatus().
VersionBumpVersion planning result from calculateVersionBumps().
ChangelogEntry / DependencyUpdateChangelog rendering inputs.
PackageVersionInfoPackage name, version, and path returned by discovery helpers.
MigrationResultResult object returned by migrateFromChangesets().
import {
calculateVersionBumps,
discoverCurrentVersions,
getStatus,
} from "@pubm/core";
const currentVersions = await discoverCurrentVersions(process.cwd());
const status = getStatus(process.cwd());
const nextVersions = calculateVersionBumps(currentVersions, process.cwd());

These exports are useful when you need the same workspace discovery logic that pubm uses internally.

ExportKindPurpose
detectWorkspacefunctionDetect pnpm, npm, Yarn, Bun, Cargo, or Deno workspaces from repository files.
discoverPackagesfunctionAuto-discover publishable packages and infer registries/ecosystems.
buildDependencyGraphfunctionBuild an internal dependency graph from package metadata.
topologicalSortfunctionSort graph nodes so dependencies come first.
resolveGroupsfunctionResolve fixed/linked groups against a discovered package list.
applyFixedGroup / applyLinkedGroupfunctionsApply group semantics to version planning.
GitclassThin wrapper around Git commands used by release automation.

Important related types:

TypePurpose
WorkspaceInfoWorkspace type plus include/exclude patterns.
DiscoverOptionsInput for discoverPackages().
DiscoveredPackageAuto-detected package path, registries, and ecosystem.
PackageNodeInput node used for dependency graph building.
import {
buildDependencyGraph,
discoverPackages,
topologicalSort,
} from "@pubm/core";
const discovered = await discoverPackages({ cwd: process.cwd() });
const graph = buildDependencyGraph([
{
name: "@acme/core",
version: "1.0.0",
path: "packages/core",
dependencies: { "@acme/utils": "^1.0.0" },
},
{
name: "@acme/utils",
version: "1.0.0",
path: "packages/utils",
dependencies: {},
},
]);
const ordered = topologicalSort(graph);

The package root also exports these helpers for tooling integrations.

ExportKindPurpose
validateEntryPointsfunctionCheck main, module, types, exports, and bin paths in a package manifest.
detectExtraneousFilesfunctionFlag files that should usually stay out of publish artifacts.
getPackageJsonfunctionRead the nearest package.json, with optional jsr.json fallback.
replaceVersion / replaceVersionAtPathfunctionsRewrite package versions in manifests.
versionfunctionRead the current package version from package.json, jsr.json, or deno.json / deno.jsonc.
generateSnapshotVersionfunctionBuild snapshot versions from base, tag, timestamp, and optional commit.
loadTokensFromDbfunctionLoad stored registry tokens, also honoring matching env vars.
syncGhSecretsfunctionPush registry tokens into GitHub Secrets via gh secret set.
execfunctionSpawn a subprocess and capture stdout/stderr.
getPackageManagerfunctionDetect the workspace package manager from lockfiles.
detectRuntime / isBunfunctionsDetect the current runtime.
notifyNewVersionfunctionCheck for a newer published pubm version and print an update banner.
consoleErrorfunctionFormat and print pubm errors.
PUBM_VERSION / PUBM_ENGINESconstantsPackage metadata exposed at runtime.

Important related types:

TypePurpose
EntryPointErrorValidation result entry for broken manifest paths.
ExtraneousFileValidation result entry for files that should not be published.
SnapshotOptionsInput for generateSnapshotVersion().
Runtime"node" | "bun".
import {
generateSnapshotVersion,
loadTokensFromDb,
validateEntryPoints,
} from "@pubm/core";
const nextSnapshot = generateSnapshotVersion({
baseVersion: "1.4.0",
tag: "snapshot",
commit: "abc1234",
template: "{base}-{tag}-{timestamp}-{commit}",
});
const entryPointErrors = validateEntryPoints(
{
main: "./dist/index.js",
types: "./dist/index.d.ts",
},
process.cwd(),
);
const tokens = loadTokensFromDb(["npm", "jsr"]);

This page documents the stable surface exported from the package root. Internal files under packages/core/src/** may exist, but if they are not re-exported from @pubm/core, they should be treated as private implementation details.