@reelout/core 0.1.1 → 0.4.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.
Files changed (137) hide show
  1. package/LICENSE +21 -0
  2. package/dist/analyzer.js +33 -0
  3. package/dist/analyzer.js.map +1 -0
  4. package/dist/builder.js +64 -0
  5. package/dist/builder.js.map +1 -0
  6. package/dist/changelog.js +63 -0
  7. package/dist/changelog.js.map +1 -0
  8. package/dist/formatError-BXNdyRfu.js +23 -0
  9. package/dist/formatError-BXNdyRfu.js.map +1 -0
  10. package/dist/index.js +199 -1
  11. package/dist/index.js.map +1 -0
  12. package/dist/types-la_KkjCS.js +1 -0
  13. package/dist/types.js +2 -0
  14. package/dist/workflow-BRMp4uB6.js +2736 -0
  15. package/dist/workflow-BRMp4uB6.js.map +1 -0
  16. package/package.json +35 -6
  17. package/src/analyzer.ts +59 -0
  18. package/src/builder.ts +116 -0
  19. package/src/cache/TTLCache.ts +100 -0
  20. package/src/cache/index.ts +4 -0
  21. package/src/changelog.ts +107 -0
  22. package/src/config/const.ts +104 -0
  23. package/src/config/createPlugin.ts +41 -0
  24. package/src/config/findReleaseRule.ts +26 -0
  25. package/src/config/index.ts +15 -0
  26. package/src/config/isSemVer.ts +31 -0
  27. package/src/config/isSemVerGitTag.ts +25 -0
  28. package/src/config/normalizeCommitFilter.ts +37 -0
  29. package/src/config/normalizeReleaseRule.ts +66 -0
  30. package/src/config/normalizeWorkspace.ts +34 -0
  31. package/src/config/resolvePlugin.ts +57 -0
  32. package/src/config/resolveReleaseChannel.ts +47 -0
  33. package/src/config/resolveVersionQualifier.ts +53 -0
  34. package/src/config/sanitizePrereleaseLabel.ts +18 -0
  35. package/src/git/branch/getCurrentGitBranch.ts +18 -0
  36. package/src/git/branch/index.ts +4 -0
  37. package/src/git/commit/createGitCommit.ts +29 -0
  38. package/src/git/commit/extractMentions.ts +34 -0
  39. package/src/git/commit/getCurrentGitCommit.ts +19 -0
  40. package/src/git/commit/getParsedGitCommit.ts +49 -0
  41. package/src/git/commit/index.ts +9 -0
  42. package/src/git/commit/parseGitCommit.ts +114 -0
  43. package/src/git/commit/parseGitPrettyFormat.ts +76 -0
  44. package/src/git/history/countGitHistory.ts +28 -0
  45. package/src/git/history/expandGitHistory.ts +112 -0
  46. package/src/git/history/index.ts +9 -0
  47. package/src/git/history/mergeGitHistory.ts +76 -0
  48. package/src/git/history/restoreFullGitHistory.ts +19 -0
  49. package/src/git/history/showGitHistory.ts +80 -0
  50. package/src/git/history/showParsedGitHistory.ts +28 -0
  51. package/src/git/index.ts +9 -0
  52. package/src/git/repository/ensureGitUserConfig.ts +50 -0
  53. package/src/git/repository/getGitConfigValue.ts +27 -0
  54. package/src/git/repository/getGitRemote.ts +20 -0
  55. package/src/git/repository/index.ts +10 -0
  56. package/src/git/repository/isGitShallowRepository.ts +21 -0
  57. package/src/git/repository/pushGitChanges.ts +26 -0
  58. package/src/git/repository/resolveGitRepository.ts +40 -0
  59. package/src/git/repository/withShallowLock.ts +62 -0
  60. package/src/git/revision/detectGitRelationship.ts +43 -0
  61. package/src/git/revision/index.ts +7 -0
  62. package/src/git/revision/isGitAncestor.ts +33 -0
  63. package/src/git/revision/readGitFile.ts +29 -0
  64. package/src/git/revision/resolveGitRevision.ts +23 -0
  65. package/src/git/tag/createGitTag.ts +25 -0
  66. package/src/git/tag/deleteGitTag.ts +17 -0
  67. package/src/git/tag/ensureGitTag.ts +63 -0
  68. package/src/git/tag/generateGitTagName.ts +43 -0
  69. package/src/git/tag/getCurrentGitTag.ts +23 -0
  70. package/src/git/tag/getGitTagMessage.ts +35 -0
  71. package/src/git/tag/getLatestGitTag.ts +22 -0
  72. package/src/git/tag/index.ts +13 -0
  73. package/src/git/tag/isGitTagConnected.ts +33 -0
  74. package/src/git/tag/isGitTagPointed.ts +38 -0
  75. package/src/git/tag/isGitTagPresent.ts +17 -0
  76. package/src/index.ts +9 -2
  77. package/src/plugin/HookManager.ts +128 -0
  78. package/src/plugin/index.ts +4 -0
  79. package/src/types.ts +259 -0
  80. package/src/util/buildTrailerPattern.ts +20 -0
  81. package/src/util/compact.ts +14 -0
  82. package/src/util/execCommand.ts +196 -0
  83. package/src/util/execGit.ts +27 -0
  84. package/src/util/formatError.ts +21 -0
  85. package/src/util/formatFile.ts +41 -0
  86. package/src/util/index.ts +18 -0
  87. package/src/util/interpolate.ts +141 -0
  88. package/src/util/isCI.ts +18 -0
  89. package/src/util/isClass.ts +34 -0
  90. package/src/util/isDefined.ts +12 -0
  91. package/src/util/isMatch.ts +43 -0
  92. package/src/util/isTruthyString.ts +19 -0
  93. package/src/util/readJson.ts +47 -0
  94. package/src/util/unique.ts +26 -0
  95. package/src/util/writeJson.ts +28 -0
  96. package/src/workflow/analysis/deriveChangeReleases.ts +76 -0
  97. package/src/workflow/analysis/deriveTransitionReleases.ts +134 -0
  98. package/src/workflow/analysis/index.ts +10 -0
  99. package/src/workflow/analysis/isCommitForPackage.ts +23 -0
  100. package/src/workflow/analysis/promotePrereleaseVersions.ts +51 -0
  101. package/src/workflow/analysis/propagateDependencyUpdates.ts +71 -0
  102. package/src/workflow/analysis/sliceUnreleased.ts +36 -0
  103. package/src/workflow/analysis/streamPackageCommits.ts +34 -0
  104. package/src/workflow/changelog/buildChangelog.ts +79 -0
  105. package/src/workflow/changelog/buildReleaseNotes.ts +50 -0
  106. package/src/workflow/changelog/conventional-changelog-conventionalcommits.d.ts +7 -0
  107. package/src/workflow/changelog/extractLatestVersion.ts +22 -0
  108. package/src/workflow/changelog/extractPlainText.ts +38 -0
  109. package/src/workflow/changelog/extractPreviousVersion.ts +77 -0
  110. package/src/workflow/changelog/extractSemVer.ts +33 -0
  111. package/src/workflow/changelog/index.ts +12 -0
  112. package/src/workflow/changelog/iterateChangelogVersions.ts +70 -0
  113. package/src/workflow/changelog/prependChangelog.ts +59 -0
  114. package/src/workflow/changelog/writeChangelog.ts +27 -0
  115. package/src/workflow/committing/generateReleaseCommitMessage.ts +121 -0
  116. package/src/workflow/committing/index.ts +5 -0
  117. package/src/workflow/committing/isReleaseCommit.ts +56 -0
  118. package/src/workflow/discovery/buildDependencyGraph.ts +43 -0
  119. package/src/workflow/discovery/discoverPackageTag.ts +98 -0
  120. package/src/workflow/discovery/index.ts +9 -0
  121. package/src/workflow/discovery/resolvePackageStableTag.ts +88 -0
  122. package/src/workflow/discovery/resolvePackageTag.ts +45 -0
  123. package/src/workflow/discovery/sortPackages.ts +75 -0
  124. package/src/workflow/discovery/verifyPackageTag.ts +49 -0
  125. package/src/workflow/executeReleaseWorkflow.ts +130 -0
  126. package/src/workflow/index.ts +10 -0
  127. package/src/workflow/report/generateReleaseReport.ts +54 -0
  128. package/src/workflow/report/index.ts +5 -0
  129. package/src/workflow/report/printReleaseReport.ts +97 -0
  130. package/src/workflow/versioning/bumpVersion.ts +76 -0
  131. package/src/workflow/versioning/deriveReleaseType.ts +33 -0
  132. package/src/workflow/versioning/determineReleaseType.ts +35 -0
  133. package/src/workflow/versioning/extractVersionQualifier.ts +29 -0
  134. package/src/workflow/versioning/index.ts +10 -0
  135. package/src/workflow/versioning/isSameReleaseCycle.ts +36 -0
  136. package/src/workflow/versioning/isStableVersion.ts +31 -0
  137. package/src/workflow/versioning/pickPriorityReleaseType.ts +27 -0
