fork-version 3.0.1 → 3.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/CHANGELOG.md +22 -0
- package/README.md +29 -6
- package/dist/{chunk-RJRVHSEG.cjs → chunk-BPV4HZ7U.cjs} +139 -59
- package/dist/chunk-BPV4HZ7U.cjs.map +1 -0
- package/dist/{chunk-D2PQT6ZM.js → chunk-FRII64VR.js} +136 -60
- package/dist/chunk-FRII64VR.js.map +1 -0
- package/dist/cli.cjs +66 -54
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +63 -51
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +31 -15
- package/dist/index.d.cts +473 -342
- package/dist/index.d.ts +473 -342
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-D2PQT6ZM.js.map +0 -1
- package/dist/chunk-RJRVHSEG.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Fork Version
|
|
2
2
|
|
|
3
|
+
## [3.1.0](https://github.com/eglavin/fork-version/compare/v3.0.2...v3.1.0) (2025-10-05)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* implement new command flow for inspect-* commands ([d89e4e0](https://github.com/eglavin/fork-version/commit/d89e4e07803180c7b79847ed4a5e1241ee19074b))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## [3.0.2](https://github.com/eglavin/fork-version/compare/v3.0.1...v3.0.2) (2025-10-02)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* dont count merges or reverts as changes ([bacf7fe](https://github.com/eglavin/fork-version/commit/bacf7fe3f10e0abaa084c068a132fedbe26c12d5))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Refactor
|
|
20
|
+
|
|
21
|
+
* move git and logger classes to the services folder ([577c4bf](https://github.com/eglavin/fork-version/commit/577c4bf2b8923b2ed17309b0d73bd1279f69a407))
|
|
22
|
+
* split version file into two ([ccf63be](https://github.com/eglavin/fork-version/commit/ccf63bed774986834642a5729b6ac56aae63e6c8))
|
|
23
|
+
|
|
24
|
+
|
|
3
25
|
## [3.0.1](https://github.com/eglavin/fork-version/compare/v3.0.0...v3.0.1) (2025-10-01)
|
|
4
26
|
|
|
5
27
|
|
package/README.md
CHANGED
|
@@ -87,6 +87,17 @@ You can then add the following entry to your package.json scripts section and us
|
|
|
87
87
|
|
|
88
88
|
For example if you use npm you can now use `npm run release` to run Fork-Version.
|
|
89
89
|
|
|
90
|
+
### Commands
|
|
91
|
+
|
|
92
|
+
Fork-Version has a number of command modes which will make the program behave differently. The default "command" is the `main` mode, this mode will be used when no other command is defined.
|
|
93
|
+
|
|
94
|
+
| Command | Description |
|
|
95
|
+
| ------------------- | ---------------------------------------------------------------------- |
|
|
96
|
+
| `main` | Bumps the version, update files, generate changelog, commits, and tag. |
|
|
97
|
+
| `inspect-version` | Prints the current version and exit. |
|
|
98
|
+
| `inspect-tag` | Prints the current git tag and exit. |
|
|
99
|
+
| `validate-config` | Validates the configuration and exit. |
|
|
100
|
+
|
|
90
101
|
### Exit Codes
|
|
91
102
|
|
|
92
103
|
When ran as a cli tool Fork-Version will exit with one of the following exit codes:
|
|
@@ -95,6 +106,7 @@ When ran as a cli tool Fork-Version will exit with one of the following exit cod
|
|
|
95
106
|
| --------- | ---------------------------- |
|
|
96
107
|
| 0 | Success |
|
|
97
108
|
| 1 | General Error |
|
|
109
|
+
| 2 | Unknown Command |
|
|
98
110
|
| 3 | Config File Validation Error |
|
|
99
111
|
|
|
100
112
|
### Command Line Options
|
|
@@ -105,17 +117,24 @@ The following help text can be viewed by running the following command: `npx for
|
|
|
105
117
|
|
|
106
118
|
```text
|
|
107
119
|
Usage:
|
|
108
|
-
$ fork-version [options]
|
|
120
|
+
$ fork-version [command?] [options?]
|
|
109
121
|
|
|
110
122
|
Commands:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
123
|
+
main Bumps the version, update files, generate changelog, commit, and tag. [Default when no command is provided]
|
|
124
|
+
inspect-version Prints the current version and exits.
|
|
125
|
+
inspect-tag Prints the current git tag and exits.
|
|
126
|
+
validate-config Validates the configuration and exits.
|
|
114
127
|
|
|
115
|
-
Options:
|
|
128
|
+
General Options:
|
|
129
|
+
--version Show the current version of Fork-Version and exit.
|
|
130
|
+
--help Show this help message and exit.
|
|
131
|
+
|
|
132
|
+
Location Options:
|
|
116
133
|
--file, -F List of the files to be updated. [Default: ["bower.json", "deno.json", "deno.jsonc", "jsr.json", "jsr.jsonc", "manifest.json", "npm-shrinkwrap.json", "package-lock.json", "package.json"]]
|
|
117
134
|
--glob, -G Glob pattern to match files to be updated.
|
|
118
135
|
--path, -P The path Fork-Version will run from. [Default: process.cwd()]
|
|
136
|
+
|
|
137
|
+
Options:
|
|
119
138
|
--changelog Name of the changelog file. [Default: "CHANGELOG.md"]
|
|
120
139
|
--header The header text for the changelog.
|
|
121
140
|
--tag-prefix Specify a prefix for the created tag. [Default: "v"]
|
|
@@ -155,6 +174,7 @@ Conventional Changelog Overrides:
|
|
|
155
174
|
Exit Codes:
|
|
156
175
|
0: Success
|
|
157
176
|
1: General Error
|
|
177
|
+
2: Unknown Command
|
|
158
178
|
3: Config File Validation Error
|
|
159
179
|
|
|
160
180
|
Examples:
|
|
@@ -169,6 +189,9 @@ Examples:
|
|
|
169
189
|
|
|
170
190
|
$ fork-version --glob "*/package.json"
|
|
171
191
|
Run fork-version and update all "package.json" files in subdirectories.
|
|
192
|
+
|
|
193
|
+
$ fork-version inspect-version
|
|
194
|
+
Prints the current version and exits.
|
|
172
195
|
```
|
|
173
196
|
|
|
174
197
|
<!-- END COMMAND LINE OPTIONS -->
|
|
@@ -268,7 +291,7 @@ Alternatively you can define your config using a key in your `package.json` file
|
|
|
268
291
|
|
|
269
292
|
| Property | Type | Default | Description |
|
|
270
293
|
| :---------------------------------------------------- | :--------------- | :---------------------- | :------------------------------------------------------------------------------------------------------------------ |
|
|
271
|
-
|
|
|
294
|
+
| command | string | `main` | The command to run. Can be one of: main, inspect-version, inspect-tag, validate-config. Defaults to main. |
|
|
272
295
|
| [files](#configfiles) | Array\<string> | `["package.json", ...]` | List of the files to be updated |
|
|
273
296
|
| [glob](#configglob) | string | - | Glob pattern to match files to be updated |
|
|
274
297
|
| path | string | `process.cwd()` | The path Fork-Version will run from |
|
|
@@ -101,11 +101,26 @@ var ChangelogPresetConfigSchema = zod.z.object({
|
|
|
101
101
|
var ForkConfigSchema = zod.z.object({
|
|
102
102
|
// Commands
|
|
103
103
|
//
|
|
104
|
+
/**
|
|
105
|
+
* The command to run, can be one of the following:
|
|
106
|
+
*
|
|
107
|
+
* - `main` - Bumps the version, update files, generate changelog, commit, and tag.
|
|
108
|
+
* - `inspect-version` - Prints the current version and exits.
|
|
109
|
+
* - `inspect-tag` - Prints the current git tag and exits.
|
|
110
|
+
* - `validate-config` - Validates the configuration and exits.
|
|
111
|
+
*
|
|
112
|
+
* @default "main"
|
|
113
|
+
*/
|
|
114
|
+
command: zod.z.literal(["main", "inspect-version", "inspect-tag", "validate-config"]).describe(
|
|
115
|
+
"The command to run. Can be one of: main, inspect-version, inspect-tag, validate-config. Defaults to main."
|
|
116
|
+
),
|
|
104
117
|
/**
|
|
105
118
|
* If set, Fork-Version will print the current version and exit.
|
|
106
119
|
* @default false
|
|
120
|
+
*
|
|
121
|
+
* @deprecated Set the `inspect-version` command instead.
|
|
107
122
|
*/
|
|
108
|
-
inspectVersion: zod.z.boolean().describe("If set, Fork-Version will print the current version and exit."),
|
|
123
|
+
inspectVersion: zod.z.boolean().optional().describe("If set, Fork-Version will print the current version and exit."),
|
|
109
124
|
// Options
|
|
110
125
|
//
|
|
111
126
|
/**
|
|
@@ -656,7 +671,7 @@ function getChangelogPresetConfig(mergedConfig, cliArguments, detectedGitHost) {
|
|
|
656
671
|
// src/config/defaults.ts
|
|
657
672
|
var DEFAULT_CONFIG = {
|
|
658
673
|
// Commands
|
|
659
|
-
|
|
674
|
+
command: "main",
|
|
660
675
|
// Options
|
|
661
676
|
files: [
|
|
662
677
|
"package.json",
|
|
@@ -792,12 +807,12 @@ function mergeFiles(configFiles, cliFiles, globResults) {
|
|
|
792
807
|
|
|
793
808
|
// src/config/user-config.ts
|
|
794
809
|
async function getUserConfig(cliArguments) {
|
|
795
|
-
const cwd = cliArguments.path ? path.resolve(cliArguments.path) : process.cwd();
|
|
810
|
+
const cwd = cliArguments.flags.path ? path.resolve(cliArguments.flags.path) : process.cwd();
|
|
796
811
|
const configFile = await loadConfigFile(cwd);
|
|
797
812
|
const mergedConfig = {
|
|
798
813
|
...DEFAULT_CONFIG,
|
|
799
814
|
...configFile,
|
|
800
|
-
...cliArguments
|
|
815
|
+
...cliArguments.flags
|
|
801
816
|
};
|
|
802
817
|
let globResults = [];
|
|
803
818
|
if (mergedConfig.glob) {
|
|
@@ -807,26 +822,38 @@ async function getUserConfig(cliArguments) {
|
|
|
807
822
|
nodir: true
|
|
808
823
|
});
|
|
809
824
|
}
|
|
810
|
-
const files = mergeFiles(configFile?.files, cliArguments
|
|
825
|
+
const files = mergeFiles(configFile?.files, cliArguments.flags.files, globResults);
|
|
811
826
|
const detectedGitHost = await detectGitHost(cwd);
|
|
812
827
|
const changelogPresetConfig = getChangelogPresetConfig(
|
|
813
828
|
mergedConfig,
|
|
814
|
-
cliArguments,
|
|
829
|
+
cliArguments.flags,
|
|
815
830
|
detectedGitHost
|
|
816
831
|
);
|
|
832
|
+
let command = DEFAULT_CONFIG.command;
|
|
833
|
+
if (cliArguments.input.length > 0 && cliArguments.input[0].trim()) {
|
|
834
|
+
command = cliArguments.input[0].trim().toLowerCase();
|
|
835
|
+
} else if (mergedConfig.command.trim()) {
|
|
836
|
+
command = mergedConfig.command.trim().toLowerCase();
|
|
837
|
+
}
|
|
838
|
+
if (mergedConfig.inspectVersion) {
|
|
839
|
+
command = "inspect-version";
|
|
840
|
+
}
|
|
841
|
+
const shouldBeSilent = ![DEFAULT_CONFIG.command].includes(command);
|
|
817
842
|
return {
|
|
818
843
|
...mergedConfig,
|
|
844
|
+
command,
|
|
819
845
|
files,
|
|
820
846
|
path: cwd,
|
|
821
847
|
preRelease: (
|
|
822
848
|
// Meow doesn't support multiple flags with the same name, so we need to check both.
|
|
823
|
-
cliArguments.preReleaseTag ?? cliArguments.preRelease ?? configFile.preRelease
|
|
849
|
+
cliArguments.flags.preReleaseTag ?? cliArguments.flags.preRelease ?? configFile.preRelease
|
|
824
850
|
),
|
|
851
|
+
silent: shouldBeSilent || mergedConfig.silent,
|
|
825
852
|
changelogPresetConfig
|
|
826
853
|
};
|
|
827
854
|
}
|
|
828
855
|
|
|
829
|
-
// src/
|
|
856
|
+
// src/services/logger.ts
|
|
830
857
|
var Logger = class {
|
|
831
858
|
constructor(config) {
|
|
832
859
|
this.config = config;
|
|
@@ -834,7 +861,7 @@ var Logger = class {
|
|
|
834
861
|
this.warn = this.warn.bind(this);
|
|
835
862
|
this.error = this.error.bind(this);
|
|
836
863
|
this.debug = this.debug.bind(this);
|
|
837
|
-
this.disableLogs = this.config.silent
|
|
864
|
+
this.disableLogs = this.config.silent;
|
|
838
865
|
}
|
|
839
866
|
disableLogs = false;
|
|
840
867
|
log(...messages) {
|
|
@@ -1170,6 +1197,76 @@ var FileManager = class {
|
|
|
1170
1197
|
}
|
|
1171
1198
|
};
|
|
1172
1199
|
|
|
1200
|
+
// src/commands/validate-config.ts
|
|
1201
|
+
function validateConfig(config) {
|
|
1202
|
+
console.log(`
|
|
1203
|
+
\u2699\uFE0F Configuration:
|
|
1204
|
+
${JSON.stringify(config, null, 2)}
|
|
1205
|
+
|
|
1206
|
+
\u2705 Configuration is valid.
|
|
1207
|
+
`);
|
|
1208
|
+
}
|
|
1209
|
+
async function getCurrentVersion(config, logger, git, fileManager, filesToUpdate) {
|
|
1210
|
+
const files = [];
|
|
1211
|
+
const versions = /* @__PURE__ */ new Set();
|
|
1212
|
+
for (const file of filesToUpdate) {
|
|
1213
|
+
if (await git.isIgnored(file)) {
|
|
1214
|
+
logger.debug(`[Git Ignored] ${file}`);
|
|
1215
|
+
continue;
|
|
1216
|
+
}
|
|
1217
|
+
const fileState = fileManager.read(file);
|
|
1218
|
+
if (fileState) {
|
|
1219
|
+
files.push(fileState);
|
|
1220
|
+
if (!config.currentVersion) {
|
|
1221
|
+
versions.add(fileState.version);
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
if (config.currentVersion) {
|
|
1226
|
+
versions.add(config.currentVersion);
|
|
1227
|
+
}
|
|
1228
|
+
if (versions.size === 0 && config.gitTagFallback) {
|
|
1229
|
+
const version = await git.getHighestSemverVersionFromTags(config.tagPrefix);
|
|
1230
|
+
if (version) {
|
|
1231
|
+
logger.warn(`Using latest git tag as fallback`);
|
|
1232
|
+
versions.add(version);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
if (versions.size === 0) {
|
|
1236
|
+
throw new Error("Unable to find current version");
|
|
1237
|
+
} else if (versions.size > 1) {
|
|
1238
|
+
if (!config.allowMultipleVersions) {
|
|
1239
|
+
throw new Error("Found multiple versions");
|
|
1240
|
+
}
|
|
1241
|
+
logger.warn(
|
|
1242
|
+
`Found multiple versions (${Array.from(versions).join(", ")}), using the higher semver version`
|
|
1243
|
+
);
|
|
1244
|
+
}
|
|
1245
|
+
const currentVersion = semver__default.default.rsort(Array.from(versions))[0];
|
|
1246
|
+
logger.log(`Current version: ${currentVersion}`);
|
|
1247
|
+
return {
|
|
1248
|
+
files,
|
|
1249
|
+
version: currentVersion
|
|
1250
|
+
};
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
// src/commands/inspect-version.ts
|
|
1254
|
+
async function inspectVersion(config, logger, fileManager, git) {
|
|
1255
|
+
let foundVersion = "";
|
|
1256
|
+
try {
|
|
1257
|
+
const currentVersion = await getCurrentVersion(config, logger, git, fileManager, config.files);
|
|
1258
|
+
if (currentVersion) foundVersion = currentVersion.version;
|
|
1259
|
+
} catch {
|
|
1260
|
+
}
|
|
1261
|
+
console.log(foundVersion);
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
// src/commands/inspect-tag.ts
|
|
1265
|
+
async function inspectTag(config, git) {
|
|
1266
|
+
const tag = await git.getMostRecentTag(config.tagPrefix);
|
|
1267
|
+
console.log(tag ?? "");
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1173
1270
|
// src/utils/trim-string-array.ts
|
|
1174
1271
|
function trimStringArray(array) {
|
|
1175
1272
|
const items = [];
|
|
@@ -1672,54 +1769,7 @@ function getReleaseType(releaseType, currentVersion, preReleaseTag) {
|
|
|
1672
1769
|
return `pre${releaseType}`;
|
|
1673
1770
|
}
|
|
1674
1771
|
|
|
1675
|
-
// src/process/version.ts
|
|
1676
|
-
async function getCurrentVersion(config, logger, git, fileManager, filesToUpdate) {
|
|
1677
|
-
const files = [];
|
|
1678
|
-
const versions = /* @__PURE__ */ new Set();
|
|
1679
|
-
for (const file of filesToUpdate) {
|
|
1680
|
-
if (await git.isIgnored(file)) {
|
|
1681
|
-
logger.debug(`[Git Ignored] ${file}`);
|
|
1682
|
-
continue;
|
|
1683
|
-
}
|
|
1684
|
-
const fileState = fileManager.read(file);
|
|
1685
|
-
if (fileState) {
|
|
1686
|
-
files.push(fileState);
|
|
1687
|
-
if (!config.currentVersion) {
|
|
1688
|
-
versions.add(fileState.version);
|
|
1689
|
-
}
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
if (config.currentVersion) {
|
|
1693
|
-
versions.add(config.currentVersion);
|
|
1694
|
-
}
|
|
1695
|
-
if (versions.size === 0 && config.gitTagFallback) {
|
|
1696
|
-
const version = await git.getHighestSemverVersionFromTags(config.tagPrefix);
|
|
1697
|
-
if (version) {
|
|
1698
|
-
logger.warn(`Using latest git tag as fallback`);
|
|
1699
|
-
versions.add(version);
|
|
1700
|
-
}
|
|
1701
|
-
}
|
|
1702
|
-
if (versions.size === 0) {
|
|
1703
|
-
throw new Error("Unable to find current version");
|
|
1704
|
-
} else if (versions.size > 1) {
|
|
1705
|
-
if (!config.allowMultipleVersions) {
|
|
1706
|
-
throw new Error("Found multiple versions");
|
|
1707
|
-
}
|
|
1708
|
-
logger.warn(
|
|
1709
|
-
`Found multiple versions (${Array.from(versions).join(", ")}), using the higher semver version`
|
|
1710
|
-
);
|
|
1711
|
-
}
|
|
1712
|
-
const currentVersion = semver__default.default.rsort(Array.from(versions))[0];
|
|
1713
|
-
if (config.inspectVersion) {
|
|
1714
|
-
console.log(currentVersion);
|
|
1715
|
-
process.exit(0);
|
|
1716
|
-
}
|
|
1717
|
-
logger.log(`Current version: ${currentVersion}`);
|
|
1718
|
-
return {
|
|
1719
|
-
files,
|
|
1720
|
-
version: currentVersion
|
|
1721
|
-
};
|
|
1722
|
-
}
|
|
1772
|
+
// src/process/get-next-version.ts
|
|
1723
1773
|
async function getNextVersion(config, logger, commits, currentVersion) {
|
|
1724
1774
|
if (config.skipBump) {
|
|
1725
1775
|
logger.warn(`Skip bump, using ${currentVersion} as the next version`);
|
|
@@ -1745,6 +1795,9 @@ async function getNextVersion(config, logger, commits, currentVersion) {
|
|
|
1745
1795
|
let level = 2;
|
|
1746
1796
|
const MINOR_TYPES = ["feat", "feature"];
|
|
1747
1797
|
for (const commit of commits) {
|
|
1798
|
+
if (commit.merge || commit.revert) {
|
|
1799
|
+
continue;
|
|
1800
|
+
}
|
|
1748
1801
|
if (commit.notes.length > 0 || commit.breakingChange) {
|
|
1749
1802
|
changes.major += commit.notes.length + (commit.breakingChange ? 1 : 0);
|
|
1750
1803
|
level = 0;
|
|
@@ -1919,6 +1972,29 @@ async function tagChanges(config, logger, git, nextVersion) {
|
|
|
1919
1972
|
);
|
|
1920
1973
|
}
|
|
1921
1974
|
|
|
1975
|
+
// src/commands/main.ts
|
|
1976
|
+
async function main(config, logger, fileManager, git) {
|
|
1977
|
+
logger.log(`Running fork-version - ${(/* @__PURE__ */ new Date()).toUTCString()}`);
|
|
1978
|
+
logger.warn(config.dryRun ? "[Dry Run] No changes will be written to disk.\n" : "");
|
|
1979
|
+
const commits = await getCommitsSinceTag(config, logger, git);
|
|
1980
|
+
const current = await getCurrentVersion(config, logger, git, fileManager, config.files);
|
|
1981
|
+
const next = await getNextVersion(config, logger, commits.commits, current.version);
|
|
1982
|
+
logger.log("Updating files: ");
|
|
1983
|
+
for (const outFile of current.files) {
|
|
1984
|
+
logger.log(` - ${outFile.path}`);
|
|
1985
|
+
fileManager.write(outFile, next.version);
|
|
1986
|
+
}
|
|
1987
|
+
await updateChangelog(config, logger, next.version);
|
|
1988
|
+
await commitChanges(config, logger, git, current.files, next.version);
|
|
1989
|
+
await tagChanges(config, logger, git, next.version);
|
|
1990
|
+
return {
|
|
1991
|
+
config,
|
|
1992
|
+
commits,
|
|
1993
|
+
current,
|
|
1994
|
+
next
|
|
1995
|
+
};
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1922
1998
|
exports.CommitParser = CommitParser;
|
|
1923
1999
|
exports.FileManager = FileManager;
|
|
1924
2000
|
exports.ForkConfigSchema = ForkConfigSchema;
|
|
@@ -1931,7 +2007,11 @@ exports.getCommitsSinceTag = getCommitsSinceTag;
|
|
|
1931
2007
|
exports.getCurrentVersion = getCurrentVersion;
|
|
1932
2008
|
exports.getNextVersion = getNextVersion;
|
|
1933
2009
|
exports.getUserConfig = getUserConfig;
|
|
2010
|
+
exports.inspectTag = inspectTag;
|
|
2011
|
+
exports.inspectVersion = inspectVersion;
|
|
2012
|
+
exports.main = main;
|
|
1934
2013
|
exports.tagChanges = tagChanges;
|
|
1935
2014
|
exports.updateChangelog = updateChangelog;
|
|
1936
|
-
|
|
1937
|
-
//# sourceMappingURL=chunk-
|
|
2015
|
+
exports.validateConfig = validateConfig;
|
|
2016
|
+
//# sourceMappingURL=chunk-BPV4HZ7U.cjs.map
|
|
2017
|
+
//# sourceMappingURL=chunk-BPV4HZ7U.cjs.map
|