@releasekit/version 0.3.0 → 0.4.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/dist/cli.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+
4
+ declare function createVersionCommand(): Command;
5
+ declare function createVersionProgram(): Command;
6
+
7
+ export { createVersionCommand, createVersionProgram };
package/dist/cli.js CHANGED
@@ -1 +1,105 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ VersionEngine,
4
+ enableJsonOutput,
5
+ loadConfig,
6
+ log,
7
+ printJsonOutput
8
+ } from "./chunk-ZTFI7TXV.js";
9
+ import {
10
+ readPackageVersion
11
+ } from "./chunk-2MN2VLZF.js";
12
+ import "./chunk-LMPZV35Z.js";
13
+
14
+ // src/cli.ts
15
+ import * as fs from "fs";
16
+ import { fileURLToPath } from "url";
17
+ import { Command } from "commander";
18
+ function createVersionCommand() {
19
+ return new Command("version").description("Version a package or packages based on configuration").option("-c, --config <path>", "Path to config file (defaults to releasekit.config.json in current directory)").option("-d, --dry-run", "Dry run (no changes made)", false).option("-b, --bump <type>", "Specify bump type (patch|minor|major)").option("-p, --prerelease [identifier]", "Create prerelease version").option("-s, --sync", "Use synchronized versioning across all packages").option("-j, --json", "Output results as JSON", false).option("-t, --target <packages>", "Comma-delimited list of package names to target").option("--project-dir <path>", "Project directory to run commands in", process.cwd()).action(async (options) => {
20
+ if (options.json) {
21
+ enableJsonOutput(options.dryRun);
22
+ }
23
+ try {
24
+ const originalCwd = process.cwd();
25
+ if (options.projectDir && options.projectDir !== originalCwd) {
26
+ try {
27
+ process.chdir(options.projectDir);
28
+ log(`Changed working directory to: ${options.projectDir}`, "debug");
29
+ } catch (error) {
30
+ throw new Error(
31
+ `Failed to change to directory "${options.projectDir}": ${error instanceof Error ? error.message : String(error)}`
32
+ );
33
+ }
34
+ }
35
+ const config = loadConfig({ cwd: options.projectDir, configPath: options.config });
36
+ log(`Loaded configuration from ${options.config || "releasekit.config.json"}`, "info");
37
+ if (options.dryRun) config.dryRun = true;
38
+ if (options.sync) config.sync = true;
39
+ if (options.bump) config.type = options.bump;
40
+ if (options.prerelease) {
41
+ config.prereleaseIdentifier = options.prerelease === true ? "next" : options.prerelease;
42
+ config.isPrerelease = true;
43
+ }
44
+ const cliTargets = options.target ? options.target.split(",").map((t) => t.trim()) : [];
45
+ if (cliTargets.length > 0) {
46
+ config.packages = cliTargets;
47
+ log(`CLI targets specified: ${cliTargets.join(", ")}`, "info");
48
+ }
49
+ const engine = new VersionEngine(config, !!options.json);
50
+ const pkgsResult = await engine.getWorkspacePackages();
51
+ const resolvedCount = pkgsResult.packages.length;
52
+ log(`Resolved ${resolvedCount} packages from workspace`, "debug");
53
+ log(`Config packages: ${JSON.stringify(config.packages)}`, "debug");
54
+ log(`Config sync: ${config.sync}`, "debug");
55
+ if (config.sync) {
56
+ log("Using sync versioning strategy.", "info");
57
+ engine.setStrategy("sync");
58
+ await engine.run(pkgsResult);
59
+ } else if (resolvedCount === 1) {
60
+ log("Using single package versioning strategy.", "info");
61
+ if (cliTargets.length > 0) {
62
+ log("--target flag is ignored for single package strategy.", "warning");
63
+ }
64
+ engine.setStrategy("single");
65
+ await engine.run(pkgsResult);
66
+ } else if (resolvedCount === 0) {
67
+ throw new Error("No packages found in workspace");
68
+ } else {
69
+ log("Using async versioning strategy.", "info");
70
+ if (cliTargets.length > 0) {
71
+ log(`Targeting specific packages: ${cliTargets.join(", ")}`, "info");
72
+ }
73
+ engine.setStrategy("async");
74
+ await engine.run(pkgsResult, cliTargets);
75
+ }
76
+ log("Versioning process completed.", "success");
77
+ printJsonOutput();
78
+ } catch (error) {
79
+ const { BaseVersionError } = await import("./baseError-FARJUY5U.js");
80
+ if (BaseVersionError.isVersionError(error)) {
81
+ error.logError();
82
+ } else {
83
+ log(`Error: ${error instanceof Error ? error.message : String(error)}`, "error");
84
+ }
85
+ process.exit(1);
86
+ }
87
+ });
88
+ }
89
+ var isMain = (() => {
90
+ try {
91
+ return process.argv[1] ? fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url) : false;
92
+ } catch {
93
+ return false;
94
+ }
95
+ })();
96
+ function createVersionProgram() {
97
+ return new Command().name("releasekit-version").description("Version a package or packages based on conventional commits").version(readPackageVersion(import.meta.url)).addCommand(createVersionCommand(), { isDefault: true });
98
+ }
99
+ if (isMain) {
100
+ createVersionProgram().parse();
101
+ }
102
+ export {
103
+ createVersionCommand,
104
+ createVersionProgram
105
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ execAsync,
3
+ execSync
4
+ } from "./chunk-LMPZV35Z.js";
5
+ export {
6
+ execAsync,
7
+ execSync
8
+ };
@@ -0,0 +1,9 @@
1
+ export { loadConfig } from './config.ts';
2
+ export { calculateVersion } from './core/versionCalculator.ts';
3
+ export { VersionEngine } from './core/versionEngine.ts';
4
+ export { createAsyncStrategy, createSingleStrategy, createSyncStrategy } from './core/versionStrategies.ts';
5
+ export { BaseVersionError } from './errors/baseError.ts';
6
+ export { VersionErrorCode, createVersionError } from './errors/versionError.ts';
7
+ export { PackageProcessor } from './package/packageProcessor.ts';
8
+ export { Config, VersionConfigBase } from './types.ts';
9
+ export { JsonOutputData, enableJsonOutput, flushPendingWrites, getJsonData } from './utils/jsonOutput.ts';
package/dist/index.js ADDED
@@ -0,0 +1,33 @@
1
+ import {
2
+ PackageProcessor,
3
+ VersionEngine,
4
+ VersionErrorCode,
5
+ calculateVersion,
6
+ createAsyncStrategy,
7
+ createSingleStrategy,
8
+ createSyncStrategy,
9
+ createVersionError,
10
+ enableJsonOutput,
11
+ flushPendingWrites,
12
+ getJsonData,
13
+ loadConfig
14
+ } from "./chunk-ZTFI7TXV.js";
15
+ import {
16
+ BaseVersionError
17
+ } from "./chunk-2MN2VLZF.js";
18
+ import "./chunk-LMPZV35Z.js";
19
+ export {
20
+ BaseVersionError,
21
+ PackageProcessor,
22
+ VersionEngine,
23
+ VersionErrorCode,
24
+ calculateVersion,
25
+ createAsyncStrategy,
26
+ createSingleStrategy,
27
+ createSyncStrategy,
28
+ createVersionError,
29
+ enableJsonOutput,
30
+ flushPendingWrites,
31
+ getJsonData,
32
+ loadConfig
33
+ };
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## How the Next Version is Calculated
6
6
 
