@codluv/versionguard 0.5.0 → 0.6.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.
@@ -1 +1 @@
1
- {"version":3,"file":"calver.d.ts","sourceRoot":"","sources":["../src/calver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,MAAM,EACN,YAAY,EAEZ,WAAW,EAEX,gBAAgB,EACjB,MAAM,SAAS,CAAC;AA8BjB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,IAAI,YAAY,CAoBhF;AAED;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAE3B;;;;OAIG;IACH,KAAK,CAAC,EAAE,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC;IAE1B;;;;OAIG;IACH,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IAEnB;;;;OAIG;IACH,GAAG,CAAC,EAAE,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC;IAExB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,YAAY,GAAG,kBAAkB,CAoB1E;AAyCD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM,CAKpE;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI,CAqDhF;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,QAAQ,CACtB,O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GAAG,MAAM,CAqB7E;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,eAAe,CAAC,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,GAAG,MAAM,EAAE,CAE5F"}
@@ -6,6 +6,17 @@ import { parse as parse$2 } from "smol-toml";
6
6
  import * as yaml from "js-yaml";
7
7
  import { globSync } from "glob";
8
8
  import { fileURLToPath } from "node:url";
9
+ function validateModifier(modifier, schemeRules) {
10
+ if (!modifier || !schemeRules?.allowedModifiers) return null;
11
+ const baseModifier = modifier.replace(/[\d.]+$/, "") || modifier;
12
+ if (!schemeRules.allowedModifiers.includes(baseModifier)) {
13
+ return {
14
+ message: `Modifier "${modifier}" is not allowed. Allowed: ${schemeRules.allowedModifiers.join(", ")}`,
15
+ severity: "error"
16
+ };
17
+ }
18
+ return null;
19
+ }
9
20
  const VALID_TOKENS = /* @__PURE__ */ new Set([
10
21
  "YYYY",
11
22
  "YY",
@@ -200,13 +211,10 @@ function validate$2(version, calverFormat, preventFutureDates = true, schemeRule
200
211
  });
201
212
  }
202
213
  }
