Replace
npm i -D @unirelman/plugin-replacepnpm add -D @unirelman/plugin-replaceyarn add -D @unirelman/plugin-replacebun add -d @unirelman/plugin-replaceimport { 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}`, }, ],});Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
files |
ReplaceFile[] |
Required | Replacements to apply. See Files. |
Phases
Section titled “Phases”| 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.
Errors
Section titled “Errors”| 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. |