7
- There are two primary methods the tool uses to decide the version bump (e.g., patch, minor, major), configured via the `versionStrategy` option in `version.config.json`:
7
+ There are two primary methods the tool uses to decide the version bump (e.g., patch, minor, major), configured via the `versionStrategy` option in `releasekit.config.json`:
8
8
 
9
9
  ### 1. Conventional Commits (`versionStrategy: "conventional"`)
10
10
 
@@ -14,7 +14,7 @@ This is the default strategy. `releasekit-version` analyzes Git commit messages
14
14
  - **Minor Bump (e.g., 1.2.3 -> 1.3.0):** Triggered by `feat:` commit types.
15
15
  - **Major Bump (e.g., 1.2.3 -> 2.0.0):** Triggered by commits with `BREAKING CHANGE:` in the footer or `feat!:`, `fix!:` etc. in the header.
16
16
 
17
- The specific preset used for analysis (e.g., "angular", "conventional") can be set using the `preset` option in `version.config.json`.
17
+ The specific preset used for analysis (e.g., "angular", "conventional") can be set using the `preset` option in `releasekit.config.json`.
18
18
 
19
19
  **Format:** `<type>(<scope>): <subject>`
20
20
 
@@ -39,9 +39,9 @@ The specific preset used for analysis (e.g., "angular", "conventional") can be s
39
39
 
