@reelout/core 0.13.0 → 0.14.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 (62) hide show
  1. package/dist/HookDispatcher-Di79rwtu.js +236 -0
  2. package/dist/HookDispatcher-Di79rwtu.js.map +1 -0
  3. package/dist/analyzer.js +12 -3
  4. package/dist/analyzer.js.map +1 -1
  5. package/dist/buildChangelog-Cxm9_lq2.js +187 -0
  6. package/dist/buildChangelog-Cxm9_lq2.js.map +1 -0
  7. package/dist/buildReleaseNotes-S6HcEQnE.js +141 -0
  8. package/dist/buildReleaseNotes-S6HcEQnE.js.map +1 -0
  9. package/dist/builder.js +14 -6
  10. package/dist/builder.js.map +1 -1
  11. package/dist/changelog.js +17 -6
  12. package/dist/changelog.js.map +1 -1
  13. package/dist/index.js +1201 -8
  14. package/dist/index.js.map +1 -1
  15. package/dist/package-Bczytil1.js +884 -0
  16. package/dist/package-Bczytil1.js.map +1 -0
  17. package/dist/propagateDependencyUpdates-QWn0H1qa.js +306 -0
  18. package/dist/propagateDependencyUpdates-QWn0H1qa.js.map +1 -0
  19. package/dist/readPackageHistory-CN5nqMcE.js +133 -0
  20. package/dist/readPackageHistory-CN5nqMcE.js.map +1 -0
  21. package/dist/resolvePackageTag-cwqG1GGt.js +30 -0
  22. package/dist/resolvePackageTag-cwqG1GGt.js.map +1 -0
  23. package/dist/types.js +0 -1
  24. package/package.json +15 -3
  25. package/src/analyzer.ts +7 -2
  26. package/src/builder.ts +12 -3
  27. package/src/changelog.ts +17 -6
  28. package/src/config/resolvePlugin.ts +1 -1
  29. package/src/git/commit/getParsedGitCommit.ts +4 -1
  30. package/src/git/commit/parseGitCommit.ts +27 -2
  31. package/src/git/commit/parseGitPrettyFormat.ts +4 -1
  32. package/src/git/history/expandGitHistory.ts +17 -3
  33. package/src/git/history/readParsedGitHistory.ts +8 -2
  34. package/src/git/repository/isGitShallowRepository.ts +2 -1
  35. package/src/git/tag/ensureGitTag.ts +35 -3
  36. package/src/plugin/createHostReleasePlugin.ts +255 -0
  37. package/src/plugin/index.ts +1 -0
  38. package/src/util/execCommand.ts +9 -0
  39. package/src/util/formatFile.ts +12 -3
  40. package/src/util/interpolate.ts +5 -3
  41. package/src/workflow/analysis/propagateDependencyUpdates.ts +1 -0
  42. package/src/workflow/changelog/buildChangelog.ts +27 -4
  43. package/src/workflow/changelog/buildReleaseNotes.ts +1 -1
  44. package/src/workflow/changelog/index.ts +0 -1
  45. package/src/workflow/changelog/prependChangelog.ts +5 -2
  46. package/src/workflow/changelog/writeChangelog.ts +5 -2
  47. package/src/workflow/commit/generateReleaseCommitMessage.ts +1 -1
  48. package/src/workflow/discovery/discoverPackageTag.ts +5 -2
  49. package/src/workflow/discovery/resolvePackageStableTag.ts +12 -7
  50. package/src/workflow/discovery/resolvePackageTag.ts +5 -2
  51. package/src/workflow/discovery/sortPackages.ts +5 -4
  52. package/src/workflow/discovery/verifyPackageTag.ts +6 -3
  53. package/src/workflow/report/printReleaseReport.ts +6 -1
  54. package/src/workflow/version/bumpVersion.ts +0 -1
  55. package/src/workflow/version/index.ts +0 -1
  56. package/dist/formatError-BMsun8Wi.js +0 -22
  57. package/dist/formatError-BMsun8Wi.js.map +0 -1
  58. package/dist/types-la_KkjCS.js +0 -1
  59. package/dist/workflow-Cqg6rLVB.js +0 -2936
  60. package/dist/workflow-Cqg6rLVB.js.map +0 -1
  61. package/src/workflow/changelog/extractPreviousVersion.ts +0 -77
  62. 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
