fork-version 1.4.91 → 1.5.0

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.
@@ -6,17 +6,16 @@ var path = require('path');
6
6
  var JoyCon = require('joycon');
7
7
  var bundleRequire = require('bundle-require');
8
8
  var glob = require('glob');
9
- var dotgitignore = require('dotgitignore');
10
9
  var meow = require('meow');
11
10
  var conventionalChangelogConfigSpec = require('conventional-changelog-config-spec');
12
11
  var child_process = require('child_process');
12
+ var detectIndent = require('detect-indent');
13
+ var detectNewline = require('detect-newline');
14
+ var cheerio = require('cheerio/slim');
13
15
  var semver3 = require('semver');
14
16
  var conventionalRecommendedBump = require('conventional-recommended-bump');
15
17
  var gitSemverTags = require('git-semver-tags');
16
18
  var conventionalChangelog = require('conventional-changelog');
17
- var detectIndent = require('detect-indent');
18
- var detectNewline = require('detect-newline');
19
- var cheerio = require('cheerio/lib/slim');
20
19
 
21
20
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
22
21
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -40,17 +39,16 @@ function _interopNamespace(e) {
40
39
  }
41
40
 
42
41
  var JoyCon__default = /*#__PURE__*/_interopDefault(JoyCon);
43
- var dotgitignore__default = /*#__PURE__*/_interopDefault(dotgitignore);
44
42
  var meow__default = /*#__PURE__*/_interopDefault(meow);
45
43
  var conventionalChangelogConfigSpec__default = /*#__PURE__*/_interopDefault(conventionalChangelogConfigSpec);
44
+ var detectIndent__default = /*#__PURE__*/_interopDefault(detectIndent);
45
+ var cheerio__namespace = /*#__PURE__*/_interopNamespace(cheerio);
46
46
  var semver3__default = /*#__PURE__*/_interopDefault(semver3);
47
47
  var conventionalRecommendedBump__default = /*#__PURE__*/_interopDefault(conventionalRecommendedBump);
48
48
  var gitSemverTags__default = /*#__PURE__*/_interopDefault(gitSemverTags);
49
49
  var conventionalChangelog__default = /*#__PURE__*/_interopDefault(conventionalChangelog);
50
- var detectIndent__default = /*#__PURE__*/_interopDefault(detectIndent);
51
- var cheerio__namespace = /*#__PURE__*/_interopNamespace(cheerio);
52
50
 
