@releasekit/version 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENCE.md +7 -0
- package/README.md +307 -0
- package/dist/baseError-IKMJCSYK.js +6 -0
- package/dist/baseError-ZCZHF6A2.js +7 -0
- package/dist/chunk-6CLV2DJG.js +2166 -0
- package/dist/chunk-7GDPUNML.js +128 -0
- package/dist/chunk-GLFC564Q.js +2174 -0
- package/dist/chunk-GQLJ7JQY.js +18 -0
- package/dist/chunk-KZDV4EBO.js +2170 -0
- package/dist/chunk-WEP3ACTS.js +2125 -0
- package/dist/cli.cjs +2313 -0
- package/dist/cli.d.cts +4 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +105 -0
- package/dist/index.cjs +2228 -0
- package/dist/index.d.cts +209 -0
- package/dist/index.d.ts +209 -0
- package/dist/index.js +30 -0
- package/docs/CI_CD_INTEGRATION.md +197 -0
- package/docs/versioning.md +501 -0
- package/package.json +80 -0
- package/version.schema.json +148 -0
package/LICENCE.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of the Turbo-version and Turbo-release software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
# package-versioner
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
<a href="https://www.npmjs.com/package/package-versioner" alt="NPM Version">
|
|
5
|
+
<img src="https://img.shields.io/npm/v/package-versioner" /></a>
|
|
6
|
+
<a href="https://www.npmjs.com/package/package-versioner" alt="NPM Downloads">
|
|
7
|
+
<img src="https://img.shields.io/npm/dw/package-versioner" /></a>
|
|
8
|
+
<br/><br/>
|
|
9
|
+
A lightweight yet powerful CLI tool for automated semantic versioning based on Git history and conventional commits. Supports both single package projects and monorepos with flexible versioning strategies.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- Automatically determines version bumps based on commit history (using conventional commits)
|
|
14
|
+
- Supports both single package projects and monorepos with minimal configuration
|
|
15
|
+
- Support for both npm (package.json) and Rust (Cargo.toml) projects
|
|
16
|
+
- Flexible versioning strategies (e.g., based on commit types, branch patterns)
|
|
17
|
+
- Integrates with conventional commits presets
|
|
18
|
+
- Customizable through a `version.config.json` file or CLI options
|
|
19
|
+
- Automatically updates `package.json` or `Cargo.toml` version
|
|
20
|
+
- Creates appropriate Git tags for releases
|
|
21
|
+
- CI/CD friendly with JSON output support
|
|
22
|
+
- Changelog data included in JSON output for use with @releasekit/notes
|
|
23
|
+
|
|
24
|
+
## Supporting JavaScript and Rust Projects
|
|
25
|
+
|
|
26
|
+
`package-versioner` provides version management for both JavaScript/TypeScript (via package.json) and Rust (via Cargo.toml) projects:
|
|
27
|
+
|
|
28
|
+
- **JavaScript/TypeScript**: Automatically detects and updates version in package.json files
|
|
29
|
+
- **Rust**: Detects and updates version in Cargo.toml files using the same versioning strategies
|
|
30
|
+
- **Mixed Projects**: Supports repositories containing both package.json and Cargo.toml files
|
|
31
|
+
|
|
32
|
+
When run, the tool will automatically discover and update the appropriate manifest file based on the project structure.
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
`package-versioner` is designed to be run directly using your preferred package manager's execution command, without needing global installation.
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Determine bump based on conventional commits since last tag
|
|
40
|
+
npx package-versioner
|
|
41
|
+
|
|
42
|
+
# Using pnpm
|
|
43
|
+
pnpm dlx package-versioner
|
|
44
|
+
|
|
45
|
+
# Using yarn
|
|
46
|
+
yarn dlx package-versioner
|
|
47
|
+
|
|
48
|
+
# Specify a bump type explicitly
|
|
49
|
+
npx package-versioner --bump minor
|
|
50
|
+
|
|
51
|
+
# Create a prerelease (e.g., alpha)
|
|
52
|
+
npx package-versioner --bump patch --prerelease alpha
|
|
53
|
+
|
|
54
|
+
# Target specific packages (only in async/independent mode, comma-separated)
|
|
55
|
+
npx package-versioner -t @scope/package-a,@scope/package-b
|
|
56
|
+
|
|
57
|
+
# Run from a different directory
|
|
58
|
+
npx package-versioner --project-dir /path/to/project
|
|
59
|
+
|
|
60
|
+
# Perform a dry run: calculates version, logs actions, but makes no file changes or Git commits/tags
|
|
61
|
+
npx package-versioner --dry-run
|
|
62
|
+
|
|
63
|
+
# Only use reachable tags (Git-semantic mode, no fallback to unreachable tags)
|
|
64
|
+
npx package-versioner --strict-reachable
|
|
65
|
+
|
|
66
|
+
# Output results as JSON (useful for CI/CD scripts)
|
|
67
|
+
npx package-versioner --json
|
|
68
|
+
|
|
69
|
+
# Combine with dry-run for CI planning
|
|
70
|
+
npx package-versioner --dry-run --json
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Note on Targeting:** Using the `-t` flag creates package-specific tags (e.g., `@scope/package-a@1.2.0`) but *not* a global tag (like `v1.2.0`). If needed, create the global tag manually in your CI/CD script after this command.
|
|
74
|
+
|
|
75
|
+
### Git Tag Reachability
|
|
76
|
+
|
|
77
|
+
By default, `package-versioner` intelligently handles Git tag reachability to provide the best user experience:
|
|
78
|
+
|
|
79
|
+
- **Default behaviour**: Uses reachable tags when available, but falls back to the latest repository tag if needed (common in feature branches)
|
|
80
|
+
- **Strict mode (`--strict-reachable`)**: Only uses tags reachable from the current commit, following strict Git semantics
|
|
81
|
+
|
|
82
|
+
This is particularly useful when working on feature branches that have diverged from the main branch where newer tags exist. The tool will automatically detect the Git context and provide helpful guidance:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# On a feature branch with unreachable tags
|
|
86
|
+
npx package-versioner --dry-run
|
|
87
|
+
# Output: "No tags reachable from current branch 'feature-x'. Using latest repository tag v1.2.3 as version base."
|
|
88
|
+
# Tip: Consider 'git merge main' or 'git rebase main' to include tag history in your branch.
|
|
89
|
+
|
|
90
|
+
# Force strict Git semantics
|
|
91
|
+
npx package-versioner --dry-run --strict-reachable
|
|
92
|
+
# Output: Uses only reachable tags, may result in "No reachable tags found"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## JSON Output
|
|
96
|
+
|
|
97
|
+
When using the `--json` flag, normal console output is suppressed and the tool outputs a structured JSON object that includes information about the versioning operation.
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"dryRun": true,
|
|
102
|
+
"updates": [
|
|
103
|
+
{
|
|
104
|
+
"packageName": "@scope/package-a",
|
|
105
|
+
"newVersion": "1.2.3",
|
|
106
|
+
"filePath": "/path/to/package.json"
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
"changelogs": [
|
|
110
|
+
{
|
|
111
|
+
"packageName": "@scope/package-a",
|
|
112
|
+
"version": "1.2.3",
|
|
113
|
+
"previousVersion": "v1.2.2",
|
|
114
|
+
"revisionRange": "v1.2.2..HEAD",
|
|
115
|
+
"repoUrl": "https://github.com/org/repo",
|
|
116
|
+
"entries": [
|
|
117
|
+
{ "type": "added", "description": "New feature", "scope": "core" },
|
|
118
|
+
{ "type": "fixed", "description": "Bug fix" }
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
"commitMessage": "chore(release): v1.2.3",
|
|
123
|
+
"tags": [
|
|
124
|
+
"v@scope/package-a@1.2.3"
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
For detailed examples of how to use this in CI/CD pipelines, see [CI/CD Integration](./docs/CI_CD_INTEGRATION.md).
|
|
130
|
+
|
|
131
|
+
## Configuration
|
|
132
|
+
|
|
133
|
+
Customize behaviour by creating a `version.config.json` file in your project root:
|
|
134
|
+
|
|
135
|
+
```json
|
|
136
|
+
{
|
|
137
|
+
"preset": "angular",
|
|
138
|
+
"versionPrefix": "v",
|
|
139
|
+
"tagTemplate": "${packageName}@${prefix}${version}",
|
|
140
|
+
"packageSpecificTags": true,
|
|
141
|
+
"commitMessage": "chore: release ${packageName}@${version} [skip ci]",
|
|
142
|
+
"strictReachable": false,
|
|
143
|
+
"sync": true,
|
|
144
|
+
"skip": [
|
|
145
|
+
"docs",
|
|
146
|
+
"e2e"
|
|
147
|
+
],
|
|
148
|
+
"packages": ["@mycompany/*"],
|
|
149
|
+
"mainPackage": "primary-package",
|
|
150
|
+
"cargo": {
|
|
151
|
+
"enabled": true,
|
|
152
|
+
"paths": ["src/", "crates/"]
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Configuration Options
|
|
158
|
+
|
|
159
|
+
#### General Options (All Projects)
|
|
160
|
+
- `preset`: Conventional commits preset to use for version calculation (default: "angular")
|
|
161
|
+
- `versionPrefix`: Prefix for version numbers in tags (default: "v")
|
|
162
|
+
- `tagTemplate`: Template for Git tags (default: "${prefix}${version}")
|
|
163
|
+
- `commitMessage`: Template for commit messages (default: "chore(release): ${version}")
|
|
164
|
+
- `strictReachable`: Only use reachable tags, no fallback to unreachable tags (default: false)
|
|
165
|
+
- `prereleaseIdentifier`: Identifier for prerelease versions (e.g., "alpha", "beta", "next") used in versions like "1.2.0-alpha.3"
|
|
166
|
+
- `mismatchStrategy`: How to handle version mismatches between git tags and package.json (default: "error"). Options:
|
|
167
|
+
- `"error"`: Throw an error and stop execution, forcing the mismatch to be resolved
|
|
168
|
+
- `"warn"`: Log a warning but continue with the higher version
|
|
169
|
+
- `"prefer-package"`: Use the package.json version when a mismatch is detected
|
|
170
|
+
- `"prefer-git"`: Use the git tag version when a mismatch is detected
|
|
171
|
+
- `"ignore"`: Silently continue with the higher version
|
|
172
|
+
- `cargo`: Options for Rust projects:
|
|
173
|
+
- `enabled`: Whether to handle Cargo.toml files (default: true)
|
|
174
|
+
- `paths`: Directories to search for Cargo.toml files (optional)
|
|
175
|
+
|
|
176
|
+
#### Monorepo-Specific Options
|
|
177
|
+
- `sync`: Whether all packages should be versioned together (default: true)
|
|
178
|
+
- `skip`: Array of package names or patterns to exclude from versioning. Supports exact names, scope wildcards, path patterns, and global wildcards (e.g., ["@scope/package-a", "@scope/*", "packages/**/*"])
|
|
179
|
+
- `packages`: Array of package names or patterns to target for versioning. Supports exact names, scope wildcards, path patterns and global wildcards (e.g., ["@scope/package-a", "@scope/*", "*"])
|
|
180
|
+
- `mainPackage`: Package name whose commit history should drive version determination
|
|
181
|
+
- `packageSpecificTags`: Whether to enable package-specific tagging behaviour (default: false)
|
|
182
|
+
- `updateInternalDependencies`: How to update internal dependencies ("patch", "minor", "major", or "inherit")
|
|
183
|
+
|
|
184
|
+
For more details on CI/CD integration and advanced usage, see [CI/CD Integration](./docs/CI_CD_INTEGRATION.md).
|
|
185
|
+
|
|
186
|
+
### Package Targeting
|
|
187
|
+
|
|
188
|
+
The `packages` configuration option controls which packages are processed for versioning. It supports several pattern types:
|
|
189
|
+
|
|
190
|
+
#### Exact Package Names
|
|
191
|
+
```json
|
|
192
|
+
{
|
|
193
|
+
"packages": ["@mycompany/core", "@mycompany/utils", "standalone-package"]
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### Scope Wildcards
|
|
198
|
+
Target all packages within a specific scope:
|
|
199
|
+
```json
|
|
200
|
+
{
|
|
201
|
+
"packages": ["@mycompany/*"]
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
#### Path Patterns / Globs
|
|
206
|
+
Target all packages in a directory or matching a path pattern:
|
|
207
|
+
```json
|
|
208
|
+
{
|
|
209
|
+
"packages": ["packages/**/*", "examples/**"]
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
This will match all packages in nested directories under `packages/` or `examples/`.
|
|
213
|
+
|
|
214
|
+
#### Global Wildcard
|
|
215
|
+
Target all packages in the workspace:
|
|
216
|
+
```json
|
|
217
|
+
{
|
|
218
|
+
"packages": ["*"]
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
#### Mixed Patterns
|
|
223
|
+
Combine different pattern types:
|
|
224
|
+
```json
|
|
225
|
+
{
|
|
226
|
+
"packages": ["@mycompany/*", "@utils/logger", "legacy-package", "packages/**/*"]
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
**Behaviour:**
|
|
231
|
+
- When `packages` is specified, **only** packages matching those patterns will be processed
|
|
232
|
+
- When `packages` is empty or not specified, **all** workspace packages will be processed
|
|
233
|
+
- The `skip` option can exclude specific packages from the selected set
|
|
234
|
+
|
|
235
|
+
**Note**: Your workspace configuration (pnpm-workspace.yaml, package.json workspaces, etc.) determines which packages are available, but the `packages` option directly controls which ones get versioned.
|
|
236
|
+
|
|
237
|
+
### Package-Specific Tagging
|
|
238
|
+
|
|
239
|
+
The `packageSpecificTags` option controls whether the tool creates and searches for package-specific Git tags:
|
|
240
|
+
|
|
241
|
+
- **When `false` (default)**: Creates global tags like `v1.2.3` and searches for the latest global tag
|
|
242
|
+
- **When `true`**: Creates package-specific tags like `@scope/package-a@v1.2.3` and searches for package-specific tags
|
|
243
|
+
|
|
244
|
+
This option works in conjunction with `tagTemplate` to control tag formatting. The `tagTemplate` is used for all tag creation, with the `packageSpecificTags` boolean controlling whether the `${packageName}` variable is populated:
|
|
245
|
+
|
|
246
|
+
- When `packageSpecificTags` is `false`: The `${packageName}` variable is empty, so templates should use `${prefix}${version}`
|
|
247
|
+
- When `packageSpecificTags` is `true`: The `${packageName}` variable contains the package name
|
|
248
|
+
|
|
249
|
+
**Examples:**
|
|
250
|
+
|
|
251
|
+
For single-package repositories or sync monorepos:
|
|
252
|
+
```json
|
|
253
|
+
{
|
|
254
|
+
"packageSpecificTags": true,
|
|
255
|
+
"tagTemplate": "${packageName}@${prefix}${version}"
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
Creates tags like `my-package@v1.2.3`
|
|
259
|
+
|
|
260
|
+
For global versioning:
|
|
261
|
+
```json
|
|
262
|
+
{
|
|
263
|
+
"packageSpecificTags": false,
|
|
264
|
+
"tagTemplate": "${prefix}${version}"
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
Creates tags like `v1.2.3`
|
|
268
|
+
|
|
269
|
+
**Important Notes:**
|
|
270
|
+
- In **sync mode** with a single package, `packageSpecificTags: true` will use the package name even though all packages are versioned together
|
|
271
|
+
- In **sync mode** with multiple packages, package names are not used regardless of the setting
|
|
272
|
+
- In **async mode**, each package gets its own tag when `packageSpecificTags` is enabled
|
|
273
|
+
|
|
274
|
+
With package-specific tagging enabled, the tool will:
|
|
275
|
+
1. Look for existing tags matching the configured pattern for each package
|
|
276
|
+
2. Create new tags using the same pattern when releasing
|
|
277
|
+
3. Fall back to global tag lookup if no package-specific tags are found
|
|
278
|
+
|
|
279
|
+
## How Versioning Works
|
|
280
|
+
|
|
281
|
+
`package-versioner` determines the next version based on your configuration (`version.config.json`). The two main approaches are:
|
|
282
|
+
|
|
283
|
+
1. **Conventional Commits:** Analyzes commit messages (like `feat:`, `fix:`, `BREAKING CHANGE:`) since the last tag.
|
|
284
|
+
2. **Branch Pattern:** Determines the bump based on the current or recently merged branch name matching predefined patterns.
|
|
285
|
+
|
|
286
|
+
For a detailed explanation of these concepts and monorepo modes (Sync vs. Async), see [Versioning Strategies and Concepts](./docs/versioning.md).
|
|
287
|
+
|
|
288
|
+
## Documentation
|
|
289
|
+
|
|
290
|
+
- [Versioning Strategies and Concepts](./docs/versioning.md) - Detailed explanation of versioning approaches
|
|
291
|
+
- [CI/CD Integration](./docs/CI_CD_INTEGRATION.md) - Guide for integrating with CI/CD pipelines
|
|
292
|
+
|
|
293
|
+
For changelog generation, use [@releasekit/notes](../notes) which consumes the JSON output from this tool.
|
|
294
|
+
|
|
295
|
+
For more details on available CLI options, run:
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
npx package-versioner --help
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## Acknowledgements
|
|
302
|
+
|
|
303
|
+
This project was originally forked from and inspired by [`jucian0/turbo-version`](https://github.com/jucian0/turbo-version). We appreciate the foundational work done by the original authors.
|
|
304
|
+
|
|
305
|
+
## License
|
|
306
|
+
|
|
307
|
+
MIT
|