fork-version 3.0.2 → 3.1.4
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 +30 -0
- package/README.md +29 -6
- package/dist/{chunk-YSWJMT7B.cjs → chunk-2VYOEMMB.cjs} +162 -60
- package/dist/chunk-2VYOEMMB.cjs.map +1 -0
- package/dist/{chunk-AZZVHG2X.js → chunk-4NLPWDCQ.js} +159 -61
- package/dist/chunk-4NLPWDCQ.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 +475 -343
- package/dist/index.d.ts +475 -343
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-AZZVHG2X.js.map +0 -1
- package/dist/chunk-YSWJMT7B.cjs.map +0 -1
|
@@ -73,11 +73,26 @@ var ChangelogPresetConfigSchema = z.object({
|
|
|
73
73
|
var ForkConfigSchema = z.object({
|
|
74
74
|
// Commands
|
|
75
75
|
//
|
|
76
|
+
/**
|
|
77
|
+
* The command to run, can be one of the following:
|
|
78
|
+
*
|
|
79
|
+
* - `main` - Bumps the version, update files, generate changelog, commit, and tag.
|
|
80
|
+
* - `inspect-version` - Prints the current version and exits.
|
|
81
|
+
* - `inspect-tag` - Prints the current git tag and exits.
|
|
82
|
+
* - `validate-config` - Validates the configuration and exits.
|
|
83
|
+
*
|
|
84
|
+
* @default "main"
|
|
85
|
+
*/
|
|
86
|
+
command: z.literal(["main", "inspect-version", "inspect-tag", "validate-config"]).describe(
|
|
87
|
+
"The command to run. Can be one of: main, inspect-version, inspect-tag, validate-config. Defaults to main."
|
|
88
|
+
),
|
|
76
89
|
/**
|
|
77
90
|
* If set, Fork-Version will print the current version and exit.
|
|
78
91
|
* @default false
|
|
92
|
+
*
|
|
93
|
+
* @deprecated Set the `inspect-version` command instead.
|
|
79
94
|
*/
|
|
80
|
-
inspectVersion: z.boolean().describe("If set, Fork-Version will print the current version and exit."),
|
|
95
|
+
inspectVersion: z.boolean().optional().describe("If set, Fork-Version will print the current version and exit."),
|
|
81
96
|
// Options
|
|
82
97
|
//
|
|
83
98
|
/**
|
|
@@ -266,6 +281,13 @@ var ForkConfigSchema = z.object({
|
|
|
266
281
|
*/
|
|
267
282
|
releaseMessageSuffix: z.string().optional().describe("Add a suffix to the release commit message.")
|
|
268
283
|
});
|
|
284
|
+
|
|
285
|
+
// src/utils/escape-regex.ts
|
|
286
|
+
function escapeRegex(input) {
|
|
287
|
+
return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// src/services/git.ts
|
|
269
291
|
var Git = class {
|
|
270
292
|
constructor(config) {
|
|
271
293
|
this.config = config;
|
|
@@ -446,12 +468,13 @@ var Git = class {
|
|
|
446
468
|
const logOutput = await this.log("--decorate", "--no-color", "--date-order");
|
|
447
469
|
const TAG_REGEX = /tag:\s*(?<tag>.+?)[,)]/gi;
|
|
448
470
|
const tags = [];
|
|
471
|
+
const escapedTagPrefix = tagPrefix ? escapeRegex(tagPrefix) : void 0;
|
|
449
472
|
let tagMatch = null;
|
|
450
473
|
while (tagMatch = TAG_REGEX.exec(logOutput)) {
|
|
451
474
|
const { tag = "" } = tagMatch.groups ?? {};
|
|
452
475
|
if (tagPrefix) {
|
|
453
476
|
if (tag.startsWith(tagPrefix)) {
|
|
454
|
-
const tagWithoutPrefix = tag.replace(new RegExp(`^${
|
|
477
|
+
const tagWithoutPrefix = tag.replace(new RegExp(`^${escapedTagPrefix}`), "");
|
|
455
478
|
if (semver.valid(tagWithoutPrefix)) {
|
|
456
479
|
tags.push(tag);
|
|
457
480
|
}
|
|
@@ -484,9 +507,10 @@ var Git = class {
|
|
|
484
507
|
*/
|
|
485
508
|
async getCleanedTags(tagPrefix) {
|
|
486
509
|
const tags = await this.getTags(tagPrefix);
|
|
510
|
+
const escapedTagPrefix = tagPrefix ? escapeRegex(tagPrefix) : void 0;
|
|
487
511
|
const cleanedTags = [];
|
|
488
512
|
for (const tag of tags) {
|
|
489
|
-
const tagWithoutPrefix = tag.replace(new RegExp(`^${
|
|
513
|
+
const tagWithoutPrefix = tag.replace(new RegExp(`^${escapedTagPrefix}`), "");
|
|
490
514
|
const cleanedTag = semver.clean(tagWithoutPrefix);
|
|
491
515
|
if (cleanedTag) {
|
|
492
516
|
cleanedTags.push(cleanedTag);
|
|
@@ -534,6 +558,8 @@ var Git = class {
|
|
|
534
558
|
// body
|
|
535
559
|
"%H",
|
|
536
560
|
// hash
|
|
561
|
+
"%d",
|
|
562
|
+
// ref names
|
|
537
563
|
"%cI",
|
|
538
564
|
// committer date
|
|
539
565
|
"%cN",
|
|
@@ -628,7 +654,7 @@ function getChangelogPresetConfig(mergedConfig, cliArguments, detectedGitHost) {
|
|
|
628
654
|
// src/config/defaults.ts
|
|
629
655
|
var DEFAULT_CONFIG = {
|
|
630
656
|
// Commands
|
|
631
|
-
|
|
657
|
+
command: "main",
|
|
632
658
|
// Options
|
|
633
659
|
files: [
|
|
634
660
|
"package.json",
|
|
@@ -764,12 +790,12 @@ function mergeFiles(configFiles, cliFiles, globResults) {
|
|
|
764
790
|
|
|
765
791
|
// src/config/user-config.ts
|
|
766
792
|
async function getUserConfig(cliArguments) {
|
|
767
|
-
const cwd = cliArguments.path ? resolve(cliArguments.path) : process.cwd();
|
|
793
|
+
const cwd = cliArguments.flags.path ? resolve(cliArguments.flags.path) : process.cwd();
|
|
768
794
|
const configFile = await loadConfigFile(cwd);
|
|
769
795
|
const mergedConfig = {
|
|
770
796
|
...DEFAULT_CONFIG,
|
|
771
797
|
...configFile,
|
|
772
|
-
...cliArguments
|
|
798
|
+
...cliArguments.flags
|
|
773
799
|
};
|
|
774
800
|
let globResults = [];
|
|
775
801
|
if (mergedConfig.glob) {
|
|
@@ -779,21 +805,33 @@ async function getUserConfig(cliArguments) {
|
|
|
779
805
|
nodir: true
|
|
780
806
|
});
|
|
781
807
|
}
|
|
782
|
-
const files = mergeFiles(configFile?.files, cliArguments
|
|
808
|
+
const files = mergeFiles(configFile?.files, cliArguments.flags.files, globResults);
|
|
783
809
|
const detectedGitHost = await detectGitHost(cwd);
|
|
784
810
|
const changelogPresetConfig = getChangelogPresetConfig(
|
|
785
811
|
mergedConfig,
|
|
786
|
-
cliArguments,
|
|
812
|
+
cliArguments.flags,
|
|
787
813
|
detectedGitHost
|
|
788
814
|
);
|
|
815
|
+
let command = DEFAULT_CONFIG.command;
|
|
816
|
+
if (cliArguments.input.length > 0 && cliArguments.input[0].trim()) {
|
|
817
|
+
command = cliArguments.input[0].trim().toLowerCase();
|
|
818
|
+
} else if (mergedConfig.command.trim()) {
|
|
819
|
+
command = mergedConfig.command.trim().toLowerCase();
|
|
820
|
+
}
|
|
821
|
+
if (mergedConfig.inspectVersion) {
|
|
822
|
+
command = "inspect-version";
|
|
823
|
+
}
|
|
824
|
+
const shouldBeSilent = ![DEFAULT_CONFIG.command].includes(command);
|
|
789
825
|
return {
|
|
790
826
|
...mergedConfig,
|
|
827
|
+
command,
|
|
791
828
|
files,
|
|
792
829
|
path: cwd,
|
|
793
830
|
preRelease: (
|
|
794
831
|
// Meow doesn't support multiple flags with the same name, so we need to check both.
|
|
795
|
-
cliArguments.preReleaseTag ?? cliArguments.preRelease ?? configFile.preRelease
|
|
832
|
+
cliArguments.flags.preReleaseTag ?? cliArguments.flags.preRelease ?? configFile.preRelease
|
|
796
833
|
),
|
|
834
|
+
silent: shouldBeSilent || mergedConfig.silent,
|
|
797
835
|
changelogPresetConfig
|
|
798
836
|
};
|
|
799
837
|
}
|
|
@@ -806,7 +844,7 @@ var Logger = class {
|
|
|
806
844
|
this.warn = this.warn.bind(this);
|
|
807
845
|
this.error = this.error.bind(this);
|
|
808
846
|
this.debug = this.debug.bind(this);
|
|
809
|
-
this.disableLogs = this.config.silent
|
|
847
|
+
this.disableLogs = this.config.silent;
|
|
810
848
|
}
|
|
811
849
|
disableLogs = false;
|
|
812
850
|
log(...messages) {
|
|
@@ -1142,6 +1180,76 @@ var FileManager = class {
|
|
|
1142
1180
|
}
|
|
1143
1181
|
};
|
|
1144
1182
|
|
|
1183
|
+
// src/commands/validate-config.ts
|
|
1184
|
+
function validateConfig(config) {
|
|
1185
|
+
console.log(`
|
|
1186
|
+
\u2699\uFE0F Configuration:
|
|
1187
|
+
${JSON.stringify(config, null, 2)}
|
|
1188
|
+
|
|
1189
|
+
\u2705 Configuration is valid.
|
|
1190
|
+
`);
|
|
1191
|
+
}
|
|
1192
|
+
async function getCurrentVersion(config, logger, git, fileManager, filesToUpdate) {
|
|
1193
|
+
const files = [];
|
|
1194
|
+
const versions = /* @__PURE__ */ new Set();
|
|
1195
|
+
for (const file of filesToUpdate) {
|
|
1196
|
+
if (await git.isIgnored(file)) {
|
|
1197
|
+
logger.debug(`[Git Ignored] ${file}`);
|
|
1198
|
+
continue;
|
|
1199
|
+
}
|
|
1200
|
+
const fileState = fileManager.read(file);
|
|
1201
|
+
if (fileState) {
|
|
1202
|
+
files.push(fileState);
|
|
1203
|
+
if (!config.currentVersion) {
|
|
1204
|
+
versions.add(fileState.version);
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
if (config.currentVersion) {
|
|
1209
|
+
versions.add(config.currentVersion);
|
|
1210
|
+
}
|
|
1211
|
+
if (versions.size === 0 && config.gitTagFallback) {
|
|
1212
|
+
const version = await git.getHighestSemverVersionFromTags(config.tagPrefix);
|
|
1213
|
+
if (version) {
|
|
1214
|
+
logger.warn(`Using latest git tag as fallback`);
|
|
1215
|
+
versions.add(version);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
if (versions.size === 0) {
|
|
1219
|
+
throw new Error("Unable to find current version");
|
|
1220
|
+
} else if (versions.size > 1) {
|
|
1221
|
+
if (!config.allowMultipleVersions) {
|
|
1222
|
+
throw new Error("Found multiple versions");
|
|
1223
|
+
}
|
|
1224
|
+
logger.warn(
|
|
1225
|
+
`Found multiple versions (${Array.from(versions).join(", ")}), using the higher semver version`
|
|
1226
|
+
);
|
|
1227
|
+
}
|
|
1228
|
+
const currentVersion = semver.rsort(Array.from(versions))[0];
|
|
1229
|
+
logger.log(`Current version: ${currentVersion}`);
|
|
1230
|
+
return {
|
|
1231
|
+
files,
|
|
1232
|
+
version: currentVersion
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
// src/commands/inspect-version.ts
|
|
1237
|
+
async function inspectVersion(config, logger, fileManager, git) {
|
|
1238
|
+
let foundVersion = "";
|
|
1239
|
+
try {
|
|
1240
|
+
const currentVersion = await getCurrentVersion(config, logger, git, fileManager, config.files);
|
|
1241
|
+
if (currentVersion) foundVersion = currentVersion.version;
|
|
1242
|
+
} catch {
|
|
1243
|
+
}
|
|
1244
|
+
console.log(foundVersion);
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
// src/commands/inspect-tag.ts
|
|
1248
|
+
async function inspectTag(config, git) {
|
|
1249
|
+
const tag = await git.getMostRecentTag(config.tagPrefix);
|
|
1250
|
+
console.log(tag ?? "");
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1145
1253
|
// src/utils/trim-string-array.ts
|
|
1146
1254
|
function trimStringArray(array) {
|
|
1147
1255
|
const items = [];
|
|
@@ -1240,6 +1348,7 @@ var CommitParser = class {
|
|
|
1240
1348
|
subject: "",
|
|
1241
1349
|
body: "",
|
|
1242
1350
|
hash: "",
|
|
1351
|
+
refNames: "",
|
|
1243
1352
|
date: "",
|
|
1244
1353
|
name: "",
|
|
1245
1354
|
email: "",
|
|
@@ -1251,7 +1360,8 @@ var CommitParser = class {
|
|
|
1251
1360
|
revert: null,
|
|
1252
1361
|
notes: [],
|
|
1253
1362
|
mentions: [],
|
|
1254
|
-
references: []
|
|
1363
|
+
references: [],
|
|
1364
|
+
tags: []
|
|
1255
1365
|
};
|
|
1256
1366
|
}
|
|
1257
1367
|
/**
|
|
@@ -1274,6 +1384,7 @@ var CommitParser = class {
|
|
|
1274
1384
|
const email = parts.pop();
|
|
1275
1385
|
const name = parts.pop();
|
|
1276
1386
|
const date = parts.pop();
|
|
1387
|
+
const refNames = parts.pop();
|
|
1277
1388
|
const hash = parts.pop();
|
|
1278
1389
|
if (email) parsedCommit.email = email.trim();
|
|
1279
1390
|
if (name) parsedCommit.name = name.trim();
|
|
@@ -1283,6 +1394,17 @@ var CommitParser = class {
|
|
|
1283
1394
|
throw new ParserError("Unable to parse commit date", rawCommit);
|
|
1284
1395
|
}
|
|
1285
1396
|
}
|
|
1397
|
+
if (refNames) {
|
|
1398
|
+
parsedCommit.refNames = refNames.trim();
|
|
1399
|
+
const TAG_REGEX = /tag:\s*(?<tag>.+?)[,)]/gi;
|
|
1400
|
+
let tagMatch = null;
|
|
1401
|
+
while (tagMatch = TAG_REGEX.exec(refNames)) {
|
|
1402
|
+
const { tag = "" } = tagMatch.groups ?? {};
|
|
1403
|
+
if (tag) {
|
|
1404
|
+
parsedCommit.tags.push(tag);
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1286
1408
|
if (hash) parsedCommit.hash = hash.trim();
|
|
1287
1409
|
const subject = parts.shift()?.trimStart();
|
|
1288
1410
|
if (subject) {
|
|
@@ -1616,53 +1738,6 @@ async function getCommitsSinceTag(config, logger, git) {
|
|
|
1616
1738
|
commits: filteredCommits
|
|
1617
1739
|
};
|
|
1618
1740
|
}
|
|
1619
|
-
async function getCurrentVersion(config, logger, git, fileManager, filesToUpdate) {
|
|
1620
|
-
const files = [];
|
|
1621
|
-
const versions = /* @__PURE__ */ new Set();
|
|
1622
|
-
for (const file of filesToUpdate) {
|
|
1623
|
-
if (await git.isIgnored(file)) {
|
|
1624
|
-
logger.debug(`[Git Ignored] ${file}`);
|
|
1625
|
-
continue;
|
|
1626
|
-
}
|
|
1627
|
-
const fileState = fileManager.read(file);
|
|
1628
|
-
if (fileState) {
|
|
1629
|
-
files.push(fileState);
|
|
1630
|
-
if (!config.currentVersion) {
|
|
1631
|
-
versions.add(fileState.version);
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1635
|
-
if (config.currentVersion) {
|
|
1636
|
-
versions.add(config.currentVersion);
|
|
1637
|
-
}
|
|
1638
|
-
if (versions.size === 0 && config.gitTagFallback) {
|
|
1639
|
-
const version = await git.getHighestSemverVersionFromTags(config.tagPrefix);
|
|
1640
|
-
if (version) {
|
|
1641
|
-
logger.warn(`Using latest git tag as fallback`);
|
|
1642
|
-
versions.add(version);
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
if (versions.size === 0) {
|
|
1646
|
-
throw new Error("Unable to find current version");
|
|
1647
|
-
} else if (versions.size > 1) {
|
|
1648
|
-
if (!config.allowMultipleVersions) {
|
|
1649
|
-
throw new Error("Found multiple versions");
|
|
1650
|
-
}
|
|
1651
|
-
logger.warn(
|
|
1652
|
-
`Found multiple versions (${Array.from(versions).join(", ")}), using the higher semver version`
|
|
1653
|
-
);
|
|
1654
|
-
}
|
|
1655
|
-
const currentVersion = semver.rsort(Array.from(versions))[0];
|
|
1656
|
-
if (config.inspectVersion) {
|
|
1657
|
-
console.log(currentVersion);
|
|
1658
|
-
process.exit(0);
|
|
1659
|
-
}
|
|
1660
|
-
logger.log(`Current version: ${currentVersion}`);
|
|
1661
|
-
return {
|
|
1662
|
-
files,
|
|
1663
|
-
version: currentVersion
|
|
1664
|
-
};
|
|
1665
|
-
}
|
|
1666
1741
|
function getPriority(type) {
|
|
1667
1742
|
return ["patch", "minor", "major"].indexOf(type ?? "");
|
|
1668
1743
|
}
|
|
@@ -1894,6 +1969,29 @@ async function tagChanges(config, logger, git, nextVersion) {
|
|
|
1894
1969
|
);
|
|
1895
1970
|
}
|
|
1896
1971
|
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1972
|
+
// src/commands/main.ts
|
|
1973
|
+
async function main(config, logger, fileManager, git) {
|
|
1974
|
+
logger.log(`Running fork-version - ${(/* @__PURE__ */ new Date()).toUTCString()}`);
|
|
1975
|
+
logger.warn(config.dryRun ? "[Dry Run] No changes will be written to disk.\n" : "");
|
|
1976
|
+
const commits = await getCommitsSinceTag(config, logger, git);
|
|
1977
|
+
const current = await getCurrentVersion(config, logger, git, fileManager, config.files);
|
|
1978
|
+
const next = await getNextVersion(config, logger, commits.commits, current.version);
|
|
1979
|
+
logger.log("Updating files: ");
|
|
1980
|
+
for (const outFile of current.files) {
|
|
1981
|
+
logger.log(` - ${outFile.path}`);
|
|
1982
|
+
fileManager.write(outFile, next.version);
|
|
1983
|
+
}
|
|
1984
|
+
await updateChangelog(config, logger, next.version);
|
|
1985
|
+
await commitChanges(config, logger, git, current.files, next.version);
|
|
1986
|
+
await tagChanges(config, logger, git, next.version);
|
|
1987
|
+
return {
|
|
1988
|
+
config,
|
|
1989
|
+
commits,
|
|
1990
|
+
current,
|
|
1991
|
+
next
|
|
1992
|
+
};
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
export { CommitParser, FileManager, ForkConfigSchema, Git, Logger, commitChanges, createParserOptions, filterRevertedCommits, getCommitsSinceTag, getCurrentVersion, getNextVersion, getUserConfig, inspectTag, inspectVersion, main, tagChanges, updateChangelog, validateConfig };
|
|
1996
|
+
//# sourceMappingURL=chunk-4NLPWDCQ.js.map
|
|
1997
|
+
//# sourceMappingURL=chunk-4NLPWDCQ.js.map
|