@reelout/core 0.1.1 → 0.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.
- package/LICENSE +21 -0
- package/dist/analyzer.js +33 -0
- package/dist/analyzer.js.map +1 -0
- package/dist/builder.js +64 -0
- package/dist/builder.js.map +1 -0
- package/dist/changelog.js +63 -0
- package/dist/changelog.js.map +1 -0
- package/dist/formatError-BXNdyRfu.js +23 -0
- package/dist/formatError-BXNdyRfu.js.map +1 -0
- package/dist/index.js +225 -1
- package/dist/index.js.map +1 -0
- package/dist/types-la_KkjCS.js +1 -0
- package/dist/types.js +2 -0
- package/dist/workflow-CroJ6v4g.js +2736 -0
- package/dist/workflow-CroJ6v4g.js.map +1 -0
- package/package.json +35 -6
- package/src/analyzer.ts +59 -0
- package/src/builder.ts +116 -0
- package/src/cache/TTLCache.ts +100 -0
- package/src/cache/index.ts +4 -0
- package/src/changelog.ts +107 -0
- package/src/config/const.ts +104 -0
- package/src/config/createPlugin.ts +41 -0
- package/src/config/findReleaseRule.ts +26 -0
- package/src/config/index.ts +15 -0
- package/src/config/isSemVer.ts +31 -0
- package/src/config/isSemVerGitTag.ts +25 -0
- package/src/config/normalizeCommitFilter.ts +37 -0
- package/src/config/normalizeReleaseRule.ts +66 -0
- package/src/config/normalizeWorkspace.ts +34 -0
- package/src/config/resolvePlugin.ts +57 -0
- package/src/config/resolveReleaseChannel.ts +47 -0
- package/src/config/resolveVersionQualifier.ts +53 -0
- package/src/config/sanitizePrereleaseLabel.ts +18 -0
- package/src/git/branch/getCurrentGitBranch.ts +18 -0
- package/src/git/branch/index.ts +4 -0
- package/src/git/commit/createGitCommit.ts +29 -0
- package/src/git/commit/extractMentions.ts +34 -0
- package/src/git/commit/getCurrentGitCommit.ts +19 -0
- package/src/git/commit/getParsedGitCommit.ts +49 -0
- package/src/git/commit/index.ts +9 -0
- package/src/git/commit/parseGitCommit.ts +114 -0
- package/src/git/commit/parseGitPrettyFormat.ts +76 -0
- package/src/git/history/countGitHistory.ts +28 -0
- package/src/git/history/expandGitHistory.ts +112 -0
- package/src/git/history/index.ts +9 -0
- package/src/git/history/mergeGitHistory.ts +76 -0
- package/src/git/history/restoreFullGitHistory.ts +19 -0
- package/src/git/history/showGitHistory.ts +80 -0
- package/src/git/history/showParsedGitHistory.ts +28 -0
- package/src/git/index.ts +9 -0
- package/src/git/repository/ensureGitUserConfig.ts +50 -0
- package/src/git/repository/getGitConfigValue.ts +27 -0
- package/src/git/repository/getGitRemote.ts +20 -0
- package/src/git/repository/index.ts +10 -0
- package/src/git/repository/isGitShallowRepository.ts +21 -0
- package/src/git/repository/pushGitChanges.ts +26 -0
- package/src/git/repository/resolveGitRepository.ts +40 -0
- package/src/git/repository/withShallowLock.ts +62 -0
- package/src/git/revision/detectGitRelationship.ts +43 -0
- package/src/git/revision/index.ts +7 -0
- package/src/git/revision/isGitAncestor.ts +33 -0
- package/src/git/revision/readGitFile.ts +29 -0
- package/src/git/revision/resolveGitRevision.ts +23 -0
- package/src/git/tag/createGitTag.ts +25 -0
- package/src/git/tag/deleteGitTag.ts +17 -0
- package/src/git/tag/ensureGitTag.ts +63 -0
- package/src/git/tag/generateGitTagName.ts +43 -0
- package/src/git/tag/getCurrentGitTag.ts +23 -0
- package/src/git/tag/getGitTagMessage.ts +35 -0
- package/src/git/tag/getLatestGitTag.ts +22 -0
- package/src/git/tag/index.ts +13 -0
- package/src/git/tag/isGitTagConnected.ts +33 -0
- package/src/git/tag/isGitTagPointed.ts +38 -0
- package/src/git/tag/isGitTagPresent.ts +17 -0
- package/src/index.ts +9 -2
- package/src/plugin/HookManager.ts +128 -0
- package/src/plugin/index.ts +4 -0
- package/src/types.ts +259 -0
- package/src/util/buildTrailerPattern.ts +20 -0
- package/src/util/compact.ts +14 -0
- package/src/util/execCommand.ts +196 -0
- package/src/util/execGit.ts +27 -0
- package/src/util/formatError.ts +21 -0
- package/src/util/formatFile.ts +41 -0
- package/src/util/index.ts +19 -0
- package/src/util/interpolate.ts +141 -0
- package/src/util/isCI.ts +18 -0
- package/src/util/isClass.ts +34 -0
- package/src/util/isDefined.ts +12 -0
- package/src/util/isMatch.ts +43 -0
- package/src/util/isQuietEnvironment.ts +35 -0
- package/src/util/isTruthyString.ts +19 -0
- package/src/util/readJson.ts +47 -0
- package/src/util/unique.ts +26 -0
- package/src/util/writeJson.ts +28 -0
- package/src/workflow/analysis/deriveChangeReleases.ts +76 -0
- package/src/workflow/analysis/deriveTransitionReleases.ts +134 -0
- package/src/workflow/analysis/index.ts +10 -0
- package/src/workflow/analysis/isCommitForPackage.ts +23 -0
- package/src/workflow/analysis/promotePrereleaseVersions.ts +51 -0
- package/src/workflow/analysis/propagateDependencyUpdates.ts +71 -0
- package/src/workflow/analysis/sliceUnreleased.ts +36 -0
- package/src/workflow/analysis/streamPackageCommits.ts +34 -0
- package/src/workflow/changelog/buildChangelog.ts +79 -0
- package/src/workflow/changelog/buildReleaseNotes.ts +50 -0
- package/src/workflow/changelog/conventional-changelog-conventionalcommits.d.ts +7 -0
- package/src/workflow/changelog/extractLatestVersion.ts +22 -0
- package/src/workflow/changelog/extractPlainText.ts +38 -0
- package/src/workflow/changelog/extractPreviousVersion.ts +77 -0
- package/src/workflow/changelog/extractSemVer.ts +33 -0
- package/src/workflow/changelog/index.ts +12 -0
- package/src/workflow/changelog/iterateChangelogVersions.ts +70 -0
- package/src/workflow/changelog/prependChangelog.ts +59 -0
- package/src/workflow/changelog/writeChangelog.ts +27 -0
- package/src/workflow/committing/generateReleaseCommitMessage.ts +121 -0
- package/src/workflow/committing/index.ts +5 -0
- package/src/workflow/committing/isReleaseCommit.ts +56 -0
- package/src/workflow/discovery/buildDependencyGraph.ts +43 -0
- package/src/workflow/discovery/discoverPackageTag.ts +98 -0
- package/src/workflow/discovery/index.ts +9 -0
- package/src/workflow/discovery/resolvePackageStableTag.ts +88 -0
- package/src/workflow/discovery/resolvePackageTag.ts +45 -0
- package/src/workflow/discovery/sortPackages.ts +75 -0
- package/src/workflow/discovery/verifyPackageTag.ts +49 -0
- package/src/workflow/executeReleaseWorkflow.ts +130 -0
- package/src/workflow/index.ts +10 -0
- package/src/workflow/report/generateReleaseReport.ts +54 -0
- package/src/workflow/report/index.ts +5 -0
- package/src/workflow/report/printReleaseReport.ts +97 -0
- package/src/workflow/versioning/bumpVersion.ts +76 -0
- package/src/workflow/versioning/deriveReleaseType.ts +33 -0
- package/src/workflow/versioning/determineReleaseType.ts +35 -0
- package/src/workflow/versioning/extractVersionQualifier.ts +29 -0
- package/src/workflow/versioning/index.ts +10 -0
- package/src/workflow/versioning/isSameReleaseCycle.ts +36 -0
- package/src/workflow/versioning/isStableVersion.ts +31 -0
- package/src/workflow/versioning/pickPriorityReleaseType.ts +27 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
const BACKSLASH = '\\'
|
|
5
|
+
const LEFT_BRACE = '{'
|
|
6
|
+
const RIGHT_BRACE = '}'
|
|
7
|
+
const DOT = '.'
|
|
8
|
+
const ESCAPE_CHARS = [BACKSLASH, LEFT_BRACE, RIGHT_BRACE]
|
|
9
|
+
const BANNED_KEYS = ['__proto__', 'constructor', 'prototype']
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Interpolate placeholders in `template` using values from `data`.
|
|
13
|
+
*
|
|
14
|
+
* - Placeholders use `{path.to.value}` (dot notation).
|
|
15
|
+
* - Backslash escapes are supported for `{`, `}`, `\`, and `.` inside tokens.
|
|
16
|
+
* - Tokens that reference banned keys (`__proto__`, `constructor`, `prototype`)
|
|
17
|
+
* are left unexpanded to avoid prototype pollution.
|
|
18
|
+
* - Only own properties are followed when resolving paths; if any step is
|
|
19
|
+
* missing, the original token text is preserved.
|
|
20
|
+
* - Resolved non-object, non-null values are stringified and inserted.
|
|
21
|
+
* - Unclosed tokens and a trailing backslash are preserved verbatim.
|
|
22
|
+
*
|
|
23
|
+
* @param template Template string containing placeholders like `{user.name}`
|
|
24
|
+
* @param data Object used to resolve placeholder paths
|
|
25
|
+
* @returns The template with placeholders replaced by corresponding values
|
|
26
|
+
*/
|
|
27
|
+
export function interpolate(
|
|
28
|
+
template: string,
|
|
29
|
+
data: Record<string, unknown>
|
|
30
|
+
): string {
|
|
31
|
+
let result = ''
|
|
32
|
+
let i = 0
|
|
33
|
+
let char: string | undefined
|
|
34
|
+
let nextChar: string | undefined
|
|
35
|
+
|
|
36
|
+
while ((char = template[i])) {
|
|
37
|
+
// Escape handling: if a backslash precedes an escapable char, emit the
|
|
38
|
+
// escaped character; otherwise emit the backslash itself.
|
|
39
|
+
if (char === BACKSLASH) {
|
|
40
|
+
nextChar = template[i + 1]
|
|
41
|
+
|
|
42
|
+
if (nextChar !== undefined && ESCAPE_CHARS.includes(nextChar)) {
|
|
43
|
+
result += nextChar
|
|
44
|
+
i += 2
|
|
45
|
+
} else {
|
|
46
|
+
result += char
|
|
47
|
+
i += 1
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Placeholder handling: parse a token starting at '{' until a matching '}'.
|
|
52
|
+
else if (char === LEFT_BRACE) {
|
|
53
|
+
const keys: string[] = []
|
|
54
|
+
let key = ''
|
|
55
|
+
let token = ''
|
|
56
|
+
let closed = false
|
|
57
|
+
i += 1
|
|
58
|
+
|
|
59
|
+
// Parse token body, supporting escaped characters and escaped dots.
|
|
60
|
+
while ((char = template[i])) {
|
|
61
|
+
if (char === RIGHT_BRACE) {
|
|
62
|
+
closed = true
|
|
63
|
+
keys.push(key)
|
|
64
|
+
i += 1
|
|
65
|
+
break
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (char === BACKSLASH) {
|
|
69
|
+
nextChar = template[i + 1]
|
|
70
|
+
|
|
71
|
+
// Allow escaping of brace, backslash, and dot inside tokens.
|
|
72
|
+
if (
|
|
73
|
+
nextChar !== undefined &&
|
|
74
|
+
[...ESCAPE_CHARS, DOT].includes(nextChar)
|
|
75
|
+
) {
|
|
76
|
+
key += nextChar
|
|
77
|
+
token += nextChar
|
|
78
|
+
i += 2
|
|
79
|
+
} else {
|
|
80
|
+
// Treat an isolated backslash as a literal within the token.
|
|
81
|
+
key += char
|
|
82
|
+
token += char
|
|
83
|
+
i += 1
|
|
84
|
+
}
|
|
85
|
+
} else if (char === DOT) {
|
|
86
|
+
// Dot separates path segments; record the current segment.
|
|
87
|
+
keys.push(key)
|
|
88
|
+
key = ''
|
|
89
|
+
token += char
|
|
90
|
+
i += 1
|
|
91
|
+
} else {
|
|
92
|
+
key += char
|
|
93
|
+
token += char
|
|
94
|
+
i += 1
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// If token closed with '}', attempt to resolve the path against `data`.
|
|
99
|
+
if (closed) {
|
|
100
|
+
let value: unknown = data
|
|
101
|
+
|
|
102
|
+
for (const key of keys) {
|
|
103
|
+
const isSafeKey = !BANNED_KEYS.includes(key)
|
|
104
|
+
|
|
105
|
+
// Only follow own properties on objects and skip banned keys.
|
|
106
|
+
if (
|
|
107
|
+
value !== null &&
|
|
108
|
+
typeof value === 'object' &&
|
|
109
|
+
Object.hasOwn(value, key) &&
|
|
110
|
+
isSafeKey
|
|
111
|
+
) {
|
|
112
|
+
value = (value as Record<string, unknown>)[key]
|
|
113
|
+
} else {
|
|
114
|
+
value = undefined
|
|
115
|
+
break
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// If resolution failed or produced an object/null, preserve the token.
|
|
120
|
+
if (value == null || typeof value === 'object') {
|
|
121
|
+
result += LEFT_BRACE + token + RIGHT_BRACE
|
|
122
|
+
} else {
|
|
123
|
+
result += String(value)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Unclosed token: preserve the raw token text (including the opening brace).
|
|
128
|
+
else {
|
|
129
|
+
result += LEFT_BRACE + token
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Ordinary characters are appended directly.
|
|
134
|
+
else {
|
|
135
|
+
result += char
|
|
136
|
+
i += 1
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return result
|
|
141
|
+
}
|
package/src/util/isCI.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
import { isTruthyString } from './isTruthyString'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Determine whether the current process is running in a CI environment.
|
|
8
|
+
*
|
|
9
|
+
* Checks if the `CI` environment variable is set to a truthy value. Ignores
|
|
10
|
+
* provider-specific variables such as `GITHUB_ACTIONS` to keep detection
|
|
11
|
+
* generic.
|
|
12
|
+
*
|
|
13
|
+
* @param env Readonly process environment variables object
|
|
14
|
+
* @returns `true` if `env.CI` normalizes to a truthy string, otherwise `false`
|
|
15
|
+
*/
|
|
16
|
+
export function isCI(env: Readonly<NodeJS.ProcessEnv>): boolean {
|
|
17
|
+
return isTruthyString(env.CI)
|
|
18
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Determine whether a given value is a constructible class.
|
|
6
|
+
*
|
|
7
|
+
* Verifies that the input is a function with a non-writable prototype, can
|
|
8
|
+
* be successfully invoked via `Reflect.construct`, and matches ES6 class
|
|
9
|
+
* syntax.
|
|
10
|
+
*
|
|
11
|
+
* @param func The unknown value to inspect
|
|
12
|
+
* @returns True if the value is a class, false otherwise
|
|
13
|
+
*/
|
|
14
|
+
export function isClass(
|
|
15
|
+
func: unknown
|
|
16
|
+
): func is new (...args: readonly unknown[]) => unknown {
|
|
17
|
+
if (typeof func !== 'function') {
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
Reflect.construct(Object, [], func)
|
|
23
|
+
} catch {
|
|
24
|
+
return false
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const descriptor = Object.getOwnPropertyDescriptor(func, 'prototype')
|
|
28
|
+
|
|
29
|
+
if (!descriptor || descriptor.writable) {
|
|
30
|
+
return false
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return /^class\s/.test(Function.prototype.toString.call(func))
|
|
34
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Type guard that asserts a value is neither `null` nor `undefined`.
|
|
6
|
+
*
|
|
7
|
+
* @param value Value to test
|
|
8
|
+
* @returns `true` when `value` is not `null` or `undefined`
|
|
9
|
+
*/
|
|
10
|
+
export function isDefined<T>(value: T): value is NonNullable<T> {
|
|
11
|
+
return value != null
|
|
12
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
import { minimatch } from 'minimatch'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Determine whether a target string matches glob patterns.
|
|
8
|
+
*
|
|
9
|
+
* Matches positive and negative glob patterns using dotfile support. Automatically
|
|
10
|
+
* expands a single negative pattern by prepending a global wildcard match.
|
|
11
|
+
*
|
|
12
|
+
* @param target Target string to evaluate against glob patterns
|
|
13
|
+
* @param patterns Single glob pattern or list of patterns to evaluate
|
|
14
|
+
* @returns True if target matches positive patterns and satisfies negative patterns
|
|
15
|
+
*/
|
|
16
|
+
export function isMatch(
|
|
17
|
+
target: string,
|
|
18
|
+
patterns: string | readonly string[]
|
|
19
|
+
): boolean {
|
|
20
|
+
if (typeof patterns === 'string') {
|
|
21
|
+
if (patterns.startsWith('!')) {
|
|
22
|
+
patterns = ['**/*', patterns]
|
|
23
|
+
} else {
|
|
24
|
+
patterns = [patterns]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const positives: string[] = []
|
|
29
|
+
const negatives: string[] = []
|
|
30
|
+
|
|
31
|
+
for (const pattern of patterns) {
|
|
32
|
+
if (pattern.startsWith('!')) {
|
|
33
|
+
negatives.push(pattern)
|
|
34
|
+
} else {
|
|
35
|
+
positives.push(pattern)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
positives.some((pattern) => minimatch(target, pattern, { dot: true })) &&
|
|
41
|
+
negatives.every((pattern) => minimatch(target, pattern, { dot: true }))
|
|
42
|
+
)
|
|
43
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
import type { ReleaseContext } from '../types'
|
|
5
|
+
import { isCI } from './isCI'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Determine whether the current run should stay quiet about verbose output.
|
|
9
|
+
*
|
|
10
|
+
* A run is quiet when nothing will keep what it prints: no terminal is attached
|
|
11
|
+
* for a human, and no CI provider is recording a job log. A plain pipe outside
|
|
12
|
+
* of CI — an agent sandbox, a script capturing output, a detached daemon — only
|
|
13
|
+
* accumulates noise, so verbose output should be withheld and left to
|
|
14
|
+
* `execCommand` for error reporting instead.
|
|
15
|
+
*
|
|
16
|
+
* CI is deliberately *not* quiet even though its streams are not TTYs: the
|
|
17
|
+
* provider persists the job log, so the output does reach someone. A caller
|
|
18
|
+
* that wants output from a pipe in a non-CI environment can set `CI=1` as an
|
|
19
|
+
* escape hatch.
|
|
20
|
+
*
|
|
21
|
+
* The verdict is per environment, not per stream, so a redirected stdout inside
|
|
22
|
+
* an interactive terminal still counts as quiet.
|
|
23
|
+
*
|
|
24
|
+
* @param context Release context carrying the destination stream and environment
|
|
25
|
+
* @returns `true` when no TTY is attached and the run is not part of CI
|
|
26
|
+
*/
|
|
27
|
+
export function isQuietEnvironment(
|
|
28
|
+
context: Pick<ReleaseContext, 'env' | 'stdout'>
|
|
29
|
+
): boolean {
|
|
30
|
+
if (isCI(context.env)) return false
|
|
31
|
+
|
|
32
|
+
const stream = context.stdout as NodeJS.WriteStream | undefined
|
|
33
|
+
|
|
34
|
+
return stream?.isTTY !== true
|
|
35
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Determine whether a string value represents a truthy boolean.
|
|
6
|
+
*
|
|
7
|
+
* Trims leading and trailing whitespace and coerces the target string to
|
|
8
|
+
* lowercase. Evaluates the string as truthy if it equals `'true'` or `'1'`.
|
|
9
|
+
*
|
|
10
|
+
* @param value The raw string to evaluate
|
|
11
|
+
* @returns `true` if `value` normalizes to `'true'` or `'1'`, otherwise `false`
|
|
12
|
+
*/
|
|
13
|
+
export function isTruthyString(value: string | undefined): boolean {
|
|
14
|
+
if (!value) return false
|
|
15
|
+
|
|
16
|
+
const normalized = value.toLowerCase().trim()
|
|
17
|
+
|
|
18
|
+
return normalized === 'true' || normalized === '1'
|
|
19
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
import { colors } from 'consola/utils'
|
|
5
|
+
import fs from 'node:fs/promises'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Read and parse a JSON file.
|
|
9
|
+
*
|
|
10
|
+
* Throws a descriptive error when the file cannot be read or parsed, or when
|
|
11
|
+
* the parsed value is not an object.
|
|
12
|
+
*
|
|
13
|
+
* @param filePath Path to the JSON file
|
|
14
|
+
* @returns Parsed JSON object
|
|
15
|
+
* @throws If the file cannot be read, parsed, or is not an object
|
|
16
|
+
*/
|
|
17
|
+
export async function readJson<T>(filePath: string): Promise<T> {
|
|
18
|
+
let content: string
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
content = await fs.readFile(filePath, 'utf-8')
|
|
22
|
+
} catch (err) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`JSON file at "${colors.bold(filePath)}" could not be read.`,
|
|
25
|
+
{ cause: err }
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let json: T
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
json = JSON.parse(content) as T
|
|
33
|
+
} catch (err) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`JSON file at "${colors.bold(filePath)}" could not be parsed.`,
|
|
36
|
+
{ cause: err }
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (typeof json !== 'object' || json === null) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`JSON file at "${colors.bold(filePath)}" does not contain a valid object.`
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return json
|
|
47
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Return a new array containing only the first-seen occurrence of each item.
|
|
6
|
+
*
|
|
7
|
+
* This preserves the original iteration order and performs equality checks
|
|
8
|
+
* using JavaScript's `Set` semantics (i.e., primitives by value, objects by
|
|
9
|
+
* reference). The input array is not mutated.
|
|
10
|
+
*
|
|
11
|
+
* @param array The array of items to deduplicate
|
|
12
|
+
* @returns A new array with duplicates removed, preserving first-seen order
|
|
13
|
+
*/
|
|
14
|
+
export function unique<T>(array: readonly T[]): T[] {
|
|
15
|
+
const seen = new Set<T>()
|
|
16
|
+
const result: T[] = []
|
|
17
|
+
|
|
18
|
+
for (const item of array) {
|
|
19
|
+
if (!seen.has(item)) {
|
|
20
|
+
seen.add(item)
|
|
21
|
+
result.push(item)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return result
|
|
26
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
import fs from 'node:fs/promises'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
import { formatFile } from './formatFile'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Write a JSON `payload` to `filePath`, formatting the content first.
|
|
10
|
+
*
|
|
11
|
+
* Ensures the directory exists and writes the formatted JSON.
|
|
12
|
+
*
|
|
13
|
+
* @param filePath Path to write the JSON file
|
|
14
|
+
* @param payload JSON-serializable object to write
|
|
15
|
+
* @returns Promise that resolves when the file is written
|
|
16
|
+
*/
|
|
17
|
+
export async function writeJson(
|
|
18
|
+
filePath: string,
|
|
19
|
+
payload: object
|
|
20
|
+
): Promise<void> {
|
|
21
|
+
let content = JSON.stringify(payload, null, 2)
|
|
22
|
+
|
|
23
|
+
content = await formatFile(filePath, content)
|
|
24
|
+
|
|
25
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true })
|
|
26
|
+
|
|
27
|
+
await fs.writeFile(filePath, content)
|
|
28
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
CommitClassifier,
|
|
6
|
+
GitCommit,
|
|
7
|
+
ReleasePlan,
|
|
8
|
+
ReleaseTypeHint,
|
|
9
|
+
} from '#types'
|
|
10
|
+
import { deriveReleaseType, pickPriorityReleaseType } from '../versioning'
|
|
11
|
+
import { isCommitForPackage } from './isCommitForPackage'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Analyze commit history to update release plans for packages.
|
|
15
|
+
*
|
|
16
|
+
* Maps commit `history` across package release `plans` to associate matching
|
|
17
|
+
* commits with their target packages. Calculates the release type for each
|
|
18
|
+
* plan based on classified `history` and applies overrides according to the
|
|
19
|
+
* provided `hint` or existing release priority.
|
|
20
|
+
*
|
|
21
|
+
* @param hint Release type override hint or default preference
|
|
22
|
+
* @param classifier Classifier function to determine commit release types
|
|
23
|
+
* @param plans List of release plans to analyze and update
|
|
24
|
+
* @param history Stream or iterable of git commits to process
|
|
25
|
+
* @returns Updated release plans with updated commit histories and release types
|
|
26
|
+
*/
|
|
27
|
+
export async function deriveChangeReleases(
|
|
28
|
+
hint: ReleaseTypeHint,
|
|
29
|
+
classifier: CommitClassifier,
|
|
30
|
+
plans: readonly ReleasePlan[],
|
|
31
|
+
history: Iterable<GitCommit> | AsyncIterable<GitCommit>
|
|
32
|
+
): Promise<ReleasePlan[]> {
|
|
33
|
+
for await (const commit of history) {
|
|
34
|
+
plans = plans.map((plan): ReleasePlan => {
|
|
35
|
+
if (!isCommitForPackage(plan.package, commit)) {
|
|
36
|
+
return plan
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
...plan,
|
|
41
|
+
history: plan.history.concat(commit),
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return plans.map((plan): ReleasePlan => {
|
|
47
|
+
let { release } = plan
|
|
48
|
+
|
|
49
|
+
let releaseType = deriveReleaseType(classifier, plan.history)
|
|
50
|
+
|
|
51
|
+
if (releaseType) {
|
|
52
|
+
switch (hint) {
|
|
53
|
+
case 'major':
|
|
54
|
+
case 'minor':
|
|
55
|
+
case 'patch':
|
|
56
|
+
releaseType = hint
|
|
57
|
+
break
|
|
58
|
+
default:
|
|
59
|
+
releaseType = pickPriorityReleaseType(release?.type, releaseType)
|
|
60
|
+
break
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (releaseType) {
|
|
65
|
+
release = {
|
|
66
|
+
...release,
|
|
67
|
+
type: releaseType,
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
...plan,
|
|
73
|
+
release,
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
ReleasePlan,
|
|
6
|
+
ReleaseType,
|
|
7
|
+
ReleaseTypeHint,
|
|
8
|
+
VersionTransition,
|
|
9
|
+
} from '#types'
|
|
10
|
+
import semver from 'semver'
|
|
11
|
+
import { extractVersionQualifier } from '../versioning/extractVersionQualifier'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Derive transition release types for release plans based on version qualifiers.
|
|
15
|
+
*
|
|
16
|
+
* Evaluates unreleased `plans` by parsing package `semver` strings and checking
|
|
17
|
+
* prerelease tags. Compares parsed version qualifiers against
|
|
18
|
+
* `versionQualifier` and assigns `major`, `minor`, or `patch` release types
|
|
19
|
+
* according to `hint`.
|
|
20
|
+
*
|
|
21
|
+
* @param hint Release type override hint to guide release classification
|
|
22
|
+
* @param versionQualifier Optional qualifier string to compare against prerelease tags
|
|
23
|
+
* @param plans List of release plans to analyze and update
|
|
24
|
+
* @returns Updated release plans with derived transition release types
|
|
25
|
+
*/
|
|
26
|
+
export function deriveTransitionReleases(
|
|
27
|
+
hint: ReleaseTypeHint,
|
|
28
|
+
versionQualifier: string | undefined,
|
|
29
|
+
plans: readonly ReleasePlan[]
|
|
30
|
+
): ReleasePlan[] {
|
|
31
|
+
return plans.map((plan) => {
|
|
32
|
+
if (plan.release) return plan
|
|
33
|
+
|
|
34
|
+
const parsed = semver.parse(plan.package.version)
|
|
35
|
+
|
|
36
|
+
if (!parsed) return plan
|
|
37
|
+
|
|
38
|
+
const { major, minor, patch } = parsed
|
|
39
|
+
const parsedVersionQualifier = extractVersionQualifier(parsed)
|
|
40
|
+
let releaseType: ReleaseType | undefined
|
|
41
|
+
let versionTransition: VersionTransition | undefined
|
|
42
|
+
|
|
43
|
+
switch (hint) {
|
|
44
|
+
case 'major':
|
|
45
|
+
if (parsed.prerelease.length === 0) {
|
|
46
|
+
if (typeof versionQualifier === 'string') {
|
|
47
|
+
releaseType = 'major'
|
|
48
|
+
} else if (major === 0 && (minor > 0 || patch > 0)) {
|
|
49
|
+
releaseType = 'major'
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
if (
|
|
53
|
+
minor === 0 &&
|
|
54
|
+
patch === 0 &&
|
|
55
|
+
parsedVersionQualifier !== versionQualifier
|
|
56
|
+
) {
|
|
57
|
+
releaseType = 'major'
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
break
|
|
61
|
+
|
|
62
|
+
case 'minor':
|
|
63
|
+
if (parsed.prerelease.length === 0) {
|
|
64
|
+
if (typeof versionQualifier === 'string') {
|
|
65
|
+
releaseType = 'minor'
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
if (
|
|
69
|
+
minor > 0 &&
|
|
70
|
+
patch === 0 &&
|
|
71
|
+
parsedVersionQualifier !== versionQualifier
|
|
72
|
+
) {
|
|
73
|
+
releaseType = 'minor'
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
break
|
|
77
|
+
|
|
78
|
+
case 'patch':
|
|
79
|
+
if (parsed.prerelease.length === 0) {
|
|
80
|
+
if (typeof versionQualifier === 'string') {
|
|
81
|
+
releaseType = 'patch'
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
if (patch > 0 && parsedVersionQualifier !== versionQualifier) {
|
|
85
|
+
releaseType = 'patch'
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
break
|
|
89
|
+
|
|
90
|
+
default:
|
|
91
|
+
if (parsed.prerelease.length === 0) {
|
|
92
|
+
if (major === 0 && (minor > 0 || patch > 0)) {
|
|
93
|
+
releaseType = 'major'
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
if (
|
|
97
|
+
minor === 0 &&
|
|
98
|
+
patch === 0 &&
|
|
99
|
+
parsedVersionQualifier !== versionQualifier
|
|
100
|
+
) {
|
|
101
|
+
releaseType = 'major'
|
|
102
|
+
} else if (
|
|
103
|
+
minor > 0 &&
|
|
104
|
+
patch === 0 &&
|
|
105
|
+
parsedVersionQualifier !== versionQualifier
|
|
106
|
+
) {
|
|
107
|
+
releaseType = 'minor'
|
|
108
|
+
} else if (patch > 0 && parsedVersionQualifier !== versionQualifier) {
|
|
109
|
+
releaseType = 'patch'
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
break
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (
|
|
116
|
+
parsedVersionQualifier == null ||
|
|
117
|
+
(parsedVersionQualifier !== '' && versionQualifier === '')
|
|
118
|
+
) {
|
|
119
|
+
versionTransition = 'advance'
|
|
120
|
+
} else {
|
|
121
|
+
versionTransition = 'continue'
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!releaseType) return plan
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
...plan,
|
|
128
|
+
release: {
|
|
129
|
+
type: releaseType,
|
|
130
|
+
transition: versionTransition,
|
|
131
|
+
},
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
export * from './deriveChangeReleases'
|
|
5
|
+
export * from './deriveTransitionReleases'
|
|
6
|
+
export * from './isCommitForPackage'
|
|
7
|
+
export * from './promotePrereleaseVersions'
|
|
8
|
+
export * from './propagateDependencyUpdates'
|
|
9
|
+
export * from './sliceUnreleased'
|
|
10
|
+
export * from './streamPackageCommits'
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
import { ALL_FILES } from '#config'
|
|
5
|
+
import type { GitCommit, Package } from '#types'
|
|
6
|
+
import { isMatch } from '#util'
|
|
7
|
+
import path from 'node:path'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Test whether a commit modifies files in a package.
|
|
11
|
+
*
|
|
12
|
+
* @param pkg Package with an explicit file pattern or base directory
|
|
13
|
+
* @param commit Parsed commit containing changed file paths
|
|
14
|
+
* @returns `true` if any changed file matches the package pattern
|
|
15
|
+
*/
|
|
16
|
+
export function isCommitForPackage(pkg: Package, commit: GitCommit): boolean {
|
|
17
|
+
return commit.files.some((file) => {
|
|
18
|
+
const { location } = pkg
|
|
19
|
+
const files = pkg.files || path.join(location, ALL_FILES)
|
|
20
|
+
|
|
21
|
+
return isMatch(file, files)
|
|
22
|
+
})
|
|
23
|
+
}
|