@reelout/core 0.13.0 → 0.14.1
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/dist/HookDispatcher-B_TrMRLU.js +236 -0
- package/dist/HookDispatcher-B_TrMRLU.js.map +1 -0
- package/dist/analyzer.js +12 -3
- package/dist/analyzer.js.map +1 -1
- package/dist/buildChangelog-CkytKypk.js +187 -0
- package/dist/buildChangelog-CkytKypk.js.map +1 -0
- package/dist/buildReleaseNotes-Dk4bEclG.js +141 -0
- package/dist/buildReleaseNotes-Dk4bEclG.js.map +1 -0
- package/dist/builder.js +14 -6
- package/dist/builder.js.map +1 -1
- package/dist/changelog.js +17 -6
- package/dist/changelog.js.map +1 -1
- package/dist/index.js +1297 -20
- package/dist/index.js.map +1 -1
- package/dist/package-la-hLPRR.js +884 -0
- package/dist/package-la-hLPRR.js.map +1 -0
- package/dist/propagateDependencyUpdates-xcPvP5SP.js +306 -0
- package/dist/propagateDependencyUpdates-xcPvP5SP.js.map +1 -0
- package/dist/readPackageHistory-6dC72rZk.js +133 -0
- package/dist/readPackageHistory-6dC72rZk.js.map +1 -0
- package/dist/resolvePackageTag-2ldvH7PC.js +30 -0
- package/dist/resolvePackageTag-2ldvH7PC.js.map +1 -0
- package/dist/types.js +0 -1
- package/package.json +15 -3
- package/src/analyzer.ts +7 -2
- package/src/builder.ts +12 -3
- package/src/changelog.ts +17 -6
- package/src/config/resolvePlugin.ts +1 -1
- package/src/git/commit/getParsedGitCommit.ts +4 -1
- package/src/git/commit/parseGitCommit.ts +27 -2
- package/src/git/commit/parseGitPrettyFormat.ts +4 -1
- package/src/git/history/expandGitHistory.ts +17 -3
- package/src/git/history/readParsedGitHistory.ts +8 -2
- package/src/git/repository/isGitShallowRepository.ts +2 -1
- package/src/git/tag/ensureGitTag.ts +35 -3
- package/src/plugin/createHostReleasePlugin.ts +255 -0
- package/src/plugin/index.ts +1 -0
- package/src/types.ts +1 -0
- package/src/util/captureCommandOutput.ts +140 -0
- package/src/util/execCommand.ts +9 -0
- package/src/util/formatFile.ts +12 -3
- package/src/util/index.ts +1 -0
- package/src/util/interpolate.ts +5 -3
- package/src/util/isQuietEnvironment.ts +19 -13
- package/src/workflow/analysis/propagateDependencyUpdates.ts +1 -0
- package/src/workflow/changelog/buildChangelog.ts +27 -4
- package/src/workflow/changelog/buildReleaseNotes.ts +1 -1
- package/src/workflow/changelog/index.ts +0 -1
- package/src/workflow/changelog/prependChangelog.ts +5 -2
- package/src/workflow/changelog/writeChangelog.ts +5 -2
- package/src/workflow/commit/generateReleaseCommitMessage.ts +1 -1
- package/src/workflow/discovery/discoverPackageTag.ts +5 -2
- package/src/workflow/discovery/resolvePackageStableTag.ts +12 -7
- package/src/workflow/discovery/resolvePackageTag.ts +5 -2
- package/src/workflow/discovery/sortPackages.ts +5 -4
- package/src/workflow/discovery/verifyPackageTag.ts +6 -3
- package/src/workflow/report/printReleaseReport.ts +6 -1
- package/src/workflow/version/bumpVersion.ts +0 -1
- package/src/workflow/version/index.ts +0 -1
- package/dist/formatError-BMsun8Wi.js +0 -22
- package/dist/formatError-BMsun8Wi.js.map +0 -1
- package/dist/types-la_KkjCS.js +0 -1
- package/dist/workflow-Cqg6rLVB.js +0 -2936
- package/dist/workflow-Cqg6rLVB.js.map +0 -1
- package/src/workflow/changelog/extractPreviousVersion.ts +0 -77
- package/src/workflow/version/promotePrereleaseVersions.ts +0 -51
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
GitRepository,
|
|
6
|
+
ReleaseContext,
|
|
7
|
+
ReleasePlan,
|
|
8
|
+
ReleasePlugin,
|
|
9
|
+
} from '../types'
|
|
10
|
+
import { formatError } from '../util/formatError'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Read the release token from the release environment.
|
|
14
|
+
*
|
|
15
|
+
* Treats unset and whitespace-only values as missing.
|
|
16
|
+
*
|
|
17
|
+
* @param env Release environment variables
|
|
18
|
+
* @param tokenEnvKey Environment variable holding the release token
|
|
19
|
+
* @returns The trimmed token, or undefined when it is not set
|
|
20
|
+
*/
|
|
21
|
+
const readToken = (
|
|
22
|
+
env: ReleaseContext['env'],
|
|
23
|
+
tokenEnvKey: string
|
|
24
|
+
): string | undefined => {
|
|
25
|
+
const token = env[tokenEnvKey]?.trim()
|
|
26
|
+
|
|
27
|
+
return token ? token : undefined
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Options for {@link createHostReleasePlugin}.
|
|
32
|
+
*/
|
|
33
|
+
export interface HostReleasePluginOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Plugin name reported to the workflow, such as `'@reelout/github'`.
|
|
36
|
+
*/
|
|
37
|
+
name: string
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Plugin version reported to the workflow.
|
|
41
|
+
*/
|
|
42
|
+
version: string
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Repository host the plugin publishes to, such as `'github'`. Compared
|
|
46
|
+
* against the `host` of the release repository, so custom hosts are
|
|
47
|
+
* supported as long as the repository detection reports them.
|
|
48
|
+
*/
|
|
49
|
+
host: string
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Human-readable host name used in log messages, such as `'GitHub'`.
|
|
53
|
+
*/
|
|
54
|
+
displayName: string
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Environment variable holding the release token, such as
|
|
58
|
+
* `'GITHUB_TOKEN'`.
|
|
59
|
+
*/
|
|
60
|
+
tokenEnvKey: string
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Verify the release token against the target repository.
|
|
64
|
+
*
|
|
65
|
+
* Runs during the `configure` stage so a provided-but-invalid token fails
|
|
66
|
+
* before any mutation, including under dry-run.
|
|
67
|
+
*
|
|
68
|
+
* @param token Release token
|
|
69
|
+
* @param repository Target repository
|
|
70
|
+
*/
|
|
71
|
+
verifyToken: (token: string, repository: GitRepository) => Promise<void>
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Create the host release for a release plan.
|
|
75
|
+
*
|
|
76
|
+
* Runs during the `publish` stage for each finalized plan.
|
|
77
|
+
*
|
|
78
|
+
* @param context Release context
|
|
79
|
+
* @param plan Release plan to publish
|
|
80
|
+
* @param token Release token
|
|
81
|
+
* @param repository Target repository
|
|
82
|
+
* @returns Promise that resolves to a rollback callback for the release,
|
|
83
|
+
* or undefined when creation was skipped
|
|
84
|
+
*/
|
|
85
|
+
createRelease: (
|
|
86
|
+
context: ReleaseContext,
|
|
87
|
+
plan: ReleasePlan,
|
|
88
|
+
token: string,
|
|
89
|
+
repository: GitRepository
|
|
90
|
+
) => Promise<(() => Promise<void>) | void>
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* A rollback callback for a created host release, paired with the tag of
|
|
95
|
+
* the release it removes.
|
|
96
|
+
*/
|
|
97
|
+
interface ReleaseRollback {
|
|
98
|
+
/**
|
|
99
|
+
* Tag of the release the rollback removes.
|
|
100
|
+
*/
|
|
101
|
+
tag: string
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Callback that removes the created release.
|
|
105
|
+
*/
|
|
106
|
+
rollback: () => Promise<void>
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Run the collected release rollbacks, logging individual rollback failures
|
|
111
|
+
* without aborting the remaining rollbacks.
|
|
112
|
+
*
|
|
113
|
+
* @param logger Logger used to report rollback failures
|
|
114
|
+
* @param displayName Human-readable host name used in log messages
|
|
115
|
+
* @param rollbacks Rollbacks collected during publishing
|
|
116
|
+
*/
|
|
117
|
+
const rollbackReleases = async (
|
|
118
|
+
logger: ReleaseContext['logger'],
|
|
119
|
+
displayName: string,
|
|
120
|
+
rollbacks: readonly ReleaseRollback[]
|
|
121
|
+
): Promise<void> => {
|
|
122
|
+
const results = await Promise.allSettled(
|
|
123
|
+
rollbacks.map(({ rollback }) => rollback())
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
for (const [index, entry] of rollbacks.entries()) {
|
|
127
|
+
const result = results[index]
|
|
128
|
+
|
|
129
|
+
if (result?.status === 'rejected') {
|
|
130
|
+
logger.error(
|
|
131
|
+
`A ${displayName} release for tag "${entry.tag}" could not be rolled back: ${formatError(result.reason)}`
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Create a built-in plugin that publishes releases to a git host.
|
|
139
|
+
*
|
|
140
|
+
* Produces the shared skeleton behind the host release plugins. The plugin
|
|
141
|
+
* stays inactive unless the release repository is hosted on the given host,
|
|
142
|
+
* and verifies the token during the `configure` stage: a missing token
|
|
143
|
+
* skips the plugin's `publish` step with a debug message — or fails the run in
|
|
144
|
+
* strict mode — and a provided token is verified against the release
|
|
145
|
+
* repository before any mutation. During `publish`, host releases are
|
|
146
|
+
* created in reverse alphabetical package order (ensuring the root package
|
|
147
|
+
* release is created last) and rolled back when subsequent publishing
|
|
148
|
+
* stages fail.
|
|
149
|
+
*
|
|
150
|
+
* @param options Host release plugin options
|
|
151
|
+
* @returns A release plugin configured for the given host
|
|
152
|
+
*/
|
|
153
|
+
export function createHostReleasePlugin(
|
|
154
|
+
options: HostReleasePluginOptions
|
|
155
|
+
): ReleasePlugin {
|
|
156
|
+
return {
|
|
157
|
+
name: options.name,
|
|
158
|
+
version: options.version,
|
|
159
|
+
configure: async (context, next) => {
|
|
160
|
+
const repository = context.repository
|
|
161
|
+
|
|
162
|
+
if (repository?.host !== options.host) {
|
|
163
|
+
context.logger.debug(
|
|
164
|
+
`${options.displayName} releases will not be created: no ${options.displayName}-hosted repository was detected.`
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
return next(context)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const token = readToken(context.env, options.tokenEnvKey)
|
|
171
|
+
|
|
172
|
+
if (!token) {
|
|
173
|
+
if (context.strict) {
|
|
174
|
+
throw new Error(
|
|
175
|
+
`The ${options.tokenEnvKey} environment variable is required in strict mode.`
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
context.logger.debug(
|
|
180
|
+
`${options.displayName} releases will not be created: ${options.tokenEnvKey} is not set.`
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
return next(context)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
await options.verifyToken(token, repository)
|
|
187
|
+
|
|
188
|
+
return next(context)
|
|
189
|
+
},
|
|
190
|
+
publish: async (context, next) => {
|
|
191
|
+
if (context.repository?.host !== options.host) {
|
|
192
|
+
context.logger.debug(
|
|
193
|
+
`${options.displayName} publishing was skipped: no ${options.displayName}-hosted repository was detected.`
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
return next(context)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const token = readToken(context.env, options.tokenEnvKey)
|
|
200
|
+
|
|
201
|
+
if (!token) {
|
|
202
|
+
return next(context)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (context.dryRun) {
|
|
206
|
+
context.logger.debug(
|
|
207
|
+
`[DRY RUN] ${options.displayName} releases will not be created.`
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
return next(context)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const plans = context.plans.toSorted((a, b) =>
|
|
214
|
+
(a.package.name || '').localeCompare(b.package.name || '')
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
const repository = context.repository
|
|
218
|
+
|
|
219
|
+
const rollbacks: ReleaseRollback[] = []
|
|
220
|
+
|
|
221
|
+
try {
|
|
222
|
+
// Create releases in reverse order
|
|
223
|
+
// so that the root package release is created last,
|
|
224
|
+
// as it is often the most important one.
|
|
225
|
+
for (const plan of plans.toReversed()) {
|
|
226
|
+
const rollback = await options.createRelease(
|
|
227
|
+
context,
|
|
228
|
+
plan,
|
|
229
|
+
token,
|
|
230
|
+
repository
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
if (rollback) {
|
|
234
|
+
rollbacks.push({
|
|
235
|
+
tag: plan.release?.tag?.name ?? 'unknown',
|
|
236
|
+
rollback,
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
} catch (err) {
|
|
241
|
+
await rollbackReleases(context.logger, options.displayName, rollbacks)
|
|
242
|
+
|
|
243
|
+
throw err
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
try {
|
|
247
|
+
return await next(context)
|
|
248
|
+
} catch (err) {
|
|
249
|
+
await rollbackReleases(context.logger, options.displayName, rollbacks)
|
|
250
|
+
|
|
251
|
+
throw err
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
}
|
|
255
|
+
}
|
package/src/plugin/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
import { Writable } from 'node:stream'
|
|
5
|
+
import type { ReleaseContext } from '../types'
|
|
6
|
+
|
|
7
|
+
/** Maximum bytes of command output kept per stream for failure diagnostics. */
|
|
8
|
+
const MAX_TAIL_BYTES = 64 * 1024
|
|
9
|
+
|
|
10
|
+
/** Wrapping streams that keep a bounded tail of everything written through them. */
|
|
11
|
+
export interface CommandOutputCapture {
|
|
12
|
+
stdout: NodeJS.WritableStream
|
|
13
|
+
stderr: NodeJS.WritableStream
|
|
14
|
+
readStdout(): string
|
|
15
|
+
readDiagnostics(): string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Options controlling where the captured output is streamed. */
|
|
19
|
+
export interface CaptureCommandOutputOptions {
|
|
20
|
+
pipe: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Capture command output at the call site, optionally streaming it live.
|
|
25
|
+
*
|
|
26
|
+
* The returned wrappers keep a tail-bounded capture of everything written
|
|
27
|
+
* through them. When `pipe` is set they also forward the output to the
|
|
28
|
+
* context streams, so it keeps flowing live into the terminal or the CI
|
|
29
|
+
* job log; otherwise the output stays inside the capture.
|
|
30
|
+
*
|
|
31
|
+
* @param context Release context carrying the destination streams
|
|
32
|
+
* @param options Whether the captured output is forwarded to the context
|
|
33
|
+
* streams
|
|
34
|
+
* @returns Wrapping streams plus the captured tail readers
|
|
35
|
+
*/
|
|
36
|
+
export function captureCommandOutput(
|
|
37
|
+
context: Pick<ReleaseContext, 'stdout' | 'stderr'>,
|
|
38
|
+
options: CaptureCommandOutputOptions
|
|
39
|
+
): CommandOutputCapture {
|
|
40
|
+
const stdoutTail = new OutputTail()
|
|
41
|
+
const stderrTail = new OutputTail()
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
stdout: createCapturingStream(
|
|
45
|
+
options.pipe ? context.stdout : undefined,
|
|
46
|
+
stdoutTail
|
|
47
|
+
),
|
|
48
|
+
stderr: createCapturingStream(
|
|
49
|
+
options.pipe ? context.stderr : undefined,
|
|
50
|
+
stderrTail
|
|
51
|
+
),
|
|
52
|
+
readStdout: () => stdoutTail.read().trim(),
|
|
53
|
+
readDiagnostics: () => stderrTail.read().trim() || stdoutTail.read().trim(),
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Append captured command output to a failure error message.
|
|
59
|
+
*
|
|
60
|
+
* Command runs that stream through call-site wrappers carry no
|
|
61
|
+
* `execCommand` diagnostics of their own; this appends the captured tail
|
|
62
|
+
* so the publish-rejection classifiers keep reading the command output
|
|
63
|
+
* from the error message.
|
|
64
|
+
*
|
|
65
|
+
* @param cause The error thrown by the command
|
|
66
|
+
* @param capture The capture created for the run
|
|
67
|
+
* @returns The error, with the captured output appended to its message
|
|
68
|
+
*/
|
|
69
|
+
export function appendCapturedDiagnostics(
|
|
70
|
+
cause: unknown,
|
|
71
|
+
capture: CommandOutputCapture
|
|
72
|
+
): unknown {
|
|
73
|
+
const error = cause instanceof Error ? cause : new Error(String(cause))
|
|
74
|
+
const diagnostics = capture.readDiagnostics()
|
|
75
|
+
|
|
76
|
+
if (diagnostics) {
|
|
77
|
+
error.message = `${error.message}\n${diagnostics}`
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return error
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
class OutputTail {
|
|
84
|
+
private chunks: Buffer[] = []
|
|
85
|
+
private size = 0
|
|
86
|
+
|
|
87
|
+
push(chunk: Buffer): void {
|
|
88
|
+
this.chunks.push(chunk)
|
|
89
|
+
this.size += chunk.length
|
|
90
|
+
|
|
91
|
+
while (this.size > MAX_TAIL_BYTES && this.chunks.length > 1) {
|
|
92
|
+
const head = this.chunks.shift()
|
|
93
|
+
|
|
94
|
+
if (!head) break
|
|
95
|
+
|
|
96
|
+
this.size -= head.length
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
read(): string {
|
|
101
|
+
let buffer: Buffer = Buffer.concat(this.chunks)
|
|
102
|
+
|
|
103
|
+
if (buffer.length > MAX_TAIL_BYTES) {
|
|
104
|
+
buffer = trimUtf8Start(buffer.subarray(buffer.length - MAX_TAIL_BYTES))
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return buffer.toString('utf-8')
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function trimUtf8Start(buffer: Buffer): Buffer {
|
|
112
|
+
let start = 0
|
|
113
|
+
|
|
114
|
+
while (start < 3 && start < buffer.length) {
|
|
115
|
+
const byte = buffer[start]
|
|
116
|
+
|
|
117
|
+
if (byte === undefined || (byte & 0xc0) !== 0x80) break
|
|
118
|
+
|
|
119
|
+
start += 1
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return start === 0 ? buffer : buffer.subarray(start)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function createCapturingStream(
|
|
126
|
+
target: NodeJS.WritableStream | undefined,
|
|
127
|
+
tail: OutputTail
|
|
128
|
+
): Writable {
|
|
129
|
+
return new Writable({
|
|
130
|
+
write(chunk, _encoding, callback) {
|
|
131
|
+
tail.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk))
|
|
132
|
+
|
|
133
|
+
if (target) {
|
|
134
|
+
target.write(chunk, callback)
|
|
135
|
+
} else {
|
|
136
|
+
callback()
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
})
|
|
140
|
+
}
|
package/src/util/execCommand.ts
CHANGED
|
@@ -51,6 +51,15 @@ export function execCommand(
|
|
|
51
51
|
const env: NodeJS.ProcessEnv = {
|
|
52
52
|
HOME: process.env.HOME,
|
|
53
53
|
PATH: process.env.PATH,
|
|
54
|
+
SSH_AUTH_SOCK: process.env.SSH_AUTH_SOCK,
|
|
55
|
+
GIT_SSH: process.env.GIT_SSH,
|
|
56
|
+
GIT_SSH_COMMAND: process.env.GIT_SSH_COMMAND,
|
|
57
|
+
http_proxy: process.env.http_proxy,
|
|
58
|
+
https_proxy: process.env.https_proxy,
|
|
59
|
+
no_proxy: process.env.no_proxy,
|
|
60
|
+
HTTP_PROXY: process.env.HTTP_PROXY,
|
|
61
|
+
HTTPS_PROXY: process.env.HTTPS_PROXY,
|
|
62
|
+
NO_PROXY: process.env.NO_PROXY,
|
|
54
63
|
...options.env,
|
|
55
64
|
}
|
|
56
65
|
|
package/src/util/formatFile.ts
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Copyright (c) 2026 Fai
|
|
3
3
|
|
|
4
|
+
import type { ConsolaInstance } from 'consola/core'
|
|
4
5
|
import prettier from 'prettier'
|
|
6
|
+
import { formatError } from './formatError'
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Format `content` for `filePath` using Prettier when possible.
|
|
8
10
|
*
|
|
9
11
|
* Resolves project/editorconfig settings and formats the provided content.
|
|
10
|
-
* Returns the original content on error or when no parser is inferred
|
|
12
|
+
* Returns the original content on error or when no parser is inferred, and
|
|
13
|
+
* reports the failure through `logger` at debug level when one is provided.
|
|
11
14
|
*
|
|
12
15
|
* @param filePath Path used to infer parser and config
|
|
13
16
|
* @param content Source content to format
|
|
17
|
+
* @param logger Optional logger that receives formatting failures
|
|
14
18
|
* @returns Formatted content or original content on failure
|
|
15
19
|
*/
|
|
16
20
|
export async function formatFile(
|
|
17
21
|
filePath: string,
|
|
18
|
-
content: string
|
|
22
|
+
content: string,
|
|
23
|
+
logger?: ConsolaInstance
|
|
19
24
|
): Promise<string> {
|
|
20
25
|
try {
|
|
21
26
|
const info = await prettier.getFileInfo(filePath, {
|
|
@@ -35,7 +40,11 @@ export async function formatFile(
|
|
|
35
40
|
parser: info.inferredParser,
|
|
36
41
|
filepath: filePath,
|
|
37
42
|
})
|
|
38
|
-
} catch {
|
|
43
|
+
} catch (error: unknown) {
|
|
44
|
+
logger?.debug(
|
|
45
|
+
`Formatting "${filePath}" failed and content stays unformatted: ${formatError(error)}`
|
|
46
|
+
)
|
|
47
|
+
|
|
39
48
|
return content
|
|
40
49
|
}
|
|
41
50
|
}
|
package/src/util/index.ts
CHANGED
package/src/util/interpolate.ts
CHANGED
|
@@ -15,10 +15,12 @@ const BANNED_KEYS = ['__proto__', 'constructor', 'prototype']
|
|
|
15
15
|
* - Backslash escapes are supported for `{`, `}`, `\`, and `.` inside tokens.
|
|
16
16
|
* - Tokens that reference banned keys (`__proto__`, `constructor`, `prototype`)
|
|
17
17
|
* are left unexpanded to avoid prototype pollution.
|
|
18
|
-
* - Only own properties are followed when resolving paths;
|
|
19
|
-
* missing, the
|
|
18
|
+
* - Only own properties are followed when resolving paths; when any step is
|
|
19
|
+
* missing, the token is preserved with its escape sequences already
|
|
20
|
+
* resolved, so an unresolved `{a\.b}` renders as `{a.b}`.
|
|
20
21
|
* - Resolved non-object, non-null values are stringified and inserted.
|
|
21
|
-
* - Unclosed tokens
|
|
22
|
+
* - Unclosed tokens keep their opening brace and resolved body; a trailing
|
|
23
|
+
* backslash is emitted as-is.
|
|
22
24
|
*
|
|
23
25
|
* @param template Template string containing placeholders like `{user.name}`
|
|
24
26
|
* @param data Object used to resolve placeholder paths
|
|
@@ -7,27 +7,33 @@ import { isCI } from './isCI'
|
|
|
7
7
|
/**
|
|
8
8
|
* Determine whether the current run should stay quiet about verbose output.
|
|
9
9
|
*
|
|
10
|
-
* A run is quiet when
|
|
11
|
-
* for a human
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* `
|
|
10
|
+
* A run is quiet when its verbose output would only accumulate noise: no
|
|
11
|
+
* terminal is attached for a human to read it live, or the run is inside CI
|
|
12
|
+
* where the provider records a job log that publish noise would pollute.
|
|
13
|
+
* The debug flag opts back in: a debug run is never quiet, not even inside
|
|
14
|
+
* CI, so `--debug` keeps the verbose output flowing. Quiet runs still
|
|
15
|
+
* surface command output on failure — `execCommand` attaches it to the
|
|
16
|
+
* failure diagnostics and captured commands attach their recorded output
|
|
17
|
+
* to the thrown error — so failures stay diagnosable.
|
|
15
18
|
*
|
|
16
|
-
* CI
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* escape hatch.
|
|
19
|
+
* CI runs stay quiet even when the provider attaches a pseudo-terminal: the
|
|
20
|
+
* `isCI` check guarantees it on top of the TTY check, so the job log keeps
|
|
21
|
+
* the publish results without the package manager noise.
|
|
20
22
|
*
|
|
21
23
|
* The verdict is per environment, not per stream, so a redirected stdout inside
|
|
22
24
|
* an interactive terminal still counts as quiet.
|
|
23
25
|
*
|
|
24
|
-
* @param context Release context carrying the
|
|
25
|
-
*
|
|
26
|
+
* @param context Release context carrying the debug flag, destination
|
|
27
|
+
* stream, and environment
|
|
28
|
+
* @returns `true` when the run is part of CI or no TTY is attached, unless
|
|
29
|
+
* the debug flag is set
|
|
26
30
|
*/
|
|
27
31
|
export function isQuietEnvironment(
|
|
28
|
-
context: Pick<ReleaseContext, 'env' | 'stdout'>
|
|
32
|
+
context: Pick<ReleaseContext, 'debug' | 'env' | 'stdout'>
|
|
29
33
|
): boolean {
|
|
30
|
-
if (
|
|
34
|
+
if (context.debug) return false
|
|
35
|
+
|
|
36
|
+
if (isCI(context.env)) return true
|
|
31
37
|
|
|
32
38
|
const stream = context.stdout as NodeJS.WriteStream | undefined
|
|
33
39
|
|
|
@@ -11,6 +11,7 @@ import { buildDependencyGraph } from '../discovery'
|
|
|
11
11
|
* Marks packages that depend on a releasing package for a `patch` release
|
|
12
12
|
* when they do not already have a release type.
|
|
13
13
|
*
|
|
14
|
+
* @param cwd Working directory path used to read Git history
|
|
14
15
|
* @param plans Array of release plans to update
|
|
15
16
|
* @returns Updated array of release plans
|
|
16
17
|
*/
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
writeChangelogString,
|
|
10
10
|
type CommitKnownProps,
|
|
11
11
|
type FinalTemplateContext,
|
|
12
|
+
type Options,
|
|
12
13
|
type TemplateContext,
|
|
13
14
|
} from 'conventional-changelog-writer'
|
|
14
15
|
import path from 'node:path'
|
|
@@ -21,10 +22,26 @@ export interface BuildChangelogOptions {
|
|
|
21
22
|
currentTag?: string | null | undefined
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
interface ConventionalCommitsPreset {
|
|
26
|
+
writer: Options
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let presetCache: ConventionalCommitsPreset | undefined
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Load the conventional commits preset on first use.
|
|
33
|
+
*
|
|
34
|
+
* Creating the preset performs setup work that used to run at import time
|
|
35
|
+
* through a module-level await; loading it lazily keeps importing this
|
|
36
|
+
* module synchronous and skips the cost for consumers that never build a
|
|
37
|
+
* changelog.
|
|
38
|
+
*
|
|
39
|
+
* @returns The cached preset, created on the first call
|
|
40
|
+
*/
|
|
41
|
+
async function loadPreset(): Promise<ConventionalCommitsPreset> {
|
|
42
|
+
presetCache ??= await createPreset()
|
|
43
|
+
|
|
44
|
+
return presetCache
|
|
28
45
|
}
|
|
29
46
|
|
|
30
47
|
/**
|
|
@@ -44,6 +61,8 @@ export async function buildChangelog(
|
|
|
44
61
|
history: Iterable<GitCommit> | AsyncIterable<GitCommit>,
|
|
45
62
|
options: BuildChangelogOptions = {}
|
|
46
63
|
): Promise<string> {
|
|
64
|
+
const preset = await loadPreset()
|
|
65
|
+
|
|
47
66
|
const repository = context.repository?.url || undefined
|
|
48
67
|
|
|
49
68
|
const version = options.version || undefined
|
|
@@ -58,6 +77,10 @@ export async function buildChangelog(
|
|
|
58
77
|
options.changelogFile || DEFAULT_CHANGELOG_FILE
|
|
59
78
|
)
|
|
60
79
|
|
|
80
|
+
const headerPartial = (context: FinalTemplateContext) => {
|
|
81
|
+
return context.version ? preset.writer.headerPartial?.(context) : undefined
|
|
82
|
+
}
|
|
83
|
+
|
|
61
84
|
const content = await writeChangelogString<CommitKnownProps>(
|
|
62
85
|
history,
|
|
63
86
|
{
|
|
@@ -75,5 +98,5 @@ export async function buildChangelog(
|
|
|
75
98
|
preset.writer
|
|
76
99
|
)
|
|
77
100
|
|
|
78
|
-
return formatFile(filePath, content)
|
|
101
|
+
return formatFile(filePath, content, context.logger)
|
|
79
102
|
}
|
|
@@ -5,7 +5,6 @@ export * from './buildChangelog'
|
|
|
5
5
|
export * from './buildReleaseNotes'
|
|
6
6
|
export * from './extractLatestVersion'
|
|
7
7
|
export * from './extractPlainText'
|
|
8
|
-
export * from './extractPreviousVersion'
|
|
9
8
|
export * from './extractSemVer'
|
|
10
9
|
export * from './iterateChangelogVersions'
|
|
11
10
|
export * from './prependChangelog'
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Copyright (c) 2026 Fai
|
|
3
3
|
|
|
4
4
|
import { formatFile } from '#util'
|
|
5
|
+
import type { ConsolaInstance } from 'consola/core'
|
|
5
6
|
import { fromMarkdown } from 'mdast-util-from-markdown'
|
|
6
7
|
import { toMarkdown } from 'mdast-util-to-markdown'
|
|
7
8
|
import fs from 'node:fs/promises'
|
|
@@ -16,11 +17,13 @@ const defaultChangelogTitle = 'Changelog'
|
|
|
16
17
|
*
|
|
17
18
|
* @param filePath Path to the changelog file
|
|
18
19
|
* @param revision Changelog content to prepend
|
|
20
|
+
* @param logger Optional logger that receives formatting failures
|
|
19
21
|
* @returns Promise that resolves when the changelog is written
|
|
20
22
|
*/
|
|
21
23
|
export async function prependChangelog(
|
|
22
24
|
filePath: string,
|
|
23
|
-
revision: string
|
|
25
|
+
revision: string,
|
|
26
|
+
logger?: ConsolaInstance
|
|
24
27
|
): Promise<void> {
|
|
25
28
|
let content = ''
|
|
26
29
|
|
|
@@ -53,7 +56,7 @@ export async function prependChangelog(
|
|
|
53
56
|
|
|
54
57
|
content = toMarkdown(root)
|
|
55
58
|
|
|
56
|
-
content = await formatFile(filePath, content)
|
|
59
|
+
content = await formatFile(filePath, content, logger)
|
|
57
60
|
|
|
58
61
|
await fs.writeFile(filePath, content)
|
|
59
62
|
}
|