1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright 2026 Mahmoud Harmouch.
//
// Licensed under the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! # Node.js Bindings
//!
//! Exposes `bump2version` to Node.js via [napi-rs](https://napi.rs).
//! All functions are **synchronous**: no Promise boilerplate required.
//!
//! ## Installation
//!
//! ```sh
//! npm install bump2version
//! ```
//!
//! Or build locally:
//!
//! ```sh
//! npm install -g @napi-rs/cli
//! napi build --platform --release --features node
//! ```
//!
//! ## Usage
//!
//! ```javascript
//! const { bumpVersion, applyFileChange } = require('bump2version');
//!
//! // Compute a new version
//! const next = bumpVersion('1.2.3', 'patch');
//! console.log(next); // '1.2.4'
//!
//! // Update a file's content in-memory
//! const updated = applyFileChange('version = 1.0.0\n', '1.0.0', '1.0.1');
//! console.log(updated); // 'version = 1.0.1\n'
//! ```
//!
//! ## See Also
//!
//! - [`crate::version::bump_version`]
//! - [napi-rs documentation](https://napi.rs/)
use crate;
use crateapply_file_change;
use crate;
use napi;
/// Bumps a version string by the specified component.
///
/// ``currentVersion``: The current version string (e.g. ``"1.2.3"``).
/// ``part``: The component to increment (``"major"``, ``"minor"``,
/// or ``"patch"``).
/// ``configPath``: Optional path to a ``.bumpversion.toml`` file.
///
/// Returns the new version string, or throws an ``Error`` on failure.
///
/// ```javascript
/// const { bumpVersion } = require('.');
/// console.log(bumpVersion('1.2.3', 'patch')); // '1.2.4'
/// console.log(bumpVersion('1.2.3', 'minor')); // '1.3.0'
/// console.log(bumpVersion('1.2.3', 'major')); // '2.0.0'
/// ```
/// Applies search-and-replace to a file's text content and returns the
/// updated string.
///
/// ``content``: The full text content of the file.
/// ``currentVersion``: The version string to search for.
/// ``newVersion``: The version string to insert.
/// ``search``: Optional search pattern template (default:
/// ``"{current_version}"``).
/// ``replace``: Optional replace pattern template (default:
/// ``"{new_version}"``).
/// ``ignoreMissing``: When ``true``, return ``content`` unchanged instead of
/// throwing if the pattern is not found.
///
/// Returns the updated content string, or throws an ``Error`` when the
/// pattern is not found (and ``ignoreMissing`` is ``false``).
///
/// ```javascript
/// const { applyFileChange } = require('.');
/// const updated = applyFileChange('version = 1.0.0\n', '1.0.0', '1.0.1');
/// console.log(updated); // 'version = 1.0.1\n'
/// ```
// Copyright 2026 Mahmoud Harmouch.
//
// Licensed under the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.