53
- // src/config/schema.ts
51
+ // src/config/schema.js
54
52
  var ChangelogPresetConfigTypeSchema = zod.z.object({
55
53
  /**
56
54
  * The type of commit message.
@@ -112,10 +110,10 @@ var ForkConfigSchema = zod.z.object({
112
110
  // Commands
113
111
  //
114
112
  /**
115
- * If set, fork-version will print the current version and exit.
113
+ * If set, Fork-Version will print the current version and exit.
116
114
  * @default false
117
115
  */
118
- inspectVersion: zod.z.boolean().describe("If set, fork-version will print the current version and exit."),
116
+ inspectVersion: zod.z.boolean().describe("If set, Fork-Version will print the current version and exit."),
119
117
  // Options
120
118
  //
121
119
  /**
@@ -138,13 +136,13 @@ var ForkConfigSchema = zod.z.object({
138
136
  */
139
137
  glob: zod.z.string().optional().describe("Glob pattern to match files to be updated."),
140
138
  /**
141
- * The path fork-version will run from.
139
+ * The path Fork-Version will run from.
142
140
  * @default
143
141
  * ```js
144
142
  * process.cwd()
145
143
  * ```
146
144
  */
147
- path: zod.z.string().describe('The path fork-version will run from. Defaults to "process.cwd()".'),
145
+ path: zod.z.string().describe('The path Fork-Version will run from. Defaults to "process.cwd()".'),
148
146
  /**
149
147
  * Name of the changelog file.
150
148
  * @default "CHANGELOG.md"
@@ -194,18 +192,26 @@ var ForkConfigSchema = zod.z.object({
194
192
  */
195
193
  preRelease: zod.z.string().or(zod.z.boolean()).optional().describe("Make a pre-release with optional label if given value is a string."),
196
194
  /**
197
- * If set, fork-version will use this version instead of trying to determine one.
195
+ * If set, Fork-Version will use this version instead of trying to determine one.
198
196
  * @example "1.0.0"
199
197
  * @default undefined
200
198
  */
201
- currentVersion: zod.z.string().optional().describe("If set, fork-version will use this version instead of trying to determine one."),
199
+ currentVersion: zod.z.string().optional().describe("If set, Fork-Version will use this version instead of trying to determine one."),
202
200
  /**
203
- * If set, fork-version will attempt to update to this version, instead of incrementing using "conventional-commit".
201
+ * If set, Fork-Version will attempt to update to this version, instead of incrementing using "conventional-commit".
204
202
  * @example "2.0.0"
205
203
  * @default undefined
206
204
  */
207
205
  nextVersion: zod.z.string().optional().describe(
208
- 'If set, fork-version will attempt to update to this version, instead of incrementing using "conventional-commit".'
206
+ 'If set, Fork-Version will attempt to update to this version, instead of incrementing using "conventional-commit".'
207
+ ),
208
+ /**
209
+ * Release as increments the version by the specified level. Overrides the default behaviour of "conventional-commit".
210
+ * @example "major", "minor", "patch"
211
+ * @default undefined
212
+ */
213
+ releaseAs: zod.z.union([zod.z.literal("major"), zod.z.literal("minor"), zod.z.literal("patch")]).optional().describe(
214
+ 'Release as increments the version by the specified level. Overrides the default behaviour of "conventional-commit".'
209
215
  ),
210
216
  // Flags
211
217
  //
@@ -215,10 +221,10 @@ var ForkConfigSchema = zod.z.object({
215
221
  */
216
222
  allowMultipleVersions: zod.z.boolean().describe("Don't throw an error if multiple versions are found in the given files."),
217
223
  /**
218
- * Commit all changes, not just files updated by fork-version.
224
+ * Commit all changes, not just files updated by Fork-Version.
219
225
  * @default false
220
226
  */
221
- commitAll: zod.z.boolean().describe("Commit all changes, not just files updated by fork-version."),
227
+ commitAll: zod.z.boolean().describe("Commit all changes, not just files updated by Fork-Version."),
222
228
  /**
223
229
  * By default the conventional-changelog spec will only add commit types of `feat` and `fix` to the generated changelog.
224
230
  * If this flag is set, all [default commit types](https://github.com/conventional-changelog/conventional-changelog-config-spec/blob/238093090c14bd7d5151eb5316e635623ce633f9/versions/2.2.0/schema.json#L18)
@@ -295,9 +301,6 @@ var ForkConfigSchema = zod.z.object({
295
301
  */
296
302
  releaseMessageSuffix: zod.z.string().optional().describe("Add a suffix to the release commit message.")
297
303
  });
298
- function defineConfig(config) {
299
- return config;
300
- }
301
304
 
302
305
  // src/config/defaults.ts
303
306
  var DEFAULT_CONFIG = {
@@ -342,48 +345,49 @@ var helperText = `Usage:
342
345
  $ fork-version [options]
343
346
 
344
347
  Commands:
345
- --help Show this help message.
346
- --version Show the current version of fork-version.
347
- --inspect-version If set, fork-version will print the current project version and exit.
348
+ --help Show this help message.
349
+ --version Show the current version of Fork-Version.
350
+ --inspect-version If set, Fork-Version will print the current project version and exit.
348
351
 
349
352
  Options:
350
- --file, -F List of the files to be updated. [Default: ["bower.json", "deno.json", "jsr.json", "manifest.json", "npm-shrinkwrap.json", "package-lock.json", "package.json"]]
351
- --glob, -G Glob pattern to match files to be updated.
352
- --path, -P The path fork-version will run from. [Default: process.cwd()]
353
- --changelog Name of the changelog file. [Default: "CHANGELOG.md"]
354
- --header The header text for the changelog.
355
- --tag-prefix Specify a prefix for the created tag. [Default: "v"]
356
- --pre-release Mark this release as a pre-release.
357
- --pre-release-tag Mark this release with a tagged pre-release. [Example: "alpha", "beta", "rc"]
358
- --current-version If set, fork-version will use this version instead of trying to determine one.
359
- --next-version If set, fork-version will attempt to update to this version, instead of incrementing using "conventional-commit".
353
+ --file, -F List of the files to be updated. [Default: ["bower.json", "deno.json", "jsr.json", "manifest.json", "npm-shrinkwrap.json", "package-lock.json", "package.json"]]
354
+ --glob, -G Glob pattern to match files to be updated.
355
+ --path, -P The path Fork-Version will run from. [Default: process.cwd()]
356
+ --changelog Name of the changelog file. [Default: "CHANGELOG.md"]
357
+ --header The header text for the changelog.
358
+ --tag-prefix Specify a prefix for the created tag. [Default: "v"]
359
+ --pre-release Mark this release as a pre-release.
360
+ --pre-release-tag Mark this release with a tagged pre-release. [Example: "alpha", "beta", "rc"]
361
+ --current-version If set, Fork-Version will use this version instead of trying to determine one.
362
+ --next-version If set, Fork-Version will attempt to update to this version, instead of incrementing using "conventional-commit".
363
+ --release-as Release as increments the version by the specified level. [Choices: "major", "minor", "patch"]
360
364
 
361
365
  Flags:
362
- --allow-multiple-versions Don't throw an error if multiple versions are found in the given files. [Default: true]
363
- --commit-all Commit all changes, not just files updated by fork-version.
364
- --changelog-all If this flag is set, all default commit types will be added to the changelog.
365
- --debug Output debug information.
366
- --dry-run No output will be written to disk or committed.
367
- --silent Run without logging to the terminal.
368
- --git-tag-fallback If unable to find a version in the given files, fallback and attempt to use the latest git tag. [Default: true]
369
- --sign If true, git will sign the commit with the systems GPG key.
370
- --verify If true, git will run user defined git hooks before committing.
366
+ --allow-multiple-versions Don't throw an error if multiple versions are found in the given files. [Default: true]
367
+ --commit-all Commit all changes, not just files updated by Fork-Version.
368
+ --changelog-all If this flag is set, all default commit types will be added to the changelog.
369
+ --debug Output debug information.
370
+ --dry-run No output will be written to disk or committed.
371
+ --silent Run without logging to the terminal.
372
+ --git-tag-fallback If unable to find a version in the given files, fallback and attempt to use the latest git tag. [Default: true]
373
+ --sign If true, git will sign the commit with the systems GPG key.
374
+ --verify If true, git will run user defined git hooks before committing.
371
375
 
372
376
  To negate a flag you can prefix it with "no-", for example "--no-git-tag-fallback" will not fallback to the latest git tag.
373
377
 
374
378
  Skip Steps:
375
- --skip-bump Skip the version bump step.
376
- --skip-changelog Skip updating the changelog.
377
- --skip-commit Skip committing the changes.
378
- --skip-tag Skip tagging the commit.
379
+ --skip-bump Skip the version bump step.
380
+ --skip-changelog Skip updating the changelog.
381
+ --skip-commit Skip committing the changes.
382
+ --skip-tag Skip tagging the commit.
379
383
 
380
384
  Conventional Changelog Overrides:
381
- --commit-url-format Override the default commit URL format.
382
- --compare-url-format Override the default compare URL format.
383
- --issue-url-format Override the default issue URL format.
384
- --user-url-format Override the default user URL format.
385
- --release-commit-message-format Override the default release commit message format.
386
- --release-message-suffix Add a suffix to the end of the release message.
385
+ --commit-url-format Override the default commit URL format.
386
+ --compare-url-format Override the default compare URL format.
387
+ --issue-url-format Override the default issue URL format.
388
+ --user-url-format Override the default user URL format.
389
+ --release-commit-message-format Override the default release commit message format.
390
+ --release-message-suffix Add a suffix to the end of the release message.
387
391
 
388
392
  Examples:
389
393
  $ fork-version
@@ -399,7 +403,7 @@ Examples:
399
403
  Run fork-version and update all "package.json" files in subdirectories.`;
400
404
  function getCliArguments() {
401
405
  return meow__default.default(helperText, {
402
- importMeta: ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('out.js', document.baseURI).href)) }),
406
+ importMeta: ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-SAIF32GN.cjs', document.baseURI).href)) }),
403
407
  booleanDefault: void 0,
404
408
  helpIndent: 0,
405
409
  flags: {
@@ -416,6 +420,7 @@ function getCliArguments() {
416
420
  preReleaseTag: { type: "string" },
417
421
  currentVersion: { type: "string" },
418
422
  nextVersion: { type: "string" },
423
+ releaseAs: { type: "string", choices: ["major", "minor", "patch"] },
419
424
  // Flags
420
425
  allowMultipleVersions: { type: "boolean" },
421
426
  commitAll: { type: "boolean" },
@@ -573,10 +578,7 @@ async function getUserConfig() {
573
578
  const detectedGitHost = await detectGitHost(cwd);
574
579
  return {
575
580
  ...mergedConfig,
576
- files: filterGitIgnoredFiles(
577
- cwd,
578
- getFilesList(configFile?.files, cliArguments.flags?.files, globResults)
579
- ),
581
+ files: getFilesList(configFile?.files, cliArguments.flags?.files, globResults),
580
582
  path: cwd,
581
583
  preRelease: (
582
584
  // Meow doesn't support multiple flags with the same name, so we need to check both.
@@ -632,10 +634,232 @@ function getFilesList(configFiles, cliFiles, globResults) {
632
634
  }
633
635
  return DEFAULT_CONFIG.files;
634
636
  }
635
- function filterGitIgnoredFiles(cwd, files) {
636
- const dotgit = dotgitignore__default.default({ cwd });
637
- return files.filter((file) => !dotgit.ignore(file));
637
+ function defineConfig(config) {
638
+ return config;
638
639
  }
640
+
641
+ // src/utils/logger.ts
642
+ var Logger = class {
643
+ constructor(config) {
644
+ this.config = config;
645
+ this.log = this.log.bind(this);
646
+ this.warn = this.warn.bind(this);
647
+ this.error = this.error.bind(this);
648
+ this.debug = this.debug.bind(this);
649
+ this.disableLogs = this.config.silent || this.config.inspectVersion;
650
+ }
651
+ disableLogs = false;
652
+ log(...messages) {
653
+ if (!this.disableLogs) {
654
+ console.log(...messages);
655
+ }
656
+ }
657
+ warn(...messages) {
658
+ if (!this.disableLogs) {
659
+ console.warn(...messages);
660
+ }
661
+ }
662
+ error(...messages) {
663
+ if (!this.disableLogs) {
664
+ console.error(...messages);
665
+ }
666
+ }
667
+ debug(...messages) {
668
+ if (this.config.debug && !this.disableLogs) {
669
+ console.debug(...messages);
670
+ }
671
+ }
672
+ };
673
+
674
+ // src/libs/stringify-package.ts
675
+ var DEFAULT_INDENT = 2;
676
+ var CRLF = "\r\n";
677
+ var LF = "\n";
678
+ function stringifyPackage(data, indent, newline) {
679
+ const stringified = JSON.stringify(data, null, indent ?? DEFAULT_INDENT);
680
+ if (newline === CRLF) {
681
+ return stringified.replace(new RegExp(LF, "g"), CRLF);
682
+ }
683
+ return stringified;
684
+ }
685
+ function fileExists(filePath) {
686
+ try {
687
+ return fs.lstatSync(filePath).isFile();
688
+ } catch (_error) {
689
+ return false;
690
+ }
691
+ }
692
+
693
+ // src/strategies/json-package.ts
694
+ var JSONPackage = class {
695
+ constructor(config, logger) {
696
+ this.config = config;
697
+ this.logger = logger;
698
+ }
699
+ read(fileName) {
700
+ const filePath = path.resolve(this.config.path, fileName);
701
+ if (fileExists(filePath)) {
702
+ const fileContents = fs.readFileSync(filePath, "utf8");
703
+ const parsedJson = JSON.parse(fileContents);
704
+ if (parsedJson.version) {
705
+ return {
706
+ name: fileName,
707
+ path: filePath,
708
+ version: parsedJson.version,
709
+ isPrivate: typeof parsedJson?.private === "boolean" ? parsedJson.private : true
710
+ };
711
+ }
712
+ this.logger.warn(`[File Manager] Unable to determine json package: ${fileName}`);
713
+ }
714
+ }
715
+ write(fileState, newVersion) {
716
+ const fileContents = fs.readFileSync(fileState.path, "utf8");
717
+ const parsedJson = JSON.parse(fileContents);
718
+ parsedJson.version = newVersion;
719
+ if (parsedJson.packages?.[""]) {
720
+ parsedJson.packages[""].version = newVersion;
721
+ }
722
+ fs.writeFileSync(
723
+ fileState.path,
724
+ stringifyPackage(parsedJson, detectIndent__default.default(fileContents).indent, detectNewline.detectNewline(fileContents)),
725
+ "utf8"
726
+ );
727
+ }
728
+ isSupportedFile(fileName) {
729
+ return fileName.endsWith(".json");
730
+ }
731
+ };
732
+ var PlainText = class {
733
+ constructor(config, logger) {
734
+ this.config = config;
735
+ this.logger = logger;
736
+ }
737
+ read(fileName) {
738
+ const filePath = path.resolve(this.config.path, fileName);
739
+ if (fileExists(filePath)) {
740
+ const fileContents = fs.readFileSync(filePath, "utf8");
741
+ return {
742
+ name: fileName,
743
+ path: filePath,
744
+ version: fileContents || ""
745
+ };
746
+ }
747
+ this.logger.warn(`[File Manager] Unable to determine plain text: ${fileName}`);
748
+ }
749
+ write(fileState, newVersion) {
750
+ fs.writeFileSync(fileState.path, newVersion, "utf8");
751
+ }
752
+ isSupportedFile(fileName) {
753
+ return fileName.endsWith("version.txt");
754
+ }
755
+ };
756
+ var MSBuildProject = class {
757
+ constructor(config, logger) {
758
+ this.config = config;
759
+ this.logger = logger;
760
+ }
761
+ read(fileName) {
762
+ const filePath = path.resolve(this.config.path, fileName);
763
+ if (fileExists(filePath)) {
764
+ const fileContents = fs.readFileSync(filePath, "utf8");
765
+ const $ = cheerio__namespace.load(fileContents, {
766
+ xmlMode: true,
767
+ xml: { decodeEntities: false }
768
+ });
769
+ const version = $("Project > PropertyGroup > Version").text();
770
+ if (version) {
771
+ return {
772
+ name: fileName,
773
+ path: filePath,
774
+ version
775
+ };
776
+ }
777
+ this.logger.warn(`[File Manager] Unable to determine ms-build package: ${fileName}`);
778
+ }
779
+ }
780
+ write(fileState, newVersion) {
781
+ const fileContents = fs.readFileSync(fileState.path, "utf8");
782
+ const $ = cheerio__namespace.load(fileContents, {
783
+ xmlMode: true,
784
+ xml: { decodeEntities: false }
785
+ });
786
+ $("Project > PropertyGroup > Version").text(newVersion);
787
+ const updatedContent = $.xml().replaceAll('"/>', '" />');
788
+ fs.writeFileSync(fileState.path, updatedContent, "utf8");
789
+ }
790
+ isSupportedFile(fileName) {
791
+ return [".csproj", ".dbproj", ".esproj", ".fsproj", ".props", ".vbproj", ".vcxproj"].findIndex(
792
+ (ext) => fileName.endsWith(ext)
793
+ ) !== -1;
794
+ }
795
+ };
796
+
797
+ // src/strategies/file-manager.ts
798
+ var FileManager = class {
799
+ constructor(config, logger) {
800
+ this.config = config;
801
+ this.logger = logger;
802
+ this.JSONPackage = new JSONPackage(config, logger);
803
+ this.PlainText = new PlainText(config, logger);
804
+ this.MSBuildProject = new MSBuildProject(config, logger);
805
+ }
806
+ JSONPackage;
807
+ PlainText;
808
+ MSBuildProject;
809
+ /**
810
+ * Get the state from the given file name.
811
+ *
812
+ * @example
813
+ * ```ts
814
+ * fileManager.read("package.json");
815
+ * ```
816
+ *
817
+ * @returns
818
+ * ```json
819
+ * { "name": "package.json", "path": "/path/to/package.json", "version": "1.2.3", "isPrivate": true }
820
+ * ```
821
+ */
822
+ read(fileName) {
823
+ const _fileName = fileName.toLowerCase();
824
+ if (this.JSONPackage.isSupportedFile(_fileName)) {
825
+ return this.JSONPackage.read(fileName);
826
+ }
827
+ if (this.PlainText.isSupportedFile(_fileName)) {
828
+ return this.PlainText.read(fileName);
829
+ }
830
+ if (this.MSBuildProject.isSupportedFile(_fileName)) {
831
+ return this.MSBuildProject.read(fileName);
832
+ }
833
+ this.logger.error(`[File Manager] Unsupported file: ${fileName}`);
834
+ }
835
+ /**
836
+ * Write the new version to the given file.
837
+ *
838
+ * @example
839
+ * ```ts
840
+ * fileManager.write(
841
+ * { name: "package.json", path: "/path/to/package.json", version: "1.2.2" },
842
+ * "1.2.3"
843
+ * );
844
+ * ```
845
+ */
846
+ write(fileState, newVersion) {
847
+ if (this.config.dryRun) {
848
+ return;
849
+ }
850
+ const _fileName = fileState.name.toLowerCase();
851
+ if (this.JSONPackage.isSupportedFile(_fileName)) {
852
+ return this.JSONPackage.write(fileState, newVersion);
853
+ }
854
+ if (this.PlainText.isSupportedFile(_fileName)) {
855
+ return this.PlainText.write(fileState, newVersion);
856
+ }
857
+ if (this.MSBuildProject.isSupportedFile(_fileName)) {
858
+ return this.MSBuildProject.write(fileState, newVersion);
859
+ }
860
+ this.logger.error(`[File Manager] Unsupported file: ${fileState.path}`);
861
+ }
862
+ };
639
863
  async function getLatestGitTagVersion(tagPrefix) {
640
864
  const gitTags = await gitSemverTags__default.default({ tagPrefix });
641
865
  if (!gitTags.length) {
@@ -679,10 +903,10 @@ function getReleaseType(releaseType, currentVersion, preReleaseTag) {
679
903
  }
680
904
 
681
905
  // src/process/version.ts
682
- async function getCurrentVersion(config, logger, fileManager) {
906
+ async function getCurrentVersion(config, logger, fileManager, filesToUpdate) {
683
907
  const files = [];
684
908
  const versions = /* @__PURE__ */ new Set();
685
- for (const file of config.files) {
909
+ for (const file of filesToUpdate) {
686
910
  const fileState = fileManager.read(file);
687
911
  if (fileState) {
688
912
  files.push(fileState);
@@ -738,17 +962,25 @@ async function getNextVersion(config, logger, currentVersion) {
738
962
  const isPreMajor = semver3__default.default.lt(currentVersion, "1.0.0");
739
963
  let recommendedBump;
740
964
  try {
741
- recommendedBump = await conventionalRecommendedBump__default.default({
742
- preset: {
743
- name: "conventionalcommits",
744
- ...config.changelogPresetConfig,
745
- preMajor: isPreMajor
746
- },
747
- path: config.path,
748
- tagPrefix: config.tagPrefix,
749
- cwd: config.path
750
- });
751
- } catch (error) {
965
+ if (config.releaseAs) {
966
+ recommendedBump = {
967
+ releaseType: config.releaseAs,
968
+ level: -1,
969
+ reason: "User defined"
970
+ };
971
+ } else {
972
+ recommendedBump = await conventionalRecommendedBump__default.default({
973
+ preset: {
974
+ name: "conventionalcommits",
975
+ ...config.changelogPresetConfig,
976
+ preMajor: isPreMajor
977
+ },
978
+ path: config.path,
979
+ tagPrefix: config.tagPrefix,
980
+ cwd: config.path
981
+ });
982
+ }
983
+ } catch (_error) {
752
984
  throw new Error(`[conventional-recommended-bump] Unable to determine next version`);
753
985
  }
754
986
  if (recommendedBump.releaseType) {
@@ -772,15 +1004,6 @@ async function getNextVersion(config, logger, currentVersion) {
772
1004
  }
773
1005
  throw new Error("Unable to find next version");
774
1006
  }
775
- function fileExists(filePath) {
776
- try {
777
- return fs.lstatSync(filePath).isFile();
778
- } catch (e) {
779
- return false;
780
- }
781
- }
782
-
783
- // src/process/changelog.ts
784
1007
  var RELEASE_PATTERN = /(^#+ \[?[0-9]+\.[0-9]+\.[0-9]+|<a name=)/m;
785
1008
  function getOldReleaseContent(filePath, exists) {
786
1009
  if (exists) {
@@ -906,216 +1129,6 @@ async function tagChanges(config, logger, git, nextVersion) {
906
1129
  );
907
1130
  }
908
1131
 
909
- // src/libs/stringify-package.ts
910
- var DEFAULT_INDENT = 2;
911
- var CRLF = "\r\n";
912
- var LF = "\n";
913
- function stringifyPackage(data, indent, newline) {
914
- const stringified = JSON.stringify(data, null, indent ?? DEFAULT_INDENT);
915
- if (newline === CRLF) {
916
- return stringified.replace(new RegExp(LF, "g"), CRLF);
917
- }
918
- return stringified;
919
- }
920
-
921
- // src/strategies/json-package.ts
922
- var JSONPackage = class {
923
- constructor(config, logger) {
924
- this.config = config;
925
- this.logger = logger;
926
- }
927
- read(fileName) {
928
- const filePath = path.resolve(this.config.path, fileName);
929
- if (fileExists(filePath)) {
930
- const fileContents = fs.readFileSync(filePath, "utf8");
931
- const parsedJson = JSON.parse(fileContents);
932
- if (parsedJson.version) {
933
- return {
934
- name: fileName,
935
- path: filePath,
936
- version: parsedJson.version,
937
- isPrivate: typeof parsedJson?.private === "boolean" ? parsedJson.private : true
938
- };
939
- }
940
- this.logger.warn(`[File Manager] Unable to determine json package: ${fileName}`);
941
- }
942
- }
943
- write(fileState, newVersion) {
944
- const fileContents = fs.readFileSync(fileState.path, "utf8");
945
- const parsedJson = JSON.parse(fileContents);
946
- parsedJson.version = newVersion;
947
- if (parsedJson.packages?.[""]) {
948
- parsedJson.packages[""].version = newVersion;
949
- }
950
- fs.writeFileSync(
951
- fileState.path,
952
- stringifyPackage(parsedJson, detectIndent__default.default(fileContents).indent, detectNewline.detectNewline(fileContents)),
953
- "utf8"
954
- );
955
- }
956
- isSupportedFile(fileName) {
957
- return fileName.endsWith(".json");
958
- }
959
- };
960
- var PlainText = class {
961
- constructor(config, logger) {
962
- this.config = config;
963
- this.logger = logger;
964
- }
965
- read(fileName) {
966
- const filePath = path.resolve(this.config.path, fileName);
967
- if (fileExists(filePath)) {
968
- const fileContents = fs.readFileSync(filePath, "utf8");
969
- return {
970
- name: fileName,
971
- path: filePath,
972
- version: fileContents || ""
973
- };
974
- }
975
- this.logger.warn(`[File Manager] Unable to determine plain text: ${fileName}`);
976
- }
977
- write(fileState, newVersion) {
978
- fs.writeFileSync(fileState.path, newVersion, "utf8");
979
- }
980
- isSupportedFile(fileName) {
981
- return fileName.endsWith("version.txt");
982
- }
983
- };
984
- var MSBuildProject = class {
985
- constructor(config, logger) {
986
- this.config = config;
987
- this.logger = logger;
988
- }
989
- read(fileName) {
990
- const filePath = path.resolve(this.config.path, fileName);
991
- if (fileExists(filePath)) {
992
- const fileContents = fs.readFileSync(filePath, "utf8");
993
- const $ = cheerio__namespace.load(fileContents, { xmlMode: true, decodeEntities: false });
994
- const version = $("Project > PropertyGroup > Version").text();
995
- if (version) {
996
- return {
997
- name: fileName,
998
- path: filePath,
999
- version
1000
- };
1001
- }
1002
- this.logger.warn(`[File Manager] Unable to determine ms-build package: ${fileName}`);
1003
- }
1004
- }
1005
- write(fileState, newVersion) {
1006
- const fileContents = fs.readFileSync(fileState.path, "utf8");
1007
- const $ = cheerio__namespace.load(fileContents, { xmlMode: true, decodeEntities: false });
1008
- $("Project > PropertyGroup > Version").text(newVersion);
1009
- const updatedContent = $.xml().replaceAll('"/>', '" />');
1010
- fs.writeFileSync(fileState.path, updatedContent, "utf8");
1011
- }
1012
- isSupportedFile(fileName) {
1013
- return [".csproj", ".dbproj", ".esproj", ".fsproj", ".props", ".vbproj", ".vcxproj"].findIndex(
1014
- (ext) => fileName.endsWith(ext)
1015
- ) !== -1;
1016
- }
1017
- };
1018
-
1019
- // src/strategies/file-manager.ts
1020
- var FileManager = class {
1021
- constructor(config, logger) {
1022
- this.config = config;
1023
- this.logger = logger;
1024
- this.JSONPackage = new JSONPackage(config, logger);
1025
- this.PlainText = new PlainText(config, logger);
1026
- this.MSBuildProject = new MSBuildProject(config, logger);
1027
- }
1028
- JSONPackage;
1029
- PlainText;
1030
- MSBuildProject;
1031
- /**
1032
- * Get the state from the given file name.
1033
- *
1034
- * @example
1035
- * ```ts
1036
- * fileManager.read("package.json");
1037
- * ```
1038
- *
1039
- * @returns
1040
- * ```json
1041
- * { "name": "package.json", "path": "/path/to/package.json", "version": "1.2.3", "isPrivate": true }
1042
- * ```
1043
- */
1044
- read(fileName) {
1045
- const _fileName = fileName.toLowerCase();
1046
- if (this.JSONPackage.isSupportedFile(_fileName)) {
1047
- return this.JSONPackage.read(fileName);
1048
- }
1049
- if (this.PlainText.isSupportedFile(_fileName)) {
1050
- return this.PlainText.read(fileName);
1051
- }
1052
- if (this.MSBuildProject.isSupportedFile(_fileName)) {
1053
- return this.MSBuildProject.read(fileName);
1054
- }
1055
- this.logger.error(`[File Manager] Unsupported file: ${fileName}`);
1056
- }
1057
- /**
1058
- * Write the new version to the given file.
1059
- *
1060
- * @example
1061
- * ```ts
1062
- * fileManager.write(
1063
- * { name: "package.json", path: "/path/to/package.json", version: "1.2.2" },
1064
- * "1.2.3"
1065
- * );
1066
- * ```
1067
- */
1068
- write(fileState, newVersion) {
1069
- if (this.config.dryRun) {
1070
- return;
1071
- }
1072
- const _fileName = fileState.name.toLowerCase();
1073
- if (this.JSONPackage.isSupportedFile(_fileName)) {
1074
- return this.JSONPackage.write(fileState, newVersion);
1075
- }
1076
- if (this.PlainText.isSupportedFile(_fileName)) {
1077
- return this.PlainText.write(fileState, newVersion);
1078
- }
1079
- if (this.MSBuildProject.isSupportedFile(_fileName)) {
1080
- return this.MSBuildProject.write(fileState, newVersion);
1081
- }
1082
- this.logger.error(`[File Manager] Unsupported file: ${fileState.path}`);
1083
- }
1084
- };
1085
-
1086
- // src/utils/logger.ts
1087
- var Logger = class {
1088
- constructor(config) {
1089
- this.config = config;
1090
- this.log = this.log.bind(this);
1091
- this.warn = this.warn.bind(this);
1092
- this.error = this.error.bind(this);
1093
- this.debug = this.debug.bind(this);
1094
- this.disableLogs = this.config.silent || this.config.inspectVersion;
1095
- }
1096
- disableLogs = false;
1097
- log(...messages) {
1098
- if (!this.disableLogs) {
1099
- console.log(...messages);
1100
- }
1101
- }
1102
- warn(...messages) {
1103
- if (!this.disableLogs) {
1104
- console.warn(...messages);
1105
- }
1106
- }
1107
- error(...messages) {
1108
- if (!this.disableLogs) {
1109
- console.error(...messages);
1110
- }
1111
- }
1112
- debug(...messages) {
1113
- if (this.config.debug && !this.disableLogs) {
1114
- console.debug(...messages);
1115
- }
1116
- }
1117
- };
1118
-
1119
1132
  exports.FileManager = FileManager;
1120
1133
  exports.ForkConfigSchema = ForkConfigSchema;
1121
1134
  exports.Logger = Logger;
@@ -1126,5 +1139,5 @@ exports.getNextVersion = getNextVersion;
1126
1139
  exports.getUserConfig = getUserConfig;
1127
1140
  exports.tagChanges = tagChanges;
1128
1141
  exports.updateChangelog = updateChangelog;
1129
- //# sourceMappingURL=out.js.map
1130
- //# sourceMappingURL=chunk-NOQPR45O.cjs.map
1142
+ //# sourceMappingURL=chunk-SAIF32GN.cjs.map
1143
+ //# sourceMappingURL=chunk-SAIF32GN.cjs.map