+ }
@@ -1,4 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Copyright (c) 2026 Fai
3
3
 
4
+ export * from './createHostReleasePlugin'
4
5
  export * from './HookDispatcher'
@@ -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
 
@@ -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
  }
@@ -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; if any step is
19
- * missing, the original token text is preserved.
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 and a trailing backslash are preserved verbatim.
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
@@ -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
- const preset = await createPreset()
25
+ interface ConventionalCommitsPreset {
26
+ writer: Options
27
+ }
28
+
29
+ let presetCache: ConventionalCommitsPreset | undefined
25
30
 
26
- const headerPartial = (context: FinalTemplateContext) => {
27
- return context.version ? preset.writer.headerPartial?.(context) : undefined
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
  }
@@ -46,5 +46,5 @@ export async function buildReleaseNotes(
46
46
 
47
47
  const filePath = path.join(context.cwd, DEFAULT_CHANGELOG_FILE)
48
48
 
49
- return formatFile(filePath, toMarkdown(root))
49
+ return formatFile(filePath, toMarkdown(root), context.logger)
50
50
  }
@@ -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
  }
@@ -3,6 +3,7 @@
3
3
 
4
4
  import { DEFAULT_CHANGELOG_FILE } from '#config'
5
5
  import type { ReleasePlan } from '#types'
6
+ import type { ConsolaInstance } from 'consola/core'
6
7
  import path from 'node:path'
7
8
  import { prependChangelog } from './prependChangelog'
8
9
 
@@ -11,17 +12,19 @@ import { prependChangelog } from './prependChangelog'
11
12
  *
12
13
  * @param cwd Repository working directory
13
14
  * @param plan Release plan containing package and changelog content
15
+ * @param logger Optional logger that receives formatting failures
14
16
  * @returns Promise that resolves when the changelog file has been written
15
17
  */
16
18
  export async function writeChangelog(
17
19
  cwd: string,
18
- plan: ReleasePlan
20
+ plan: ReleasePlan,
21
+ logger?: ConsolaInstance
19
22
  ): Promise<void> {
20
23
  if (plan.release?.changelog) {
21
24
  const changelogFile = plan.package.changelogFile || DEFAULT_CHANGELOG_FILE
22
25
 
23
26
  const filePath = path.join(cwd, plan.package.location, changelogFile)
24
27
 
25
- await prependChangelog(filePath, plan.release.changelog)
28
+ await prependChangelog(filePath, plan.release.changelog, logger)
26
29
  }
27
30
  }
@@ -4,7 +4,7 @@
4
4
  import { GIT_TRAILER_RELEASE_AGENT } from '#config'
5
5
  import { mergeGitHistory } from '#git'
6
6
  import type { GitCommit, GitCommitType, ReleasePlan } from '#types'
7
- import { version } from '../../../package.json'
7
+ import { version } from '../../../package.json' with { type: 'json' }
8
8
 
