versionary 1.10.0 → 1.11.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,3 +1,3 @@
1
1
  import type { VersionaryConfig } from "../types/config.js";
2
2
  import type { ReleasePlan } from "./plan.js";
3
- export declare function applyConfiguredArtifactRules(cwd: string, config: VersionaryConfig, plan: ReleasePlan): string[];
3
+ export declare function applyConfiguredArtifactRules(cwd: string, config: VersionaryConfig, plan: ReleasePlan, releaseDate?: string): string[];
@@ -162,9 +162,10 @@ function parseRegexPattern(pattern) {
162
162
  return new RegExp(pattern, "m");
163
163
  }
164
164
  const REPLACEMENT_TOKEN_PATTERN = /\{\{\s*([A-Za-z]+)\s*\}\}/gu;
165
- function renderReplacementTemplate(template, version) {
165
+ function renderReplacementTemplate(template, version, releaseDate) {
166
166
  const parsed = parseVersion(version);
167
167
  const tokens = {
168
+ date: releaseDate,
168
169
  version,
169
170
  major: String(parsed.major),
170
171
  minor: String(parsed.minor),
@@ -174,6 +175,9 @@ function renderReplacementTemplate(template, version) {
174
175
  };
175
176
  return template.replace(REPLACEMENT_TOKEN_PATTERN, (_whole, name) => {
176
177
  const key = name.toLowerCase();
178
+ if (key === "date" && releaseDate === undefined) {
179
+ throw new Error("The {{date}} replacement token requires a release date.");
180
+ }
177
181
  const value = tokens[key];
178
182
  if (value === undefined) {
179
183
  throw new Error(`Unknown replacement token "{{${name}}}". Supported tokens: ${Object.keys(tokens)
@@ -183,7 +187,7 @@ function renderReplacementTemplate(template, version) {
183
187
  return value;
184
188
  });
185
189
  }
186
- function applyRegexRule(content, pattern, version, expectedMatches, replacementTemplate) {
190
+ function applyRegexRule(content, pattern, version, expectedMatches, replacementTemplate, releaseDate) {
187
191
  const regex = parseRegexPattern(pattern);
188
192
  const matchFlags = regex.flags.includes("g")
189
193
  ? regex.flags
@@ -195,7 +199,7 @@ function applyRegexRule(content, pattern, version, expectedMatches, replacementT
195
199
  }
196
200
  const renderedReplacement = replacementTemplate === undefined
197
201
  ? undefined
198
- : renderReplacementTemplate(replacementTemplate, version);
202
+ : renderReplacementTemplate(replacementTemplate, version, releaseDate);
199
203
  let updated = content;
200
204
  for (let index = matches.length - 1; index >= 0; index -= 1) {
201
205
  const match = matches[index];
@@ -397,12 +401,12 @@ function applyNixRulePreservingFormatting(content, fieldPath, version) {
397
401
  }
398
402
  return `${content.slice(0, target.start)}${target.replacement}${content.slice(target.end)}`;
399
403
  }
400
- function applyArtifactRuleToContent(content, rule, version) {
404
+ function applyArtifactRuleToContent(content, rule, version, releaseDate) {
401
405
  if (rule.type === "regex") {
402
406
  if (!rule.pattern) {
403
407
  throw new Error('regex artifact rules require "pattern".');
404
408
  }
405
- return applyRegexRule(content, rule.pattern, version, rule["expected-matches"] ?? 1, rule.replacement);
409
+ return applyRegexRule(content, rule.pattern, version, rule["expected-matches"] ?? 1, rule.replacement, releaseDate);
406
410
  }
407
411
  if (rule.type === "json") {
408
412
  const parsed = JSON.parse(content);
@@ -422,7 +426,7 @@ function applyArtifactRuleToContent(content, rule, version) {
422
426
  function normalizeRelative(base, target) {
423
427
  return path.relative(base, target).replaceAll("\\", "/");
424
428
  }
425
- function applyArtifactRulesForPackage(cwd, packagePath, packageConfig, version) {
429
+ function applyArtifactRulesForPackage(cwd, packagePath, packageConfig, version, releaseDate) {
426
430
  const rules = packageConfig["extra-files"] ?? [];
427
431
  if (rules.length === 0) {
428
432
  return [];
@@ -437,7 +441,7 @@ function applyArtifactRulesForPackage(cwd, packagePath, packageConfig, version)
437
441
  const existing = fs.readFileSync(targetPath, "utf8");
438
442
  let next;
439
443
  try {
440
- next = applyArtifactRuleToContent(existing, rule, version);
444
+ next = applyArtifactRuleToContent(existing, rule, version, releaseDate);
441
445
  }
442
446
  catch (error) {
443
447
  const message = error instanceof Error ? error.message : String(error);
@@ -448,7 +452,7 @@ function applyArtifactRulesForPackage(cwd, packagePath, packageConfig, version)
448
452
  }
449
453
  return updated;
450
454
  }
451
- export function applyConfiguredArtifactRules(cwd, config, plan) {
455
+ export function applyConfiguredArtifactRules(cwd, config, plan, releaseDate) {
452
456
  const packageConfigs = config.packages ?? {};
453
457
  if (!plan.packages || plan.packages.length === 0) {
454
458
  return [];
@@ -462,7 +466,7 @@ export function applyConfiguredArtifactRules(cwd, config, plan) {
462
466
  if (!packageConfig?.["extra-files"]?.length) {
463
467
  continue;
464
468
  }
465
- const files = applyArtifactRulesForPackage(cwd, packagePlan.path, packageConfig, packagePlan.nextVersion);
469
+ const files = applyArtifactRulesForPackage(cwd, packagePlan.path, packageConfig, packagePlan.nextVersion, releaseDate);
466
470
  for (const file of files) {
467
471
  updated.add(file);
468
472
  }
@@ -417,7 +417,7 @@ export function prepareReleasePr(cwd = process.cwd(), options = {}) {
417
417
  for (const strategyGroup of writesByStrategy.values()) {
418
418
  updatedVersionFiles.push(...(strategyGroup.strategy.finalizeVersionWrites?.(cwd, strategyGroup.writes, finalizeContext) ?? []));
419
419
  }
420
- const updatedArtifactFiles = applyConfiguredArtifactRules(cwd, loaded.config, plan);
420
+ const updatedArtifactFiles = applyConfiguredArtifactRules(cwd, loaded.config, plan, finalizeContext.releaseDate);
421
421
  const packageReleaseMetadata = buildPackageReleaseMetadata(cwd, plan, loaded.config);
422
422
  const highlightsResult = resolveReleaseHighlights(cwd, plan.changelogFile, plan.changelogFormat);
423
423
  const highlights = highlightsResult.highlights;
@@ -575,7 +575,7 @@ function materializeCandidateChanges(cwd, plan, options) {
575
575
  for (const strategyGroup of writesByStrategy.values()) {
576
576
  updatedVersionFiles.push(...(strategyGroup.strategy.finalizeVersionWrites?.(cwd, strategyGroup.writes, finalizeContext) ?? []));
577
577
  }
578
- const updatedArtifactFiles = applyConfiguredArtifactRules(cwd, loaded.config, plan);
578
+ const updatedArtifactFiles = applyConfiguredArtifactRules(cwd, loaded.config, plan, finalizeContext.releaseDate);
579
579
  const packageReleaseMetadata = buildPackageReleaseMetadata(cwd, plan, loaded.config);
580
580
  const rootIsReleasing = Boolean(plan.packages?.find((pkg) => pkg.path === ".")?.nextVersion);
581
581
  const highlights = rootIsReleasing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "versionary",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "Automatic release framework based on conventional commits and semantic versioning",
5
5
  "keywords": [
6
6
  "releasing",