semantic-release-replace-plugin / Replacement
Replacement is similar to the interface used by https://www.npmjs.com/package/replace-in-file
with the difference being the single string for to
and from
.
• Optional
allowEmptyPaths: boolean
• Optional
countMatches: boolean
• Optional
disableGlobs: boolean
• Optional
dry: boolean
• Optional
encoding: string
• files: string
[]
files to search for replacements
The RegExp pattern to use to match.
Uses String.replace(new RegExp(s, 'gm'), to)
for implementation, if
from
is a string.
For advanced matching, i.e. when using a release.config.js
file, consult
the documentation of the replace-in-file
package
(https://github.com/adamreisnz/replace-in-file/blob/main/README.md) on its
from
option. This allows explicit specification of RegExp
s, callback
functions, etc.
Multiple matchers may be provided as an array, following the same conversion rules as mentioned above.
• Optional
ignore: string
[]
• Optional
results: { file
: string
; hasChanged
: boolean
; numMatches?
: number
; numReplacements?
: number
}[]
The results array can be passed to ensure that the expected replacements have been made, and if not, throw and exception with the diff.
The replacement value using a template of variables.
__VERSION__ = "${nextRelease.version}"
The context object is used to render the template. Additional values can be found at: https://semantic-release.gitbook.io/semantic-release/developer-guide/js-api#result
For advanced replacement (NOTE: only for use with release.config.js
file version), pass in a function to replace non-standard variables
{
from: `__VERSION__ = 11`, // eslint-disable-line
to: (matched) => `__VERSION: ${parseInt(matched.split('=')[1].trim()) + 1}`, // eslint-disable-line
},
The args
for a callback function can take a variety of shapes. In its
simplest form, e.g. if from
is a string, it's the filename in which the
replacement is done. If from
is a regular expression the args
of the
callback include captures, the offset of the matched string, the matched
string, etc. See the String.replace
documentation for details
Multiple replacements may be specified as an array. These can be either
strings or callback functions. Note that the amount of replacements needs
to match the amount of from
matchers.