9
9
  const NOTABLE_TYPES: readonly GitCommitType[] = [
10
10
  'feat',
@@ -8,6 +8,7 @@ import {
8
8
  readGitFile,
9
9
  resolveGitRevision,
10
10
  } from '#git'
11
+ import type { EnsureGitTagOptions } from '#git'
11
12
  import type { Package, Tag } from '#types'
12
13
  import { readFile } from 'node:fs/promises'
13
14
  import path from 'node:path'
@@ -24,11 +25,13 @@ import { verifyPackageTag } from './verifyPackageTag'
24
25
  *
25
26
  * @param cwd The current working directory
26
27
  * @param pkg The package configuration object
28
+ * @param options Dry-run and logging guards for the local tag cleanup
27
29
  * @returns The validated `Tag` object or null if validation fails
28
30
  */
29
31
  export async function discoverPackageTag(
30
32
  cwd: string,
31
- pkg: Package
33
+ pkg: Package,
34
+ options?: EnsureGitTagOptions
32
35
  ): Promise<Tag | null> {
33
36
  if (pkg.tag) {
34
37
  return pkg.tag
@@ -64,7 +67,7 @@ export async function discoverPackageTag(
64
67
  return null
65
68
  }
66
69
 
67
- if (!(await verifyPackageTag(cwd, pkg, expectedTagName))) {
70
+ if (!(await verifyPackageTag(cwd, pkg, expectedTagName, options))) {
68
71
  return null
69
72
  }
70
73
 
@@ -3,8 +3,8 @@
3
3
 
4
4
  import { DEFAULT_CHANGELOG_FILE } from '#config'
5
5
  import { generateGitTagName, getGitTagMessage } from '#git'
6
+ import type { EnsureGitTagOptions } from '#git'
6
7
  import type { Package, Tag } from '#types'
7
- import assert from 'node:assert'
8
8
  import { readFile } from 'node:fs/promises'
9
9
  import path from 'node:path'
10
10
  import semver from 'semver'
@@ -18,15 +18,21 @@ import { verifyPackageTag } from './verifyPackageTag'
18
18
  * semver order. Ignores prerelease versions unless transitioning across major
19
19
  * or prerelease boundaries, and verifies that the matching Git tag exists.
20
20
  *
21
+ * Stable releases below `1.0.0` are only considered when the preceding
22
+ * version was a prerelease, so a repository with exclusively 0.x releases
23
+ * resolves to no stable tag.
24
+ *
21
25
  * @param cwd Absolute path to the root working directory
22
26
  * @param pkg Package configuration object
27
+ * @param options Dry-run and logging guards for the local tag cleanup
23
28
  * @returns Verified tag metadata object or `null` if no stable tag is resolved
24
29
  * @throws If a version is invalid, versions are not in strict descending
25
30
  * order, or the corresponding Git tag is missing
26
31
  */
27
32
  export async function resolvePackageStableTag(
28
33
  cwd: string,
29
- pkg: Package
34
+ pkg: Package,
35
+ options?: EnsureGitTagOptions
30
36
  ): Promise<Tag | null> {
31
37
  const changelogFile = pkg.changelogFile || DEFAULT_CHANGELOG_FILE
32
38
 
@@ -51,10 +57,9 @@ export async function resolvePackageStableTag(
51
57
  for (const version of iterateChangelogVersions(changelogContent)) {
52
58
  const currentVersion = semver.parse(version)
53
59
 
54
- assert(
55
- currentVersion,
56
- `Version "${version}" is not a valid semantic version.`
57
- )
60
+ if (!currentVersion) {
61
+ throw new Error(`Version "${version}" is not a valid semantic version.`)
62
+ }
58
63
 
59
64
  if (precedingVersion && semver.gte(currentVersion, precedingVersion)) {
60
65
  throw new Error(
@@ -69,7 +74,7 @@ export async function resolvePackageStableTag(
69
74
  ) {
70
75
  const tagName = generateGitTagName(pkg.entry, pkg.name, version)
71
76
 
72
- if (!(await verifyPackageTag(cwd, pkg, tagName))) {
77
+ if (!(await verifyPackageTag(cwd, pkg, tagName, options))) {
73
78
  throw new Error(
74
79
  `Git tag "${tagName}" is not associated with package "${pkg.name ?? ''}" in directory "${pkg.location}".`
75
80
  )
@@ -2,6 +2,7 @@
2
2
  // Copyright (c) 2026 Fai
3
3
 
4
4
  import { generateGitTagName, getGitTagMessage } from '#git'
5
+ import type { EnsureGitTagOptions } from '#git'
5
6
  import type { Package, Tag } from '#types'
6
7
  import { verifyPackageTag } from './verifyPackageTag'
7
8
 
@@ -14,11 +15,13 @@ import { verifyPackageTag } from './verifyPackageTag'
14
15
  *
15
16
  * @param cwd Repository working directory
16
17
  * @param pkg Package descriptor containing version and location context
18
+ * @param options Dry-run and logging guards for the local tag cleanup
17
19
  * @returns A promise resolving to the tag metadata or null when not found
18
20
  */
19
21
  export async function resolvePackageTag(
20
22
  cwd: string,
21
- pkg: Package
23
+ pkg: Package,
24
+ options?: EnsureGitTagOptions
22
25
  ): Promise<Tag | null> {
23
26
  if (pkg.tag) {
24
27
  return pkg.tag
@@ -34,7 +37,7 @@ export async function resolvePackageTag(
34
37
  return null
35
38
  }
36
39
 
37
- if (await verifyPackageTag(cwd, pkg, expectedTagName)) {
40
+ if (await verifyPackageTag(cwd, pkg, expectedTagName, options)) {
38
41
  return {
39
42
  name: expectedTagName,
40
43
  message: await getGitTagMessage(cwd, expectedTagName),
@@ -11,12 +11,13 @@ interface PackageNode {
11
11
  /**
12
12
  * Sort workspace packages topologically based on their dependency graphs.
13
13
  *
14
- * Deepest dependents are placed first in the resulting array, ensuring that
15
- * a package always precedes its own dependencies. Ties and circular dependencies
16
- * are resolved deterministically using an alphabetical sort on the package directory (`dir`).
14
+ * Deepest dependencies are placed first in the resulting array, ensuring that
15
+ * a package always follows its own dependencies. Ties and circular dependencies
16
+ * are resolved deterministically using an alphabetical sort on the package
17
+ * location (`location`).
17
18
  *
18
19
  * @param packages The workspace packages to sort.
19
- * @returns A new array of packages sorted by dependency depth and directory path.
20
+ * @returns A new array of packages sorted by dependency depth and location.
20
21
  */
21
22
  export function sortPackages(packages: readonly Package[]): Package[] {
22
23
  const packageNodes: PackageNode[] = []
@@ -7,6 +7,7 @@ import {
7
7
  getParsedGitCommit,
8
8
  isGitTagConnected,
9
9
  } from '#git'
10
+ import type { EnsureGitTagOptions } from '#git'
10
11
  import type { GitCommit, Package } from '#types'
11
12
  import { packageContainsCommit } from '../analysis/packageContainsCommit'
12
13
 
@@ -20,14 +21,16 @@ import { packageContainsCommit } from '../analysis/packageContainsCommit'
20
21
  * @param cwd Repository working directory path
21
22
  * @param pkg Package descriptor containing version and location context
22
23
  * @param tagName Name of the Git tag to verify
24
+ * @param options Dry-run and logging guards for the local tag cleanup
23
25
  * @returns True if the tag is valid and connected; otherwise, false
24
26
  */
25
27
  export async function verifyPackageTag(
26
28
  cwd: string,
27
29
  pkg: Package,
28
- tagName: string
30
+ tagName: string,
31
+ options?: EnsureGitTagOptions
29
32
  ): Promise<boolean> {
30
- await ensureGitTag(cwd, tagName)
33
+ await ensureGitTag(cwd, tagName, options)
31
34
 
32
35
  const tagRef = `refs/tags/${tagName}`
33
36
 
@@ -43,7 +46,7 @@ export async function verifyPackageTag(
43
46
  return false
44
47
  }
45
48
 
46
- await expandGitHistory(cwd, { until: tagRef })
49
+ await expandGitHistory(cwd, { until: tagRef, logger: options?.logger })
47
50
 
48
51
  return isGitTagConnected(cwd, tagName)
49
52
  }