semantic-release-next-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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dankeboy36
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # semantic-release-next-version
2
+
3
+ This library calculates the next `semantic-release` version in **dry-run mode**.
4
+ It does not push tags and does not need GitHub or npm tokens.
5
+
6
+ You can use it in CI and on your local machine to set a version before packaging
7
+ (for example before building binaries, VSIX files, ZIPs, etc.).
8
+
9
+ ---
10
+
11
+ ## Why this exists
12
+
13
+ `semantic-release` is very good at deciding when to bump `major.minor.patch`,
14
+ based on conventional commits. But normally it needs credentials and it will try
15
+ to push tags.
16
+
17
+ This library does **only the version calculation**:
18
+
19
+ - no push
20
+ - no publish
21
+ - no tokens
22
+
23
+ Some repositories produce artifacts (binaries, VSIX, ZIPs, etc.) that need a
24
+ correct version **before** the real release job runs. On preview builds (PRs or
25
+ feature branches) the artifacts should get a preview version like:
26
+
27
+ ```
28
+ x.y.z-preview-<commit>
29
+ ```
30
+
31
+ GitHub Actions runs these PR builds, but we want to **limit token access** so
32
+ that builds cannot push tags or publish anything. With this library we can
33
+ compute the version safely, without loading any secrets until the actual release
34
+ job on the `main` branch.
35
+
36
+ Useful when:
37
+
38
+ - PRs need preview artifacts
39
+ - CI should not have push/publish permissions
40
+ - You want strict token separation between build and release steps
41
+ - You only want to load secrets in the final release job
42
+
43
+ ---
44
+
45
+ ## Requirements
46
+
47
+ - The repo must have full git history and tags (`fetch-depth: 0` in CI).
48
+ - Conventional commits (`feat:`, `fix:`, etc.).
49
+ - Node.js 20 or newer.
50
+ - Peer deps installed in your project:
51
+ - `semantic-release` (>=25 <26)
52
+ - `@semantic-release/commit-analyzer`
53
+
54
+ ---
55
+
56
+ ## Install
57
+
58
+ ```sh
59
+ npm install semantic-release-next-version
60
+ ```
61
+
62
+ ---
63
+
64
+ ## Usage (CI example)
65
+
66
+ Here is how it works today in GitHub Actions:
67
+
68
+ ```yaml
69
+ jobs:
70
+ determine-version:
71
+ runs-on: ubuntu-latest
72
+ outputs:
73
+ version: ${{ steps.get_version.outputs.version }}
74
+ steps:
75
+ - uses: actions/checkout@v4
76
+ with:
77
+ fetch-depth: 0
78
+
79
+ - uses: actions/setup-node@v4
80
+ with:
81
+ node-version: 22.x
82
+ cache: npm
83
+
84
+ - run: npm ci
85
+
86
+ - name: Get Next Version
87
+ id: get_version
88
+ run: |
89
+ set -euo pipefail
90
+ MODE=""
91
+ if [ "${{ github.ref }}" = "refs/heads/main" ]; then MODE="--release"; fi
92
+ VERSION=$(npx next-version-helper $MODE)
93
+ if [ -z "$VERSION" ]; then
94
+ echo "semantic-release did not return a next version." >&2
95
+ exit 1
96
+ fi
97
+ echo "version=$VERSION" >> "$GITHUB_OUTPUT"
98
+ ```
99
+
100
+ Now other jobs can use the version:
101
+
102
+ ```yaml
103
+ - name: Set Version in Package
104
+ run: |
105
+ VERSION="${{ needs.determine-version.outputs.version }}"
106
+ npm version "$VERSION" --no-git-tag-version
107
+ ```
108
+
109
+ ---
110
+
111
+ ## Usage (Local)
112
+
113
+ ```sh
114
+ npx next-version-helper
115
+ # → 0.4.0-preview-abc1234 (default preview mode)
116
+
117
+ npx next-version-helper --release
118
+ # → 0.4.0
119
+
120
+ # When you run from outside the repo (e.g. a packed tarball):
121
+ npx next-version-helper --cwd /path/to/your/checkout --release
122
+ ```
123
+
124
+ You can also call it from JS:
125
+
126
+ ```js
127
+ import { getNextVersion } from 'semantic-release-next-version'
128
+
129
+ const version = await getNextVersion({
130
+ cwd: process.cwd(),
131
+ release: false,
132
+ mainBranch: 'main', // override if your primary branch differs
133
+ })
134
+ console.log(version)
135
+ ```
136
+
137
+ ---
138
+
139
+ ## CLI options
140
+
141
+ - `--release` / `-r`: return plain `x.y.z` (no preview suffix).
142
+ - `--cwd <path>`: run against a different working directory (useful when you call from a temp folder).
143
+ - `--main-branch <name>`: set the primary release branch (default: `main`).
144
+ - `--help` / `--version`
145
+
146
+ ---
147
+
148
+ ## Behavior
149
+
150
+ - On `main` branch with `--release` → returns `x.y.z`.
151
+ - On any branch without `--release` → returns `x.y.z-preview-<hash>`.
152
+ - If there is no new release → exits with an error
153
+ - Uses `@semantic-release/commit-analyzer` by default (must be installed).
154
+ - Main branch defaults to `main`; override with `--main-branch` or `mainBranch` in code.
155
+ - `--cwd` lets you run the CLI outside the repo root (for example after `npm pack`).
156
+
157
+ ---
158
+
159
+ ## Notes
160
+
161
+ - This library is **opinionated**.
162
+ - It needs conventional commits.
163
+ - It respects `GITHUB_HEAD_REF`/`GITHUB_REF_NAME` for branch detection.
164
+ - No pushing, no publishing, no credentials.
165
+
166
+ ---
167
+
168
+ ## License
169
+
170
+ MIT
171
+
172
+ ---
173
+
174
+ ## Debugging
175
+
176
+ - Enable verbose logs by setting `DEBUG=semantic-release-next-version` (optionally add `,semantic-release:*` for semantic-release internals).
177
+ - In GitHub Actions, you can set `DEBUG` in a step that runs the CLI (the CI smoke test does this).
178
+ - When running from a packed tarball or temp dir, pass `--cwd /path/to/repo` and `--main-branch <branch>` so branch detection stays correct.
package/bin/cli.cjs ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+
3
+ // @ts-check
4
+
5
+ Promise.resolve()
6
+ .then(() => import('../dist/cli.js'))
7
+ .then(({ run }) => run(process.argv))
8
+ .then((code) => {
9
+ if (typeof code === 'number') {
10
+ process.exitCode = code
11
+ }
12
+ })
13
+ .catch((error) => {
14
+ console.error(error)
15
+ process.exitCode = 1
16
+ })