fork-version 1.4.90 → 1.4.95

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.
@@ -1,22 +1,22 @@
1
1
  import { z } from 'zod';
2
- import { readFileSync, writeFileSync, lstatSync } from 'fs';
3
- import { resolve, parse } from 'path';
2
+ import { readFileSync, writeFileSync } from 'node:fs';
3
+ import { resolve, parse } from 'node:path';
4
4
  import JoyCon from 'joycon';
5
5
  import { bundleRequire } from 'bundle-require';
6
6
  import { glob } from 'glob';
7
- import dotgitignore from 'dotgitignore';
8
7
  import meow from 'meow';
9
8
  import conventionalChangelogConfigSpec from 'conventional-changelog-config-spec';
10
- import { execFile } from 'child_process';
9
+ import { execFile } from 'node:child_process';
10
+ import detectIndent from 'detect-indent';
11
+ import { detectNewline } from 'detect-newline';
12
+ import { lstatSync } from 'fs';
13
+ import * as cheerio from 'cheerio/slim';
11
14
  import semver3 from 'semver';
12
15
  import conventionalRecommendedBump from 'conventional-recommended-bump';
13
16
  import gitSemverTags from 'git-semver-tags';
14
17
  import conventionalChangelog from 'conventional-changelog';
15
- import detectIndent from 'detect-indent';
16
- import { detectNewline } from 'detect-newline';
17
- import * as cheerio from 'cheerio/lib/slim';
18
18
 
19
- // src/config/schema.ts
19
+ // src/config/schema.js
20
20
  var ChangelogPresetConfigTypeSchema = z.object({
21
21
  /**
22
22
  * The type of commit message.
@@ -261,9 +261,6 @@ var ForkConfigSchema = z.object({
261
261
  */
262
262
  releaseMessageSuffix: z.string().optional().describe("Add a suffix to the release commit message.")
263
263
  });
264
- function defineConfig(config) {
265
- return config;
266
- }
267
264
 
268
265
  // src/config/defaults.ts
