fork-version 4.1.4 → 4.1.8
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 +40 -0
- package/README.md +38 -4
- package/dist/{chunk-CISRFIID.cjs → chunk-KRGBUNRK.cjs} +362 -167
- package/dist/chunk-KRGBUNRK.cjs.map +1 -0
- package/dist/{chunk-I76EAKJC.js → chunk-X4NB24VR.js} +361 -165
- package/dist/chunk-X4NB24VR.js.map +1 -0
- package/dist/cli.cjs +16 -15
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +10 -9
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +19 -23
- package/dist/index.d.cts +142 -189
- package/dist/index.d.ts +142 -189
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-CISRFIID.cjs.map +0 -1
- package/dist/chunk-I76EAKJC.js.map +0 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var zod = require('zod');
|
|
4
4
|
var child_process = require('child_process');
|
|
5
|
-
var
|
|
5
|
+
var semver5 = require('semver');
|
|
6
6
|
var path = require('path');
|
|
7
7
|
var promises = require('fs/promises');
|
|
8
8
|
var conventionalChangelogConfigSpec = require('conventional-changelog-config-spec');
|
|
@@ -35,7 +35,7 @@ function _interopNamespace(e) {
|
|
|
35
35
|
return Object.freeze(n);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
var
|
|
38
|
+
var semver5__default = /*#__PURE__*/_interopDefault(semver5);
|
|
39
39
|
var conventionalChangelogConfigSpec__default = /*#__PURE__*/_interopDefault(conventionalChangelogConfigSpec);
|
|
40
40
|
var JoyCon__default = /*#__PURE__*/_interopDefault(JoyCon);
|
|
41
41
|
var cheerio__namespace = /*#__PURE__*/_interopNamespace(cheerio);
|
|
@@ -108,12 +108,13 @@ var ForkConfigSchema = zod.z.object({
|
|
|
108
108
|
* - `main` - Bumps the version, update files, generate changelog, commit, and tag.
|
|
109
109
|
* - `inspect-version` - Prints the current version and exits.
|
|
110
110
|
* - `inspect-tag` - Prints the current git tag and exits.
|
|
111
|
+
* - `inspect` - Prints the current version and git tag and exits.
|
|
111
112
|
* - `validate-config` - Validates the configuration and exits.
|
|
112
113
|
*
|
|
113
114
|
* @default "main"
|
|
114
115
|
*/
|
|
115
|
-
command: zod.z.literal(["main", "inspect-version", "inspect-tag", "validate-config"]).describe(
|
|
116
|
-
"The command to run. Can be one of: main, inspect-version, inspect-tag, validate-config. Defaults to main."
|
|
116
|
+
command: zod.z.literal(["main", "inspect", "inspect-version", "inspect-tag", "validate-config"]).describe(
|
|
117
|
+
"The command to run. Can be one of: main, inspect, inspect-version, inspect-tag, validate-config. Defaults to main."
|
|
117
118
|
),
|
|
118
119
|
/**
|
|
119
120
|
* If set, Fork-Version will print the current version and exit.
|
|
@@ -276,6 +277,11 @@ var ForkConfigSchema = zod.z.object({
|
|
|
276
277
|
* @default false
|
|
277
278
|
*/
|
|
278
279
|
verify: zod.z.boolean().describe("If true, git will run user defined git hooks before committing."),
|
|
280
|
+
/**
|
|
281
|
+
* Print inspected output as a parsable json string.
|
|
282
|
+
* @default false
|
|
283
|
+
*/
|
|
284
|
+
asJson: zod.z.boolean().describe("Print inspected output as a parsable json string."),
|
|
279
285
|
// Skip Steps
|
|
280
286
|
//
|
|
281
287
|
/**
|
|
@@ -298,17 +304,34 @@ var ForkConfigSchema = zod.z.object({
|
|
|
298
304
|
* @default false
|
|
299
305
|
*/
|
|
300
306
|
skipTag: zod.z.boolean().describe("Skip the tag step."),
|
|
307
|
+
// Parser Options
|
|
308
|
+
//
|
|
309
|
+
/**
|
|
310
|
+
* The detected git host:
|
|
311
|
+
* - `GitHub`
|
|
312
|
+
* - `GitLab`
|
|
313
|
+
* - `Bitbucket`
|
|
314
|
+
* - `Azure Devops`
|
|
315
|
+
* - Or undefined if unknown or not detected.
|
|
316
|
+
*/
|
|
317
|
+
detectedGitHost: zod.z.string().optional().describe(
|
|
318
|
+
"The detected git host, such as GitHub, GitLab, Bitbucket, Azure Devops, or undefined if unknown or not detected."
|
|
319
|
+
),
|
|
301
320
|
/**
|
|
302
321
|
* Override the default "conventional-changelog-conventionalcommits" preset configuration.
|
|
303
322
|
*/
|
|
304
|
-
changelogPresetConfig: ChangelogPresetConfigSchema.partial().describe(
|
|
323
|
+
changelogPresetConfig: ChangelogPresetConfigSchema.partial().optional().describe(
|
|
305
324
|
'Override the default "conventional-changelog-conventionalcommits" preset configuration.'
|
|
306
325
|
),
|
|
307
326
|
/**
|
|
308
327
|
* Add a suffix to the release commit message.
|
|
309
328
|
* @example "[skip ci]"
|
|
310
329
|
*/
|
|
311
|
-
releaseMessageSuffix: zod.z.string().optional().describe("Add a suffix to the release commit message.")
|
|
330
|
+
releaseMessageSuffix: zod.z.string().optional().describe("Add a suffix to the release commit message."),
|
|
331
|
+
/**
|
|
332
|
+
* Options to pass to commits parser.
|
|
333
|
+
*/
|
|
334
|
+
commitParserOptions: zod.z.looseObject().optional().describe("Options to pass to commits parser.")
|
|
312
335
|
});
|
|
313
336
|
|
|
314
337
|
// src/utils/escape-regex.ts
|
|
@@ -318,8 +341,11 @@ function escapeRegex(input) {
|
|
|
318
341
|
|
|
319
342
|
// src/services/git.ts
|
|
320
343
|
var Git = class {
|
|
344
|
+
#path;
|
|
345
|
+
#dryRun;
|
|
321
346
|
constructor(config) {
|
|
322
|
-
this
|
|
347
|
+
this.#path = config.path;
|
|
348
|
+
this.#dryRun = config.dryRun ?? false;
|
|
323
349
|
this.add = this.add.bind(this);
|
|
324
350
|
this.commit = this.commit.bind(this);
|
|
325
351
|
this.tag = this.tag.bind(this);
|
|
@@ -329,8 +355,6 @@ var Git = class {
|
|
|
329
355
|
this.getRemoteUrl = this.getRemoteUrl.bind(this);
|
|
330
356
|
this.getTags = this.getTags.bind(this);
|
|
331
357
|
this.getMostRecentTag = this.getMostRecentTag.bind(this);
|
|
332
|
-
this.getCleanedTags = this.getCleanedTags.bind(this);
|
|
333
|
-
this.getHighestSemverVersionFromTags = this.getHighestSemverVersionFromTags.bind(this);
|
|
334
358
|
this.getCommits = this.getCommits.bind(this);
|
|
335
359
|
}
|
|
336
360
|
async #execGit(command, args) {
|
|
@@ -339,7 +363,7 @@ var Git = class {
|
|
|
339
363
|
"git",
|
|
340
364
|
[command, ...args],
|
|
341
365
|
{
|
|
342
|
-
cwd: this
|
|
366
|
+
cwd: this.#path,
|
|
343
367
|
maxBuffer: Infinity
|
|
344
368
|
},
|
|
345
369
|
(error, stdout, stderr) => {
|
|
@@ -363,7 +387,7 @@ var Git = class {
|
|
|
363
387
|
* ```
|
|
364
388
|
*/
|
|
365
389
|
async add(...args) {
|
|
366
|
-
if (this
|
|
390
|
+
if (this.#dryRun) {
|
|
367
391
|
return "";
|
|
368
392
|
}
|
|
369
393
|
return this.#execGit("add", args.filter(Boolean));
|
|
@@ -379,7 +403,7 @@ var Git = class {
|
|
|
379
403
|
* ```
|
|
380
404
|
*/
|
|
381
405
|
async commit(...args) {
|
|
382
|
-
if (this
|
|
406
|
+
if (this.#dryRun) {
|
|
383
407
|
return "";
|
|
384
408
|
}
|
|
385
409
|
return this.#execGit("commit", args.filter(Boolean));
|
|
@@ -395,7 +419,7 @@ var Git = class {
|
|
|
395
419
|
* ```
|
|
396
420
|
*/
|
|
397
421
|
async tag(...args) {
|
|
398
|
-
if (this
|
|
422
|
+
if (this.#dryRun) {
|
|
399
423
|
return "";
|
|
400
424
|
}
|
|
401
425
|
return this.#execGit("tag", args.filter(Boolean));
|
|
@@ -504,18 +528,18 @@ var Git = class {
|
|
|
504
528
|
if (tagPrefix) {
|
|
505
529
|
if (tag.startsWith(tagPrefix)) {
|
|
506
530
|
const tagWithoutPrefix = tag.replace(new RegExp(`^${escapedTagPrefix}`), "");
|
|
507
|
-
if (
|
|
531
|
+
if (semver5__default.default.valid(tagWithoutPrefix)) {
|
|
508
532
|
tags.push(tag);
|
|
509
533
|
}
|
|
510
534
|
}
|
|
511
|
-
} else if (/^\d/.test(tag) &&
|
|
535
|
+
} else if (/^\d/.test(tag) && semver5__default.default.valid(tag)) {
|
|
512
536
|
tags.push(tag);
|
|
513
537
|
}
|
|
514
538
|
}
|
|
515
539
|
return tags;
|
|
516
540
|
}
|
|
517
541
|
/**
|
|
518
|
-
* Returns the
|
|
542
|
+
* Returns the most recent tag from the commit history, or `undefined` if no valid semver tags are found
|
|
519
543
|
*
|
|
520
544
|
* @example
|
|
521
545
|
* ```ts
|
|
@@ -526,40 +550,6 @@ var Git = class {
|
|
|
526
550
|
const tags = await this.getTags(tagPrefix);
|
|
527
551
|
return tags[0] || void 0;
|
|
528
552
|
}
|
|
529
|
-
/**
|
|
530
|
-
* Get cleaned semver tags, with any tag prefix's removed
|
|
531
|
-
*
|
|
532
|
-
* @example
|
|
533
|
-
* ```ts
|
|
534
|
-
* await git.getCleanedTags("v"); // ["1.2.3", "1.2.2", "1.2.1"]
|
|
535
|
-
* ```
|
|
536
|
-
*/
|
|
537
|
-
async getCleanedTags(tagPrefix) {
|
|
538
|
-
const tags = await this.getTags(tagPrefix);
|
|
539
|
-
const escapedTagPrefix = tagPrefix ? escapeRegex(tagPrefix) : void 0;
|
|
540
|
-
const cleanedTags = [];
|
|
541
|
-
for (const tag of tags) {
|
|
542
|
-
const tagWithoutPrefix = tag.replace(new RegExp(`^${escapedTagPrefix}`), "");
|
|
543
|
-
const cleanedTag = semver__default.default.clean(tagWithoutPrefix);
|
|
544
|
-
if (cleanedTag) {
|
|
545
|
-
cleanedTags.push(cleanedTag);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
return cleanedTags;
|
|
549
|
-
}
|
|
550
|
-
/**
|
|
551
|
-
* Get the highest semver version from git tags. This will return the highest
|
|
552
|
-
* semver version found for the given tag prefix, regardless of the commit date.
|
|
553
|
-
*
|
|
554
|
-
* @example
|
|
555
|
-
* ```ts
|
|
556
|
-
* await git.getHighestSemverVersionFromTags("v"); // "1.2.3"
|
|
557
|
-
* ```
|
|
558
|
-
*/
|
|
559
|
-
async getHighestSemverVersionFromTags(tagPrefix) {
|
|
560
|
-
const cleanedTags = await this.getCleanedTags(tagPrefix);
|
|
561
|
-
return cleanedTags.sort(semver__default.default.rcompare)[0] || void 0;
|
|
562
|
-
}
|
|
563
553
|
/**
|
|
564
554
|
* Get commit history in a parsable format
|
|
565
555
|
*
|
|
@@ -618,7 +608,7 @@ ${SCISSOR}
|
|
|
618
608
|
return splitCommits;
|
|
619
609
|
}
|
|
620
610
|
};
|
|
621
|
-
function getChangelogPresetConfig(mergedConfig, cliArguments,
|
|
611
|
+
function getChangelogPresetConfig(mergedConfig, cliArguments, detectedChangelogOptions) {
|
|
622
612
|
const preset = {
|
|
623
613
|
name: "conventionalcommits"
|
|
624
614
|
};
|
|
@@ -642,8 +632,8 @@ function getChangelogPresetConfig(mergedConfig, cliArguments, detectedGitHost) {
|
|
|
642
632
|
}
|
|
643
633
|
});
|
|
644
634
|
}
|
|
645
|
-
if (
|
|
646
|
-
Object.entries(
|
|
635
|
+
if (detectedChangelogOptions) {
|
|
636
|
+
Object.entries(detectedChangelogOptions).forEach(([key, value]) => {
|
|
647
637
|
if (value !== void 0) {
|
|
648
638
|
preset[key] = value;
|
|
649
639
|
}
|
|
@@ -714,48 +704,180 @@ All notable changes to this project will be documented in this file. See [fork-v
|
|
|
714
704
|
gitTagFallback: true,
|
|
715
705
|
sign: false,
|
|
716
706
|
verify: false,
|
|
707
|
+
asJson: false,
|
|
717
708
|
// Skip Steps
|
|
718
709
|
skipBump: false,
|
|
719
710
|
skipChangelog: false,
|
|
720
711
|
skipCommit: false,
|
|
721
|
-
skipTag: false
|
|
722
|
-
changelogPresetConfig: {}
|
|
712
|
+
skipTag: false
|
|
723
713
|
};
|
|
724
714
|
|
|
725
|
-
// src/
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
715
|
+
// src/detect-git-host/host-github.ts
|
|
716
|
+
function detectGitHubOptions(remoteUrl) {
|
|
717
|
+
let matches = null;
|
|
718
|
+
if (/^https:\/\/(.*)?github\.com/.test(remoteUrl)) {
|
|
719
|
+
matches = /^https:\/\/(.*)?github\.com\/(?<organisation>.*?)\/(?<repository>.*?)(?:\.git)?$/.exec(
|
|
720
|
+
remoteUrl
|
|
721
|
+
);
|
|
722
|
+
} else if (remoteUrl.startsWith("git@github.com:")) {
|
|
723
|
+
matches = /^git@github\.com:(?<organisation>.*?)\/(?<repository>.*?)(?:\.git)?$/.exec(
|
|
724
|
+
remoteUrl
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
if (matches?.groups) {
|
|
728
|
+
const { organisation = "", repository = "" } = matches.groups;
|
|
729
|
+
return {
|
|
730
|
+
hostName: "GitHub",
|
|
731
|
+
changelogOptions: {
|
|
732
|
+
commitUrlFormat: `https://github.com/${organisation}/${repository}/commit/{{hash}}`,
|
|
733
|
+
compareUrlFormat: `https://github.com/${organisation}/${repository}/compare/{{previousTag}}...{{currentTag}}`,
|
|
734
|
+
issueUrlFormat: `https://github.com/${organisation}/${repository}/issues/{{id}}`,
|
|
735
|
+
issuePrefixes: ["#", "gh-"]
|
|
736
|
+
},
|
|
737
|
+
commitParserOptions: {
|
|
738
|
+
mergePattern: /^Merge pull request #(?<id>\d*) from (?<source>.*)/i,
|
|
739
|
+
issuePrefixes: ["#", "gh-"]
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
return void 0;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// src/detect-git-host/host-gitlab.ts
|
|
747
|
+
function detectGitlabOptions(remoteUrl) {
|
|
748
|
+
let matches = null;
|
|
749
|
+
if (/^https:\/\/(.*)?gitlab\.com/.test(remoteUrl)) {
|
|
750
|
+
matches = /^https:\/\/(.*)?gitlab\.com\/(?<organisation>.*?)\/(?<repository>.*?)(?:\.git)?$/.exec(
|
|
751
|
+
remoteUrl
|
|
752
|
+
);
|
|
753
|
+
} else if (remoteUrl.startsWith("git@gitlab.com:")) {
|
|
754
|
+
matches = /^git@gitlab\.com:(?<organisation>.*?)\/(?<repository>.*?)(?:\.git)?$/.exec(
|
|
755
|
+
remoteUrl
|
|
756
|
+
);
|
|
757
|
+
}
|
|
758
|
+
if (matches?.groups) {
|
|
759
|
+
const { organisation = "", repository = "" } = matches.groups;
|
|
760
|
+
return {
|
|
761
|
+
hostName: "GitLab",
|
|
762
|
+
changelogOptions: {
|
|
763
|
+
commitUrlFormat: `https://gitlab.com/${organisation}/${repository}/-/commit/{{hash}}`,
|
|
764
|
+
compareUrlFormat: `https://gitlab.com/${organisation}/${repository}/-/compare/{{previousTag}}...{{currentTag}}`,
|
|
765
|
+
issueUrlFormat: `https://gitlab.com/${organisation}/${repository}/-/issues/{{id}}`
|
|
766
|
+
},
|
|
767
|
+
commitParserOptions: {
|
|
768
|
+
mergePattern: /^Merge branch '(?<source>.*)' into '(.*)'/i,
|
|
769
|
+
// https://docs.gitlab.com/user/project/issues/managing_issues/#default-closing-pattern
|
|
770
|
+
referenceActions: [
|
|
771
|
+
"close",
|
|
772
|
+
"closes",
|
|
773
|
+
"closed",
|
|
774
|
+
"closing",
|
|
775
|
+
"fix",
|
|
776
|
+
"fixes",
|
|
777
|
+
"fixed",
|
|
778
|
+
"fixing",
|
|
779
|
+
"resolve",
|
|
780
|
+
"resolves",
|
|
781
|
+
"resolved",
|
|
782
|
+
"resolving",
|
|
783
|
+
"implement",
|
|
784
|
+
"implements",
|
|
785
|
+
"implemented",
|
|
786
|
+
"implementing"
|
|
787
|
+
]
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
return void 0;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
// src/detect-git-host/host-bitbucket.ts
|
|
795
|
+
function detectBitbucketOptions(remoteUrl) {
|
|
796
|
+
let matches = null;
|
|
797
|
+
if (/^https:\/\/(.*)?bitbucket\.(org|com)/.test(remoteUrl)) {
|
|
798
|
+
matches = /^https:\/\/(.*)?bitbucket\.(?<domain>org|com)\/(?<organisation>.*?)\/(?<repository>.*?)(?:\.git)?$/.exec(
|
|
799
|
+
remoteUrl
|
|
800
|
+
);
|
|
801
|
+
} else if (remoteUrl.startsWith("git@bitbucket.org:")) {
|
|
802
|
+
matches = /^git@bitbucket\.(?<domain>org|com):(?<organisation>.*?)\/(?<repository>.*?)(?:\.git)?$/.exec(
|
|
803
|
+
remoteUrl
|
|
804
|
+
);
|
|
805
|
+
}
|
|
806
|
+
if (matches?.groups) {
|
|
807
|
+
const { domain = "", organisation = "", repository = "" } = matches.groups;
|
|
808
|
+
return {
|
|
809
|
+
hostName: "Bitbucket",
|
|
810
|
+
changelogOptions: {
|
|
811
|
+
commitUrlFormat: `https://bitbucket.${domain}/${organisation}/${repository}/commits/{{hash}}`,
|
|
812
|
+
compareUrlFormat: `https://bitbucket.${domain}/${organisation}/${repository}/branches/compare/{{currentTag}}..{{previousTag}}`,
|
|
813
|
+
// Bitbucket doesn't have a builtin issue tracker like GitHub or GitLab, this should be overridden by the user if they want to link to issues in their changelog.
|
|
814
|
+
issueUrlFormat: `https://bitbucket.${domain}/${organisation}/${repository}/issues/{{id}}`
|
|
815
|
+
},
|
|
816
|
+
commitParserOptions: {
|
|
817
|
+
mergePattern: /^Merged in (?<source>.*) \(pull request #(?<id>\d*)\)/i
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
return void 0;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// src/detect-git-host/host-azure-devops.ts
|
|
825
|
+
function detectAzureDevopsOptions(remoteUrl) {
|
|
826
|
+
let matches = null;
|
|
827
|
+
if (/^https:\/\/(.*)?dev\.azure\.com/.test(remoteUrl)) {
|
|
828
|
+
matches = /^https:\/\/(.*)?dev\.azure\.com\/(?<organisation>.*?)\/(?<project>.*?)\/_git\/(?<repository>.*?)(?:\.git)?$/.exec(
|
|
733
829
|
remoteUrl
|
|
734
830
|
);
|
|
735
|
-
if (match?.groups) {
|
|
736
|
-
const { organisation = "", project = "", repository = "" } = match.groups;
|
|
737
|
-
return {
|
|
738
|
-
detectedGitHost: "Azure",
|
|
739
|
-
commitUrlFormat: `{{host}}/${organisation}/${project}/_git/${repository}/commit/{{hash}}`,
|
|
740
|
-
compareUrlFormat: `{{host}}/${organisation}/${project}/_git/${repository}/branchCompare?baseVersion=GT{{previousTag}}&targetVersion=GT{{currentTag}}`,
|
|
741
|
-
issueUrlFormat: `{{host}}/${organisation}/${project}/_workitems/edit/{{id}}`
|
|
742
|
-
};
|
|
743
|
-
}
|
|
744
831
|
} else if (remoteUrl.startsWith("git@ssh.dev.azure.com:")) {
|
|
745
|
-
|
|
832
|
+
matches = /^git@ssh\.dev\.azure\.com:v\d\/(?<organisation>.*?)\/(?<project>.*?)\/(?<repository>.*?)(?:\.git)?$/.exec(
|
|
746
833
|
remoteUrl
|
|
747
834
|
);
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
835
|
+
}
|
|
836
|
+
if (matches?.groups) {
|
|
837
|
+
const { organisation = "", project = "", repository = "" } = matches.groups;
|
|
838
|
+
return {
|
|
839
|
+
hostName: "Azure Devops",
|
|
840
|
+
changelogOptions: {
|
|
841
|
+
commitUrlFormat: `https://dev.azure.com/${organisation}/${project}/_git/${repository}/commit/{{hash}}`,
|
|
842
|
+
compareUrlFormat: `https://dev.azure.com/${organisation}/${project}/_git/${repository}/branchCompare?baseVersion=GT{{previousTag}}&targetVersion=GT{{currentTag}}`,
|
|
843
|
+
issueUrlFormat: `https://dev.azure.com/${organisation}/${project}/_workitems/edit/{{id}}`
|
|
844
|
+
},
|
|
845
|
+
commitParserOptions: {
|
|
846
|
+
mergePattern: /^Merged PR (?<id>\d*): (?<source>.*)/i
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
return void 0;
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
// src/detect-git-host/detect-git-host.ts
|
|
854
|
+
async function detectGitHost(path) {
|
|
855
|
+
const remoteUrl = await new Git({ path }).getRemoteUrl();
|
|
856
|
+
if (remoteUrl.includes("github.com")) {
|
|
857
|
+
const githubOptions = detectGitHubOptions(remoteUrl);
|
|
858
|
+
if (githubOptions) {
|
|
859
|
+
return githubOptions;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
if (remoteUrl.includes("gitlab.com")) {
|
|
863
|
+
const gitlabOptions = detectGitlabOptions(remoteUrl);
|
|
864
|
+
if (gitlabOptions) {
|
|
865
|
+
return gitlabOptions;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
if (/bitbucket\.(org|com)/.test(remoteUrl)) {
|
|
869
|
+
const bitbucketOptions = detectBitbucketOptions(remoteUrl);
|
|
870
|
+
if (bitbucketOptions) {
|
|
871
|
+
return bitbucketOptions;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
if (remoteUrl.includes("dev.azure.com")) {
|
|
875
|
+
const azureDevopsOptions = detectAzureDevopsOptions(remoteUrl);
|
|
876
|
+
if (azureDevopsOptions) {
|
|
877
|
+
return azureDevopsOptions;
|
|
756
878
|
}
|
|
757
879
|
}
|
|
758
|
-
return
|
|
880
|
+
return void 0;
|
|
759
881
|
}
|
|
760
882
|
var PACKAGE_JSON_CONFIG_KEY = "fork-version";
|
|
761
883
|
async function loadConfigFile(cwd) {
|
|
@@ -842,11 +964,6 @@ async function getUserConfig(cliArguments) {
|
|
|
842
964
|
}
|
|
843
965
|
const files = mergeFiles(configFile?.files, cliArguments.flags.files, globResults);
|
|
844
966
|
const detectedGitHost = await detectGitHost(cwd);
|
|
845
|
-
const changelogPresetConfig = getChangelogPresetConfig(
|
|
846
|
-
mergedConfig,
|
|
847
|
-
cliArguments.flags,
|
|
848
|
-
detectedGitHost
|
|
849
|
-
);
|
|
850
967
|
let command = DEFAULT_CONFIG.command;
|
|
851
968
|
if (cliArguments.input.length > 0 && cliArguments.input[0].trim()) {
|
|
852
969
|
command = cliArguments.input[0].trim().toLowerCase();
|
|
@@ -867,37 +984,47 @@ async function getUserConfig(cliArguments) {
|
|
|
867
984
|
cliArguments.flags.preReleaseTag ?? cliArguments.flags.preRelease ?? configFile.preRelease
|
|
868
985
|
),
|
|
869
986
|
silent: shouldBeSilent || mergedConfig.silent,
|
|
870
|
-
|
|
987
|
+
detectedGitHost: detectedGitHost?.hostName,
|
|
988
|
+
changelogPresetConfig: getChangelogPresetConfig(
|
|
989
|
+
mergedConfig,
|
|
990
|
+
cliArguments.flags,
|
|
991
|
+
detectedGitHost?.changelogOptions
|
|
992
|
+
),
|
|
993
|
+
commitParserOptions: {
|
|
994
|
+
...detectedGitHost?.commitParserOptions,
|
|
995
|
+
...mergedConfig.commitParserOptions
|
|
996
|
+
}
|
|
871
997
|
};
|
|
872
998
|
}
|
|
873
999
|
var Logger = class {
|
|
1000
|
+
#silent;
|
|
1001
|
+
#debug;
|
|
874
1002
|
constructor(config) {
|
|
875
|
-
this
|
|
1003
|
+
this.#silent = config.silent ?? false;
|
|
1004
|
+
this.#debug = config.debug ?? false;
|
|
876
1005
|
this.log = this.log.bind(this);
|
|
877
1006
|
this.warn = this.warn.bind(this);
|
|
878
1007
|
this.error = this.error.bind(this);
|
|
879
1008
|
this.debug = this.debug.bind(this);
|
|
880
1009
|
this.skipping = this.skipping.bind(this);
|
|
881
|
-
this.disableLogs = this.config.silent;
|
|
882
1010
|
}
|
|
883
|
-
disableLogs = false;
|
|
884
1011
|
log(message) {
|
|
885
|
-
if (!this
|
|
1012
|
+
if (!this.#silent) {
|
|
886
1013
|
console.log(message);
|
|
887
1014
|
}
|
|
888
1015
|
}
|
|
889
1016
|
warn(message) {
|
|
890
|
-
if (!this
|
|
1017
|
+
if (!this.#silent) {
|
|
891
1018
|
console.warn(util.styleText("yellowBright", message));
|
|
892
1019
|
}
|
|
893
1020
|
}
|
|
894
1021
|
error(message) {
|
|
895
|
-
if (!this
|
|
1022
|
+
if (!this.#silent) {
|
|
896
1023
|
console.error(util.styleText("redBright", message));
|
|
897
1024
|
}
|
|
898
1025
|
}
|
|
899
1026
|
debug(message, ...optionalParams) {
|
|
900
|
-
if (this
|
|
1027
|
+
if (!this.#silent && this.#debug) {
|
|
901
1028
|
console.debug(util.styleText("cyanBright", message));
|
|
902
1029
|
if (optionalParams.length > 0) {
|
|
903
1030
|
console.debug(...optionalParams);
|
|
@@ -905,7 +1032,7 @@ var Logger = class {
|
|
|
905
1032
|
}
|
|
906
1033
|
}
|
|
907
1034
|
skipping(message) {
|
|
908
|
-
if (!this
|
|
1035
|
+
if (!this.#silent) {
|
|
909
1036
|
console.log(util.styleText("magenta", message));
|
|
910
1037
|
}
|
|
911
1038
|
}
|
|
@@ -1233,66 +1360,6 @@ ${JSON.stringify(config, null, 2)}
|
|
|
1233
1360
|
\u2705 Configuration is valid.
|
|
1234
1361
|
`);
|
|
1235
1362
|
}
|
|
1236
|
-
async function getCurrentVersion(config, logger, git, fileManager, filesToUpdate) {
|
|
1237
|
-
const files = [];
|
|
1238
|
-
const versions = /* @__PURE__ */ new Set();
|
|
1239
|
-
for (const file of filesToUpdate) {
|
|
1240
|
-
if (await git.isIgnored(file)) {
|
|
1241
|
-
logger.debug(`[Git Ignored] ${file}`);
|
|
1242
|
-
continue;
|
|
1243
|
-
}
|
|
1244
|
-
const fileState = fileManager.read(file);
|
|
1245
|
-
if (fileState) {
|
|
1246
|
-
files.push(fileState);
|
|
1247
|
-
if (!config.currentVersion) {
|
|
1248
|
-
versions.add(fileState.version);
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
if (config.currentVersion) {
|
|
1253
|
-
versions.add(config.currentVersion);
|
|
1254
|
-
}
|
|
1255
|
-
if (versions.size === 0 && config.gitTagFallback) {
|
|
1256
|
-
const version = await git.getHighestSemverVersionFromTags(config.tagPrefix);
|
|
1257
|
-
if (version) {
|
|
1258
|
-
logger.warn(`Using latest git tag as fallback`);
|
|
1259
|
-
versions.add(version);
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
if (versions.size === 0) {
|
|
1263
|
-
throw new Error("Unable to find current version");
|
|
1264
|
-
} else if (versions.size > 1) {
|
|
1265
|
-
if (!config.allowMultipleVersions) {
|
|
1266
|
-
throw new Error("Found multiple versions");
|
|
1267
|
-
}
|
|
1268
|
-
logger.warn(
|
|
1269
|
-
`Found multiple versions (${Array.from(versions).join(", ")}), using the higher semver version`
|
|
1270
|
-
);
|
|
1271
|
-
}
|
|
1272
|
-
const currentVersion = semver__default.default.rsort(Array.from(versions))[0];
|
|
1273
|
-
logger.log(`Current version: ${currentVersion}`);
|
|
1274
|
-
return {
|
|
1275
|
-
files,
|
|
1276
|
-
version: currentVersion
|
|
1277
|
-
};
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
// src/commands/inspect-version.ts
|
|
1281
|
-
async function inspectVersion(config, logger, fileManager, git) {
|
|
1282
|
-
let foundVersion = "";
|
|
1283
|
-
try {
|
|
1284
|
-
const currentVersion = await getCurrentVersion(config, logger, git, fileManager, config.files);
|
|
1285
|
-
if (currentVersion) foundVersion = currentVersion.version;
|
|
1286
|
-
} catch {
|
|
1287
|
-
}
|
|
1288
|
-
console.log(foundVersion);
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
// src/commands/inspect-tag.ts
|
|
1292
|
-
async function inspectTag(config, git) {
|
|
1293
|
-
const tag = await git.getMostRecentTag(config.tagPrefix);
|
|
1294
|
-
console.log(tag ?? "");
|
|
1295
|
-
}
|
|
1296
1363
|
|
|
1297
1364
|
// src/utils/trim-string-array.ts
|
|
1298
1365
|
function trimStringArray(array) {
|
|
@@ -1756,10 +1823,16 @@ function filterRevertedCommits(parsedCommits) {
|
|
|
1756
1823
|
}
|
|
1757
1824
|
return commitsWithoutReverts;
|
|
1758
1825
|
}
|
|
1826
|
+
function cleanTag(tag, tagPrefix) {
|
|
1827
|
+
if (!tag) return void 0;
|
|
1828
|
+
const escapedTagPrefix = tagPrefix ? escapeRegex(tagPrefix) : void 0;
|
|
1829
|
+
const tagWithoutPrefix = escapedTagPrefix ? tag.replace(new RegExp(`^${escapedTagPrefix}`), "") : tag;
|
|
1830
|
+
return semver5__default.default.clean(tagWithoutPrefix) ?? void 0;
|
|
1831
|
+
}
|
|
1759
1832
|
|
|
1760
1833
|
// src/process/get-commits.ts
|
|
1761
1834
|
async function getCommitsSinceTag(config, logger, git) {
|
|
1762
|
-
const commitParser = new CommitParser();
|
|
1835
|
+
const commitParser = new CommitParser(config.commitParserOptions);
|
|
1763
1836
|
if (config.debug) commitParser.setLogger(logger);
|
|
1764
1837
|
const latestTag = await git.getMostRecentTag(config.tagPrefix);
|
|
1765
1838
|
if (!latestTag) {
|
|
@@ -1779,14 +1852,130 @@ async function getCommitsSinceTag(config, logger, git) {
|
|
|
1779
1852
|
);
|
|
1780
1853
|
return {
|
|
1781
1854
|
latestTag,
|
|
1855
|
+
latestTagVersion: cleanTag(latestTag, config.tagPrefix),
|
|
1782
1856
|
commits: filteredCommits
|
|
1783
1857
|
};
|
|
1784
1858
|
}
|
|
1859
|
+
async function getCurrentVersion(config, logger, git, fileManager, filesToUpdate, latestTagVersion) {
|
|
1860
|
+
const files = [];
|
|
1861
|
+
const versions = /* @__PURE__ */ new Set();
|
|
1862
|
+
for (const file of filesToUpdate) {
|
|
1863
|
+
if (await git.isIgnored(file)) {
|
|
1864
|
+
logger.debug(`[Git Ignored] ${file}`);
|
|
1865
|
+
continue;
|
|
1866
|
+
}
|
|
1867
|
+
const fileState = fileManager.read(file);
|
|
1868
|
+
if (fileState) {
|
|
1869
|
+
files.push(fileState);
|
|
1870
|
+
if (!config.currentVersion) {
|
|
1871
|
+
versions.add(fileState.version);
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
if (config.currentVersion) {
|
|
1876
|
+
versions.add(config.currentVersion);
|
|
1877
|
+
}
|
|
1878
|
+
if (versions.size === 0 && config.gitTagFallback && latestTagVersion) {
|
|
1879
|
+
logger.warn(`Using latest git tag as fallback`);
|
|
1880
|
+
versions.add(latestTagVersion);
|
|
1881
|
+
}
|
|
1882
|
+
if (versions.size === 0) {
|
|
1883
|
+
throw new Error("Unable to find current version");
|
|
1884
|
+
} else if (versions.size > 1) {
|
|
1885
|
+
if (!config.allowMultipleVersions) {
|
|
1886
|
+
throw new Error("Found multiple versions");
|
|
1887
|
+
}
|
|
1888
|
+
logger.warn(
|
|
1889
|
+
`Found multiple versions (${Array.from(versions).join(", ")}), using the higher semver version`
|
|
1890
|
+
);
|
|
1891
|
+
}
|
|
1892
|
+
const currentVersion = semver5__default.default.rsort(Array.from(versions))[0];
|
|
1893
|
+
logger.log(`Current version: ${currentVersion}`);
|
|
1894
|
+
return {
|
|
1895
|
+
files,
|
|
1896
|
+
version: currentVersion
|
|
1897
|
+
};
|
|
1898
|
+
}
|
|
1899
|
+
async function inspect(config, logger, fileManager, git) {
|
|
1900
|
+
let latestTag = "";
|
|
1901
|
+
let latestVersion = "";
|
|
1902
|
+
try {
|
|
1903
|
+
const commits = await getCommitsSinceTag(config, logger, git);
|
|
1904
|
+
if (commits.latestTag) {
|
|
1905
|
+
latestTag = commits.latestTag;
|
|
1906
|
+
latestVersion = commits.latestTagVersion ?? "";
|
|
1907
|
+
}
|
|
1908
|
+
const currentVersion = await getCurrentVersion(
|
|
1909
|
+
config,
|
|
1910
|
+
logger,
|
|
1911
|
+
git,
|
|
1912
|
+
fileManager,
|
|
1913
|
+
config.files,
|
|
1914
|
+
latestVersion
|
|
1915
|
+
);
|
|
1916
|
+
if (currentVersion.version) {
|
|
1917
|
+
latestVersion = currentVersion.version;
|
|
1918
|
+
}
|
|
1919
|
+
} catch {
|
|
1920
|
+
}
|
|
1921
|
+
if (!latestVersion && !latestTag) {
|
|
1922
|
+
console.error(
|
|
1923
|
+
util.styleText(
|
|
1924
|
+
"yellowBright",
|
|
1925
|
+
"No version found. Make sure you have at least one tag in your repository."
|
|
1926
|
+
)
|
|
1927
|
+
);
|
|
1928
|
+
process.exit(1);
|
|
1929
|
+
return;
|
|
1930
|
+
}
|
|
1931
|
+
switch (config.command) {
|
|
1932
|
+
case "inspect-version": {
|
|
1933
|
+
console.log(
|
|
1934
|
+
config.asJson ? JSON.stringify(
|
|
1935
|
+
{
|
|
1936
|
+
version: latestVersion
|
|
1937
|
+
},
|
|
1938
|
+
null,
|
|
1939
|
+
2
|
|
1940
|
+
) : latestVersion
|
|
1941
|
+
);
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
case "inspect-tag": {
|
|
1945
|
+
console.log(
|
|
1946
|
+
config.asJson ? JSON.stringify(
|
|
1947
|
+
{
|
|
1948
|
+
tag: latestTag
|
|
1949
|
+
},
|
|
1950
|
+
null,
|
|
1951
|
+
2
|
|
1952
|
+
) : latestTag
|
|
1953
|
+
);
|
|
1954
|
+
return;
|
|
1955
|
+
}
|
|
1956
|
+
default: {
|
|
1957
|
+
console.log(
|
|
1958
|
+
config.asJson ? JSON.stringify(
|
|
1959
|
+
{
|
|
1960
|
+
version: latestVersion,
|
|
1961
|
+
tag: latestTag
|
|
1962
|
+
},
|
|
1963
|
+
null,
|
|
1964
|
+
2
|
|
1965
|
+
) : `
|
|
1966
|
+
Version: ${latestVersion}
|
|
1967
|
+
Tag: ${latestTag}
|
|
1968
|
+
`.trim()
|
|
1969
|
+
);
|
|
1970
|
+
return;
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1785
1974
|
function getPriority(type) {
|
|
1786
1975
|
return ["patch", "minor", "major"].indexOf(type ?? "");
|
|
1787
1976
|
}
|
|
1788
1977
|
function getVersionType(version) {
|
|
1789
|
-
const parseVersion =
|
|
1978
|
+
const parseVersion = semver5__default.default.parse(version);
|
|
1790
1979
|
if (parseVersion?.major) {
|
|
1791
1980
|
return "major";
|
|
1792
1981
|
} else if (parseVersion?.minor) {
|
|
@@ -1800,7 +1989,7 @@ function getReleaseType(releaseType, currentVersion, preReleaseTag) {
|
|
|
1800
1989
|
if (!preReleaseTag) {
|
|
1801
1990
|
return releaseType;
|
|
1802
1991
|
}
|
|
1803
|
-
const currentVersionsIsPreRelease = Array.isArray(
|
|
1992
|
+
const currentVersionsIsPreRelease = Array.isArray(semver5__default.default.prerelease(currentVersion));
|
|
1804
1993
|
if (currentVersionsIsPreRelease) {
|
|
1805
1994
|
const currentReleaseType = getVersionType(currentVersion);
|
|
1806
1995
|
if (currentReleaseType === releaseType || getPriority(currentReleaseType) > getPriority(releaseType)) {
|
|
@@ -1819,7 +2008,7 @@ async function getNextVersion(config, logger, commits, currentVersion) {
|
|
|
1819
2008
|
};
|
|
1820
2009
|
}
|
|
1821
2010
|
if (config.nextVersion) {
|
|
1822
|
-
if (!
|
|
2011
|
+
if (!semver5__default.default.valid(config.nextVersion)) {
|
|
1823
2012
|
throw new Error(`Invalid Version: ${config.nextVersion}`);
|
|
1824
2013
|
}
|
|
1825
2014
|
logger.log(`Next version: ${config.nextVersion}`);
|
|
@@ -1827,7 +2016,7 @@ async function getNextVersion(config, logger, commits, currentVersion) {
|
|
|
1827
2016
|
version: config.nextVersion
|
|
1828
2017
|
};
|
|
1829
2018
|
}
|
|
1830
|
-
const isPreMajor =
|
|
2019
|
+
const isPreMajor = semver5__default.default.lt(currentVersion, "1.0.0");
|
|
1831
2020
|
let releaseType = "patch";
|
|
1832
2021
|
const changes = {
|
|
1833
2022
|
major: 0,
|
|
@@ -1877,7 +2066,7 @@ async function getNextVersion(config, logger, commits, currentVersion) {
|
|
|
1877
2066
|
}
|
|
1878
2067
|
}
|
|
1879
2068
|
const releaseTypeOrPreRelease = getReleaseType(releaseType, currentVersion, config.preRelease);
|
|
1880
|
-
const nextVersion =
|
|
2069
|
+
const nextVersion = semver5__default.default.inc(
|
|
1881
2070
|
currentVersion,
|
|
1882
2071
|
releaseTypeOrPreRelease,
|
|
1883
2072
|
typeof config.preRelease === "string" ? config.preRelease : ""
|
|
@@ -2029,7 +2218,14 @@ async function main(config, logger, fileManager, git) {
|
|
|
2029
2218
|
logger.log(`Running fork-version - ${(/* @__PURE__ */ new Date()).toUTCString()}`);
|
|
2030
2219
|
logger.warn(config.dryRun ? "[Dry Run] No changes will be written to disk.\n" : "");
|
|
2031
2220
|
const commits = await getCommitsSinceTag(config, logger, git);
|
|
2032
|
-
const current = await getCurrentVersion(
|
|
2221
|
+
const current = await getCurrentVersion(
|
|
2222
|
+
config,
|
|
2223
|
+
logger,
|
|
2224
|
+
git,
|
|
2225
|
+
fileManager,
|
|
2226
|
+
config.files,
|
|
2227
|
+
commits.latestTagVersion
|
|
2228
|
+
);
|
|
2033
2229
|
const next = await getNextVersion(config, logger, commits.commits, current.version);
|
|
2034
2230
|
logger.log("Updating files: ");
|
|
2035
2231
|
for (const outFile of current.files) {
|
|
@@ -2059,11 +2255,10 @@ exports.getCommitsSinceTag = getCommitsSinceTag;
|
|
|
2059
2255
|
exports.getCurrentVersion = getCurrentVersion;
|
|
2060
2256
|
exports.getNextVersion = getNextVersion;
|
|
2061
2257
|
exports.getUserConfig = getUserConfig;
|
|
2062
|
-
exports.
|
|
2063
|
-
exports.inspectVersion = inspectVersion;
|
|
2258
|
+
exports.inspect = inspect;
|
|
2064
2259
|
exports.main = main;
|
|
2065
2260
|
exports.tagChanges = tagChanges;
|
|
2066
2261
|
exports.updateChangelog = updateChangelog;
|
|
2067
2262
|
exports.validateConfig = validateConfig;
|
|
2068
|
-
//# sourceMappingURL=chunk-
|
|
2069
|
-
//# sourceMappingURL=chunk-
|
|
2263
|
+
//# sourceMappingURL=chunk-KRGBUNRK.cjs.map
|
|
2264
|
+
//# sourceMappingURL=chunk-KRGBUNRK.cjs.map
|