40
40
  This strategy uses the name of the current Git branch (or the most recently merged branch matching a pattern, if applicable) to determine the version bump.
41
41
 
42
- You define patterns in the `branchPattern` array in `version.config.json`. Each pattern is a string like `"prefix:bumptype"`.
42
+ You define patterns in the `branchPattern` array in `releasekit.config.json`. Each pattern is a string like `"prefix:bumptype"`.
43
43
 
44
- **Example `version.config.json`:**
44
+ **Example `releasekit.config.json`:**
45
45
 
46
46
  ```json
47
47
  {
@@ -156,7 +156,7 @@ Mismatches are detected in the following cases:
156
156
  - Git tag is ahead by a major or minor version (e.g., tag `2.0.0` vs package `1.0.0`)
157
157
  - Git tag is a prerelease but package.json is a stable release (e.g., tag `1.0.0-beta.1` vs package `1.0.0`)
158
158
 
159
- Configure it in `version.config.json`:
159
+ Configure it in `releasekit.config.json`:
160
160
  ```json
161
161
  {
162
162
  "mismatchStrategy": "prefer-package"
@@ -277,7 +277,7 @@ This configuration will process all packages in the `@mycompany` scope except fo
277
277
 
278
278
  ### Tag Template Configuration
279
279
 
280
- You can customize how tags are formatted using the following configuration options in `version.config.json`:
280
+ You can customize how tags are formatted using the following configuration options in `releasekit.config.json`:
281
281
 
282
282
  ```json
283
283
  {
@@ -430,7 +430,7 @@ For global commit messages, use templates without `${packageName}`:
430
430
 
431
431
  ## Monorepo Versioning Modes
432
432
 
433
- While primarily used for single packages now, `releasekit-version` retains options for monorepo workflows, controlled mainly by the `sync` flag in `version.config.json`.
433
+ While primarily used for single packages now, `releasekit-version` retains options for monorepo workflows, controlled mainly by the `sync` flag in `releasekit.config.json`.
434
434
 
435
435
  ### Sync Mode (`sync: true`)
436
436
 
@@ -475,7 +475,7 @@ npx releasekit-version --bump minor --prerelease beta
475
475
  # Result: 1.0.0 -> 1.1.0-beta.0
476
476
  ```
477
477
 
478
- You can also set a default prerelease identifier in your `version.config.json`:
478
+ You can also set a default prerelease identifier in your `releasekit.config.json`:
479
479
 
480
480
  ```json
481
481
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@releasekit/version",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Semantic versioning based on Git history and conventional commits",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
@@ -1,197 +0,0 @@
1
- # CI/CD Integration
2
-
3
- `releasekit-version` is designed to work seamlessly in CI/CD pipelines, making it easy to automate versioning as part of your release workflow.
4
-
5
- ## JSON Output Mode
6
-
7
- For programmatic consumption in CI/CD scripts, `releasekit-version` provides a structured JSON output option:
8
-
9
- ```bash
10
- # Output results in JSON format
11
- npx releasekit-version --json
12
-
13
- # Combine with dry-run for planning
14
- npx releasekit-version --dry-run --json
15
- ```
16
-
17
- This will suppress all normal console output and instead output a single JSON object containing:
18
-
19
- ```json
20
- {
21
- "dryRun": false, // Whether this was a dry run
22
- "updates": [ // Array of packages that were updated
23
- {
24
- "packageName": "@scope/package-a", // Package name
25
- "newVersion": "1.2.3", // New version number
26
- "filePath": "/path/to/package.json" // Path to the updated package.json
27
- }
28
- ],
29
- "changelogs": [ // Structured changelog data per package
30
- {
31
- "packageName": "@scope/package-a", // Package name
32
- "version": "1.2.3", // New version
33
- "previousVersion": "v1.2.2", // Previous tag (null if none)
34
- "revisionRange": "v1.2.2..HEAD", // Git revision range used
35
- "repoUrl": "https://github.com/org/repo", // Repository URL (null if unknown)
36
- "entries": [ // Parsed changelog entries
37
- { "type": "added", "description": "New feature", "scope": "core" },
38
- { "type": "fixed", "description": "Bug fix" }
39
- ]
40
- }
41
- ],
42
- "commitMessage": "chore: release my-package v1.2.3", // The commit message that was used
43
- "tags": [ // Array of tags that were created
44
- "v1.2.3" // or package-specific tags in targeted mode
45
- ]
46
- }
47
- ```
48
-
49
- ### Benefits of JSON Output
50
-
51
- The structured JSON output provides several advantages for CI/CD integration:
52
-
53
- - **Reliable Parsing**: Unlike text logs that might change format or include ANSI color codes, the JSON structure remains consistent
54
- - **Programmatic Access**: Easily extract specific values like version numbers for subsequent steps
55
- - **Conditional Workflows**: Trigger different CI actions based on the presence of updates or specific version changes
56
- - **Audit Trail**: Store the JSON output as artifacts for version change tracking
57
- - **Error Handling**: Better detect and respond to versioning issues in your pipeline
58
-
59
- ## Sample CI/CD Integration Patterns
60
-
61
- Here are some common ways to incorporate `releasekit-version` into your CI/CD pipeline:
62
-
63
- ### GitHub Actions Workflow Example
64
-
65
- ```yaml
66
- name: Release
67
-
68
- on:
69
- push:
70
- branches: [main]
71
-
72
- jobs:
73
- version:
74
- runs-on: ubuntu-latest
75
- outputs:
76
- changes_detected: ${{ steps.version.outputs.changes_detected }}
77
- new_version: ${{ steps.version.outputs.new_version }}
78
-
79
- steps:
80
- - uses: actions/checkout@v6
81
- with:
82
- fetch-depth: 0 # Important for git history
83
-
84
- - name: Setup Node.js
85
- uses: actions/setup-node@v6
86
- with:
87
- node-version: '18'
88
-
89
- - name: Install dependencies
90
- run: npm ci
91
-
92
- - name: Determine version
93
- id: version
94
- run: |
95
- # Run in JSON mode for parsing
96
- VERSION_OUTPUT=$(npx releasekit-version --json)
97
- echo "Version output: $VERSION_OUTPUT"
98
-
99
- # Use jq to parse the JSON output
100
- CHANGES_DETECTED=$(echo "$VERSION_OUTPUT" | jq -r '.updates | length > 0')
101
- echo "changes_detected=$CHANGES_DETECTED" >> $GITHUB_OUTPUT
102
-
103
- if [ "$CHANGES_DETECTED" = "true" ]; then
104
- # Extract the first package's new version as representative version
105
- NEW_VERSION=$(echo "$VERSION_OUTPUT" | jq -r '.updates[0].newVersion')
106
- echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
107
- fi
108
-
109
- publish:
110
- needs: version
111
- if: needs.version.outputs.changes_detected == 'true'
112
- runs-on: ubuntu-latest
113
- steps:
114
- # Publishing steps using the detected version
115
- - run: echo "Would publish version ${{ needs.version.outputs.new_version }}"
116
- ```
117
-
118
- ### GitLab CI Pipeline Example
119
-
120
- ```yaml
121
- stages:
122
- - version
123
- - publish
124
-
125
- determine_version:
126
- stage: version
127
- script:
128
- - npm ci
129
- - |
130
- VERSION_OUTPUT=$(npx releasekit-version --json)
131
- echo "VERSION_OUTPUT=$VERSION_OUTPUT" >> version.env
132
-
133
- # Parse values for use in later stages
134
- CHANGES_DETECTED=$(echo "$VERSION_OUTPUT" | jq -r '.updates | length > 0')
135
- echo "CHANGES_DETECTED=$CHANGES_DETECTED" >> version.env
136
-
137
- if [ "$CHANGES_DETECTED" = "true" ]; then
138
- NEW_VERSION=$(echo "$VERSION_OUTPUT" | jq -r '.updates[0].newVersion')
139
- echo "NEW_VERSION=$NEW_VERSION" >> version.env
140
- fi
141
- artifacts:
142
- reports:
143
- dotenv: version.env
144
-
145
- publish:
146
- stage: publish
147
- needs: determine_version
148
- script:
149
- - echo "Publishing version $NEW_VERSION"
150
- rules:
151
- - if: $CHANGES_DETECTED == "true"
152
- ```
153
-
154
- ## Working with Tags in CI
155
-
156
- When using the targeted mode with `-t` flag, `releasekit-version` creates package-specific tags (e.g., `@scope/package-a@1.2.0`) but not a global tag. If your release process needs a global tag, you can add a step to your CI/CD pipeline:
157
-
158
- ```bash
159
- # Create a global tag based on the representative version
160
- NEW_VERSION=$(echo "$VERSION_OUTPUT" | jq -r '.updates[0].newVersion')
161
- git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION"
162
- git push origin "v$NEW_VERSION"
163
- ```
164
-
165
- ## Environment Variables
166
-
167
- `releasekit-version` respects the following environment variables:
168
-
169
- - `NO_COLOR=1`: Disables colored output in logs (automatically detected in CI environments)
170
- - `CI=true`: Most CI environments set this automatically, which helps the tool adjust its output behaviour
171
-
172
- ## Skipping CI for Version Commits
173
-
174
- If you want to prevent additional CI runs when version commits are made, you can include CI skip flags in your commit message template in `version.config.json`:
175
-
176
- ```json
177
- {
178
- "commitMessage": "chore: release ${packageName} v${version} [skip ci]",
179
- // other configuration options...
180
- }
181
- ```
182
-
183
- Common CI skip patterns include:
184
- - `[skip ci]` or `[ci skip]` - Works in GitHub Actions, GitLab CI, CircleCI
185
- - `[skip-ci]` - Alternative format supported by some CI systems
186
- - `[no ci]` - Another variant
187
-
188
- Each CI system might have slightly different syntax, so check your CI provider's documentation for the exact skip token to use.
189
-
190
- ## Tips for Reliable CI/CD Integration
191
-
192
- 1. **Always use `--json`** in CI/CD pipelines for consistent output parsing
193
- 2. **Use the `fetch-depth: 0`** option in GitHub Actions (or equivalent in other CIs) to ensure access to the full Git history
194
- 3. **Store the JSON output** as a build artifact for debugging and auditing
195
- 4. **Consider dry runs** in your preview/staging branches to validate version changes before they're applied
196
- 5. **Use `--project-dir`** when running from a different directory than your project root
197
- 6. **Be mindful of Git credentials** - ensure your CI has proper permissions for creating commits and tags