269
266
  var DEFAULT_CONFIG = {
@@ -469,12 +466,9 @@ function getChangelogPresetConfig(mergedConfig, cliArgumentsFlags, detectedGitHo
469
466
  return ChangelogPresetConfigSchema.passthrough().parse(preset);
470
467
  }
471
468
  async function detectGitHost(cwd) {
472
- const remoteUrl = await new Promise((onResolve, onReject) => {
473
- execFile("git", ["config", "--get", "remote.origin.url"], { cwd }, (error, stdout, stderr) => {
474
- if (error) {
475
- onReject(error);
476
- }
477
- onResolve(stdout ? stdout.trim() : stderr);
469
+ const remoteUrl = await new Promise((onResolve) => {
470
+ execFile("git", ["config", "--get", "remote.origin.url"], { cwd }, (_error, stdout) => {
471
+ onResolve(stdout ? stdout.trim() : "");
478
472
  });
479
473
  });
480
474
  if (remoteUrl.startsWith("https://") && remoteUrl.includes("@dev.azure.com/")) {
@@ -542,10 +536,7 @@ async function getUserConfig() {
542
536
  const detectedGitHost = await detectGitHost(cwd);
543
537
  return {
544
538
  ...mergedConfig,
545
- files: filterGitIgnoredFiles(
546
- cwd,
547
- getFilesList(configFile?.files, cliArguments.flags?.files, globResults)
548
- ),
539
+ files: getFilesList(configFile?.files, cliArguments.flags?.files, globResults),
549
540
  path: cwd,
550
541
  preRelease: (
551
542
  // Meow doesn't support multiple flags with the same name, so we need to check both.
@@ -601,10 +592,232 @@ function getFilesList(configFiles, cliFiles, globResults) {
601
592
  }
602
593
  return DEFAULT_CONFIG.files;
603
594
  }
604
- function filterGitIgnoredFiles(cwd, files) {
605
- const dotgit = dotgitignore({ cwd });
606
- return files.filter((file) => !dotgit.ignore(file));
595
+ function defineConfig(config) {
596
+ return config;
607
597
  }
598
+
599
+ // src/utils/logger.ts
600
+ var Logger = class {
601
+ constructor(config) {
602
+ this.config = config;
603
+ this.log = this.log.bind(this);
604
+ this.warn = this.warn.bind(this);
605
+ this.error = this.error.bind(this);
606
+ this.debug = this.debug.bind(this);
607
+ this.disableLogs = this.config.silent || this.config.inspectVersion;
608
+ }
609
+ disableLogs = false;
610
+ log(...messages) {
611
+ if (!this.disableLogs) {
612
+ console.log(...messages);
613
+ }
614
+ }
615
+ warn(...messages) {
616
+ if (!this.disableLogs) {
617
+ console.warn(...messages);
618
+ }
619
+ }
620
+ error(...messages) {
621
+ if (!this.disableLogs) {
622
+ console.error(...messages);
623
+ }
624
+ }
625
+ debug(...messages) {
626
+ if (this.config.debug && !this.disableLogs) {
627
+ console.debug(...messages);
628
+ }
629
+ }
630
+ };
631
+
632
+ // src/libs/stringify-package.ts
633
+ var DEFAULT_INDENT = 2;
634
+ var CRLF = "\r\n";
635
+ var LF = "\n";
636
+ function stringifyPackage(data, indent, newline) {
637
+ const stringified = JSON.stringify(data, null, indent ?? DEFAULT_INDENT);
638
+ if (newline === CRLF) {
639
+ return stringified.replace(new RegExp(LF, "g"), CRLF);
640
+ }
641
+ return stringified;
642
+ }
643
+ function fileExists(filePath) {
644
+ try {
645
+ return lstatSync(filePath).isFile();
646
+ } catch (_error) {
647
+ return false;
648
+ }
649
+ }
650
+
651
+ // src/strategies/json-package.ts
652
+ var JSONPackage = class {
653
+ constructor(config, logger) {
654
+ this.config = config;
655
+ this.logger = logger;
656
+ }
657
+ read(fileName) {
658
+ const filePath = resolve(this.config.path, fileName);
659
+ if (fileExists(filePath)) {
660
+ const fileContents = readFileSync(filePath, "utf8");
661
+ const parsedJson = JSON.parse(fileContents);
662
+ if (parsedJson.version) {
663
+ return {
664
+ name: fileName,
665
+ path: filePath,
666
+ version: parsedJson.version,
667
+ isPrivate: typeof parsedJson?.private === "boolean" ? parsedJson.private : true
668
+ };
669
+ }
670
+ this.logger.warn(`[File Manager] Unable to determine json package: ${fileName}`);
671
+ }
672
+ }
673
+ write(fileState, newVersion) {
674
+ const fileContents = readFileSync(fileState.path, "utf8");
675
+ const parsedJson = JSON.parse(fileContents);
676
+ parsedJson.version = newVersion;
677
+ if (parsedJson.packages?.[""]) {
678
+ parsedJson.packages[""].version = newVersion;
679
+ }
680
+ writeFileSync(
681
+ fileState.path,
682
+ stringifyPackage(parsedJson, detectIndent(fileContents).indent, detectNewline(fileContents)),
683
+ "utf8"
684
+ );
685
+ }
686
+ isSupportedFile(fileName) {
687
+ return fileName.endsWith(".json");
688
+ }
689
+ };
690
+ var PlainText = class {
691
+ constructor(config, logger) {
692
+ this.config = config;
693
+ this.logger = logger;
694
+ }
695
+ read(fileName) {
696
+ const filePath = resolve(this.config.path, fileName);
697
+ if (fileExists(filePath)) {
698
+ const fileContents = readFileSync(filePath, "utf8");
699
+ return {
700
+ name: fileName,
701
+ path: filePath,
702
+ version: fileContents || ""
703
+ };
704
+ }
705
+ this.logger.warn(`[File Manager] Unable to determine plain text: ${fileName}`);
706
+ }
707
+ write(fileState, newVersion) {
708
+ writeFileSync(fileState.path, newVersion, "utf8");
709
+ }
710
+ isSupportedFile(fileName) {
711
+ return fileName.endsWith("version.txt");
712
+ }
713
+ };
714
+ var MSBuildProject = class {
715
+ constructor(config, logger) {
716
+ this.config = config;
717
+ this.logger = logger;
718
+ }
719
+ read(fileName) {
720
+ const filePath = resolve(this.config.path, fileName);
721
+ if (fileExists(filePath)) {
722
+ const fileContents = readFileSync(filePath, "utf8");
723
+ const $ = cheerio.load(fileContents, {
724
+ xmlMode: true,
725
+ xml: { decodeEntities: false }
726
+ });
727
+ const version = $("Project > PropertyGroup > Version").text();
728
+ if (version) {
729
+ return {
730
+ name: fileName,
731
+ path: filePath,
732
+ version
733
+ };
734
+ }
735
+ this.logger.warn(`[File Manager] Unable to determine ms-build package: ${fileName}`);
736
+ }
737
+ }
738
+ write(fileState, newVersion) {
739
+ const fileContents = readFileSync(fileState.path, "utf8");
740
+ const $ = cheerio.load(fileContents, {
741
+ xmlMode: true,
742
+ xml: { decodeEntities: false }
743
+ });
744
+ $("Project > PropertyGroup > Version").text(newVersion);
745
+ const updatedContent = $.xml().replaceAll('"/>', '" />');
746
+ writeFileSync(fileState.path, updatedContent, "utf8");
747
+ }
748
+ isSupportedFile(fileName) {
749
+ return [".csproj", ".dbproj", ".esproj", ".fsproj", ".props", ".vbproj", ".vcxproj"].findIndex(
750
+ (ext) => fileName.endsWith(ext)
751
+ ) !== -1;
752
+ }
753
+ };
754
+
755
+ // src/strategies/file-manager.ts
756
+ var FileManager = class {
757
+ constructor(config, logger) {
758
+ this.config = config;
759
+ this.logger = logger;
760
+ this.JSONPackage = new JSONPackage(config, logger);
761
+ this.PlainText = new PlainText(config, logger);
762
+ this.MSBuildProject = new MSBuildProject(config, logger);
763
+ }
764
+ JSONPackage;
765
+ PlainText;
766
+ MSBuildProject;
767
+ /**
768
+ * Get the state from the given file name.
769
+ *
770
+ * @example
771
+ * ```ts
772
+ * fileManager.read("package.json");
773
+ * ```
774
+ *
775
+ * @returns
776
+ * ```json
777
+ * { "name": "package.json", "path": "/path/to/package.json", "version": "1.2.3", "isPrivate": true }
778
+ * ```
779
+ */
780
+ read(fileName) {
781
+ const _fileName = fileName.toLowerCase();
782
+ if (this.JSONPackage.isSupportedFile(_fileName)) {
783
+ return this.JSONPackage.read(fileName);
784
+ }
785
+ if (this.PlainText.isSupportedFile(_fileName)) {
786
+ return this.PlainText.read(fileName);
787
+ }
788
+ if (this.MSBuildProject.isSupportedFile(_fileName)) {
789
+ return this.MSBuildProject.read(fileName);
790
+ }
791
+ this.logger.error(`[File Manager] Unsupported file: ${fileName}`);
792
+ }
793
+ /**
794
+ * Write the new version to the given file.
795
+ *
796
+ * @example
797
+ * ```ts
798
+ * fileManager.write(
799
+ * { name: "package.json", path: "/path/to/package.json", version: "1.2.2" },
800
+ * "1.2.3"
801
+ * );
802
+ * ```
803
+ */
804
+ write(fileState, newVersion) {
805
+ if (this.config.dryRun) {
806
+ return;
807
+ }
808
+ const _fileName = fileState.name.toLowerCase();
809
+ if (this.JSONPackage.isSupportedFile(_fileName)) {
810
+ return this.JSONPackage.write(fileState, newVersion);
811
+ }
812
+ if (this.PlainText.isSupportedFile(_fileName)) {
813
+ return this.PlainText.write(fileState, newVersion);
814
+ }
815
+ if (this.MSBuildProject.isSupportedFile(_fileName)) {
816
+ return this.MSBuildProject.write(fileState, newVersion);
817
+ }
818
+ this.logger.error(`[File Manager] Unsupported file: ${fileState.path}`);
819
+ }
820
+ };
608
821
  async function getLatestGitTagVersion(tagPrefix) {
609
822
  const gitTags = await gitSemverTags({ tagPrefix });
610
823
  if (!gitTags.length) {
@@ -648,10 +861,10 @@ function getReleaseType(releaseType, currentVersion, preReleaseTag) {
648
861
  }
649
862
 
650
863
  // src/process/version.ts
651
- async function getCurrentVersion(config, logger, fileManager) {
864
+ async function getCurrentVersion(config, logger, fileManager, filesToUpdate) {
652
865
  const files = [];
653
866
  const versions = /* @__PURE__ */ new Set();
654
- for (const file of config.files) {
867
+ for (const file of filesToUpdate) {
655
868
  const fileState = fileManager.read(file);
656
869
  if (fileState) {
657
870
  files.push(fileState);
@@ -717,7 +930,7 @@ async function getNextVersion(config, logger, currentVersion) {
717
930
  tagPrefix: config.tagPrefix,
718
931
  cwd: config.path
719
932
  });
720
- } catch (error) {
933
+ } catch (_error) {
721
934
  throw new Error(`[conventional-recommended-bump] Unable to determine next version`);
722
935
  }
723
936
  if (recommendedBump.releaseType) {
@@ -741,15 +954,6 @@ async function getNextVersion(config, logger, currentVersion) {
741
954
  }
742
955
  throw new Error("Unable to find next version");
743
956
  }
744
- function fileExists(filePath) {
745
- try {
746
- return lstatSync(filePath).isFile();
747
- } catch (e) {
748
- return false;
749
- }
750
- }
751
-
752
- // src/process/changelog.ts
753
957
  var RELEASE_PATTERN = /(^#+ \[?[0-9]+\.[0-9]+\.[0-9]+|<a name=)/m;
754
958
  function getOldReleaseContent(filePath, exists) {
755
959
  if (exists) {
@@ -875,216 +1079,6 @@ async function tagChanges(config, logger, git, nextVersion) {
875
1079
  );
876
1080
  }
877
1081
 
878
- // src/libs/stringify-package.ts
879
- var DEFAULT_INDENT = 2;
880
- var CRLF = "\r\n";
881
- var LF = "\n";
882
- function stringifyPackage(data, indent, newline) {
883
- const stringified = JSON.stringify(data, null, indent ?? DEFAULT_INDENT);
884
- if (newline === CRLF) {
885
- return stringified.replace(new RegExp(LF, "g"), CRLF);
886
- }
887
- return stringified;
888
- }
889
-
890
- // src/strategies/json-package.ts
891
- var JSONPackage = class {
892
- constructor(config, logger) {
893
- this.config = config;
894
- this.logger = logger;
895
- }
896
- read(fileName) {
897
- const filePath = resolve(this.config.path, fileName);
898
- if (fileExists(filePath)) {
899
- const fileContents = readFileSync(filePath, "utf8");
900
- const parsedJson = JSON.parse(fileContents);
901
- if (parsedJson.version) {
902
- return {
903
- name: fileName,
904
- path: filePath,
905
- version: parsedJson.version,
906
- isPrivate: typeof parsedJson?.private === "boolean" ? parsedJson.private : true
907
- };
908
- }
909
- this.logger.warn(`[File Manager] Unable to determine json package: ${fileName}`);
910
- }
911
- }
912
- write(fileState, newVersion) {
913
- const fileContents = readFileSync(fileState.path, "utf8");
914
- const parsedJson = JSON.parse(fileContents);
915
- parsedJson.version = newVersion;
916
- if (parsedJson.packages?.[""]) {
917
- parsedJson.packages[""].version = newVersion;
918
- }
919
- writeFileSync(
920
- fileState.path,
921
- stringifyPackage(parsedJson, detectIndent(fileContents).indent, detectNewline(fileContents)),
922
- "utf8"
923
- );
924
- }
925
- isSupportedFile(fileName) {
926
- return fileName.endsWith(".json");
927
- }
928
- };
929
- var PlainText = class {
930
- constructor(config, logger) {
931
- this.config = config;
932
- this.logger = logger;
933
- }
934
- read(fileName) {
935
- const filePath = resolve(this.config.path, fileName);
936
- if (fileExists(filePath)) {
937
- const fileContents = readFileSync(filePath, "utf8");
938
- return {
939
- name: fileName,
940
- path: filePath,
941
- version: fileContents || ""
942
- };
943
- }
944
- this.logger.warn(`[File Manager] Unable to determine plain text: ${fileName}`);
945
- }
946
- write(fileState, newVersion) {
947
- writeFileSync(fileState.path, newVersion, "utf8");
948
- }
949
- isSupportedFile(fileName) {
950
- return fileName.endsWith("version.txt");
951
- }
952
- };
953
- var MSBuildProject = class {
954
- constructor(config, logger) {
955
- this.config = config;
956
- this.logger = logger;
957
- }
958
- read(fileName) {
959
- const filePath = resolve(this.config.path, fileName);
960
- if (fileExists(filePath)) {
961
- const fileContents = readFileSync(filePath, "utf8");
962
- const $ = cheerio.load(fileContents, { xmlMode: true, decodeEntities: false });
963
- const version = $("Project > PropertyGroup > Version").text();
964
- if (version) {
965
- return {
966
- name: fileName,
967
- path: filePath,
968
- version
969
- };
970
- }
971
- this.logger.warn(`[File Manager] Unable to determine ms-build package: ${fileName}`);
972
- }
973
- }
974
- write(fileState, newVersion) {
975
- const fileContents = readFileSync(fileState.path, "utf8");
976
- const $ = cheerio.load(fileContents, { xmlMode: true, decodeEntities: false });
977
- $("Project > PropertyGroup > Version").text(newVersion);
978
- const updatedContent = $.xml().replaceAll('"/>', '" />');
979
- writeFileSync(fileState.path, updatedContent, "utf8");
980
- }
981
- isSupportedFile(fileName) {
982
- return [".csproj", ".dbproj", ".esproj", ".fsproj", ".props", ".vbproj", ".vcxproj"].findIndex(
983
- (ext) => fileName.endsWith(ext)
984
- ) !== -1;
985
- }
986
- };
987
-
988
- // src/strategies/file-manager.ts
989
- var FileManager = class {
990
- constructor(config, logger) {
991
- this.config = config;
992
- this.logger = logger;
993
- this.JSONPackage = new JSONPackage(config, logger);
994
- this.PlainText = new PlainText(config, logger);
995
- this.MSBuildProject = new MSBuildProject(config, logger);
996
- }
997
- JSONPackage;
998
- PlainText;
999
- MSBuildProject;
1000
- /**
1001
- * Get the state from the given file name.
1002
- *
1003
- * @example
1004
- * ```ts
1005
- * fileManager.read("package.json");
1006
- * ```
1007
- *
1008
- * @returns
1009
- * ```json
1010
- * { "name": "package.json", "path": "/path/to/package.json", "version": "1.2.3", "isPrivate": true }
1011
- * ```
1012
- */
1013
- read(fileName) {
1014
- const _fileName = fileName.toLowerCase();
1015
- if (this.JSONPackage.isSupportedFile(_fileName)) {
1016
- return this.JSONPackage.read(fileName);
1017
- }
1018
- if (this.PlainText.isSupportedFile(_fileName)) {
1019
- return this.PlainText.read(fileName);
1020
- }
1021
- if (this.MSBuildProject.isSupportedFile(_fileName)) {
1022
- return this.MSBuildProject.read(fileName);
1023
- }
1024
- this.logger.error(`[File Manager] Unsupported file: ${fileName}`);
1025
- }
1026
- /**
1027
- * Write the new version to the given file.
1028
- *
1029
- * @example
1030
- * ```ts
1031
- * fileManager.write(
1032
- * { name: "package.json", path: "/path/to/package.json", version: "1.2.2" },
1033
- * "1.2.3"
1034
- * );
1035
- * ```
1036
- */
1037
- write(fileState, newVersion) {
1038
- if (this.config.dryRun) {
1039
- return;
1040
- }
1041
- const _fileName = fileState.name.toLowerCase();
1042
- if (this.JSONPackage.isSupportedFile(_fileName)) {
1043
- return this.JSONPackage.write(fileState, newVersion);
1044
- }
1045
- if (this.PlainText.isSupportedFile(_fileName)) {
1046
- return this.PlainText.write(fileState, newVersion);
1047
- }
1048
- if (this.MSBuildProject.isSupportedFile(_fileName)) {
1049
- return this.MSBuildProject.write(fileState, newVersion);
1050
- }
1051
- this.logger.error(`[File Manager] Unsupported file: ${fileState.path}`);
1052
- }
1053
- };
1054
-
1055
- // src/utils/logger.ts
1056
- var Logger = class {
1057
- constructor(config) {
1058
- this.config = config;
1059
- this.log = this.log.bind(this);
1060
- this.warn = this.warn.bind(this);
1061
- this.error = this.error.bind(this);
1062
- this.debug = this.debug.bind(this);
1063
- this.disableLogs = this.config.silent || this.config.inspectVersion;
1064
- }
1065
- disableLogs = false;
1066
- log(...messages) {
1067
- if (!this.disableLogs) {
1068
- console.log(...messages);
1069
- }
1070
- }
1071
- warn(...messages) {
1072
- if (!this.disableLogs) {
1073
- console.warn(...messages);
1074
- }
1075
- }
1076
- error(...messages) {
1077
- if (!this.disableLogs) {
1078
- console.error(...messages);
1079
- }
1080
- }
1081
- debug(...messages) {
1082
- if (this.config.debug && !this.disableLogs) {
1083
- console.debug(...messages);
1084
- }
1085
- }
1086
- };
1087
-
1088
1082
  export { FileManager, ForkConfigSchema, Logger, commitChanges, defineConfig, getCurrentVersion, getNextVersion, getUserConfig, tagChanges, updateChangelog };
1089
- //# sourceMappingURL=out.js.map
1090
- //# sourceMappingURL=chunk-ODYTFXKR.js.map
1083
+ //# sourceMappingURL=chunk-7ZOLJADN.js.map
1084
+ //# sourceMappingURL=chunk-7ZOLJADN.js.map