@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.
- package/dist/HookDispatcher-Di79rwtu.js +236 -0
- package/dist/HookDispatcher-Di79rwtu.js.map +1 -0
- package/dist/analyzer.js +12 -3
- package/dist/analyzer.js.map +1 -1
- package/dist/buildChangelog-Cxm9_lq2.js +187 -0
- package/dist/buildChangelog-Cxm9_lq2.js.map +1 -0
- package/dist/buildReleaseNotes-S6HcEQnE.js +141 -0
- package/dist/buildReleaseNotes-S6HcEQnE.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 +1201 -8
- package/dist/index.js.map +1 -1
- package/dist/package-Bczytil1.js +884 -0
- package/dist/package-Bczytil1.js.map +1 -0
- package/dist/propagateDependencyUpdates-QWn0H1qa.js +306 -0
- package/dist/propagateDependencyUpdates-QWn0H1qa.js.map +1 -0
- package/dist/readPackageHistory-CN5nqMcE.js +133 -0
- package/dist/readPackageHistory-CN5nqMcE.js.map +1 -0
- package/dist/resolvePackageTag-cwqG1GGt.js +30 -0
- package/dist/resolvePackageTag-cwqG1GGt.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/util/execCommand.ts +9 -0
- package/src/util/formatFile.ts +12 -3
- package/src/util/interpolate.ts +5 -3
- 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,30 @@
|
|
|
1
|
+
import { a as generateGitTagName, i as getGitTagMessage, n as verifyPackageTag } from "./package-Bczytil1.js";
|
|
2
|
+
// src/workflow/discovery/resolvePackageTag.ts
|
|
3
|
+
/**
|
|
4
|
+
* Resolve the release tag for a single package version.
|
|
5
|
+
*
|
|
6
|
+
* Returns the cached `pkg.tag` immediately if it already exists. Generates an
|
|
7
|
+
* expected tag name from the package metadata and verifies its integrity using
|
|
8
|
+
* `verifyPackageTag`.
|
|
9
|
+
*
|
|
10
|
+
* @param cwd Repository working directory
|
|
11
|
+
* @param pkg Package descriptor containing version and location context
|
|
12
|
+
* @param options Dry-run and logging guards for the local tag cleanup
|
|
13
|
+
* @returns A promise resolving to the tag metadata or null when not found
|
|
14
|
+
*/
|
|
15
|
+
async function resolvePackageTag(cwd, pkg, options) {
|
|
16
|
+
if (pkg.tag) return pkg.tag;
|
|
17
|
+
let expectedTagName;
|
|
18
|
+
try {
|
|
19
|
+
expectedTagName = generateGitTagName(pkg.entry, pkg.name, pkg.version);
|
|
20
|
+
} catch {}
|
|
21
|
+
if (!expectedTagName) return null;
|
|
22
|
+
if (await verifyPackageTag(cwd, pkg, expectedTagName, options)) return {
|
|
23
|
+
name: expectedTagName,
|
|
24
|
+
message: await getGitTagMessage(cwd, expectedTagName)
|
|
25
|
+
};
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
export { resolvePackageTag as t };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=resolvePackageTag-cwqG1GGt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvePackageTag-cwqG1GGt.js","names":[],"sources":["../src/workflow/discovery/resolvePackageTag.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { generateGitTagName, getGitTagMessage } from '#git'\nimport type { EnsureGitTagOptions } from '#git'\nimport type { Package, Tag } from '#types'\nimport { verifyPackageTag } from './verifyPackageTag'\n\n/**\n * Resolve the release tag for a single package version.\n *\n * Returns the cached `pkg.tag` immediately if it already exists. Generates an\n * expected tag name from the package metadata and verifies its integrity using\n * `verifyPackageTag`.\n *\n * @param cwd Repository working directory\n * @param pkg Package descriptor containing version and location context\n * @param options Dry-run and logging guards for the local tag cleanup\n * @returns A promise resolving to the tag metadata or null when not found\n */\nexport async function resolvePackageTag(\n cwd: string,\n pkg: Package,\n options?: EnsureGitTagOptions\n): Promise<Tag | null> {\n if (pkg.tag) {\n return pkg.tag\n }\n\n let expectedTagName: string | null | undefined\n\n try {\n expectedTagName = generateGitTagName(pkg.entry, pkg.name, pkg.version)\n } catch {}\n\n if (!expectedTagName) {\n return null\n }\n\n if (await verifyPackageTag(cwd, pkg, expectedTagName, options)) {\n return {\n name: expectedTagName,\n message: await getGitTagMessage(cwd, expectedTagName),\n }\n }\n\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;AAoBA,eAAsB,kBACpB,KACA,KACA,SACqB;CACrB,IAAI,IAAI,KACN,OAAO,IAAI;CAGb,IAAI;CAEJ,IAAI;EACF,kBAAkB,mBAAmB,IAAI,OAAO,IAAI,MAAM,IAAI,OAAO;CACvE,QAAQ,CAAC;CAET,IAAI,CAAC,iBACH,OAAO;CAGT,IAAI,MAAM,iBAAiB,KAAK,KAAK,iBAAiB,OAAO,GAC3D,OAAO;EACL,MAAM;EACN,SAAS,MAAM,iBAAiB,KAAK,eAAe;CACtD;CAGF,OAAO;AACT"}
|
package/dist/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reelout/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Release engine for commit analysis, version planning, lifecycle hooks, and release notes.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"release",
|
|
7
|
+
"versioning",
|
|
8
|
+
"monorepo",
|
|
9
|
+
"changelog",
|
|
10
|
+
"conventional-commits",
|
|
11
|
+
"plugin"
|
|
12
|
+
],
|
|
5
13
|
"repository": {
|
|
6
14
|
"type": "git",
|
|
7
15
|
"url": "git+https://github.com/reelout/reelout.git",
|
|
8
16
|
"directory": "packages/core"
|
|
9
17
|
},
|
|
10
18
|
"license": "MIT",
|
|
19
|
+
"sideEffects": false,
|
|
11
20
|
"type": "module",
|
|
12
21
|
"imports": {
|
|
13
22
|
"#*": [
|
|
@@ -44,8 +53,8 @@
|
|
|
44
53
|
"conventional-commits-parser": "^7.1.4",
|
|
45
54
|
"hosted-git-info": "^10.1.1",
|
|
46
55
|
"mdast-util-from-markdown": "^2.1.0",
|
|
47
|
-
"mdast-util-to-markdown": "^2.2.
|
|
48
|
-
"minimatch": "^11.0.
|
|
56
|
+
"mdast-util-to-markdown": "^2.2.4",
|
|
57
|
+
"minimatch": "^11.0.9",
|
|
49
58
|
"prettier": "^3.10.1",
|
|
50
59
|
"semver": "^7.8.6"
|
|
51
60
|
},
|
|
@@ -57,6 +66,9 @@
|
|
|
57
66
|
"engines": {
|
|
58
67
|
"node": ">=24.15"
|
|
59
68
|
},
|
|
69
|
+
"publishConfig": {
|
|
70
|
+
"access": "public"
|
|
71
|
+
},
|
|
60
72
|
"scripts": {
|
|
61
73
|
"build": "vite build --ssr --sourcemap",
|
|
62
74
|
"dev": "vite build --ssr --watch"
|
package/src/analyzer.ts
CHANGED
|
@@ -50,7 +50,10 @@ const analyzer = (): ReleasePlugin => ({
|
|
|
50
50
|
if (plan.package.entry || plan.package.name) {
|
|
51
51
|
const tag =
|
|
52
52
|
plan.package.tag ??
|
|
53
|
-
(await resolvePackageTag(context.cwd, plan.package
|
|
53
|
+
(await resolvePackageTag(context.cwd, plan.package, {
|
|
54
|
+
logger: context.logger,
|
|
55
|
+
dryRun: context.dryRun,
|
|
56
|
+
}))
|
|
54
57
|
|
|
55
58
|
if (tag && !plan.package.tag) {
|
|
56
59
|
plan.package.tag = tag
|
|
@@ -59,7 +62,9 @@ const analyzer = (): ReleasePlugin => ({
|
|
|
59
62
|
history = readPackageHistory(
|
|
60
63
|
context.cwd,
|
|
61
64
|
plan.package,
|
|
62
|
-
tag
|
|
65
|
+
tag
|
|
66
|
+
? { until: tag.name, logger: context.logger }
|
|
67
|
+
: { logger: context.logger }
|
|
63
68
|
)
|
|
64
69
|
}
|
|
65
70
|
|
package/src/builder.ts
CHANGED
|
@@ -41,7 +41,6 @@ const builder = (): ReleasePlugin => ({
|
|
|
41
41
|
try {
|
|
42
42
|
version = bumpVersion({
|
|
43
43
|
version: plan.package.version,
|
|
44
|
-
private: plan.package.private,
|
|
45
44
|
release: plan.release.type,
|
|
46
45
|
identifier: context.versionQualifier,
|
|
47
46
|
transition: plan.release.transition,
|
|
@@ -84,11 +83,15 @@ const builder = (): ReleasePlugin => ({
|
|
|
84
83
|
isSameReleaseCycle(plan.package.version, plan.release.version)
|
|
85
84
|
) {
|
|
86
85
|
const previousTag = (
|
|
87
|
-
await resolvePackageStableTag(context.cwd, plan.package
|
|
86
|
+
await resolvePackageStableTag(context.cwd, plan.package, {
|
|
87
|
+
logger: context.logger,
|
|
88
|
+
dryRun: context.dryRun,
|
|
89
|
+
})
|
|
88
90
|
)?.name
|
|
89
91
|
|
|
90
92
|
const history = readPackageHistory(context.cwd, plan.package, {
|
|
91
93
|
until: previousTag,
|
|
94
|
+
logger: context.logger,
|
|
92
95
|
})
|
|
93
96
|
|
|
94
97
|
tagMessage = await buildReleaseNotes(context, history)
|
|
@@ -96,7 +99,13 @@ const builder = (): ReleasePlugin => ({
|
|
|
96
99
|
tagMessage = await buildReleaseNotes(context, plan.history)
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
|
-
} catch {
|
|
102
|
+
} catch (err) {
|
|
103
|
+
context.logger.warn(
|
|
104
|
+
colors.yellow(
|
|
105
|
+
`Release notes could not be generated for tag "${colors.bold(tagName ?? '')}" of package at "${colors.bold(plan.package.location)}": ${formatError(err)}`
|
|
106
|
+
)
|
|
107
|
+
)
|
|
108
|
+
}
|
|
100
109
|
|
|
101
110
|
if (tagName) {
|
|
102
111
|
plan.release.tag = {
|
package/src/changelog.ts
CHANGED
|
@@ -33,7 +33,10 @@ const changelog = (): ReleasePlugin => ({
|
|
|
33
33
|
context.packages = await Promise.all(
|
|
34
34
|
context.packages.map(async (pkg): Promise<Package> => ({
|
|
35
35
|
...pkg,
|
|
36
|
-
tag: await resolvePackageTag(context.cwd, pkg
|
|
36
|
+
tag: await resolvePackageTag(context.cwd, pkg, {
|
|
37
|
+
logger: context.logger,
|
|
38
|
+
dryRun: context.dryRun,
|
|
39
|
+
}),
|
|
37
40
|
}))
|
|
38
41
|
)
|
|
39
42
|
|
|
@@ -57,12 +60,20 @@ const changelog = (): ReleasePlugin => ({
|
|
|
57
60
|
|
|
58
61
|
let changelog: string | null | undefined
|
|
59
62
|
|
|
60
|
-
let previousTag = (
|
|
61
|
-
|
|
63
|
+
let previousTag = (
|
|
64
|
+
await resolvePackageTag(context.cwd, plan.package, {
|
|
65
|
+
logger: context.logger,
|
|
66
|
+
dryRun: context.dryRun,
|
|
67
|
+
})
|
|
68
|
+
)?.name
|
|
62
69
|
|
|
63
70
|
if (!previousTag) {
|
|
64
|
-
previousTag = (
|
|
65
|
-
|
|
71
|
+
previousTag = (
|
|
72
|
+
await discoverPackageTag(context.cwd, plan.package, {
|
|
73
|
+
logger: context.logger,
|
|
74
|
+
dryRun: context.dryRun,
|
|
75
|
+
})
|
|
76
|
+
)?.name
|
|
66
77
|
}
|
|
67
78
|
|
|
68
79
|
try {
|
|
@@ -96,7 +107,7 @@ const changelog = (): ReleasePlugin => ({
|
|
|
96
107
|
context.logger.debug('[DRY RUN] Changelog files will not be written.')
|
|
97
108
|
} else {
|
|
98
109
|
for (const plan of context.plans) {
|
|
99
|
-
await writeChangelog(context.cwd, plan)
|
|
110
|
+
await writeChangelog(context.cwd, plan, context.logger)
|
|
100
111
|
}
|
|
101
112
|
}
|
|
102
113
|
|
|
@@ -35,7 +35,10 @@ export async function getParsedGitCommit(
|
|
|
35
35
|
|
|
36
36
|
const entry = parseGitPrettyFormat(stdout)
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
// The working directory is intentionally absent from the key: commit
|
|
39
|
+
// hashes are content-addressed, so the same hash resolves to the same
|
|
40
|
+
// commit in every repository that shares the object.
|
|
41
|
+
const key = JSON.stringify([entry.hash, entry.parent, markers])
|
|
39
42
|
|
|
40
43
|
const cached = cache.get(key)
|
|
41
44
|
|
|
@@ -7,7 +7,10 @@ import type {
|
|
|
7
7
|
GitCommitTrailer,
|
|
8
8
|
GitCommitType,
|
|
9
9
|
} from '#types'
|
|
10
|
-
import type {
|
|
10
|
+
import type {
|
|
11
|
+
Commit as ParsedCommit,
|
|
12
|
+
CommitBase,
|
|
13
|
+
} from 'conventional-commits-parser'
|
|
11
14
|
import { CommitParser } from 'conventional-commits-parser'
|
|
12
15
|
import { buildTrailerPattern } from '../../util/buildTrailerPattern'
|
|
13
16
|
import { extractMentions } from './extractMentions'
|
|
@@ -38,6 +41,28 @@ const BREAKING_MARKERS: readonly string[] = [
|
|
|
38
41
|
'BREAKING-CHANGE',
|
|
39
42
|
]
|
|
40
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Converge the parser's dynamically-shaped result into the typed commit
|
|
46
|
+
* shape used for release analysis.
|
|
47
|
+
*
|
|
48
|
+
* The parser assigns `type`, `scope`, and `subject` at runtime through its
|
|
49
|
+
* default header correspondence, so they exist on the result without being
|
|
50
|
+
* part of its declared return type; `header` is always a string once
|
|
51
|
+
* parsing succeeds because the parser rejects empty input.
|
|
52
|
+
*
|
|
53
|
+
* @param parsed The parser result to converge
|
|
54
|
+
* @returns The typed commit shape
|
|
55
|
+
*/
|
|
56
|
+
function toCommit(parsed: ParsedCommit): Commit {
|
|
57
|
+
return {
|
|
58
|
+
...parsed,
|
|
59
|
+
type: parsed.type ?? null,
|
|
60
|
+
scope: parsed.scope ?? null,
|
|
61
|
+
subject: parsed.subject ?? '',
|
|
62
|
+
header: parsed.header ?? '',
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
41
66
|
/**
|
|
42
67
|
* Parse a git log entry into a structured commit object.
|
|
43
68
|
*
|
|
@@ -61,7 +86,7 @@ export async function parseGitCommit(
|
|
|
61
86
|
notesPattern: () => buildTrailerPattern(BREAKING_MARKERS.concat(markers)),
|
|
62
87
|
})
|
|
63
88
|
|
|
64
|
-
const commit = parser.parse(message)
|
|
89
|
+
const commit = toCommit(parser.parse(message))
|
|
65
90
|
|
|
66
91
|
const notes: GitCommitNote[] = []
|
|
67
92
|
|
|
@@ -60,7 +60,10 @@ export function parseGitPrettyFormat(raw: string): GitLogEntry {
|
|
|
60
60
|
|
|
61
61
|
if (!hash || !authorDate || !committerDate || typeof subject !== 'string') {
|
|
62
62
|
throw new Error(
|
|
63
|
-
`The input "${colors.bold(raw)}" is not in the expected pretty format
|
|
63
|
+
`The input "${colors.bold(raw.slice(0, 200))}" is not in the expected pretty format.`,
|
|
64
|
+
{
|
|
65
|
+
cause: new Error(`Pretty-format payload length: ${raw.length}`),
|
|
66
|
+
}
|
|
64
67
|
)
|
|
65
68
|
}
|
|
66
69
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Copyright (c) 2026 Fai
|
|
3
3
|
|
|
4
|
-
import { execGit } from '#util'
|
|
4
|
+
import { execGit, formatError } from '#util'
|
|
5
|
+
import type { ConsolaInstance } from 'consola/core'
|
|
5
6
|
import { isGitShallowRepository } from '../repository/isGitShallowRepository'
|
|
6
7
|
import { withShallowLock } from '../repository/withShallowLock'
|
|
7
8
|
import { isGitAncestor } from '../revision/isGitAncestor'
|
|
@@ -26,6 +27,11 @@ export interface ExpandGitHistoryOptions {
|
|
|
26
27
|
* If provided the function will first attempt a single fetch to reach this commit
|
|
27
28
|
*/
|
|
28
29
|
until?: string | null | undefined
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Optional logger that receives failed fetch attempts at debug level
|
|
33
|
+
*/
|
|
34
|
+
logger?: ConsolaInstance | undefined
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
/**
|
|
@@ -73,7 +79,11 @@ export async function expandGitHistory(
|
|
|
73
79
|
])
|
|
74
80
|
|
|
75
81
|
return true
|
|
76
|
-
} catch {
|
|
82
|
+
} catch (error: unknown) {
|
|
83
|
+
options.logger?.debug(
|
|
84
|
+
`Shallow fetch to reach "${until}" failed and incremental deepening will be attempted: ${formatError(error)}`
|
|
85
|
+
)
|
|
86
|
+
}
|
|
77
87
|
}
|
|
78
88
|
|
|
79
89
|
// Incremental deepening: account for existing local depth when `from` is set
|
|
@@ -105,7 +115,11 @@ export async function expandGitHistory(
|
|
|
105
115
|
])
|
|
106
116
|
|
|
107
117
|
return true
|
|
108
|
-
} catch {
|
|
118
|
+
} catch (error: unknown) {
|
|
119
|
+
options.logger?.debug(
|
|
120
|
+
`Shallow history at "${cwd}" could not be deepened by ${pageSize} commits: ${formatError(error)}`
|
|
121
|
+
)
|
|
122
|
+
|
|
109
123
|
return false
|
|
110
124
|
}
|
|
111
125
|
})
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Copyright (c) 2026 Fai
|
|
3
3
|
|
|
4
4
|
import type { GitCommit } from '#types'
|
|
5
|
+
import { formatError } from '#util'
|
|
5
6
|
import { getParsedGitCommit } from '../commit/getParsedGitCommit'
|
|
6
7
|
import { readGitHistory, type ReadGitHistoryOptions } from './readGitHistory'
|
|
7
8
|
|
|
@@ -10,7 +11,8 @@ import { readGitHistory, type ReadGitHistoryOptions } from './readGitHistory'
|
|
|
10
11
|
*
|
|
11
12
|
* Fetches commits using `readGitHistory` and parses each commit with
|
|
12
13
|
* `getParsedGitCommit`. Yields successfully parsed `GitCommit` objects on demand
|
|
13
|
-
* and skips unparsable commits
|
|
14
|
+
* and skips unparsable commits, reporting each skipped commit through
|
|
15
|
+
* `options.logger` at debug level when one is provided.
|
|
14
16
|
*
|
|
15
17
|
* @param cwd Repository working directory path
|
|
16
18
|
* @param options Filter and pagination options passed to `readGitHistory`
|
|
@@ -23,6 +25,10 @@ export async function* readParsedGitHistory(
|
|
|
23
25
|
for await (const commit of readGitHistory(cwd, options)) {
|
|
24
26
|
try {
|
|
25
27
|
yield await getParsedGitCommit(cwd, commit)
|
|
26
|
-
} catch {
|
|
28
|
+
} catch (error: unknown) {
|
|
29
|
+
options?.logger?.debug(
|
|
30
|
+
`Commit "${commit}" could not be parsed and was skipped: ${formatError(error)}`
|
|
31
|
+
)
|
|
32
|
+
}
|
|
27
33
|
}
|
|
28
34
|
}
|
|
@@ -10,7 +10,8 @@ import { execGit } from '#util'
|
|
|
10
10
|
* Useful before operations that require full history.
|
|
11
11
|
*
|
|
12
12
|
* @param cwd Repository working directory
|
|
13
|
-
* @returns `true` if shallow, `false` if full clone
|
|
13
|
+
* @returns `true` if shallow, `false` if full clone
|
|
14
|
+
* @throws If the underlying Git command fails
|
|
14
15
|
*/
|
|
15
16
|
export async function isGitShallowRepository(cwd: string): Promise<boolean> {
|
|
16
17
|
const stdout = (
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Copyright (c) 2026 Fai
|
|
3
3
|
|
|
4
4
|
import { execGit } from '#util'
|
|
5
|
+
import type { ConsolaInstance } from 'consola'
|
|
5
6
|
import { countGitHistory } from '../history/countGitHistory'
|
|
6
7
|
import { withShallowLock } from '../repository/withShallowLock'
|
|
7
8
|
import { deleteGitTag } from './deleteGitTag'
|
|
@@ -11,18 +12,39 @@ const MIN_HISTORY_DEPTH = 2
|
|
|
11
12
|
const ORIGIN_NOT_REPO = `fatal: 'origin' does not appear to be a git repository`
|
|
12
13
|
const REMOTE_REF_NOT_FOUND = `fatal: couldn't find remote ref`
|
|
13
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Options guarding the destructive local tag cleanup in `ensureGitTag`.
|
|
17
|
+
*/
|
|
18
|
+
export interface EnsureGitTagOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Logger warned before a stale local tag is deleted.
|
|
21
|
+
*/
|
|
22
|
+
logger?: ConsolaInstance | undefined
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Skip deleting stale local tags, warning instead.
|
|
26
|
+
*/
|
|
27
|
+
dryRun?: boolean | undefined
|
|
28
|
+
}
|
|
29
|
+
|
|
14
30
|
/**
|
|
15
31
|
* Ensure a tag exists locally, fetching it shallowly from `origin` if needed.
|
|
16
32
|
*
|
|
17
33
|
* Acquires a shallow-fetch lock, verifies local presence and history depth,
|
|
18
34
|
* attempts a shallow fetch of `refs/tags/<tag>` when required, and removes a
|
|
19
|
-
* local tag if the remote reports the tag is missing
|
|
35
|
+
* local tag if the remote reports the tag is missing — warning before the
|
|
36
|
+
* deletion and skipping it entirely in dry-run mode.
|
|
20
37
|
*
|
|
21
38
|
* @param cwd Working directory
|
|
22
39
|
* @param tag Tag name (for example `v1.2.0`)
|
|
40
|
+
* @param options Dry-run and logging guards for the local tag deletion
|
|
23
41
|
* @returns `true` if the tag is present or was fetched; otherwise `false`
|
|
24
42
|
*/
|
|
25
|
-
export function ensureGitTag(
|
|
43
|
+
export function ensureGitTag(
|
|
44
|
+
cwd: string,
|
|
45
|
+
tag: string,
|
|
46
|
+
options?: EnsureGitTagOptions
|
|
47
|
+
): Promise<boolean> {
|
|
26
48
|
return withShallowLock(cwd, async () => {
|
|
27
49
|
const tagRef = `refs/tags/${tag}`
|
|
28
50
|
|
|
@@ -53,7 +75,17 @@ export function ensureGitTag(cwd: string, tag: string): Promise<boolean> {
|
|
|
53
75
|
|
|
54
76
|
if (errorMessage?.includes(REMOTE_REF_NOT_FOUND)) {
|
|
55
77
|
if (await isGitTagPresent(cwd, tag)) {
|
|
56
|
-
|
|
78
|
+
if (options?.dryRun) {
|
|
79
|
+
options.logger?.warn(
|
|
80
|
+
`[DRY RUN] Local tag "${tag}" would be deleted because the remote no longer reports it.`
|
|
81
|
+
)
|
|
82
|
+
} else {
|
|
83
|
+
options?.logger?.warn(
|
|
84
|
+
`Local tag "${tag}" is being deleted because the remote no longer reports it.`
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
await deleteGitTag(cwd, tag)
|
|
88
|
+
}
|
|
57
89
|
}
|
|
58
90
|
}
|
|
59
91
|
}
|