package/src/builder.ts ADDED
@@ -0,0 +1,116 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import { generateGitTagName } from '#git'
5
+ import type { ReleasePlan, ReleasePlugin } from '#types'
6
+ import { formatError } from '#util'
7
+ import {
8
+ buildReleaseNotes,
9
+ bumpVersion,
10
+ isSameReleaseCycle,
11
+ resolvePackageStableTag,
12
+ streamPackageCommits,
13
+ } from '#workflow'
14
+ import { colors } from 'consola/utils'
15
+ import { version } from '../package.json'
16
+
17
+ /**
18
+ * Built-in plugin that prepares release metadata and artifacts for active plans.
19
+ *
20
+ * @remarks
21
+ * **Lifecycle Stages:**
22
+ * - `build`: Computes bumped package versions, derives standardized Git tag names,
23
+ * and generates release notes/tag messages from unreleased commit history.
24
+ *
25
+ * @returns A release plugin configured for release metadata preparation.
26
+ */
27
+ const builder = (): ReleasePlugin => ({
28
+ name: '@reelout/core/builder',
29
+ version,
30
+ build: async (context, next) => {
31
+ context.plans = await Promise.all(
32
+ context.plans.map(async (plan): Promise<ReleasePlan> => {
33
+ plan = { ...plan }
34
+
35
+ if (!plan.release) return plan
36
+
37
+ plan.release = { ...plan.release }
38
+
39
+ let version: string | null | undefined
40
+
41
+ try {
42
+ version = bumpVersion({
43
+ version: plan.package.version,
44
+ private: plan.package.private,
45
+ release: plan.release.type,
46
+ identifier: context.versionQualifier,
47
+ transition: plan.release.transition,
48
+ })
49
+ } catch (err) {
50
+ context.logger.warn(
51
+ colors.yellow(
52
+ `Version could not be determined for package at "${colors.bold(plan.package.location)}": ${formatError(err)}`
53
+ )
54
+ )
55
+ }
56
+
57
+ if (version) {
58
+ plan.release.version = version
59
+ }
60
+
61
+ let tagName: string | null | undefined
62
+
63
+ try {
64
+ tagName = generateGitTagName(
65
+ plan.package.entry,
66
+ plan.package.name,
67
+ plan.release.version
68
+ )
69
+ } catch (err) {
70
+ context.logger.warn(
71
+ colors.yellow(
72
+ `Tag could not be determined for package at "${colors.bold(plan.package.location)}": ${formatError(err)}`
73
+ )
74
+ )
75
+ }
76
+
77
+ let tagMessage: string | undefined
78
+
79
+ try {
80
+ if (tagName) {
81
+ if (
82
+ context.allowEmpty &&
83
+ plan.history.length === 0 &&
84
+ isSameReleaseCycle(plan.package.version, plan.release.version)
85
+ ) {
86
+ const previousTag = (
87
+ await resolvePackageStableTag(context.cwd, plan.package)
88
+ )?.name
89
+
90
+ const history = streamPackageCommits(context.cwd, plan.package, {
91
+ until: previousTag,
92
+ })
93
+
94
+ tagMessage = await buildReleaseNotes(context, history)
95
+ } else {
96
+ tagMessage = await buildReleaseNotes(context, plan.history)
97
+ }
98
+ }
99
+ } catch {}
100
+
101
+ if (tagName) {
102
+ plan.release.tag = {
103
+ name: tagName,
104
+ message: tagMessage,
105
+ }
106
+ }
107
+
108
+ return plan
109
+ })
110
+ )
111
+
112
+ return next(context)
113
+ },
114
+ })
115
+
116
+ export default builder
@@ -0,0 +1,100 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ interface Entry<V> {
5
+ value: V
6
+ timer: NodeJS.Timeout
7
+ ttl: number
8
+ }
9
+
10
+ /**
11
+ * A simple time-to-live cache that automatically evicts entries after a TTL.
12
+ *
13
+ * - Entries are removed automatically when their TTL expires.
14
+ * - Reading an entry resets its TTL to the original value.
15
+ * - Setting an existing key clears its previous timer and resets the TTL.
16
+ *
17
+ * @template K Type of cache keys
18
+ * @template V Type of cache values
19
+ */
20
+ export class TTLCache<K, V> {
21
+ private cache = new Map<K, Entry<V>>()
22
+
23
+ /**
24
+ * Store a value under `key` for `ttl` milliseconds.
25
+ *
26
+ * If the key already exists its previous timer is cleared and the TTL is reset.
27
+ *
28
+ * @param key Cache key
29
+ * @param value Value to store
30
+ * @param ttl Time to live in milliseconds (default: 60_000)
31
+ */
32
+ set(key: K, value: V, ttl: number = 60_000): void {
33
+ const ref = this.cache.get(key)
34
+
35
+ if (ref) {
36
+ clearTimeout(ref.timer)
37
+ }
38
+
39
+ const timer = setTimeout(() => {
40
+ this.cache.delete(key)
41
+ }, ttl).unref()
42
+
43
+ this.cache.set(key, { value, timer, ttl })
44
+ }
45
+
46
+ /**
47
+ * Retrieve the value for `key`, or `undefined` if not present.
48
+ *
49
+ * Reading an entry resets its TTL to the original `ttl` provided when it was set.
50
+ *
51
+ * @param key Cache key
52
+ * @returns The stored value or `undefined` if not present
53
+ */
54
+ get(key: K): V | undefined {
55
+ const ref = this.cache.get(key)
56
+
57
+ if (!ref) return undefined
58
+
59
+ this.set(key, ref.value, ref.ttl)
60
+
61
+ return ref.value
62
+ }
63
+
64
+ /**
65
+ * Check whether `key` exists in the cache.
66
+ *
67
+ * @param key Cache key
68
+ * @returns `true` if present; otherwise `false`
69
+ */
70
+ has(key: K): boolean {
71
+ return this.cache.has(key)
72
+ }
73
+
74
+ /**
75
+ * Remove `key` from the cache and clear its eviction timer.
76
+ *
77
+ * @param key Cache key
78
+ * @returns `true` if the key was present and removed; otherwise `false`
79
+ */
80
+ delete(key: K): boolean {
81
+ const ref = this.cache.get(key)
82
+
83
+ if (!ref) return false
84
+
85
+ clearTimeout(ref.timer)
86
+
87
+ return this.cache.delete(key)
88
+ }
89
+
90
+ /**
91
+ * Clear all entries and their timers.
92
+ */
93
+ clear(): void {
94
+ for (const { timer } of this.cache.values()) {
95
+ clearTimeout(timer)
96
+ }
97
+
98
+ this.cache.clear()
99
+ }
100
+ }
@@ -0,0 +1,4 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ export * from './TTLCache'
@@ -0,0 +1,107 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import { HookPriority } from '#plugin'
5
+ import type { Package, ReleasePlugin } from '#types'
6
+ import { formatError } from '#util'
7
+ import {
8
+ buildChangelog,
9
+ discoverPackageTag,
10
+ resolvePackageTag,
11
+ writeChangelog,
12
+ } from '#workflow'
13
+ import { colors } from 'consola/utils'
14
+ import { version } from '../package.json'
15
+
16
+ /**
17
+ * Built-in plugin that resolves package tags, generates release changelogs, and persists changelog files.
18
+ *
19
+ * @remarks
20
+ * **Lifecycle Stages:**
21
+ * - `discover`: Resolves missing Git tags for workspace packages (low priority execution).
22
+ * - `build`: Generates Markdown changelogs for planned releases based on historical commits.
23
+ * - `write`: Writes generated changelog files to disk (skipped during dry-run mode).
24
+ *
25
+ * @returns A release plugin configured for changelog generation and file persistence.
26
+ */
27
+ const changelog = (): ReleasePlugin => ({
28
+ name: '@reelout/core/changelog',
29
+ version,
30
+ discover: {
31
+ priority: HookPriority.Low,
32
+ handler: async (context, next) => {
33
+ context.packages = await Promise.all(
34
+ context.packages.map(async (pkg): Promise<Package> => ({
35
+ ...pkg,
36
+ tag: await resolvePackageTag(context.cwd, pkg),
37
+ }))
38
+ )
39
+
40
+ await next(context)
41
+ },
42
+ },
43
+ build: async (context, next) => {
44
+ context.plans = await Promise.all(
45
+ context.plans.map(async (plan) => {
46
+ plan = { ...plan }
47
+
48
+ if (!plan.release) {
49
+ return plan
50
+ }
51
+
52
+ if (!plan.release.version) {
53
+ return plan
54
+ }
55
+
56
+ plan.release = { ...plan.release }
57
+
58
+ let changelog: string | null | undefined
59
+
60
+ let previousTag = (await resolvePackageTag(context.cwd, plan.package))
61
+ ?.name
62
+
63
+ if (!previousTag) {
64
+ previousTag = (await discoverPackageTag(context.cwd, plan.package))
65
+ ?.name
66
+ }
67
+
68
+ try {
69
+ changelog = await buildChangelog(context, plan.history, {
70
+ packageDir: plan.package.location,
71
+ changelogFile: plan.package.changelogFile,
72
+ version: plan.release.version,
73
+ previousTag,
74
+ currentTag: plan.release.tag?.name,
75
+ })
76
+ } catch (err) {
77
+ context.logger.warn(
78
+ colors.yellow(
79
+ `Changelog could not be generated for package at "${colors.bold(plan.package.location)}": ${formatError(err)}`
80
+ )
81
+ )
82
+ }
83
+
84
+ if (changelog) {
85
+ plan.release.changelog = changelog
86
+ }
87
+
88
+ return plan
89
+ })
90
+ )
91
+
92
+ return next(context)
93
+ },
94
+ write: async (context, next) => {
95
+ if (context.dryRun) {
96
+ context.logger.debug('[DRY RUN] Changelog files will not be written.')
97
+ } else {
98
+ for (const plan of context.plans) {
99
+ await writeChangelog(context.cwd, plan)
100
+ }
101
+ }
102
+
103
+ return next(context)
104
+ },
105
+ })
106
+
107
+ export default changelog
@@ -0,0 +1,104 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import type { ReleaseHookName } from '#types'
5
+ import { Writable } from 'node:stream'
6
+
7
+ export const ALL_FILES = '**/*'
8
+
9
+ export const DEFAULT_CHANGELOG_FILE = 'CHANGELOG.md'
10
+
11
+ export const GIT_TRAILER_RELEASE_AGENT = 'Release-Agent'
12
+
13
+ /**
14
+ * 1. Primitive Building Blocks
15
+ *
16
+ * Base regular expression patterns for wildcards, alphanumeric strings with hyphens,
17
+ * and standard non-negative integers.
18
+ */
19
+ const WILDCARD = '\\*'
20
+ const ALPHANUM_DASH = '[0-9a-zA-Z-]+'
21
+ const NUMERIC_IDENTIFIER = '0|[1-9]\\d*'
22
+
23
+ /**
24
+ * 2. Package Name & Prefix Constructs
25
+ *
26
+ * Matches package name prefixes (unscoped or scoped) or a simple `v` prefix.
27
+ *
28
+ * Capture Groups:
29
+ * - Group 1: Package name (e.g., `my-package` or `@scope/my-package`)
30
+ */
31
+ const PKG_NAME_PART = `(?:${WILDCARD}|${ALPHANUM_DASH})`
32
+ const CAPTURED_PACKAGE_NAME = `(${PKG_NAME_PART}|@${PKG_NAME_PART}\\/${PKG_NAME_PART})`
33
+ const OPTIONAL_VERSION_PREFIX = `(?:v|${CAPTURED_PACKAGE_NAME}@)`
34
+
35
+ /**
36
+ * 3. Core SemVer Components
37
+ *
38
+ * Matches standard `MAJOR.MINOR.PATCH` versions or wildcard variants (e.g., `1.0.0`, `*.*.*`).
39
+ *
40
+ * Capture Groups:
41
+ * - Group 3: Major version
42
+ * - Group 4: Minor version
43
+ * - Group 5: Patch version
44
+ */
45
+ const CAPTURED_VERSION_DIGIT = `(${WILDCARD}|${NUMERIC_IDENTIFIER})`
46
+ const SEMVER_CORE = `${CAPTURED_VERSION_DIGIT}\\.${CAPTURED_VERSION_DIGIT}\\.${CAPTURED_VERSION_DIGIT}`
47
+
48
+ /**
49
+ * 4. Prerelease & Build Metadata
50
+ *
51
+ * Matches optional prerelease identifiers (e.g., `-alpha.1`) and build metadata (e.g., `+build123`).
52
+ *
53
+ * Capture Groups:
54
+ * - Group 6: Complete prerelease string (without `-`)
55
+ * - Group 7: Non-numeric prerelease token
56
+ * - Group 8: Complete build metadata string (without `+`)
57
+ */
58
+ const CAPTURED_NON_NUMERIC_PRERELEASE_ID = `(\\d*[a-zA-Z-][0-9a-zA-Z-]*)`
59
+ const PRERELEASE_IDENTIFIER = `(?:${WILDCARD}|${NUMERIC_IDENTIFIER}|${CAPTURED_NON_NUMERIC_PRERELEASE_ID})`
60
+ const OPTIONAL_PRERELEASE_SECTION = `(?:-(${PRERELEASE_IDENTIFIER}(?:\\.${PRERELEASE_IDENTIFIER})*))`
61
+ const OPTIONAL_BUILD_SECTION = `(?:\\+(${ALPHANUM_DASH}(?:\\.${ALPHANUM_DASH})*))`
62
+
63
+ /**
64
+ * 5. Assembled SemVer Pattern
65
+ *
66
+ * Combines core SemVer components with optional prerelease identifiers and build metadata.
67
+ *
68
+ * Capture Groups:
69
+ * - Group 2: Full SemVer version string (excluding package/prefix)
70
+ */
71
+ const CAPTURED_SEMVER_VERSION = `(${SEMVER_CORE}${OPTIONAL_PRERELEASE_SECTION}?${OPTIONAL_BUILD_SECTION}?)`
72
+ const FULL_SEMVER_PATTERN = `${OPTIONAL_VERSION_PREFIX}?${CAPTURED_SEMVER_VERSION}`
73
+
74
+ /**
75
+ * Regular expression to match and capture Semantic Versioning (SemVer) strings,
76
+ * including optional package prefixes (e.g., `@scope/pkg@`) and `v` prefixes.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * SEMVER_REGEX.test('1.0.0') // true
81
+ * SEMVER_REGEX.test('v1.2.3-beta.1+sha.1234') // true
82
+ * SEMVER_REGEX.test('@scope/package@1.0.0') // true
83
+ * ```
84
+ *
85
+ * @see {@link https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string SemVer Specification}
86
+ */
87
+ export const SEMVER_REGEX = new RegExp(FULL_SEMVER_PATTERN)
88
+
89
+ export const DEV_NULL = new Writable({
90
+ /* istanbul ignore next */
91
+ write(_chunk, _encoding, callback) {
92
+ callback()
93
+ },
94
+ })
95
+
96
+ export const RELEASE_HOOK_NAMES = [
97
+ 'configure',
98
+ 'discover',
99
+ 'analyze',
100
+ 'build',
101
+ 'write',
102
+ 'publish',
103
+ 'finalize',
104
+ ] as const satisfies ReleaseHookName[]
@@ -0,0 +1,41 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import type { ReleasePlugin } from '#types'
5
+ import { isClass } from '#util'
6
+
7
+ /**
8
+ * Instantiate or invoke a plugin factory to produce a release plugin instance.
9
+ *
10
+ * Accepts class constructors, factory functions, tuple configurations, or
11
+ * existing plugin objects. Instantiates classes using `new` or invokes factory
12
+ * functions with options, validating that the resulting object satisfies the
13
+ * plugin structure.
14
+ *
15
+ * @param plugin A plugin constructor, factory function, tuple, or object
16
+ * @returns A validated release plugin instance or null
17
+ */
18
+ export async function createPlugin(
19
+ plugin: unknown
20
+ ): Promise<ReleasePlugin | null> {
21
+ let options: unknown
22
+
23
+ if (Array.isArray(plugin)) {
24
+ ;[plugin, options] = plugin
25
+ }
26
+
27
+ if (typeof plugin === 'function') {
28
+ plugin = isClass(plugin) ? new plugin(options) : await plugin(options)
29
+ }
30
+
31
+ if (
32
+ plugin != null &&
33
+ typeof plugin === 'object' &&
34
+ Object.hasOwn(plugin, 'name') &&
35
+ typeof (plugin as ReleasePlugin).name === 'string'
36
+ ) {
37
+ return plugin as ReleasePlugin
38
+ }
39
+
40
+ return null
41
+ }
@@ -0,0 +1,26 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import type { GitRef, ResolvedReleaseRule } from '#types'
5
+ import { isMatch } from '#util'
6
+
7
+ /**
8
+ * Find the first release rule matching a release reference.
9
+ *
10
+ * Matches rules sequentially against the reference type and pattern.
11
+ *
12
+ * @param ref Release reference object
13
+ * @param rules Array of release rules to match against
14
+ * @returns The first matching release rule or `undefined`
15
+ */
16
+ export function findReleaseRule(
17
+ ref: GitRef,
18
+ rules: readonly ResolvedReleaseRule[]
19
+ ): ResolvedReleaseRule | undefined {
20
+ return rules.find((rule) => {
21
+ return (
22
+ (rule.type == null || rule.type === ref.type) &&
23
+ isMatch(ref.name, rule.pattern)
24
+ )
25
+ })
26
+ }
@@ -0,0 +1,15 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ export * from './const'
5
+ export * from './createPlugin'
6
+ export * from './findReleaseRule'
7
+ export * from './isSemVer'
8
+ export * from './isSemVerGitTag'
9
+ export * from './normalizeCommitFilter'
10
+ export * from './normalizeReleaseRule'
11
+ export * from './normalizeWorkspace'
12
+ export * from './resolvePlugin'
13
+ export * from './resolveReleaseChannel'
14
+ export * from './resolveVersionQualifier'
15
+ export * from './sanitizePrereleaseLabel'
@@ -0,0 +1,31 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import semver from 'semver'
5
+
6
+ /**
7
+ * Determine whether a value is a valid Semantic Versioning string.
8
+ *
9
+ * Rejects non-string values, leading or trailing whitespace, and leading `v`
10
+ * prefixes. Validates the candidate string using `semver.parse`.
11
+ *
12
+ * @param version Candidate value to evaluate for SemVer compliance
13
+ * @returns `true` if `version` is a valid SemVer string, or `false` otherwise
14
+ */
15
+ export function isSemVer(
16
+ version: string | null | undefined
17
+ ): version is string {
18
+ if (typeof version !== 'string') {
19
+ return false
20
+ }
21
+
22
+ if (version !== version.trim()) {
23
+ return false
24
+ }
25
+
26
+ if (version.startsWith('v')) {
27
+ return false
28
+ }
29
+
30
+ return semver.parse(version) != null
31
+ }
@@ -0,0 +1,25 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import { SEMVER_REGEX } from './const'
5
+
6
+ /**
7
+ * Determine whether a tag string is a valid SemVer-style Git tag.
8
+ *
9
+ * Anchors `SEMVER_REGEX.source` for full-string matching and applies the
10
+ * repository's Git-tag acceptance rules.
11
+ *
12
+ * @param tag Tag string to validate
13
+ * @returns `true` if `tag` is accepted as a SemVer-style Git tag; otherwise `false`
14
+ */
15
+ export function isSemVerGitTag(tag: string): boolean {
16
+ const match = new RegExp(`^${SEMVER_REGEX.source}$`).exec(tag)
17
+
18
+ if (!match) return false
19
+
20
+ const isScopedPackage = Boolean(match[1])
21
+
22
+ const hasVersionPrefix = tag.startsWith('v')
23
+
24
+ return isScopedPackage || hasVersionPrefix
25
+ }
@@ -0,0 +1,37 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import type { CommitClassifier, ReleaseConfig, ReleaseType } from '#types'
5
+
6
+ /**
7
+ * Normalize a commit classifier into a consistent function.
8
+ *
9
+ * Accepts `null`/`undefined` (returns no-op classifier), a function classifier,
10
+ * or a config object mapping commit types to release types. Returns a classifier
11
+ * function that maps commits to their corresponding release types.
12
+ *
13
+ * @param classifier Commit classifier config, function, or falsy value
14
+ * @returns Normalized classifier function
15
+ */
16
+ export function normalizeCommitFilter(
17
+ classifier: ReleaseConfig['classifier'] | null | undefined
18
+ ): CommitClassifier {
19
+ if (classifier == null) {
20
+ return () => null
21
+ }
22
+
23
+ if (typeof classifier === 'function') {
24
+ return classifier
25
+ }
26
+
27
+ const map = new Map(
28
+ Object.entries(classifier).flatMap(([releaseType, commitTypes]) => {
29
+ return commitTypes.map((commitType) => [
30
+ commitType,
31
+ releaseType as ReleaseType,
32
+ ])
33
+ })
34
+ )
35
+
36
+ return (commit) => (commit.type ? map.get(commit.type) : null)
37
+ }
@@ -0,0 +1,66 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import type { ReleaseRule, ResolvedReleaseRule } from '#types'
5
+ import { sanitizePrereleaseLabel } from './sanitizePrereleaseLabel'
6
+
7
+ /**
8
+ * Normalize a release rule input into a resolved release rule object.
9
+ *
10
+ * Converts `string` shorthand inputs into structured rule objects with sanitized
11
+ * labels. Resolves `versionQualifier` and `releaseChannel` against `pattern`.
12
+ * Returns `null` if `rule` is invalid, falsy, or missing `pattern`.
13
+ *
14
+ * @param rule Raw release rule input, `string` shorthand, or falsy value
15
+ * @returns Resolved `ResolvedReleaseRule` object, or `null` if `rule` is invalid
16
+ */
17
+ export function normalizeReleaseRule(
18
+ rule: ReleaseRule | string | false | null | undefined
19
+ ): ResolvedReleaseRule | null {
20
+ if (typeof rule === 'string') {
21
+ rule = {
22
+ pattern: rule,
23
+ qualifier: sanitizePrereleaseLabel(rule),
24
+ channel: sanitizePrereleaseLabel(rule),
25
+ }
26
+ }
27
+
28
+ if (typeof rule !== 'object' || rule == null) {
29
+ return null
30
+ }
31
+
32
+ const { pattern } = rule
33
+
34
+ if (pattern == null) {
35
+ return null
36
+ }
37
+
38
+ return {
39
+ type: rule.type,
40
+ pattern,
41
+ versionQualifier: resolveRuleValue(rule.qualifier, pattern),
42
+ releaseChannel: resolveRuleValue(rule.channel, pattern),
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Resolve a rule property value from an explicit `string` or pattern fallback.
48
+ *
49
+ * @param value Explicit `string` value, `boolean` flag, or `undefined`
50
+ * @param pattern Fallback pattern string used when `value` is `true`
51
+ * @returns Resolved `string` value or `undefined`
52
+ */
53
+ function resolveRuleValue(
54
+ value: string | boolean | undefined,
55
+ pattern: string
56
+ ): string | undefined {
57
+ if (typeof value === 'string') {
58
+ return value
59
+ }
60
+
61
+ if (value) {
62
+ return sanitizePrereleaseLabel(pattern)
63
+ }
64
+
65
+ return undefined
66
+ }