203
- if (parsed.modifier && schemeRules?.allowedModifiers) {
204
- const baseModifier = parsed.modifier.replace(/[\d.]+$/, "") || parsed.modifier;
205
- if (!schemeRules.allowedModifiers.includes(baseModifier)) {
206
- errors.push({
207
- message: `Modifier "${parsed.modifier}" is not allowed. Allowed: ${schemeRules.allowedModifiers.join(", ")}`,
208
- severity: "error"
209
- });
214
+ if (parsed.modifier) {
215
+ const modifierError = validateModifier(parsed.modifier, schemeRules);
216
+ if (modifierError) {
217
+ errors.push(modifierError);
210
218
  }
211
219
  }
212
220
  if (schemeRules?.maxNumericSegments) {
@@ -1336,17 +1344,42 @@ function getStructuralErrors(version) {
1336
1344
  });
1337
1345
  return errors;
1338
1346
  }
1339
- function validate$1(version) {
1340
- const parsed = parse(version);
1347
+ function validate$1(version, semverConfig, schemeRules) {
1348
+ let input = version;
1349
+ if (input.startsWith("v") || input.startsWith("V")) {
1350
+ if (semverConfig?.allowVPrefix) {
1351
+ input = input.slice(1);
1352
+ }
1353
+ }
1354
+ const parsed = parse(input);
1341
1355
  if (!parsed) {
1342
1356
  return {
1343
1357
  valid: false,
1344
1358
  errors: getStructuralErrors(version)
1345
1359
  };
1346
1360
  }
1361
+ const errors = [];
1362
+ if (semverConfig && !semverConfig.allowBuildMetadata && parsed.build.length > 0) {
1363
+ errors.push({
1364
+ message: `Build metadata is not allowed: "${parsed.build.join(".")}"`,
1365
+ severity: "error"
1366
+ });
1367
+ }
1368
+ if (semverConfig?.requirePrerelease && parsed.prerelease.length === 0) {
1369
+ errors.push({
1370
+ message: "A prerelease label is required (e.g., 1.2.3-alpha.1)",
1371
+ severity: "error"
1372
+ });
1373
+ }
1374
+ if (parsed.prerelease.length > 0) {
1375
+ const modifierError = validateModifier(parsed.prerelease[0], schemeRules);
1376
+ if (modifierError) {
1377
+ errors.push(modifierError);
1378
+ }
1379
+ }
1347
1380
  return {
1348
- valid: true,
1349
- errors: [],
1381
+ valid: errors.filter((e) => e.severity === "error").length === 0,
1382
+ errors,
1350
1383
  version: { type: "semver", version: parsed }
1351
1384
  };
1352
1385
  }
@@ -1527,6 +1560,14 @@ function checkHardcodedVersions(expectedVersion, config, ignorePatterns, cwd = p
1527
1560
  }
1528
1561
  return mismatches;
1529
1562
  }
1563
+ const DEFAULT_SEMVER_CONFIG = {
1564
+ allowVPrefix: false,
1565
+ allowBuildMetadata: true,
1566
+ requirePrerelease: false
1567
+ };
1568
+ function getSemVerConfig(config) {
1569
+ return { ...DEFAULT_SEMVER_CONFIG, ...config.versioning.semver };
1570
+ }
1530
1571
  function getCalVerConfig(config) {
1531
1572
  if (!config.versioning.calver) {
1532
1573
  throw new Error('CalVer configuration is required when versioning.type is "calver"');
@@ -1703,6 +1744,11 @@ const DEFAULT_CONFIG = {
1703
1744
  maxNumericSegments: 3,
1704
1745
  allowedModifiers: ["dev", "alpha", "beta", "rc"]
1705
1746
  },
1747
+ semver: {
1748
+ allowVPrefix: false,
1749
+ allowBuildMetadata: true,
1750
+ requirePrerelease: false
1751
+ },
1706
1752
  calver: {
1707
1753
  format: "YYYY.MM.PATCH",
1708
1754
  preventFutureDates: true,
@@ -1782,8 +1828,16 @@ function initConfig(cwd = process.cwd()) {
1782
1828
  }
1783
1829
  function generateDefaultConfig() {
1784
1830
  return `# VersionGuard Configuration
1831
+ # Change "type" to switch between semver and calver — both blocks are always present.
1785
1832
  versioning:
1786
1833
  type: semver
1834
+ semver:
1835
+ allowVPrefix: false
1836
+ allowBuildMetadata: true
1837
+ requirePrerelease: false
1838
+ calver:
1839
+ format: "YYYY.MM.PATCH"
1840
+ preventFutureDates: true
1787
1841
 
1788
1842
  sync:
1789
1843
  files:
@@ -2615,7 +2669,7 @@ function getTagPreflightError(config, cwd, expectedVersion, allowAutoFix = false
2615
2669
  return "Working tree must be clean before creating or validating release tags";
2616
2670
  }
2617
2671
  const version = expectedVersion ?? getPackageVersion(cwd, config.manifest);
2618
- const versionResult = config.versioning.type === "semver" ? validate$1(version) : validate$2(
2672
+ const versionResult = config.versioning.type === "semver" ? validate$1(version, getSemVerConfig(config), config.versioning.schemeRules) : validate$2(
2619
2673
  version,
2620
2674
  config.versioning.calver?.format ?? "YYYY.MM.PATCH",
2621
2675
  config.versioning.calver?.preventFutureDates ?? true,
@@ -2700,7 +2754,7 @@ function suggestTagMessage(version, cwd = process.cwd()) {
2700
2754
  }
2701
2755
  function validateVersion(version, config) {
2702
2756
  if (config.versioning.type === "semver") {
2703
- return validate$1(version);
2757
+ return validate$1(version, getSemVerConfig(config), config.versioning.schemeRules);
2704
2758
  }
2705
2759
  const calverConfig = getCalVerConfig(config);
2706
2760
  return validate$2(
@@ -2828,6 +2882,7 @@ function isWorktreeClean(cwd) {
2828
2882
  }
2829
2883
  }
2830
2884
  export {
2885
+ validateVersion as $,
2831
2886
  checkHardcodedVersions as A,
2832
2887
  checkHookIntegrity as B,
2833
2888
  checkHooksPathOverride as C,
@@ -2840,21 +2895,21 @@ export {
2840
2895
  JsonVersionSource as J,
2841
2896
  getCalVerConfig as K,
2842
2897
  getLatestTag as L,
2843
- getTagFeedback as M,
2844
- getVersionSource as N,
2845
- initConfig as O,
2846
- resolveVersionSource as P,
2847
- semver as Q,
2898
+ getSemVerConfig as M,
2899
+ getTagFeedback as N,
2900
+ getVersionSource as O,
2901
+ initConfig as P,
2902
+ resolveVersionSource as Q,
2848
2903
  RegexVersionSource as R,
2849
- suggestTagMessage as S,
2904
+ semver as S,
2850
2905
  TomlVersionSource as T,
2851
- sync as U,
2906
+ suggestTagMessage as U,
2852
2907
  VersionFileSource as V,
2853
- syncVersion as W,
2854
- validateChangelog as X,
2908
+ sync as W,
2909
+ syncVersion as X,
2855
2910
  YamlVersionSource as Y,
2856
- validateTagForPush as Z,
2857
- validateVersion as _,
2911
+ validateChangelog as Z,
2912
+ validateTagForPush as _,
2858
2913
  installHooks as a,
2859
2914
  getPackageVersion as b,
2860
2915
  createCkmEngine as c,
@@ -2882,4 +2937,4 @@ export {
2882
2937
  canBump as y,
2883
2938
  checkEnforceHooksPolicy as z
2884
2939
  };
2885
- //# sourceMappingURL=index-CwOyEn5L.js.map
2940
+ //# sourceMappingURL=index-DeZAx4Le.js.map