fork-version 1.6.0 → 1.7.3

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 CHANGED
@@ -1,5 +1,37 @@
1
1
  # Fork Version
2
2
 
3
+ ## 1.7.3 (2024-11-03)
4
+
5
+
6
+ ### Refactor
7
+
8
+ * general cleanup of error message handling ([#78](https://github.com/eglavin/fork-version/issues/78)) ([a83ff13](https://github.com/eglavin/fork-version/commit/a83ff13443d50edfba18c5502d9c38e834e3236d))
9
+
10
+
11
+ ## 1.7.2 (2024-11-02)
12
+
13
+
14
+ ### Chore
15
+
16
+ * bump pnpm dependency ([#77](https://github.com/eglavin/fork-version/issues/77)) ([158c70c](https://github.com/eglavin/fork-version/commit/158c70c06311fb624be03b522c06730f8f314d37))
17
+
18
+
19
+ ## 1.7.1 (2024-11-01)
20
+
21
+
22
+ ### Docs
23
+
24
+ * update using npx section of readme ([737a72a](https://github.com/eglavin/fork-version/commit/737a72a8485a5e1035543245c498e9f76ce1050b))
25
+
26
+
27
+ ## 1.7.0 (2024-10-31)
28
+
29
+
30
+ ### Features
31
+
32
+ * add yaml support ([#76](https://github.com/eglavin/fork-version/issues/76)) ([2a0d89e](https://github.com/eglavin/fork-version/commit/2a0d89e6174ef098ec7fc697ff05e24572b4a84c))
33
+
34
+
3
35
  ## 1.6.0 (2024-10-27)
4
36
 
5
37
 
package/README.md CHANGED
@@ -41,19 +41,28 @@ Fork-Version can be configured either through a config file or by passing option
41
41
 
42
42
  ### Using `npx` (Recommended)
43
43
 
44
- To use Fork-Version with `npx` you can use the following command, by using `npx` you can also use Fork-Version without installation and on other projects including non node projects.
44
+ To use Fork-Version without installation you can use `npx`:
45
45
 
46
46
  ```sh
47
47
  npx fork-version
48
48
  ```
49
49
 
50
+ `npx` is a package runner which allows you to execute npm packages without installation, this can be useful when working on projects outside of the Node ecosystem.
51
+
50
52
  > [!NOTE]
51
- > If you want to use a specific version you can add a version tag to the end of the name.
53
+ > By default `npx` will use the latest release, if you want to use a specific version you can add a version tag to the end of the name.
52
54
  >
53
- > Example: `npx fork-version@1.4.67`
55
+ > Example: `npx fork-version@1.7.0`
54
56
  >
55
57
  > The version tag needs to match against one of the [published versions on npm](https://www.npmjs.com/package/fork-version?activeTab=versions).
56
58
 
59
+ Alternatively you can use other npm compatible javascript runtime's:
60
+
61
+ | Runner | Command |
62
+ | ------ | -------------------------- |
63
+ | bun | `bunx fork-version` |
64
+ | deno | `deno -A npm:fork-version` |
65
+
57
66
  ### Install Locally
58
67
 
59
68
  To install the package locally to your project you can use one of the following commands:
@@ -63,6 +72,7 @@ To install the package locally to your project you can use one of the following
63
72
  | npm | `npm install fork-version --save-dev` |
64
73
  | yarn | `yarn add fork-version --dev` |
65
74
  | pnpm | `pnpm add fork-version --save-dev` |
75
+ | bun | `bun install fork-version --dev` |
66
76
 
67
77
  You can then add the following entry to your package.json scripts section and use it like any other script you already use in your project.
68
78
 
@@ -76,6 +86,16 @@ You can then add the following entry to your package.json scripts section and us
76
86
 
77
87
  For example if you use npm you can now use `npm run release` to run Fork-Version.
78
88
 
89
+ ### Exit Codes
90
+
91
+ When ran as a cli tool Fork-Version will exit with one of the following exit codes:
92
+
93
+ | Exit Code | Description |
94
+ | --------- | ---------------------------- |
95
+ | 0 | Success |
96
+ | 1 | General Error |
97
+ | 3 | Config File Validation Error |
98
+
79
99
  ### Command Line Options
80
100
 
81
101
  <!-- START COMMAND LINE OPTIONS -->
@@ -129,6 +149,11 @@ Conventional Changelog Overrides:
129
149
  --release-commit-message-format Override the default release commit message format.
130
150
  --release-message-suffix Add a suffix to the end of the release message.
131
151
 
152
+ Exit Codes:
153
+ 0: Success
154
+ 1: General Error
155
+ 3: Config File Validation Error
156
+
132
157
  Examples:
133
158
  $ fork-version
134
159
  Run fork-version in the current directory with default options.
@@ -374,6 +399,7 @@ Adds a suffix to the end of the release message, useful to add a `[skip ci]` mes
374
399
  ### Supported File Types
375
400
 
376
401
  - [Json Package](#json-package)
402
+ - [Yaml Package](#yaml-package)
377
403
  - [Plain Text](#plain-text)
378
404
  - [MS Build](#ms-build)
379
405
 
@@ -389,6 +415,20 @@ A json package is a json file which contains a version property, such as a npm p
389
415
  }
390
416
  ```
391
417
 
418
+ #### Yaml Package
419
+
420
+ A yaml package is a yaml file which contains a version property, such as a dart pubspec.yaml file.
421
+
422
+ ```yaml
423
+ name: wordionary
424
+ description: "My project"
425
+ publish_to: 'none'
426
+ version: 1.2.3
427
+ ```
428
+
429
+ > [!NOTE]
430
+ > If you're using Fork-Version for a flutter project, Fork-Version will split the version and the builder number on the "+" character, the version will be updated and the builder number will be left as is.
431
+
392
432
  #### Plain Text
393
433
 
394
434
  A plain text file will have just the version as the content.
@@ -10,6 +10,7 @@ var meow = require('meow');
10
10
  var conventionalChangelogConfigSpec = require('conventional-changelog-config-spec');
11
11
  var child_process = require('child_process');
12
12
  var jsoncParser = require('jsonc-parser');
13
+ var yaml = require('yaml');
13
14
  var cheerio = require('cheerio/slim');
14
15
  var semver3 = require('semver');
15
16
  var conventionalRecommendedBump = require('conventional-recommended-bump');
@@ -389,6 +390,11 @@ Conventional Changelog Overrides:
389
390
  --release-commit-message-format Override the default release commit message format.
390
391
  --release-message-suffix Add a suffix to the end of the release message.
391
392
 
393
+ Exit Codes:
394
+ 0: Success
395
+ 1: General Error
396
+ 3: Config File Validation Error
397
+
392
398
  Examples:
393
399
  $ fork-version
394
400
  Run fork-version in the current directory with default options.
@@ -403,7 +409,7 @@ Examples:
403
409
  Run fork-version and update all "package.json" files in subdirectories.`;
404
410
  function getCliArguments() {
405
411
  return meow__default.default(helperText, {
406
- importMeta: ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-MC3XSR7P.cjs', document.baseURI).href)) }),
412
+ importMeta: ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-PKSCXRF2.cjs', document.baseURI).href)) }),
407
413
  booleanDefault: void 0,
408
414
  helpIndent: 0,
409
415
  flags: {
@@ -601,7 +607,7 @@ async function loadConfigFile(configFilePath) {
601
607
  if (fileContent2[PACKAGE_JSON_CONFIG_KEY] && typeof fileContent2[PACKAGE_JSON_CONFIG_KEY] === "object") {
602
608
  const parsed3 = ForkConfigSchema.partial().safeParse(fileContent2[PACKAGE_JSON_CONFIG_KEY]);
603
609
  if (!parsed3.success) {
604
- throw parsed3.error;
610
+ throw new Error(`Validation error in: ${configFilePath}`, { cause: parsed3.error });
605
611
  }
606
612
  return parsed3.data;
607
613
  }
@@ -609,14 +615,14 @@ async function loadConfigFile(configFilePath) {
609
615
  }
610
616
  const parsed2 = ForkConfigSchema.partial().safeParse(fileContent2);
611
617
  if (!parsed2.success) {
612
- throw parsed2.error;
618
+ throw new Error(`Validation error in: ${configFilePath}`, { cause: parsed2.error });
613
619
  }
614
620
  return parsed2.data;
615
621
  }
616
622
  const fileContent = await bundleRequire.bundleRequire({ filepath: configFilePath });
617
623
  const parsed = ForkConfigSchema.partial().safeParse(fileContent.mod.default || fileContent.mod);
618
624
  if (!parsed.success) {
619
- throw parsed.error;
625
+ throw new Error(`Validation error in: ${configFilePath}`, { cause: parsed.error });
620
626
  }
621
627
  return parsed.data;
622
628
  }
@@ -707,7 +713,7 @@ var JSONPackage = class {
707
713
  isPrivate: typeof parsedJson?.private === "boolean" ? parsedJson.private : true
708
714
  };
709
715
  }
710
- this.logger.warn(`[File Manager] Unable to determine json package: ${fileName}`);
716
+ this.logger.warn(`[File Manager] Unable to determine json version: ${fileName}`);
711
717
  }
712
718
  }
713
719
  write(fileState, newVersion) {
@@ -732,6 +738,59 @@ function setStringInJsonc(jsonc, jsonPath, newString) {
732
738
  const edits = jsoncParser.modify(jsonc, jsonPath, newString, {});
733
739
  return jsoncParser.applyEdits(jsonc, edits);
734
740
  }
741
+ var YAMLPackage = class {
742
+ constructor(config, logger) {
743
+ this.config = config;
744
+ this.logger = logger;
745
+ }
746
+ /**
747
+ * If the version is returned with a "+" symbol in the value then the version might be from a
748
+ * flutter `pubspec.yaml` file, if so we want to retain the input builderNumber by splitting it
749
+ * and joining it again later.
750
+ */
751
+ handleBuildNumber(fileVersion) {
752
+ const [version, builderNumber] = fileVersion.split("+");
753
+ if (/^\d+$/.test(builderNumber)) {
754
+ return {
755
+ version,
756
+ builderNumber
757
+ };
758
+ }
759
+ return {
760
+ version: fileVersion
761
+ };
762
+ }
763
+ read(fileName) {
764
+ const filePath = path.resolve(this.config.path, fileName);
765
+ if (fileExists(filePath)) {
766
+ const fileContents = fs.readFileSync(filePath, "utf-8");
767
+ const fileVersion = yaml.parse(fileContents)?.version;
768
+ if (fileVersion) {
769
+ const parsedVersion = this.handleBuildNumber(fileVersion);
770
+ return {
771
+ name: fileName,
772
+ path: filePath,
773
+ version: parsedVersion.version || "",
774
+ builderNumber: parsedVersion.builderNumber ?? void 0
775
+ };
776
+ }
777
+ }
778
+ this.logger.warn(`[File Manager] Unable to determine yaml version: ${fileName}`);
779
+ }
780
+ write(fileState, newVersion) {
781
+ const fileContents = fs.readFileSync(fileState.path, "utf8");
782
+ const yamlDocument = yaml.parseDocument(fileContents);
783
+ let newFileVersion = newVersion;
784
+ if (fileState.builderNumber !== void 0) {
785
+ newFileVersion += `+${fileState.builderNumber}`;
786
+ }
787
+ yamlDocument.set("version", newFileVersion);
788
+ fs.writeFileSync(fileState.path, yamlDocument.toString(), "utf8");
789
+ }
790
+ isSupportedFile(fileName) {
791
+ return fileName.endsWith(".yaml") || fileName.endsWith(".yml");
792
+ }
793
+ };
735
794
  var PlainText = class {
736
795
  constructor(config, logger) {
737
796
  this.config = config;
@@ -747,7 +806,7 @@ var PlainText = class {
747
806
  version: fileContents || ""
748
807
  };
749
808
  }
750
- this.logger.warn(`[File Manager] Unable to determine plain text: ${fileName}`);
809
+ this.logger.warn(`[File Manager] Unable to determine plain text version: ${fileName}`);
751
810
  }
752
811
  write(fileState, newVersion) {
753
812
  fs.writeFileSync(fileState.path, newVersion, "utf8");
@@ -777,7 +836,7 @@ var MSBuildProject = class {
777
836
  version
778
837
  };
779
838
  }
780
- this.logger.warn(`[File Manager] Unable to determine ms-build package: ${fileName}`);
839
+ this.logger.warn(`[File Manager] Unable to determine ms-build version: ${fileName}`);
781
840
  }
782
841
  }
783
842
  write(fileState, newVersion) {
@@ -803,10 +862,12 @@ var FileManager = class {
803
862
  this.config = config;
804
863
  this.logger = logger;
805
864
  this.JSONPackage = new JSONPackage(config, logger);
865
+ this.YAMLPackage = new YAMLPackage(config, logger);
806
866
  this.PlainText = new PlainText(config, logger);
807
867
  this.MSBuildProject = new MSBuildProject(config, logger);
808
868
  }
809
869
  JSONPackage;
870
+ YAMLPackage;
810
871
  PlainText;
811
872
  MSBuildProject;
812
873
  /**
@@ -827,6 +888,9 @@ var FileManager = class {
827
888
  if (this.JSONPackage.isSupportedFile(_fileName)) {
828
889
  return this.JSONPackage.read(fileName);
829
890
  }
891
+ if (this.YAMLPackage.isSupportedFile(_fileName)) {
892
+ return this.YAMLPackage.read(fileName);
893
+ }
830
894
  if (this.PlainText.isSupportedFile(_fileName)) {
831
895
  return this.PlainText.read(fileName);
832
896
  }
@@ -854,6 +918,9 @@ var FileManager = class {
854
918
  if (this.JSONPackage.isSupportedFile(_fileName)) {
855
919
  return this.JSONPackage.write(fileState, newVersion);
856
920
  }
921
+ if (this.YAMLPackage.isSupportedFile(_fileName)) {
922
+ return this.YAMLPackage.write(fileState, newVersion);
923
+ }
857
924
  if (this.PlainText.isSupportedFile(_fileName)) {
858
925
  return this.PlainText.write(fileState, newVersion);
859
926
  }
@@ -906,17 +973,20 @@ function getReleaseType(releaseType, currentVersion, preReleaseTag) {
906
973
  }
907
974
 
908
975
  // src/process/version.ts
909
- async function getCurrentVersion(config, logger, fileManager, filesToUpdate) {
976
+ async function getCurrentVersion(config, logger, git, fileManager, filesToUpdate) {
910
977
  const files = [];
911
978
  const versions = /* @__PURE__ */ new Set();
912
979
  for (const file of filesToUpdate) {
980
+ if (await git.shouldIgnore(file)) {
981
+ logger.debug(`[Git Ignored] ${file}`);
982
+ continue;
983
+ }
913
984
  const fileState = fileManager.read(file);
914
985
  if (fileState) {
915
986
  files.push(fileState);
916
- if (config.currentVersion) {
917
- continue;
987
+ if (!config.currentVersion) {
988
+ versions.add(fileState.version);
918
989
  }
919
- versions.add(fileState.version);
920
990
  }
921
991
  }
922
992
  if (config.currentVersion) {
@@ -925,7 +995,7 @@ async function getCurrentVersion(config, logger, fileManager, filesToUpdate) {
925
995
  if (versions.size === 0 && config.gitTagFallback) {
926
996
  const version = await getLatestGitTagVersion(config.tagPrefix);
927
997
  if (version) {
928
- logger.log(`[Version] Using git tag fallback.`);
998
+ logger.warn(`Using latest git tag fallback`);
929
999
  versions.add(version);
930
1000
  }
931
1001
  }
@@ -935,8 +1005,9 @@ async function getCurrentVersion(config, logger, fileManager, filesToUpdate) {
935
1005
  if (!config.allowMultipleVersions) {
936
1006
  throw new Error("Found multiple versions");
937
1007
  }
938
- logger.warn("[WARNING] Found multiple versions, using the first one.");
939
- logger.log(`Versions: ${Array.from(versions).join(", ")}`);
1008
+ logger.warn(
1009
+ `Found multiple versions (${Array.from(versions).join(", ")}), using the higher semver version`
1010
+ );
940
1011
  }
941
1012
  const currentVersion = semver3__default.default.rsort(Array.from(versions))[0];
942
1013
  if (config.inspectVersion) {
@@ -951,7 +1022,7 @@ async function getCurrentVersion(config, logger, fileManager, filesToUpdate) {
951
1022
  }
952
1023
  async function getNextVersion(config, logger, currentVersion) {
953
1024
  if (config.skipBump) {
954
- logger.log("Skip bump, using current version as next version");
1025
+ logger.warn(`Skip bump, using ${currentVersion} as the next version`);
955
1026
  return {
956
1027
  version: currentVersion
957
1028
  };
@@ -964,14 +1035,14 @@ async function getNextVersion(config, logger, currentVersion) {
964
1035
  }
965
1036
  const isPreMajor = semver3__default.default.lt(currentVersion, "1.0.0");
966
1037
  let recommendedBump;
967
- try {
968
- if (config.releaseAs) {
969
- recommendedBump = {
970
- releaseType: config.releaseAs,
971
- level: -1,
972
- reason: "User defined"
973
- };
974
- } else {
1038
+ if (config.releaseAs) {
1039
+ recommendedBump = {
1040
+ releaseType: config.releaseAs,
1041
+ level: -1,
1042
+ reason: "User defined"
1043
+ };
1044
+ } else {
1045
+ try {
975
1046
  recommendedBump = await conventionalRecommendedBump__default.default({
976
1047
  preset: {
977
1048
  name: "conventionalcommits",
@@ -982,9 +1053,11 @@ async function getNextVersion(config, logger, currentVersion) {
982
1053
  tagPrefix: config.tagPrefix,
983
1054
  cwd: config.path
984
1055
  });
1056
+ } catch (cause) {
1057
+ throw new Error(`[conventional-recommended-bump] Unable to determine next version`, {
1058
+ cause
1059
+ });
985
1060
  }
986
- } catch (_error) {
987
- throw new Error(`[conventional-recommended-bump] Unable to determine next version`);
988
1061
  }
989
1062
  if (recommendedBump.releaseType) {
990
1063
  const releaseType = getReleaseType(
@@ -992,18 +1065,18 @@ async function getNextVersion(config, logger, currentVersion) {
992
1065
  currentVersion,
993
1066
  config.preRelease
994
1067
  );
995
- const state = {
1068
+ const nextVersion = semver3__default.default.inc(
1069
+ currentVersion,
1070
+ releaseType,
1071
+ typeof config.preRelease === "string" ? config.preRelease : void 0
1072
+ ) ?? "";
1073
+ logger.log(`Next version: ${nextVersion} (${releaseType})`);
1074
+ return {
996
1075
  ...recommendedBump,
997
1076
  preMajor: isPreMajor,
998
1077
  releaseType,
999
- version: semver3__default.default.inc(
1000
- currentVersion,
1001
- releaseType,
1002
- typeof config.preRelease === "string" ? config.preRelease : void 0
1003
- ) ?? ""
1078
+ version: nextVersion
1004
1079
  };
1005
- logger.log(`Next version: ${state.version} (${state.releaseType})`);
1006
- return state;
1007
1080
  }
1008
1081
  throw new Error("Unable to find next version");
1009
1082
  }
@@ -1038,9 +1111,8 @@ function getNewReleaseContent(config, logger, nextVersion) {
1038
1111
  merges: null,
1039
1112
  path: config.path
1040
1113
  }
1041
- ).on("error", (error) => {
1042
- logger.error("[conventional-changelog] Unable to parse changes");
1043
- throw error;
1114
+ ).on("error", (cause) => {
1115
+ throw new Error("[conventional-changelog] Unable to parse changes", { cause });
1044
1116
  }).on("data", (chunk) => {
1045
1117
  newContent += chunk.toString();
1046
1118
  }).on("end", () => {
@@ -1050,7 +1122,7 @@ function getNewReleaseContent(config, logger, nextVersion) {
1050
1122
  }
1051
1123
  async function updateChangelog(config, logger, nextVersion) {
1052
1124
  if (config.skipChangelog) {
1053
- logger.log("Skip changelog update");
1125
+ logger.warn("Skip changelog update");
1054
1126
  return;
1055
1127
  }
1056
1128
  if (config.header.search(RELEASE_PATTERN) !== -1) {
@@ -1058,12 +1130,13 @@ async function updateChangelog(config, logger, nextVersion) {
1058
1130
  }
1059
1131
  const changelogPath = path.resolve(config.path, config.changelog);
1060
1132
  if (!config.dryRun && !fileExists(changelogPath)) {
1061
- logger.log(`Creating Changelog file: ${changelogPath}`);
1133
+ logger.log(`Creating Changelog: ${changelogPath}`);
1062
1134
  fs.writeFileSync(changelogPath, "\n", "utf8");
1135
+ } else {
1136
+ logger.log(`Updating Changelog: ${changelogPath}`);
1063
1137
  }
1064
1138
  const oldContent = getOldReleaseContent(changelogPath, fileExists(changelogPath));
1065
1139
  const newContent = await getNewReleaseContent(config, logger, nextVersion);
1066
- logger.log(`Updating Changelog: ${changelogPath}`);
1067
1140
  if (!config.dryRun && newContent) {
1068
1141
  fs.writeFileSync(
1069
1142
  changelogPath,
@@ -1087,7 +1160,7 @@ function formatCommitMessage(message, version) {
1087
1160
  // src/process/commit.ts
1088
1161
  async function commitChanges(config, logger, git, files, nextVersion) {
1089
1162
  if (config.skipCommit) {
1090
- logger.log("Skip commit");
1163
+ logger.warn("Skip commit");
1091
1164
  return;
1092
1165
  }
1093
1166
  logger.log("Committing changes");
@@ -1119,7 +1192,7 @@ async function commitChanges(config, logger, git, files, nextVersion) {
1119
1192
  // src/process/tag.ts
1120
1193
  async function tagChanges(config, logger, git, nextVersion) {
1121
1194
  if (config.skipTag) {
1122
- logger.log("Skip tag creation");
1195
+ logger.warn("Skip tag creation");
1123
1196
  return;
1124
1197
  }
1125
1198
  const tag = `${config.tagPrefix}${nextVersion}`;
@@ -1142,5 +1215,5 @@ exports.getNextVersion = getNextVersion;
1142
1215
  exports.getUserConfig = getUserConfig;
1143
1216
  exports.tagChanges = tagChanges;
1144
1217
  exports.updateChangelog = updateChangelog;
1145
- //# sourceMappingURL=chunk-MC3XSR7P.cjs.map
1146
- //# sourceMappingURL=chunk-MC3XSR7P.cjs.map
1218
+ //# sourceMappingURL=chunk-PKSCXRF2.cjs.map
1219
+ //# sourceMappingURL=chunk-PKSCXRF2.cjs.map