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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { execFile } from 'child_process';
|
|
3
|
-
import
|
|
3
|
+
import semver5 from 'semver';
|
|
4
4
|
import { resolve, join, isAbsolute, parse, basename } from 'path';
|
|
5
5
|
import { glob } from 'fs/promises';
|
|
6
6
|
import conventionalChangelogConfigSpec from 'conventional-changelog-config-spec';
|
|
@@ -80,12 +80,13 @@ var ForkConfigSchema = z.object({
|
|
|
80
80
|
* - `main` - Bumps the version, update files, generate changelog, commit, and tag.
|
|
81
81
|
* - `inspect-version` - Prints the current version and exits.
|
|
82
82
|
* - `inspect-tag` - Prints the current git tag and exits.
|
|
83
|
+
* - `inspect` - Prints the current version and git tag and exits.
|
|
83
84
|
* - `validate-config` - Validates the configuration and exits.
|
|
84
85
|
*
|
|
85
86
|
* @default "main"
|
|
86
87
|
*/
|
|
87
|
-
command: z.literal(["main", "inspect-version", "inspect-tag", "validate-config"]).describe(
|
|
88
|
-
"The command to run. Can be one of: main, inspect-version, inspect-tag, validate-config. Defaults to main."
|
|
88
|
+
command: z.literal(["main", "inspect", "inspect-version", "inspect-tag", "validate-config"]).describe(
|
|
89
|
+
"The command to run. Can be one of: main, inspect, inspect-version, inspect-tag, validate-config. Defaults to main."
|
|
89
90
|
),
|
|
90
91
|
/**
|
|
91
92
|
* If set, Fork-Version will print the current version and exit.
|
|
@@ -248,6 +249,11 @@ var ForkConfigSchema = z.object({
|
|
|
248
249
|
* @default false
|
|
249
250
|
*/
|
|
250
251
|
verify: z.boolean().describe("If true, git will run user defined git hooks before committing."),
|
|
252
|
+
/**
|
|
253
|
+
* Print inspected output as a parsable json string.
|
|
254
|
+
* @default false
|
|
255
|
+
*/
|
|
256
|
+
asJson: z.boolean().describe("Print inspected output as a parsable json string."),
|
|
251
257
|
// Skip Steps
|
|
252
258
|
//
|
|
253
259
|
/**
|
|
@@ -270,17 +276,34 @@ var ForkConfigSchema = z.object({
|
|
|
270
276
|
* @default false
|
|
271
277
|
*/
|
|
272
278
|
skipTag: z.boolean().describe("Skip the tag step."),
|
|
279
|
+
// Parser Options
|
|
280
|
+
//
|
|
281
|
+
/**
|
|
282
|
+
* The detected git host:
|
|
283
|
+
* - `GitHub`
|
|
284
|
+
* - `GitLab`
|
|
285
|
+
* - `Bitbucket`
|
|
286
|
+
* - `Azure Devops`
|
|
287
|
+
* - Or undefined if unknown or not detected.
|
|
288
|
+
*/
|
|
289
|
+
detectedGitHost: z.string().optional().describe(
|
|
290
|
+
"The detected git host, such as GitHub, GitLab, Bitbucket, Azure Devops, or undefined if unknown or not detected."
|
|
291
|
+
),
|
|
273
292
|
/**
|
|
274
293
|
* Override the default "conventional-changelog-conventionalcommits" preset configuration.
|
|
275
294
|
*/
|
|
276
|
-
changelogPresetConfig: ChangelogPresetConfigSchema.partial().describe(
|
|
295
|
+
changelogPresetConfig: ChangelogPresetConfigSchema.partial().optional().describe(
|
|
277
296
|
'Override the default "conventional-changelog-conventionalcommits" preset configuration.'
|
|
278
297
|
),
|
|
279
298
|
/**
|
|
280
299
|
* Add a suffix to the release commit message.
|
|
281
300
|
* @example "[skip ci]"
|
|
282
301
|
*/
|
|
283
|
-
releaseMessageSuffix: z.string().optional().describe("Add a suffix to the release commit message.")
|
|
302
|
+
releaseMessageSuffix: z.string().optional().describe("Add a suffix to the release commit message."),
|
|
303
|
+
/**
|
|
304
|
+
* Options to pass to commits parser.
|
|
305
|
+
*/
|
|
306
|
+
commitParserOptions: z.looseObject().optional().describe("Options to pass to commits parser.")
|
|
284
307
|
});
|
|
285
308
|
|
|
286
309
|
// src/utils/escape-regex.ts
|
|
@@ -290,8 +313,11 @@ function escapeRegex(input) {
|
|
|
290
313
|
|
|
291
314
|
// src/services/git.ts
|
|
292
315
|
var Git = class {
|
|
316
|
+
#path;
|
|
317
|
+
#dryRun;
|
|
293
318
|
constructor(config) {
|
|
294
|
-
this
|
|
319
|
+
this.#path = config.path;
|
|
320
|
+
this.#dryRun = config.dryRun ?? false;
|
|
295
321
|
this.add = this.add.bind(this);
|
|
296
322
|
this.commit = this.commit.bind(this);
|
|
297
323
|
this.tag = this.tag.bind(this);
|
|
@@ -301,8 +327,6 @@ var Git = class {
|
|
|
301
327
|
this.getRemoteUrl = this.getRemoteUrl.bind(this);
|
|
302
328
|
this.getTags = this.getTags.bind(this);
|
|
303
329
|
this.getMostRecentTag = this.getMostRecentTag.bind(this);
|
|
304
|
-
this.getCleanedTags = this.getCleanedTags.bind(this);
|
|
305
|
-
this.getHighestSemverVersionFromTags = this.getHighestSemverVersionFromTags.bind(this);
|
|
306
330
|
this.getCommits = this.getCommits.bind(this);
|
|
307
331
|
}
|
|
308
332
|
async #execGit(command, args) {
|
|
@@ -311,7 +335,7 @@ var Git = class {
|
|
|
311
335
|
"git",
|
|
312
336
|
[command, ...args],
|
|
313
337
|
{
|
|
314
|
-
cwd: this
|
|
338
|
+
cwd: this.#path,
|
|
315
339
|
maxBuffer: Infinity
|
|
316
340
|
},
|
|
317
341
|
(error, stdout, stderr) => {
|
|
@@ -335,7 +359,7 @@ var Git = class {
|
|
|
335
359
|
* ```
|
|
336
360
|
*/
|
|
337
361
|
async add(...args) {
|
|
338
|
-
if (this
|
|
362
|
+
if (this.#dryRun) {
|
|
339
363
|
return "";
|
|
340
364
|
}
|
|
341
365
|
return this.#execGit("add", args.filter(Boolean));
|
|
@@ -351,7 +375,7 @@ var Git = class {
|
|
|
351
375
|
* ```
|
|
352
376
|
*/
|
|
353
377
|
async commit(...args) {
|
|
354
|
-
if (this
|
|
378
|
+
if (this.#dryRun) {
|
|
355
379
|
return "";
|
|
356
380
|
}
|
|
357
381
|
return this.#execGit("commit", args.filter(Boolean));
|
|
@@ -367,7 +391,7 @@ var Git = class {
|
|
|
367
391
|
* ```
|
|
368
392
|
*/
|
|
369
393
|
async tag(...args) {
|
|
370
|
-
if (this
|
|
394
|
+
if (this.#dryRun) {
|
|
371
395
|
return "";
|
|
372
396
|
}
|
|
373
397
|
return this.#execGit("tag", args.filter(Boolean));
|
|
@@ -476,18 +500,18 @@ var Git = class {
|
|
|
476
500
|
if (tagPrefix) {
|
|
477
501
|
if (tag.startsWith(tagPrefix)) {
|
|
478
502
|
const tagWithoutPrefix = tag.replace(new RegExp(`^${escapedTagPrefix}`), "");
|
|
479
|
-
if (
|
|
503
|
+
if (semver5.valid(tagWithoutPrefix)) {
|
|
480
504
|
tags.push(tag);
|
|
481
505
|
}
|
|
482
506
|
}
|
|
483
|
-
} else if (/^\d/.test(tag) &&
|
|
507
|
+
} else if (/^\d/.test(tag) && semver5.valid(tag)) {
|
|
484
508
|
tags.push(tag);
|
|
485
509
|
}
|
|
486
510
|
}
|
|
487
511
|
return tags;
|
|
488
512
|
}
|
|
489
513
|
/**
|
|
490
|
-
* Returns the
|
|
514
|
+
* Returns the most recent tag from the commit history, or `undefined` if no valid semver tags are found
|
|
491
515
|
*
|
|
492
516
|
* @example
|
|
493
517
|
* ```ts
|
|
@@ -498,40 +522,6 @@ var Git = class {
|
|
|
498
522
|
const tags = await this.getTags(tagPrefix);
|
|
499
523
|
return tags[0] || void 0;
|
|
500
524
|
}
|
|
501
|
-
/**
|
|
502
|
-
* Get cleaned semver tags, with any tag prefix's removed
|
|
503
|
-
*
|
|
504
|
-
* @example
|
|
505
|
-
* ```ts
|
|
506
|
-
* await git.getCleanedTags("v"); // ["1.2.3", "1.2.2", "1.2.1"]
|
|
507
|
-
* ```
|
|
508
|
-
*/
|
|
509
|
-
async getCleanedTags(tagPrefix) {
|
|
510
|
-
const tags = await this.getTags(tagPrefix);
|
|
511
|
-
const escapedTagPrefix = tagPrefix ? escapeRegex(tagPrefix) : void 0;
|
|
512
|
-
const cleanedTags = [];
|
|
513
|
-
for (const tag of tags) {
|
|
514
|
-
const tagWithoutPrefix = tag.replace(new RegExp(`^${escapedTagPrefix}`), "");
|
|
515
|
-
const cleanedTag = semver.clean(tagWithoutPrefix);
|
|
516
|
-
if (cleanedTag) {
|
|
517
|
-
cleanedTags.push(cleanedTag);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
return cleanedTags;
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* Get the highest semver version from git tags. This will return the highest
|
|
524
|
-
* semver version found for the given tag prefix, regardless of the commit date.
|
|
525
|
-
*
|
|
526
|
-
* @example
|
|
527
|
-
* ```ts
|
|
528
|
-
* await git.getHighestSemverVersionFromTags("v"); // "1.2.3"
|
|
529
|
-
* ```
|
|
530
|
-
*/
|
|
531
|
-
async getHighestSemverVersionFromTags(tagPrefix) {
|
|
532
|
-
const cleanedTags = await this.getCleanedTags(tagPrefix);
|
|
533
|
-
return cleanedTags.sort(semver.rcompare)[0] || void 0;
|
|
534
|
-
}
|
|
535
525
|
/**
|
|
536
526
|
* Get commit history in a parsable format
|
|
537
527
|
*
|
|
@@ -590,7 +580,7 @@ ${SCISSOR}
|
|
|
590
580
|
return splitCommits;
|
|
591
581
|
}
|
|
592
582
|
};
|
|
593
|
-
function getChangelogPresetConfig(mergedConfig, cliArguments,
|
|
583
|
+
function getChangelogPresetConfig(mergedConfig, cliArguments, detectedChangelogOptions) {
|
|
594
584
|
const preset = {
|
|
595
585
|
name: "conventionalcommits"
|
|
596
586
|
};
|
|
@@ -614,8 +604,8 @@ function getChangelogPresetConfig(mergedConfig, cliArguments, detectedGitHost) {
|
|
|
614
604
|
}
|
|
615
605
|
});
|
|
616
606
|
}
|
|
617
|
-
if (
|
|
618
|
-
Object.entries(
|
|
607
|
+
if (detectedChangelogOptions) {
|
|
608
|
+
Object.entries(detectedChangelogOptions).forEach(([key, value]) => {
|
|
619
609
|
if (value !== void 0) {
|
|
620
610
|
preset[key] = value;
|
|
621
611
|
}
|
|
@@ -686,48 +676,180 @@ All notable changes to this project will be documented in this file. See [fork-v
|
|
|
686
676
|
gitTagFallback: true,
|
|
687
677
|
sign: false,
|
|
688
678
|
verify: false,
|
|
679
|
+
asJson: false,
|
|
689
680
|
// Skip Steps
|
|
690
681
|
skipBump: false,
|
|
691
682
|
skipChangelog: false,
|
|
692
683
|
skipCommit: false,
|
|
693
|
-
skipTag: false
|
|
694
|
-
changelogPresetConfig: {}
|
|
684
|
+
skipTag: false
|
|
695
685
|
};
|
|
696
686
|
|
|
697
|
-
// src/
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
687
|
+
// src/detect-git-host/host-github.ts
|
|
688
|
+
function detectGitHubOptions(remoteUrl) {
|
|
689
|
+
let matches = null;
|
|
690
|
+
if (/^https:\/\/(.*)?github\.com/.test(remoteUrl)) {
|
|
691
|
+
matches = /^https:\/\/(.*)?github\.com\/(?<organisation>.*?)\/(?<repository>.*?)(?:\.git)?$/.exec(
|
|
692
|
+
remoteUrl
|
|
693
|
+
);
|
|
694
|
+
} else if (remoteUrl.startsWith("git@github.com:")) {
|
|
695
|
+
matches = /^git@github\.com:(?<organisation>.*?)\/(?<repository>.*?)(?:\.git)?$/.exec(
|
|
696
|
+
remoteUrl
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
if (matches?.groups) {
|
|
700
|
+
const { organisation = "", repository = "" } = matches.groups;
|
|
701
|
+
return {
|
|
702
|
+
hostName: "GitHub",
|
|
703
|
+
changelogOptions: {
|
|
704
|
+
commitUrlFormat: `https://github.com/${organisation}/${repository}/commit/{{hash}}`,
|
|
705
|
+
compareUrlFormat: `https://github.com/${organisation}/${repository}/compare/{{previousTag}}...{{currentTag}}`,
|
|
706
|
+
issueUrlFormat: `https://github.com/${organisation}/${repository}/issues/{{id}}`,
|
|
707
|
+
issuePrefixes: ["#", "gh-"]
|
|
708
|
+
},
|
|
709
|
+
commitParserOptions: {
|
|
710
|
+
mergePattern: /^Merge pull request #(?<id>\d*) from (?<source>.*)/i,
|
|
711
|
+
issuePrefixes: ["#", "gh-"]
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
return void 0;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
// src/detect-git-host/host-gitlab.ts
|
|
719
|
+
function detectGitlabOptions(remoteUrl) {
|
|
720
|
+
let matches = null;
|
|
721
|
+
if (/^https:\/\/(.*)?gitlab\.com/.test(remoteUrl)) {
|
|
722
|
+
matches = /^https:\/\/(.*)?gitlab\.com\/(?<organisation>.*?)\/(?<repository>.*?)(?:\.git)?$/.exec(
|
|
723
|
+
remoteUrl
|
|
724
|
+
);
|
|
725
|
+
} else if (remoteUrl.startsWith("git@gitlab.com:")) {
|
|
726
|
+
matches = /^git@gitlab\.com:(?<organisation>.*?)\/(?<repository>.*?)(?:\.git)?$/.exec(
|
|
727
|
+
remoteUrl
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
if (matches?.groups) {
|
|
731
|
+
const { organisation = "", repository = "" } = matches.groups;
|
|
732
|
+
return {
|
|
733
|
+
hostName: "GitLab",
|
|
734
|
+
changelogOptions: {
|
|
735
|
+
commitUrlFormat: `https://gitlab.com/${organisation}/${repository}/-/commit/{{hash}}`,
|
|
736
|
+
compareUrlFormat: `https://gitlab.com/${organisation}/${repository}/-/compare/{{previousTag}}...{{currentTag}}`,
|
|
737
|
+
issueUrlFormat: `https://gitlab.com/${organisation}/${repository}/-/issues/{{id}}`
|
|
738
|
+
},
|
|
739
|
+
commitParserOptions: {
|
|
740
|
+
mergePattern: /^Merge branch '(?<source>.*)' into '(.*)'/i,
|
|
741
|
+
// https://docs.gitlab.com/user/project/issues/managing_issues/#default-closing-pattern
|
|
742
|
+
referenceActions: [
|
|
743
|
+
"close",
|
|
744
|
+
"closes",
|
|
745
|
+
"closed",
|
|
746
|
+
"closing",
|
|
747
|
+
"fix",
|
|
748
|
+
"fixes",
|
|
749
|
+
"fixed",
|
|
750
|
+
"fixing",
|
|
751
|
+
"resolve",
|
|
752
|
+
"resolves",
|
|
753
|
+
"resolved",
|
|
754
|
+
"resolving",
|
|
755
|
+
"implement",
|
|
756
|
+
"implements",
|
|
757
|
+
"implemented",
|
|
758
|
+
"implementing"
|
|
759
|
+
]
|
|
760
|
+
}
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
return void 0;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// src/detect-git-host/host-bitbucket.ts
|
|
767
|
+
function detectBitbucketOptions(remoteUrl) {
|
|
768
|
+
let matches = null;
|
|
769
|
+
if (/^https:\/\/(.*)?bitbucket\.(org|com)/.test(remoteUrl)) {
|
|
770
|
+
matches = /^https:\/\/(.*)?bitbucket\.(?<domain>org|com)\/(?<organisation>.*?)\/(?<repository>.*?)(?:\.git)?$/.exec(
|
|
771
|
+
remoteUrl
|
|
772
|
+
);
|
|
773
|
+
} else if (remoteUrl.startsWith("git@bitbucket.org:")) {
|
|
774
|
+
matches = /^git@bitbucket\.(?<domain>org|com):(?<organisation>.*?)\/(?<repository>.*?)(?:\.git)?$/.exec(
|
|
775
|
+
remoteUrl
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
if (matches?.groups) {
|
|
779
|
+
const { domain = "", organisation = "", repository = "" } = matches.groups;
|
|
780
|
+
return {
|
|
781
|
+
hostName: "Bitbucket",
|
|
782
|
+
changelogOptions: {
|
|
783
|
+
commitUrlFormat: `https://bitbucket.${domain}/${organisation}/${repository}/commits/{{hash}}`,
|
|
784
|
+
compareUrlFormat: `https://bitbucket.${domain}/${organisation}/${repository}/branches/compare/{{currentTag}}..{{previousTag}}`,
|
|
785
|
+
// 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.
|
|
786
|
+
issueUrlFormat: `https://bitbucket.${domain}/${organisation}/${repository}/issues/{{id}}`
|
|
787
|
+
},
|
|
788
|
+
commitParserOptions: {
|
|
789
|
+
mergePattern: /^Merged in (?<source>.*) \(pull request #(?<id>\d*)\)/i
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
return void 0;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
// src/detect-git-host/host-azure-devops.ts
|
|
797
|
+
function detectAzureDevopsOptions(remoteUrl) {
|
|
798
|
+
let matches = null;
|
|
799
|
+
if (/^https:\/\/(.*)?dev\.azure\.com/.test(remoteUrl)) {
|
|
800
|
+
matches = /^https:\/\/(.*)?dev\.azure\.com\/(?<organisation>.*?)\/(?<project>.*?)\/_git\/(?<repository>.*?)(?:\.git)?$/.exec(
|
|
705
801
|
remoteUrl
|
|
706
802
|
);
|
|
707
|
-
if (match?.groups) {
|
|
708
|
-
const { organisation = "", project = "", repository = "" } = match.groups;
|
|
709
|
-
return {
|
|
710
|
-
detectedGitHost: "Azure",
|
|
711
|
-
commitUrlFormat: `{{host}}/${organisation}/${project}/_git/${repository}/commit/{{hash}}`,
|
|
712
|
-
compareUrlFormat: `{{host}}/${organisation}/${project}/_git/${repository}/branchCompare?baseVersion=GT{{previousTag}}&targetVersion=GT{{currentTag}}`,
|
|
713
|
-
issueUrlFormat: `{{host}}/${organisation}/${project}/_workitems/edit/{{id}}`
|
|
714
|
-
};
|
|
715
|
-
}
|
|
716
803
|
} else if (remoteUrl.startsWith("git@ssh.dev.azure.com:")) {
|
|
717
|
-
|
|
804
|
+
matches = /^git@ssh\.dev\.azure\.com:v\d\/(?<organisation>.*?)\/(?<project>.*?)\/(?<repository>.*?)(?:\.git)?$/.exec(
|
|
718
805
|
remoteUrl
|
|
719
806
|
);
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
807
|
+
}
|
|
808
|
+
if (matches?.groups) {
|
|
809
|
+
const { organisation = "", project = "", repository = "" } = matches.groups;
|
|
810
|
+
return {
|
|
811
|
+
hostName: "Azure Devops",
|
|
812
|
+
changelogOptions: {
|
|
813
|
+
commitUrlFormat: `https://dev.azure.com/${organisation}/${project}/_git/${repository}/commit/{{hash}}`,
|
|
814
|
+
compareUrlFormat: `https://dev.azure.com/${organisation}/${project}/_git/${repository}/branchCompare?baseVersion=GT{{previousTag}}&targetVersion=GT{{currentTag}}`,
|
|
815
|
+
issueUrlFormat: `https://dev.azure.com/${organisation}/${project}/_workitems/edit/{{id}}`
|
|
816
|
+
},
|
|
817
|
+
commitParserOptions: {
|
|
818
|
+
mergePattern: /^Merged PR (?<id>\d*): (?<source>.*)/i
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
return void 0;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// src/detect-git-host/detect-git-host.ts
|
|
826
|
+
async function detectGitHost(path) {
|
|
827
|
+
const remoteUrl = await new Git({ path }).getRemoteUrl();
|
|
828
|
+
if (remoteUrl.includes("github.com")) {
|
|
829
|
+
const githubOptions = detectGitHubOptions(remoteUrl);
|
|
830
|
+
if (githubOptions) {
|
|
831
|
+
return githubOptions;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
if (remoteUrl.includes("gitlab.com")) {
|
|
835
|
+
const gitlabOptions = detectGitlabOptions(remoteUrl);
|
|
836
|
+
if (gitlabOptions) {
|
|
837
|
+
return gitlabOptions;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
if (/bitbucket\.(org|com)/.test(remoteUrl)) {
|
|
841
|
+
const bitbucketOptions = detectBitbucketOptions(remoteUrl);
|
|
842
|
+
if (bitbucketOptions) {
|
|
843
|
+
return bitbucketOptions;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
if (remoteUrl.includes("dev.azure.com")) {
|
|
847
|
+
const azureDevopsOptions = detectAzureDevopsOptions(remoteUrl);
|
|
848
|
+
if (azureDevopsOptions) {
|
|
849
|
+
return azureDevopsOptions;
|
|
728
850
|
}
|
|
729
851
|
}
|
|
730
|
-
return
|
|
852
|
+
return void 0;
|
|
731
853
|
}
|
|
732
854
|
var PACKAGE_JSON_CONFIG_KEY = "fork-version";
|
|
733
855
|
async function loadConfigFile(cwd) {
|
|
@@ -814,11 +936,6 @@ async function getUserConfig(cliArguments) {
|
|
|
814
936
|
}
|
|
815
937
|
const files = mergeFiles(configFile?.files, cliArguments.flags.files, globResults);
|
|
816
938
|
const detectedGitHost = await detectGitHost(cwd);
|
|
817
|
-
const changelogPresetConfig = getChangelogPresetConfig(
|
|
818
|
-
mergedConfig,
|
|
819
|
-
cliArguments.flags,
|
|
820
|
-
detectedGitHost
|
|
821
|
-
);
|
|
822
939
|
let command = DEFAULT_CONFIG.command;
|
|
823
940
|
if (cliArguments.input.length > 0 && cliArguments.input[0].trim()) {
|
|
824
941
|
command = cliArguments.input[0].trim().toLowerCase();
|
|
@@ -839,37 +956,47 @@ async function getUserConfig(cliArguments) {
|
|
|
839
956
|
cliArguments.flags.preReleaseTag ?? cliArguments.flags.preRelease ?? configFile.preRelease
|
|
840
957
|
),
|
|
841
958
|
silent: shouldBeSilent || mergedConfig.silent,
|
|
842
|
-
|
|
959
|
+
detectedGitHost: detectedGitHost?.hostName,
|
|
960
|
+
changelogPresetConfig: getChangelogPresetConfig(
|
|
961
|
+
mergedConfig,
|
|
962
|
+
cliArguments.flags,
|
|
963
|
+
detectedGitHost?.changelogOptions
|
|
964
|
+
),
|
|
965
|
+
commitParserOptions: {
|
|
966
|
+
...detectedGitHost?.commitParserOptions,
|
|
967
|
+
...mergedConfig.commitParserOptions
|
|
968
|
+
}
|
|
843
969
|
};
|
|
844
970
|
}
|
|
845
971
|
var Logger = class {
|
|
972
|
+
#silent;
|
|
973
|
+
#debug;
|
|
846
974
|
constructor(config) {
|
|
847
|
-
this
|
|
975
|
+
this.#silent = config.silent ?? false;
|
|
976
|
+
this.#debug = config.debug ?? false;
|
|
848
977
|
this.log = this.log.bind(this);
|
|
849
978
|
this.warn = this.warn.bind(this);
|
|
850
979
|
this.error = this.error.bind(this);
|
|
851
980
|
this.debug = this.debug.bind(this);
|
|
852
981
|
this.skipping = this.skipping.bind(this);
|
|
853
|
-
this.disableLogs = this.config.silent;
|
|
854
982
|
}
|
|
855
|
-
disableLogs = false;
|
|
856
983
|
log(message) {
|
|
857
|
-
if (!this
|
|
984
|
+
if (!this.#silent) {
|
|
858
985
|
console.log(message);
|
|
859
986
|
}
|
|
860
987
|
}
|
|
861
988
|
warn(message) {
|
|
862
|
-
if (!this
|
|
989
|
+
if (!this.#silent) {
|
|
863
990
|
console.warn(styleText("yellowBright", message));
|
|
864
991
|
}
|
|
865
992
|
}
|
|
866
993
|
error(message) {
|
|
867
|
-
if (!this
|
|
994
|
+
if (!this.#silent) {
|
|
868
995
|
console.error(styleText("redBright", message));
|
|
869
996
|
}
|
|
870
997
|
}
|
|
871
998
|
debug(message, ...optionalParams) {
|
|
872
|
-
if (this
|
|
999
|
+
if (!this.#silent && this.#debug) {
|
|
873
1000
|
console.debug(styleText("cyanBright", message));
|
|
874
1001
|
if (optionalParams.length > 0) {
|
|
875
1002
|
console.debug(...optionalParams);
|
|
@@ -877,7 +1004,7 @@ var Logger = class {
|
|
|
877
1004
|
}
|
|
878
1005
|
}
|
|
879
1006
|
skipping(message) {
|
|
880
|
-
if (!this
|
|
1007
|
+
if (!this.#silent) {
|
|
881
1008
|
console.log(styleText("magenta", message));
|
|
882
1009
|
}
|
|
883
1010
|
}
|
|
@@ -1205,66 +1332,6 @@ ${JSON.stringify(config, null, 2)}
|
|
|
1205
1332
|
\u2705 Configuration is valid.
|
|
1206
1333
|
`);
|
|
1207
1334
|
}
|
|
1208
|
-
async function getCurrentVersion(config, logger, git, fileManager, filesToUpdate) {
|
|
1209
|
-
const files = [];
|
|
1210
|
-
const versions = /* @__PURE__ */ new Set();
|
|
1211
|
-
for (const file of filesToUpdate) {
|
|
1212
|
-
if (await git.isIgnored(file)) {
|
|
1213
|
-
logger.debug(`[Git Ignored] ${file}`);
|
|
1214
|
-
continue;
|
|
1215
|
-
}
|
|
1216
|
-
const fileState = fileManager.read(file);
|
|
1217
|
-
if (fileState) {
|
|
1218
|
-
files.push(fileState);
|
|
1219
|
-
if (!config.currentVersion) {
|
|
1220
|
-
versions.add(fileState.version);
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
if (config.currentVersion) {
|
|
1225
|
-
versions.add(config.currentVersion);
|
|
1226
|
-
}
|
|
1227
|
-
if (versions.size === 0 && config.gitTagFallback) {
|
|
1228
|
-
const version = await git.getHighestSemverVersionFromTags(config.tagPrefix);
|
|
1229
|
-
if (version) {
|
|
1230
|
-
logger.warn(`Using latest git tag as fallback`);
|
|
1231
|
-
versions.add(version);
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
if (versions.size === 0) {
|
|
1235
|
-
throw new Error("Unable to find current version");
|
|
1236
|
-
} else if (versions.size > 1) {
|
|
1237
|
-
if (!config.allowMultipleVersions) {
|
|
1238
|
-
throw new Error("Found multiple versions");
|
|
1239
|
-
}
|
|
1240
|
-
logger.warn(
|
|
1241
|
-
`Found multiple versions (${Array.from(versions).join(", ")}), using the higher semver version`
|
|
1242
|
-
);
|
|
1243
|
-
}
|
|
1244
|
-
const currentVersion = semver.rsort(Array.from(versions))[0];
|
|
1245
|
-
logger.log(`Current version: ${currentVersion}`);
|
|
1246
|
-
return {
|
|
1247
|
-
files,
|
|
1248
|
-
version: currentVersion
|
|
1249
|
-
};
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
// src/commands/inspect-version.ts
|
|
1253
|
-
async function inspectVersion(config, logger, fileManager, git) {
|
|
1254
|
-
let foundVersion = "";
|
|
1255
|
-
try {
|
|
1256
|
-
const currentVersion = await getCurrentVersion(config, logger, git, fileManager, config.files);
|
|
1257
|
-
if (currentVersion) foundVersion = currentVersion.version;
|
|
1258
|
-
} catch {
|
|
1259
|
-
}
|
|
1260
|
-
console.log(foundVersion);
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
|
-
// src/commands/inspect-tag.ts
|
|
1264
|
-
async function inspectTag(config, git) {
|
|
1265
|
-
const tag = await git.getMostRecentTag(config.tagPrefix);
|
|
1266
|
-
console.log(tag ?? "");
|
|
1267
|
-
}
|
|
1268
1335
|
|
|
1269
1336
|
// src/utils/trim-string-array.ts
|
|
1270
1337
|
function trimStringArray(array) {
|
|
@@ -1728,10 +1795,16 @@ function filterRevertedCommits(parsedCommits) {
|
|
|
1728
1795
|
}
|
|
1729
1796
|
return commitsWithoutReverts;
|
|
1730
1797
|
}
|
|
1798
|
+
function cleanTag(tag, tagPrefix) {
|
|
1799
|
+
if (!tag) return void 0;
|
|
1800
|
+
const escapedTagPrefix = tagPrefix ? escapeRegex(tagPrefix) : void 0;
|
|
1801
|
+
const tagWithoutPrefix = escapedTagPrefix ? tag.replace(new RegExp(`^${escapedTagPrefix}`), "") : tag;
|
|
1802
|
+
return semver5.clean(tagWithoutPrefix) ?? void 0;
|
|
1803
|
+
}
|
|
1731
1804
|
|
|
1732
1805
|
// src/process/get-commits.ts
|
|
1733
1806
|
async function getCommitsSinceTag(config, logger, git) {
|
|
1734
|
-
const commitParser = new CommitParser();
|
|
1807
|
+
const commitParser = new CommitParser(config.commitParserOptions);
|
|
1735
1808
|
if (config.debug) commitParser.setLogger(logger);
|
|
1736
1809
|
const latestTag = await git.getMostRecentTag(config.tagPrefix);
|
|
1737
1810
|
if (!latestTag) {
|
|
@@ -1751,14 +1824,130 @@ async function getCommitsSinceTag(config, logger, git) {
|
|
|
1751
1824
|
);
|
|
1752
1825
|
return {
|
|
1753
1826
|
latestTag,
|
|
1827
|
+
latestTagVersion: cleanTag(latestTag, config.tagPrefix),
|
|
1754
1828
|
commits: filteredCommits
|
|
1755
1829
|
};
|
|
1756
1830
|
}
|
|
1831
|
+
async function getCurrentVersion(config, logger, git, fileManager, filesToUpdate, latestTagVersion) {
|
|
1832
|
+
const files = [];
|
|
1833
|
+
const versions = /* @__PURE__ */ new Set();
|
|
1834
|
+
for (const file of filesToUpdate) {
|
|
1835
|
+
if (await git.isIgnored(file)) {
|
|
1836
|
+
logger.debug(`[Git Ignored] ${file}`);
|
|
1837
|
+
continue;
|
|
1838
|
+
}
|
|
1839
|
+
const fileState = fileManager.read(file);
|
|
1840
|
+
if (fileState) {
|
|
1841
|
+
files.push(fileState);
|
|
1842
|
+
if (!config.currentVersion) {
|
|
1843
|
+
versions.add(fileState.version);
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
if (config.currentVersion) {
|
|
1848
|
+
versions.add(config.currentVersion);
|
|
1849
|
+
}
|
|
1850
|
+
if (versions.size === 0 && config.gitTagFallback && latestTagVersion) {
|
|
1851
|
+
logger.warn(`Using latest git tag as fallback`);
|
|
1852
|
+
versions.add(latestTagVersion);
|
|
1853
|
+
}
|
|
1854
|
+
if (versions.size === 0) {
|
|
1855
|
+
throw new Error("Unable to find current version");
|
|
1856
|
+
} else if (versions.size > 1) {
|
|
1857
|
+
if (!config.allowMultipleVersions) {
|
|
1858
|
+
throw new Error("Found multiple versions");
|
|
1859
|
+
}
|
|
1860
|
+
logger.warn(
|
|
1861
|
+
`Found multiple versions (${Array.from(versions).join(", ")}), using the higher semver version`
|
|
1862
|
+
);
|
|
1863
|
+
}
|
|
1864
|
+
const currentVersion = semver5.rsort(Array.from(versions))[0];
|
|
1865
|
+
logger.log(`Current version: ${currentVersion}`);
|
|
1866
|
+
return {
|
|
1867
|
+
files,
|
|
1868
|
+
version: currentVersion
|
|
1869
|
+
};
|
|
1870
|
+
}
|
|
1871
|
+
async function inspect(config, logger, fileManager, git) {
|
|
1872
|
+
let latestTag = "";
|
|
1873
|
+
let latestVersion = "";
|
|
1874
|
+
try {
|
|
1875
|
+
const commits = await getCommitsSinceTag(config, logger, git);
|
|
1876
|
+
if (commits.latestTag) {
|
|
1877
|
+
latestTag = commits.latestTag;
|
|
1878
|
+
latestVersion = commits.latestTagVersion ?? "";
|
|
1879
|
+
}
|
|
1880
|
+
const currentVersion = await getCurrentVersion(
|
|
1881
|
+
config,
|
|
1882
|
+
logger,
|
|
1883
|
+
git,
|
|
1884
|
+
fileManager,
|
|
1885
|
+
config.files,
|
|
1886
|
+
latestVersion
|
|
1887
|
+
);
|
|
1888
|
+
if (currentVersion.version) {
|
|
1889
|
+
latestVersion = currentVersion.version;
|
|
1890
|
+
}
|
|
1891
|
+
} catch {
|
|
1892
|
+
}
|
|
1893
|
+
if (!latestVersion && !latestTag) {
|
|
1894
|
+
console.error(
|
|
1895
|
+
styleText(
|
|
1896
|
+
"yellowBright",
|
|
1897
|
+
"No version found. Make sure you have at least one tag in your repository."
|
|
1898
|
+
)
|
|
1899
|
+
);
|
|
1900
|
+
process.exit(1);
|
|
1901
|
+
return;
|
|
1902
|
+
}
|
|
1903
|
+
switch (config.command) {
|
|
1904
|
+
case "inspect-version": {
|
|
1905
|
+
console.log(
|
|
1906
|
+
config.asJson ? JSON.stringify(
|
|
1907
|
+
{
|
|
1908
|
+
version: latestVersion
|
|
1909
|
+
},
|
|
1910
|
+
null,
|
|
1911
|
+
2
|
|
1912
|
+
) : latestVersion
|
|
1913
|
+
);
|
|
1914
|
+
return;
|
|
1915
|
+
}
|
|
1916
|
+
case "inspect-tag": {
|
|
1917
|
+
console.log(
|
|
1918
|
+
config.asJson ? JSON.stringify(
|
|
1919
|
+
{
|
|
1920
|
+
tag: latestTag
|
|
1921
|
+
},
|
|
1922
|
+
null,
|
|
1923
|
+
2
|
|
1924
|
+
) : latestTag
|
|
1925
|
+
);
|
|
1926
|
+
return;
|
|
1927
|
+
}
|
|
1928
|
+
default: {
|
|
1929
|
+
console.log(
|
|
1930
|
+
config.asJson ? JSON.stringify(
|
|
1931
|
+
{
|
|
1932
|
+
version: latestVersion,
|
|
1933
|
+
tag: latestTag
|
|
1934
|
+
},
|
|
1935
|
+
null,
|
|
1936
|
+
2
|
|
1937
|
+
) : `
|
|
1938
|
+
Version: ${latestVersion}
|
|
1939
|
+
Tag: ${latestTag}
|
|
1940
|
+
`.trim()
|
|
1941
|
+
);
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1757
1946
|
function getPriority(type) {
|
|
1758
1947
|
return ["patch", "minor", "major"].indexOf(type ?? "");
|
|
1759
1948
|
}
|
|
1760
1949
|
function getVersionType(version) {
|
|
1761
|
-
const parseVersion =
|
|
1950
|
+
const parseVersion = semver5.parse(version);
|
|
1762
1951
|
if (parseVersion?.major) {
|
|
1763
1952
|
return "major";
|
|
1764
1953
|
} else if (parseVersion?.minor) {
|
|
@@ -1772,7 +1961,7 @@ function getReleaseType(releaseType, currentVersion, preReleaseTag) {
|
|
|
1772
1961
|
if (!preReleaseTag) {
|
|
1773
1962
|
return releaseType;
|
|
1774
1963
|
}
|
|
1775
|
-
const currentVersionsIsPreRelease = Array.isArray(
|
|
1964
|
+
const currentVersionsIsPreRelease = Array.isArray(semver5.prerelease(currentVersion));
|
|
1776
1965
|
if (currentVersionsIsPreRelease) {
|
|
1777
1966
|
const currentReleaseType = getVersionType(currentVersion);
|
|
1778
1967
|
if (currentReleaseType === releaseType || getPriority(currentReleaseType) > getPriority(releaseType)) {
|
|
@@ -1791,7 +1980,7 @@ async function getNextVersion(config, logger, commits, currentVersion) {
|
|
|
1791
1980
|
};
|
|
1792
1981
|
}
|
|
1793
1982
|
if (config.nextVersion) {
|
|
1794
|
-
if (!
|
|
1983
|
+
if (!semver5.valid(config.nextVersion)) {
|
|
1795
1984
|
throw new Error(`Invalid Version: ${config.nextVersion}`);
|
|
1796
1985
|
}
|
|
1797
1986
|
logger.log(`Next version: ${config.nextVersion}`);
|
|
@@ -1799,7 +1988,7 @@ async function getNextVersion(config, logger, commits, currentVersion) {
|
|
|
1799
1988
|
version: config.nextVersion
|
|
1800
1989
|
};
|
|
1801
1990
|
}
|
|
1802
|
-
const isPreMajor =
|
|
1991
|
+
const isPreMajor = semver5.lt(currentVersion, "1.0.0");
|
|
1803
1992
|
let releaseType = "patch";
|
|
1804
1993
|
const changes = {
|
|
1805
1994
|
major: 0,
|
|
@@ -1849,7 +2038,7 @@ async function getNextVersion(config, logger, commits, currentVersion) {
|
|
|
1849
2038
|
}
|
|
1850
2039
|
}
|
|
1851
2040
|
const releaseTypeOrPreRelease = getReleaseType(releaseType, currentVersion, config.preRelease);
|
|
1852
|
-
const nextVersion =
|
|
2041
|
+
const nextVersion = semver5.inc(
|
|
1853
2042
|
currentVersion,
|
|
1854
2043
|
releaseTypeOrPreRelease,
|
|
1855
2044
|
typeof config.preRelease === "string" ? config.preRelease : ""
|
|
@@ -2001,7 +2190,14 @@ async function main(config, logger, fileManager, git) {
|
|
|
2001
2190
|
logger.log(`Running fork-version - ${(/* @__PURE__ */ new Date()).toUTCString()}`);
|
|
2002
2191
|
logger.warn(config.dryRun ? "[Dry Run] No changes will be written to disk.\n" : "");
|
|
2003
2192
|
const commits = await getCommitsSinceTag(config, logger, git);
|
|
2004
|
-
const current = await getCurrentVersion(
|
|
2193
|
+
const current = await getCurrentVersion(
|
|
2194
|
+
config,
|
|
2195
|
+
logger,
|
|
2196
|
+
git,
|
|
2197
|
+
fileManager,
|
|
2198
|
+
config.files,
|
|
2199
|
+
commits.latestTagVersion
|
|
2200
|
+
);
|
|
2005
2201
|
const next = await getNextVersion(config, logger, commits.commits, current.version);
|
|
2006
2202
|
logger.log("Updating files: ");
|
|
2007
2203
|
for (const outFile of current.files) {
|
|
@@ -2019,6 +2215,6 @@ async function main(config, logger, fileManager, git) {
|
|
|
2019
2215
|
};
|
|
2020
2216
|
}
|
|
2021
2217
|
|
|
2022
|
-
export { CommitParser, FileManager, ForkConfigSchema, Git, Logger, commitChanges, createParserOptions, filterRevertedCommits, getCommitsSinceTag, getCurrentVersion, getNextVersion, getUserConfig,
|
|
2023
|
-
//# sourceMappingURL=chunk-
|
|
2024
|
-
//# sourceMappingURL=chunk-
|
|
2218
|
+
export { CommitParser, FileManager, ForkConfigSchema, Git, Logger, commitChanges, createParserOptions, filterRevertedCommits, getCommitsSinceTag, getCurrentVersion, getNextVersion, getUserConfig, inspect, main, tagChanges, updateChangelog, validateConfig };
|
|
2219
|
+
//# sourceMappingURL=chunk-X4NB24VR.js.map
|
|
2220
|
+
//# sourceMappingURL=chunk-X4NB24VR.js.map
|