Skip to content

Replace

Terminal window
npm i -D @unirelman/plugin-replace
unirelman.config.ts
import { createReplacePlugin } from "@unirelman/plugin-replace";
createReplacePlugin({
files: [
{
path: "README.md",
scope: "my-package",
search: ({ currentVersion }) => new RegExp(RegExp.escape(`my-package@${currentVersion}`)),
replace: ({ nextVersion }) => `my-package@${nextVersion}`,
},
],
});
Option Type Default Description
files ReplaceFile[] Required Replacements to apply. See Files.
Phase Behavior
generateFileOperations Writes each listed file with its replacements applied, for the scopes with a next version.
Member Type Default Description
path string Required Path of the file, relative to the project root.
scope string Required Scope whose versions the entry uses.
search RegExp | (input) => RegExp Required Text to replace. Every match is replaced.
replace (input) => string Required Replacement, inserted as is.
allowNoMatch boolean false Whether an entry without a match is skipped instead of throwing.

input is { scopeName, currentVersion, nextVersion }, with currentVersion undefined when no plugin provides the current version. An entry applies when its scope gets a next version; the entries of a file apply in order.

Error Cause
ReplaceUnknownScopeError An entry names a scope the plugin is not registered for.
ReplaceNoMatchError A file has no match for the search of an entry, without allowNoMatch.
CoreFileNotFoundError A listed file is missing.
CoreConflictingFileOperationError Another plugin writes a listed file in the same release.