@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
@@ -0,0 +1,130 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import { RELEASE_HOOK_NAMES } from '#config'
5
+ import { HookManager, type HookHandler } from '#plugin'
6
+ import type { ReleaseContext, ReleaseHookName, ReleasePlugin } from '#types'
7
+ import { colors } from 'consola/utils'
8
+ import { generateReleaseReport, printReleaseReport } from './report'
9
+
10
+ /**
11
+ * Execute the complete release workflow across all configured plugins.
12
+ *
13
+ * Runs each lifecycle phase sequentially, dispatching plugin hooks in onion
14
+ * order based on declared priority. Logs hook execution timing for non-silent
15
+ * runs and prints a release report upon completion or failure.
16
+ *
17
+ * @param context Release execution context containing runtime options and logger
18
+ * @param plugins List of release plugins to execute
19
+ * @returns Promise that resolves when all workflow phases complete
20
+ * @throws If any lifecycle hook execution fails
21
+ */
22
+ export async function executeReleaseWorkflow(
23
+ context: ReleaseContext,
24
+ plugins: readonly ReleasePlugin[]
25
+ ): Promise<void> {
26
+ const isSilent = import.meta.env.MODE === 'test'
27
+
28
+ try {
29
+ context.status = null
30
+ context.error = null
31
+
32
+ const manager = new HookManager<
33
+ Record<ReleaseHookName, HookHandler<ReleaseContext>>
34
+ >()
35
+
36
+ for (const hookName of RELEASE_HOOK_NAMES) {
37
+ for (const plugin of plugins) {
38
+ let hook = plugin[hookName]
39
+
40
+ if (typeof hook === 'function') {
41
+ hook = { handler: hook }
42
+ }
43
+
44
+ const handler = hook?.handler
45
+ const priority = hook?.priority
46
+
47
+ if (handler) {
48
+ manager.on(
49
+ hookName,
50
+ async (context, next) => {
51
+ const current = (context.phase = {
52
+ hook: hookName,
53
+ plugin: plugin.name,
54
+ })
55
+
56
+ const label = `${colors.gray(`[${current.hook}]`)} ${current.plugin}`
57
+ let startedLogging = false
58
+ let hasError = false
59
+
60
+ if (!isSilent) {
61
+ startedLogging = true
62
+ context.logger.start(label)
63
+ }
64
+
65
+ const currentFrame = { startTime: performance.now() }
66
+ const nextFrame = { duration: 0 }
67
+
68
+ try {
69
+ return await handler.call(plugin, context, async () => {
70
+ const startTime = performance.now()
71
+
72
+ try {
73
+ return await next(context)
74
+ } finally {
75
+ nextFrame.duration = performance.now() - startTime
76
+ }
77
+ })
78
+ } catch (err) {
79
+ hasError = true
80
+ throw err
81
+ } finally {
82
+ if (startedLogging) {
83
+ const duration =
84
+ performance.now() -
85
+ currentFrame.startTime -
86
+ nextFrame.duration
87
+ const color = duration >= 5000 ? colors.yellow : colors.cyan
88
+ const message = [
89
+ label,
90
+ color(`${(duration / 1000).toFixed(2)}s`),
91
+ ].join(' ')
92
+
93
+ if (hasError) {
94
+ context.logger.error(message)
95
+ } else {
96
+ context.logger.success(message)
97
+ }
98
+ }
99
+ }
100
+ },
101
+ priority
102
+ )
103
+ }
104
+ }
105
+ }
106
+
107
+ const dispatch = async (
108
+ index: number,
109
+ context: ReleaseContext
110
+ ): Promise<void> => {
111
+ const hook = RELEASE_HOOK_NAMES[index]
112
+
113
+ if (!hook) return
114
+
115
+ return await manager.emit(hook, context, (context) =>
116
+ dispatch(index + 1, context)
117
+ )
118
+ }
119
+
120
+ await dispatch(0, context)
121
+
122
+ context.status = 'success'
123
+ } catch (err) {
124
+ context.status = 'failure'
125
+ context.error = err
126
+ throw err
127
+ } finally {
128
+ printReleaseReport(context.logger, generateReleaseReport(context))
129
+ }
130
+ }
@@ -0,0 +1,10 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ export * from './analysis'
5
+ export * from './changelog'
6
+ export * from './committing'
7
+ export * from './discovery'
8
+ export * from './executeReleaseWorkflow'
9
+ export * from './report'
10
+ export * from './versioning'
@@ -0,0 +1,54 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import type { ReleaseContext, ReleaseReport } from '#types'
5
+ import { compact } from '#util'
6
+
7
+ /**
8
+ * Generate a structured release report from the current workflow state.
9
+ *
10
+ * Extracts state information from `context` and organizes it into a report
11
+ * containing workflow status, release plans, and package metadata. Omits
12
+ * unversioned release plans from the finalized output.
13
+ *
14
+ * @param context Release execution context containing workflow state and plans
15
+ * @returns Structured release report object containing workflow results
16
+ */
17
+ export function generateReleaseReport(context: ReleaseContext): ReleaseReport {
18
+ return {
19
+ status: context.status,
20
+ phase: context.phase,
21
+ error: Error.isError(context.error)
22
+ ? context.error.message
23
+ : typeof context.error === 'string'
24
+ ? context.error
25
+ : null,
26
+ packages: context.packages.map((pkg) => ({
27
+ location: pkg.location,
28
+ name: pkg.name,
29
+ version: pkg.version,
30
+ })),
31
+ plans: compact(
32
+ context.plans.map((plan) => {
33
+ if (!plan.release?.version) return null
34
+
35
+ return {
36
+ package: {
37
+ provider: plan.package.provider,
38
+ entry: plan.package.entry,
39
+ location: plan.package.location,
40
+ name: plan.package.name,
41
+ version: plan.package.version,
42
+ private: !!plan.package.private,
43
+ },
44
+ release: {
45
+ type: plan.release.type,
46
+ version: plan.release.version,
47
+ tag: plan.release.tag?.name,
48
+ changelog: plan.release.changelog,
49
+ },
50
+ }
51
+ })
52
+ ),
53
+ }
54
+ }
@@ -0,0 +1,5 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ export * from './generateReleaseReport'
5
+ export * from './printReleaseReport'
@@ -0,0 +1,97 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import type { ReleaseReport } from '#types'
5
+ import type { ConsolaInstance } from 'consola/core'
6
+ import { colors } from 'consola/utils'
7
+ import path from 'node:path'
8
+
9
+ /**
10
+ * Print a formatted release report to the logger.
11
+ *
12
+ * Logs workflow `status` and details for planned package releases. Displays
13
+ * package names, directories, and version changes on success, or outputs the
14
+ * error message on failure.
15
+ *
16
+ * @param logger Logger instance for outputting messages
17
+ * @param report Release report containing status and package details
18
+ */
19
+ export function printReleaseReport(
20
+ logger: ConsolaInstance,
21
+ report: ReleaseReport
22
+ ): void {
23
+ if (report.status) {
24
+ const statusLabel = {
25
+ success: colors.green('SUCCESS'),
26
+ failure: colors.red('FAILURE'),
27
+ }[report.status]
28
+
29
+ logger.info(`Status: ${statusLabel}`)
30
+ }
31
+
32
+ if (report.status === 'failure') {
33
+ return logger.error(
34
+ [
35
+ 'Release complete:',
36
+ colors.red(
37
+ report.error ||
38
+ 'An unexpected error occurred during the release process.'
39
+ ),
40
+ ].join(' ')
41
+ )
42
+ }
43
+
44
+ if (report.plans.length === 0) {
45
+ return logger.info(
46
+ [
47
+ 'Release complete:',
48
+ colors.yellow('No packages are scheduled for release.'),
49
+ ].join(' ')
50
+ )
51
+ }
52
+
53
+ const header = [
54
+ 'Release complete:',
55
+ colors.bold(colors.green(`${report.plans.length} released`)),
56
+ colors.gray(`(${report.packages.length})`),
57
+ ].join(' ')
58
+
59
+ const list = report.plans
60
+ .toSorted((a, b) =>
61
+ (a.package.name || '').localeCompare(b.package.name || '')
62
+ )
63
+ .map((plan) => {
64
+ let dir = path.normalize(path.join(plan.package.location, '.'))
65
+
66
+ dir = dir === '.' ? dir : `./${dir}`
67
+
68
+ const name = plan.package.name
69
+ ? colors.bgBlue(` ${plan.package.name} `)
70
+ : !plan.package.entry && colors.gray(` ${dir} `)
71
+
72
+ let version = [plan.release.version, plan.package.version].join(' ← ')
73
+
74
+ version = ` ${version} `
75
+
76
+ const type = plan.release.type && colors.gray(` ${plan.release.type} `)
77
+
78
+ const summary = [
79
+ name,
80
+ plan.release.type === 'major'
81
+ ? colors.bgRed(version)
82
+ : colors.bgGreen(version),
83
+ type,
84
+ ]
85
+ .filter(Boolean)
86
+ .join('')
87
+
88
+ const changelog = plan.release.changelog
89
+ ?.replace(/^(#+ .+)$/gm, (_, header) => colors.cyan(header))
90
+ .trim()
91
+
92
+ return [summary, changelog].filter(Boolean).join('\n\n')
93
+ })
94
+ .join('\n\n')
95
+
96
+ logger.info(`${header}\n\n${list}\n`)
97
+ }
@@ -0,0 +1,76 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import type { ReleaseType, VersionTransition } from '#types'
5
+ import semver from 'semver'
6
+ import { extractVersionQualifier } from './extractVersionQualifier'
7
+
8
+ export interface BumpVersionOptions {
9
+ version: string
10
+ private?: boolean | undefined
11
+ release: ReleaseType | null | undefined
12
+ identifier?: string | null | undefined
13
+ transition?: VersionTransition | null | undefined
14
+ }
15
+
16
+ /**
17
+ * Bump a semantic version string based on release and transition rules.
18
+ *
19
+ * Parses the target version and determines the next version string using the
20
+ * specified release type, prerelease identifier, and transition mode. Adjusts
21
+ * prerelease types when continuing an existing qualifier and returns `null` when
22
+ * `options.release` is omitted or if transition conditions fail.
23
+ *
24
+ * @param options Version bump configuration including release type, identifier, and transition rules
25
+ * @returns The bumped semantic version string, or `null` if no bump occurs
26
+ * @throws If `options.version` is not a valid semantic version
27
+ */
28
+ export function bumpVersion(options: BumpVersionOptions): string | null {
29
+ const { version } = options
30
+
31
+ const parsed = semver.parse(version)
32
+
33
+ if (!parsed) {
34
+ throw new Error(`Version "${version}" is not a valid semantic version.`)
35
+ }
36
+
37
+ if (!options.release) {
38
+ return null
39
+ }
40
+
41
+ if (parsed.prerelease.length > 0) {
42
+ if (options.transition === 'advance' && options.identifier == null) {
43
+ return null
44
+ }
45
+ } else {
46
+ if (options.transition === 'continue') {
47
+ return null
48
+ }
49
+ }
50
+
51
+ let release: semver.ReleaseType = options.release
52
+ let identifier: string | undefined
53
+
54
+ if (typeof options.identifier === 'string') {
55
+ release = `pre${options.release}` as const
56
+ identifier = options.identifier
57
+
58
+ const parsedIdentifier = extractVersionQualifier(parsed)
59
+
60
+ const transition =
61
+ options.transition ??
62
+ (parsedIdentifier && identifier === '' ? 'advance' : 'continue')
63
+
64
+ if (typeof parsedIdentifier === 'string' && transition === 'continue') {
65
+ if (
66
+ (release === 'premajor' && parsed.minor === 0 && parsed.patch === 0) ||
67
+ (release === 'preminor' && parsed.patch === 0) ||
68
+ release === 'prepatch'
69
+ ) {
70
+ release = 'prerelease'
71
+ }
72
+ }
73
+ }
74
+
75
+ return semver.inc(parsed, release, { loose: false }, identifier, '0')
76
+ }
@@ -0,0 +1,33 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import type { CommitClassifier, GitCommit, ReleaseType } from '#types'
5
+ import { determineReleaseType } from './determineReleaseType'
6
+ import { pickPriorityReleaseType } from './pickPriorityReleaseType'
7
+
8
+ /**
9
+ * Derive the combined release type from a commit history collection.
10
+ *
11
+ * Processes commits sequentially, accumulating the highest-precedence release
12
+ * type found by evaluating each individual commit and comparing it against the
13
+ * current maximum via `pickPriorityReleaseType`.
14
+ *
15
+ * @param classifier Function mapping commits to release types
16
+ * @param history Array of parsed commits to evaluate
17
+ * @returns `ReleaseType` string, or `null` when no matching rule applies
18
+ */
19
+ export function deriveReleaseType(
20
+ classifier: CommitClassifier,
21
+ history: readonly GitCommit[]
22
+ ): ReleaseType | null {
23
+ let releaseType: ReleaseType | null = null
24
+
25
+ for (const commit of history) {
26
+ releaseType = pickPriorityReleaseType(
27
+ releaseType,
28
+ determineReleaseType(classifier, commit)
29
+ )
30
+ }
31
+
32
+ return releaseType
33
+ }
@@ -0,0 +1,35 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import type { CommitClassifier, GitCommit, ReleaseType } from '#types'
5
+
6
+ /**
7
+ * Determine the release type for a single commit.
8
+ *
9
+ * Automatically returns `'major'` if the commit is marked as a breaking change.
10
+ * Otherwise, routes the commit through the custom `classifier` and ensures the
11
+ * resolved value is a valid semantic versioning release type.
12
+ *
13
+ * @param classifier Function mapping commits to release types
14
+ * @param commit Parsed commit to evaluate
15
+ * @returns `ReleaseType` string, or `null` when no matching rule applies
16
+ */
17
+ export function determineReleaseType(
18
+ classifier: CommitClassifier,
19
+ commit: GitCommit
20
+ ): ReleaseType | null {
21
+ if (commit.notes.length > 0) {
22
+ return 'major'
23
+ }
24
+
25
+ const type = classifier(commit)
26
+
27
+ switch (type) {
28
+ case 'major':
29
+ case 'minor':
30
+ case 'patch':
31
+ return type
32
+ }
33
+
34
+ return null
35
+ }
@@ -0,0 +1,29 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import type semver from 'semver'
5
+
6
+ /**
7
+ * Extract the version qualifier string from a parsed `SemVer` instance.
8
+ *
9
+ * Strips the trailing numeric counter from the `prerelease` components if
10
+ * present. Joins any remaining prerelease identifiers with a dot separator.
11
+ *
12
+ * @param version Parsed `SemVer` instance or nullish value to inspect
13
+ * @returns The extracted qualifier string or `undefined` if no prerelease exists
14
+ */
15
+ export function extractVersionQualifier(
16
+ version: semver.SemVer | null | undefined
17
+ ): string | undefined {
18
+ if (version != null && version.prerelease.length > 0) {
19
+ const prerelease = [...version.prerelease]
20
+
21
+ if (typeof prerelease.at(-1) === 'number') {
22
+ prerelease.pop()
23
+ }
24
+
25
+ return prerelease.join('.')
26
+ } else {
27
+ return undefined
28
+ }
29
+ }
@@ -0,0 +1,10 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ export * from './bumpVersion'
5
+ export * from './deriveReleaseType'
6
+ export * from './determineReleaseType'
7
+ export * from './extractVersionQualifier'
8
+ export * from './isSameReleaseCycle'
9
+ export * from './isStableVersion'
10
+ export * from './pickPriorityReleaseType'
@@ -0,0 +1,36 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import semver from 'semver'
5
+
6
+ /**
7
+ * Determine whether two semantic version strings or objects belong to the same release cycle.
8
+ *
9
+ * Compares the main version components of `currentVersion` and `nextVersion` to
10
+ * determine equality. Treats a transition from a non-zero `0.x` version to
11
+ * `1.0.0` as part of the same release cycle. Returns `false` if either input
12
+ * cannot be parsed.
13
+ *
14
+ * @param currentVersion Starting version string, `semver.SemVer` instance, or nullish value
15
+ * @param nextVersion Target version string, `semver.SemVer` instance, or nullish value
16
+ * @returns `true` if both versions belong to the same release cycle, `false` otherwise
17
+ */
18
+ export function isSameReleaseCycle(
19
+ currentVersion: string | semver.SemVer | null | undefined,
20
+ nextVersion: string | semver.SemVer | null | undefined
21
+ ): boolean {
22
+ const current = semver.parse(currentVersion)
23
+ const next = semver.parse(nextVersion)
24
+
25
+ if (!current || !next) return false
26
+
27
+ if (current.compareMain(next) === 0) return true
28
+
29
+ return (
30
+ current.major === 0 &&
31
+ (current.minor > 0 || current.patch > 0) &&
32
+ next.major === 1 &&
33
+ next.minor === 0 &&
34
+ next.patch === 0
35
+ )
36
+ }
@@ -0,0 +1,31 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import { colors } from 'consola/utils'
5
+ import semver from 'semver'
6
+
7
+ /**
8
+ * Determine whether a version string represents a stable SemVer release.
9
+ *
10
+ * A version is considered stable when:
11
+ * - It is a valid SemVer string.
12
+ * - Its major version is greater than 0 (not 0.x.x).
13
+ * - It contains no prerelease identifiers (no `-alpha`, `-beta`, `-rc`, etc.).
14
+ *
15
+ * Build metadata (the `+` suffix) does not affect stability.
16
+ *
17
+ * @param version Semantic version string to check
18
+ * @returns `true` if `version` is a stable SemVer; otherwise `false`
19
+ * @throws If `version` is not a valid SemVer string
20
+ */
21
+ export function isStableVersion(version: string): boolean {
22
+ const parsed = semver.parse(version)
23
+
24
+ if (!parsed) {
25
+ throw new Error(
26
+ `The version "${colors.bold(version)}" is not a valid SemVer.`
27
+ )
28
+ }
29
+
30
+ return parsed.major > 0 && parsed.prerelease.length === 0
31
+ }
@@ -0,0 +1,27 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import type { ReleaseType } from '#types'
5
+
6
+ /**
7
+ * Determine the highest-priority release type between two candidates.
8
+ *
9
+ * Compares release types by precedence order: `major` > `minor` > `patch`.
10
+ * Returns the higher-precedence type, or `null` if neither applies.
11
+ *
12
+ * @param curr Current accumulated release type
13
+ * @param next Candidate release type to consider
14
+ * @returns Highest-precedence `ReleaseType`, or `null` if neither applies
15
+ */
16
+ export function pickPriorityReleaseType(
17
+ curr: ReleaseType | null | undefined,
18
+ next: ReleaseType | null | undefined
19
+ ): ReleaseType | null {
20
+ for (const type of ['major', 'minor', 'patch'] satisfies ReleaseType[]) {
21
+ if (curr === type || next === type) {
22
+ return type
23
+ }
24
+ }
25
+
26
+ return null
27
+ }