version_bump/plugins/npm
The npm publish plugin (plugin name “npm”).
Mirrors @semantic-release/npm. It manages a package.json and the npm
registry across three hooks:
- verify_conditions: there must be a
package.jsonincontext.cwdand anNPM_TOKENavailable (checked incontext.env, then the process env). - prepare: rewrite the
"version"field ofpackage.jsonto the next release version, preserving the rest of the file verbatim. - publish: run
npm publishincontext.cwd, returning aRelease.
The only PURE function is set_version, which performs the package.json
version rewrite as a string transformation so it can be unit-tested without
any IO. It is exported for that reason.
Values
pub fn plugin() -> plugin.Plugin
Build the npm plugin: implements verify_conditions, prepare, and
publish.
pub fn set_version(
package_json: String,
version: String,
) -> Result(String, error.ReleaseError)
Replace the top-level "version" field in a package.json document with
version, leaving the rest of the document byte-for-byte intact.
PURE: a string transformation, no IO. Returns a PluginError when no
"version" field is present so callers can surface a clear message rather
than silently producing a package.json without a version.
The match targets the first "version": "..." pair, which in a well-formed
package.json is the top-level package version. Only the quoted value is
rewritten; surrounding whitespace and formatting are preserved.