@reelout/core 0.6.0 → 0.7.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/analyzer.js +14 -10
- package/dist/analyzer.js.map +1 -1
- package/dist/builder.js +1 -1
- package/dist/changelog.js +1 -1
- package/dist/index.js +2 -36
- package/dist/index.js.map +1 -1
- package/dist/{workflow-c9uKSARL.js → workflow-BolfadM0.js} +690 -773
- package/dist/workflow-BolfadM0.js.map +1 -0
- package/package.json +1 -1
- package/src/analyzer.ts +27 -17
- package/src/config/const.ts +0 -2
- package/src/git/history/index.ts +2 -2
- package/src/git/history/{showGitHistory.ts → readGitHistory.ts} +3 -3
- package/src/git/history/{showParsedGitHistory.ts → readParsedGitHistory.ts} +6 -6
- package/src/git/tag/generateGitTagName.ts +1 -0
- package/src/git/tag/index.ts +1 -1
- package/src/git/tag/{isGitTagPointed.ts → isGitTagExact.ts} +1 -1
- package/src/workflow/analysis/deriveChangeReleases.ts +3 -3
- package/src/workflow/analysis/deriveTransitionReleases.ts +1 -1
- package/src/workflow/analysis/index.ts +1 -5
- package/src/workflow/analysis/{isCommitForPackage.ts → packageContainsCommit.ts} +4 -1
- package/src/workflow/analysis/readPackageHistory.ts +28 -9
- package/src/workflow/commit/index.ts +4 -0
- package/src/workflow/discovery/verifyPackageTag.ts +2 -2
- package/src/workflow/index.ts +2 -2
- package/src/workflow/{versioning/determineReleaseType.ts → version/deriveCommitReleaseType.ts} +2 -2
- package/src/workflow/{versioning → version}/deriveReleaseType.ts +2 -2
- package/src/workflow/{versioning → version}/index.ts +2 -1
- package/dist/workflow-c9uKSARL.js.map +0 -1
- package/src/workflow/analysis/collectUnreleased.ts +0 -44
- package/src/workflow/analysis/sliceUnreleased.ts +0 -24
- package/src/workflow/analysis/sliceUnreleasedForPackage.ts +0 -41
- package/src/workflow/committing/formatReleaseFilterPatterns.ts +0 -18
- package/src/workflow/committing/index.ts +0 -7
- package/src/workflow/committing/isReleaseCommit.ts +0 -56
- package/src/workflow/committing/readReleaseFilterPatterns.ts +0 -38
- /package/src/workflow/{committing → commit}/generateReleaseCommitMessage.ts +0 -0
- /package/src/workflow/{versioning → version}/bumpVersion.ts +0 -0
- /package/src/workflow/{versioning → version}/extractVersionQualifier.ts +0 -0
- /package/src/workflow/{versioning → version}/isSameReleaseCycle.ts +0 -0
- /package/src/workflow/{versioning → version}/isStableVersion.ts +0 -0
- /package/src/workflow/{versioning → version}/pickPriorityReleaseType.ts +0 -0
- /package/src/workflow/{analysis → version}/promotePrereleaseVersions.ts +0 -0
package/dist/analyzer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { h as resolvePackageTag, lt as deriveTransitionReleases, m as propagateDependencyUpdates, p as readPackageHistory, s as version, ut as deriveChangeReleases } from "./workflow-BolfadM0.js";
|
|
2
2
|
// src/analyzer.ts
|
|
3
3
|
/**
|
|
4
4
|
* Built-in plugin that inspects repository history and produces release plans for packages.
|
|
@@ -10,11 +10,12 @@ import { A as deriveChangeReleases, Vt as isMatch, _ as propagateDependencyUpdat
|
|
|
10
10
|
* classifications, handles transition releases for empty changesets (if
|
|
11
11
|
* enabled), and propagates dependency updates across internal packages.
|
|
12
12
|
*
|
|
13
|
-
* History slicing starts at
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* History slicing starts at each package's own verified release tag: the
|
|
14
|
+
* tag matching the package's current version is resolved and verified, and
|
|
15
|
+
* only commits after it are analyzed. Packages that can never be tagged
|
|
16
|
+
* (workspace packages without a name) are ignored: they keep their release
|
|
17
|
+
* plan but receive no history-based release. Packages without a verified
|
|
18
|
+
* tag are analyzed from the beginning of history.
|
|
18
19
|
*
|
|
19
20
|
* @returns A release plugin configured for package change analysis.
|
|
20
21
|
*/
|
|
@@ -27,12 +28,15 @@ var analyzer = () => ({
|
|
|
27
28
|
history: [],
|
|
28
29
|
release: null
|
|
29
30
|
}));
|
|
30
|
-
const window = await collectUnreleased(context.cwd);
|
|
31
|
-
const patterns = readReleaseFilterPatterns(window.stop);
|
|
32
31
|
const plans = [];
|
|
33
32
|
for (const plan of context.plans) {
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
let history = [];
|
|
34
|
+
if (plan.package.entry || plan.package.name) {
|
|
35
|
+
const tag = plan.package.tag ?? await resolvePackageTag(context.cwd, plan.package);
|
|
36
|
+
if (tag && !plan.package.tag) plan.package.tag = tag;
|
|
37
|
+
history = readPackageHistory(context.cwd, plan.package, tag ? { until: tag.name } : void 0);
|
|
38
|
+
}
|
|
39
|
+
plans.push(...await deriveChangeReleases(context.type, context.classifier, [plan], history));
|
|
36
40
|
}
|
|
37
41
|
context.plans = plans;
|
|
38
42
|
if (context.allowEmpty) context.plans = deriveTransitionReleases(context.type, context.versionQualifier, context.plans);
|
package/dist/analyzer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzer.js","names":[],"sources":["../src/analyzer.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { ReleasePlan, ReleasePlugin } from '#types'\nimport {
|
|
1
|
+
{"version":3,"file":"analyzer.js","names":[],"sources":["../src/analyzer.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { GitCommit, ReleasePlan, ReleasePlugin } from '#types'\nimport {\n deriveChangeReleases,\n deriveTransitionReleases,\n propagateDependencyUpdates,\n readPackageHistory,\n resolvePackageTag,\n} from '#workflow'\nimport { version } from '../package.json'\n\n/**\n * Built-in plugin that inspects repository history and produces release plans for packages.\n *\n * @remarks\n * **Lifecycle Stages:**\n * - `analyze`: Initializes release plans if empty, extracts unreleased Git\n * commit history, calculates package version bumps based on commit\n * classifications, handles transition releases for empty changesets (if\n * enabled), and propagates dependency updates across internal packages.\n *\n * History slicing starts at each package's own verified release tag: the\n * tag matching the package's current version is resolved and verified, and\n * only commits after it are analyzed. Packages that can never be tagged\n * (workspace packages without a name) are ignored: they keep their release\n * plan but receive no history-based release. Packages without a verified\n * tag are analyzed from the beginning of history.\n *\n * @returns A release plugin configured for package change analysis.\n */\nconst analyzer = (): ReleasePlugin => ({\n name: '@reelout/core/analyzer',\n version,\n analyze: async (context, next) => {\n if (context.plans.length === 0) {\n context.plans = context.packages.map((pkg): ReleasePlan => ({\n package: pkg,\n history: [],\n release: null,\n }))\n }\n\n const plans: ReleasePlan[] = []\n\n for (const plan of context.plans) {\n let history: Iterable<GitCommit> | AsyncIterable<GitCommit> = []\n\n if (plan.package.entry || plan.package.name) {\n const tag =\n plan.package.tag ??\n (await resolvePackageTag(context.cwd, plan.package))\n\n if (tag && !plan.package.tag) {\n plan.package.tag = tag\n }\n\n history = readPackageHistory(\n context.cwd,\n plan.package,\n tag ? { until: tag.name } : undefined\n )\n }\n\n plans.push(\n ...(await deriveChangeReleases(\n context.type,\n context.classifier,\n [plan],\n history\n ))\n )\n }\n\n context.plans = plans\n\n if (context.allowEmpty) {\n context.plans = deriveTransitionReleases(\n context.type,\n context.versionQualifier,\n context.plans\n )\n }\n\n context.plans = await propagateDependencyUpdates(context.cwd, context.plans)\n\n return next(context)\n },\n})\n\nexport default analyzer\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAgCA,IAAM,kBAAiC;CACrC,MAAM;CACN;CACA,SAAS,OAAO,SAAS,SAAS;EAChC,IAAI,QAAQ,MAAM,WAAW,GAC3B,QAAQ,QAAQ,QAAQ,SAAS,KAAK,SAAsB;GAC1D,SAAS;GACT,SAAS,CAAC;GACV,SAAS;EACX,EAAE;EAGJ,MAAM,QAAuB,CAAC;EAE9B,KAAK,MAAM,QAAQ,QAAQ,OAAO;GAChC,IAAI,UAA0D,CAAC;GAE/D,IAAI,KAAK,QAAQ,SAAS,KAAK,QAAQ,MAAM;IAC3C,MAAM,MACJ,KAAK,QAAQ,OACZ,MAAM,kBAAkB,QAAQ,KAAK,KAAK,OAAO;IAEpD,IAAI,OAAO,CAAC,KAAK,QAAQ,KACvB,KAAK,QAAQ,MAAM;IAGrB,UAAU,mBACR,QAAQ,KACR,KAAK,SACL,MAAM,EAAE,OAAO,IAAI,KAAK,IAAI,KAAA,CAC9B;GACF;GAEA,MAAM,KACJ,GAAI,MAAM,qBACR,QAAQ,MACR,QAAQ,YACR,CAAC,IAAI,GACL,OACF,CACF;EACF;EAEA,QAAQ,QAAQ;EAEhB,IAAI,QAAQ,YACV,QAAQ,QAAQ,yBACd,QAAQ,MACR,QAAQ,kBACR,QAAQ,KACV;EAGF,QAAQ,QAAQ,MAAM,2BAA2B,QAAQ,KAAK,QAAQ,KAAK;EAE3E,OAAO,KAAK,OAAO;CACrB;AACF"}
|
package/dist/builder.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as generateGitTagName, Ut as bumpVersion, d as buildReleaseNotes, g as resolvePackageStableTag, p as readPackageHistory, s as version, zt as isSameReleaseCycle } from "./workflow-BolfadM0.js";
|
|
2
2
|
import { t as formatError } from "./formatError-BMsun8Wi.js";
|
|
3
3
|
import { colors } from "consola/utils";
|
|
4
4
|
// src/builder.ts
|
package/dist/changelog.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as HookPriority, c as writeChangelog, f as buildChangelog,
|
|
1
|
+
import { a as HookPriority, c as writeChangelog, f as buildChangelog, h as resolvePackageTag, s as version, v as discoverPackageTag } from "./workflow-BolfadM0.js";
|
|
2
2
|
import { t as formatError } from "./formatError-BMsun8Wi.js";
|
|
3
3
|
import { colors } from "consola/utils";
|
|
4
4
|
// src/changelog.ts
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as getCurrentGitCommit, A as generateGitTagName, At as buildTrailerPattern, B as getGitConfigValue, Bt as deriveReleaseType, C as extractPlainText, Ct as isClass, D as getLatestGitTag, Dt as execCommand, E as isGitTagConnected, Et as execGit, F as readGitFile, Ft as RELEASE_HOOK_NAMES, G as GIT_REL_FLAGS, H as readParsedGitHistory, Ht as deriveCommitReleaseType, I as resolveGitRepository, It as SEMVER_REGEX, J as resolveGitRevision, K as detectGitRelationship, L as pushGitChanges, Lt as promotePrereleaseVersions, M as isGitTagPresent, Mt as DEFAULT_CHANGELOG_FILE, N as deleteGitTag, Nt as DEV_NULL, O as getGitTagMessage, Ot as compact, P as createGitTag, Pt as GIT_TRAILER_RELEASE_AGENT, Q as countGitHistory, R as getGitRemote, Rt as isStableVersion, S as extractSemVer, St as isMatch, T as isGitTagExact, Tt as formatFile, U as readGitHistory, Ut as bumpVersion, V as restoreFullGitHistory, Vt as pickPriorityReleaseType, W as mergeGitHistory, Wt as extractVersionQualifier, X as withShallowLock, Y as isGitAncestor, Z as isGitShallowRepository, _ as filterPackages, _t as findReleaseRule, a as HookPriority, at as TTLCache, b as extractLatestVersion, bt as unique, c as writeChangelog, ct as getCurrentGitBranch, d as buildReleaseNotes, dt as packageContainsCommit, et as getParsedGitCommit, f as buildChangelog, ft as resolveVersionQualifier, g as resolvePackageStableTag, gt as isSemVer, h as resolvePackageTag, ht as isSemVerGitTag, i as HookManager, it as parseGitCommit, j as ensureGitTag, jt as ALL_FILES, k as getCurrentGitTag, kt as isDefined, l as prependChangelog, lt as deriveTransitionReleases, m as propagateDependencyUpdates, mt as sanitizePrereleaseLabel, n as printReleaseReport, nt as GIT_PRETTY_FORMAT, o as generateReleaseCommitMessage, ot as extractMentions, p as readPackageHistory, pt as resolveReleaseChannel, q as expandGitHistory, r as generateReleaseReport, rt as parseGitPrettyFormat, st as createGitCommit, t as executeReleaseWorkflow, tt as GIT_PRETTY_FIELD_SEPARATOR, u as extractPreviousVersion, ut as deriveChangeReleases, v as discoverPackageTag, vt as createPlugin, w as buildDependencyGraph, wt as interpolate, x as iterateChangelogVersions, xt as readJson, y as verifyPackageTag, yt as writeJson, z as ensureGitUserConfig, zt as isSameReleaseCycle } from "./workflow-BolfadM0.js";
|
|
2
2
|
import { t as formatError } from "./formatError-BMsun8Wi.js";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import path from "node:path";
|
|
@@ -57,26 +57,6 @@ function isQuietEnvironment(context) {
|
|
|
57
57
|
if (isCI(context.env)) return false;
|
|
58
58
|
return context.stdout?.isTTY !== true;
|
|
59
59
|
}
|
|
60
|
-
// src/util/unique.ts
|
|
61
|
-
/**
|
|
62
|
-
* Return a new array containing only the first-seen occurrence of each item.
|
|
63
|
-
*
|
|
64
|
-
* This preserves the original iteration order and performs equality checks
|
|
65
|
-
* using JavaScript's `Set` semantics (i.e., primitives by value, objects by
|
|
66
|
-
* reference). The input array is not mutated.
|
|
67
|
-
*
|
|
68
|
-
* @param array The array of items to deduplicate
|
|
69
|
-
* @returns A new array with duplicates removed, preserving first-seen order
|
|
70
|
-
*/
|
|
71
|
-
function unique(array) {
|
|
72
|
-
const seen = /* @__PURE__ */ new Set();
|
|
73
|
-
const result = [];
|
|
74
|
-
for (const item of array) if (!seen.has(item)) {
|
|
75
|
-
seen.add(item);
|
|
76
|
-
result.push(item);
|
|
77
|
-
}
|
|
78
|
-
return result;
|
|
79
|
-
}
|
|
80
60
|
// src/config/normalizeCommitFilter.ts
|
|
81
61
|
/**
|
|
82
62
|
* Normalize a commit classifier into a consistent function.
|
|
@@ -211,20 +191,6 @@ function sortPackages(packages) {
|
|
|
211
191
|
}
|
|
212
192
|
return packageNodes.toSorted((a, b) => b.level - a.level).map((node) => node.package);
|
|
213
193
|
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Format filter patterns as a release filter trailer value.
|
|
217
|
-
*
|
|
218
|
-
* Escapes the commas within patterns and joins them with commas, so
|
|
219
|
-
* `readReleaseFilterPatterns` can split the trailer value back into the
|
|
220
|
-
* original patterns.
|
|
221
|
-
*
|
|
222
|
-
* @param patterns Filter patterns to format into a trailer value
|
|
223
|
-
* @returns The comma-joined, escaped trailer value
|
|
224
|
-
*/
|
|
225
|
-
function formatReleaseFilterPatterns(patterns) {
|
|
226
|
-
return patterns.map((pattern) => pattern.replaceAll(",", "\\,")).join(", ");
|
|
227
|
-
}
|
|
228
|
-
export { ALL_FILES, DEFAULT_CHANGELOG_FILE, DEV_NULL, GIT_PRETTY_FIELD_SEPARATOR, GIT_PRETTY_FORMAT, GIT_REL_FLAGS, GIT_TRAILER_RELEASE_AGENT, GIT_TRAILER_RELEASE_FILTER, HookManager, HookPriority, RELEASE_HOOK_NAMES, SEMVER_REGEX, TTLCache, buildChangelog, buildDependencyGraph, buildReleaseNotes, buildTrailerPattern, bumpVersion, collectUnreleased, compact, countGitHistory, createGitCommit, createGitTag, createPlugin, deleteGitTag, deriveChangeReleases, deriveReleaseType, deriveTransitionReleases, detectGitRelationship, determineReleaseType, discoverPackageTag, ensureGitTag, ensureGitUserConfig, execCommand, execGit, executeReleaseWorkflow, expandGitHistory, extractLatestVersion, extractMentions, extractPlainText, extractPreviousVersion, extractSemVer, extractVersionQualifier, filterPackages, findReleaseRule, formatError, formatFile, formatReleaseFilterPatterns, generateGitTagName, generateReleaseCommitMessage, generateReleaseReport, getCurrentGitBranch, getCurrentGitCommit, getCurrentGitTag, getGitConfigValue, getGitRemote, getGitTagMessage, getLatestGitTag, getParsedGitCommit, interpolate, isCI, isClass, isCommitForPackage, isDefined, isGitAncestor, isGitShallowRepository, isGitTagConnected, isGitTagPointed, isGitTagPresent, isMatch, isQuietEnvironment, isReleaseCommit, isSameReleaseCycle, isSemVer, isSemVerGitTag, isStableVersion, isTruthyString, iterateChangelogVersions, mergeGitHistory, normalizeCommitFilter, normalizeReleaseRule, normalizeWorkspace, parseGitCommit, parseGitPrettyFormat, pickPriorityReleaseType, prependChangelog, printReleaseReport, promotePrereleaseVersions, propagateDependencyUpdates, pushGitChanges, readGitFile, readJson, readPackageHistory, readReleaseFilterPatterns, resolveGitRepository, resolveGitRevision, resolvePackageStableTag, resolvePackageTag, resolvePlugin, resolveReleaseChannel, resolveVersionQualifier, restoreFullGitHistory, sanitizePrereleaseLabel, showGitHistory, showParsedGitHistory, sliceUnreleased, sliceUnreleasedForPackage, sortPackages, unique, verifyPackageTag, withShallowLock, writeChangelog, writeJson };
|
|
194
|
+
export { ALL_FILES, DEFAULT_CHANGELOG_FILE, DEV_NULL, GIT_PRETTY_FIELD_SEPARATOR, GIT_PRETTY_FORMAT, GIT_REL_FLAGS, GIT_TRAILER_RELEASE_AGENT, HookManager, HookPriority, RELEASE_HOOK_NAMES, SEMVER_REGEX, TTLCache, buildChangelog, buildDependencyGraph, buildReleaseNotes, buildTrailerPattern, bumpVersion, compact, countGitHistory, createGitCommit, createGitTag, createPlugin, deleteGitTag, deriveChangeReleases, deriveCommitReleaseType, deriveReleaseType, deriveTransitionReleases, detectGitRelationship, discoverPackageTag, ensureGitTag, ensureGitUserConfig, execCommand, execGit, executeReleaseWorkflow, expandGitHistory, extractLatestVersion, extractMentions, extractPlainText, extractPreviousVersion, extractSemVer, extractVersionQualifier, filterPackages, findReleaseRule, formatError, formatFile, generateGitTagName, generateReleaseCommitMessage, generateReleaseReport, getCurrentGitBranch, getCurrentGitCommit, getCurrentGitTag, getGitConfigValue, getGitRemote, getGitTagMessage, getLatestGitTag, getParsedGitCommit, interpolate, isCI, isClass, isDefined, isGitAncestor, isGitShallowRepository, isGitTagConnected, isGitTagExact, isGitTagPresent, isMatch, isQuietEnvironment, isSameReleaseCycle, isSemVer, isSemVerGitTag, isStableVersion, isTruthyString, iterateChangelogVersions, mergeGitHistory, normalizeCommitFilter, normalizeReleaseRule, normalizeWorkspace, packageContainsCommit, parseGitCommit, parseGitPrettyFormat, pickPriorityReleaseType, prependChangelog, printReleaseReport, promotePrereleaseVersions, propagateDependencyUpdates, pushGitChanges, readGitFile, readGitHistory, readJson, readPackageHistory, readParsedGitHistory, resolveGitRepository, resolveGitRevision, resolvePackageStableTag, resolvePackageTag, resolvePlugin, resolveReleaseChannel, resolveVersionQualifier, restoreFullGitHistory, sanitizePrereleaseLabel, sortPackages, unique, verifyPackageTag, withShallowLock, writeChangelog, writeJson };
|
|
229
195
|
|
|
230
196
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/util/isTruthyString.ts","../src/util/isCI.ts","../src/util/isQuietEnvironment.ts","../src/util/unique.ts","../src/config/normalizeCommitFilter.ts","../src/config/normalizeReleaseRule.ts","../src/config/normalizeWorkspace.ts","../src/config/resolvePlugin.ts","../src/workflow/discovery/sortPackages.ts","../src/workflow/committing/formatReleaseFilterPatterns.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\n/**\n * Determine whether a string value represents a truthy boolean.\n *\n * Trims leading and trailing whitespace and coerces the target string to\n * lowercase. Evaluates the string as truthy if it equals `'true'` or `'1'`.\n *\n * @param value The raw string to evaluate\n * @returns `true` if `value` normalizes to `'true'` or `'1'`, otherwise `false`\n */\nexport function isTruthyString(value: string | undefined): boolean {\n if (!value) return false\n\n const normalized = value.toLowerCase().trim()\n\n return normalized === 'true' || normalized === '1'\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { isTruthyString } from './isTruthyString'\n\n/**\n * Determine whether the current process is running in a CI environment.\n *\n * Checks if the `CI` environment variable is set to a truthy value. Ignores\n * provider-specific variables such as `GITHUB_ACTIONS` to keep detection\n * generic.\n *\n * @param env Readonly process environment variables object\n * @returns `true` if `env.CI` normalizes to a truthy string, otherwise `false`\n */\nexport function isCI(env: Readonly<NodeJS.ProcessEnv>): boolean {\n return isTruthyString(env.CI)\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { ReleaseContext } from '../types'\nimport { isCI } from './isCI'\n\n/**\n * Determine whether the current run should stay quiet about verbose output.\n *\n * A run is quiet when nothing will keep what it prints: no terminal is attached\n * for a human, and no CI provider is recording a job log. A plain pipe outside\n * of CI — an agent sandbox, a script capturing output, a detached daemon — only\n * accumulates noise, so verbose output should be withheld and left to\n * `execCommand` for error reporting instead.\n *\n * CI is deliberately *not* quiet even though its streams are not TTYs: the\n * provider persists the job log, so the output does reach someone. A caller\n * that wants output from a pipe in a non-CI environment can set `CI=1` as an\n * escape hatch.\n *\n * The verdict is per environment, not per stream, so a redirected stdout inside\n * an interactive terminal still counts as quiet.\n *\n * @param context Release context carrying the destination stream and environment\n * @returns `true` when no TTY is attached and the run is not part of CI\n */\nexport function isQuietEnvironment(\n context: Pick<ReleaseContext, 'env' | 'stdout'>\n): boolean {\n if (isCI(context.env)) return false\n\n const stream = context.stdout as NodeJS.WriteStream | undefined\n\n return stream?.isTTY !== true\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\n/**\n * Return a new array containing only the first-seen occurrence of each item.\n *\n * This preserves the original iteration order and performs equality checks\n * using JavaScript's `Set` semantics (i.e., primitives by value, objects by\n * reference). The input array is not mutated.\n *\n * @param array The array of items to deduplicate\n * @returns A new array with duplicates removed, preserving first-seen order\n */\nexport function unique<T>(array: readonly T[]): T[] {\n const seen = new Set<T>()\n const result: T[] = []\n\n for (const item of array) {\n if (!seen.has(item)) {\n seen.add(item)\n result.push(item)\n }\n }\n\n return result\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { CommitClassifier, ReleaseConfig, ReleaseType } from '#types'\n\n/**\n * Normalize a commit classifier into a consistent function.\n *\n * Accepts `null`/`undefined` (returns no-op classifier), a function classifier,\n * or a config object mapping commit types to release types. Returns a classifier\n * function that maps commits to their corresponding release types.\n *\n * @param classifier Commit classifier config, function, or falsy value\n * @returns Normalized classifier function\n */\nexport function normalizeCommitFilter(\n classifier: ReleaseConfig['classifier'] | null | undefined\n): CommitClassifier {\n if (classifier == null) {\n return () => null\n }\n\n if (typeof classifier === 'function') {\n return classifier\n }\n\n const map = new Map(\n Object.entries(classifier).flatMap(([releaseType, commitTypes]) => {\n return commitTypes.map((commitType) => [\n commitType,\n releaseType as ReleaseType,\n ])\n })\n )\n\n return (commit) => (commit.type ? map.get(commit.type) : null)\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { ReleaseRule, ResolvedReleaseRule } from '#types'\nimport { sanitizePrereleaseLabel } from './sanitizePrereleaseLabel'\n\n/**\n * Normalize a release rule input into a resolved release rule object.\n *\n * Converts `string` shorthand inputs into structured rule objects with sanitized\n * labels. Resolves `versionQualifier` and `releaseChannel` against `pattern`.\n * Returns `null` if `rule` is invalid, falsy, or missing `pattern`.\n *\n * @param rule Raw release rule input, `string` shorthand, or falsy value\n * @returns Resolved `ResolvedReleaseRule` object, or `null` if `rule` is invalid\n */\nexport function normalizeReleaseRule(\n rule: ReleaseRule | string | false | null | undefined\n): ResolvedReleaseRule | null {\n if (typeof rule === 'string') {\n rule = {\n pattern: rule,\n qualifier: sanitizePrereleaseLabel(rule),\n channel: sanitizePrereleaseLabel(rule),\n }\n }\n\n if (typeof rule !== 'object' || rule == null) {\n return null\n }\n\n const { pattern } = rule\n\n if (pattern == null) {\n return null\n }\n\n return {\n type: rule.type,\n pattern,\n versionQualifier: resolveRuleValue(rule.qualifier, pattern),\n releaseChannel: resolveRuleValue(rule.channel, pattern),\n }\n}\n\n/**\n * Resolve a rule property value from an explicit `string` or pattern fallback.\n *\n * @param value Explicit `string` value, `boolean` flag, or `undefined`\n * @param pattern Fallback pattern string used when `value` is `true`\n * @returns Resolved `string` value or `undefined`\n */\nfunction resolveRuleValue(\n value: string | boolean | undefined,\n pattern: string\n): string | undefined {\n if (typeof value === 'string') {\n return value\n }\n\n if (value) {\n return sanitizePrereleaseLabel(pattern)\n }\n\n return undefined\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { Workspace } from '#types'\nimport path from 'node:path'\n\n/**\n * Normalize and validate workspace configuration for a repository.\n *\n * Resolves the workspace entry directory relative to `cwd` and normalizes\n * the path representation. Returns a workspace object with normalized `entry`\n * and optional workspace members.\n *\n * @param cwd Repository working directory\n * @param workspace Partial workspace configuration (optional)\n * @returns Normalized workspace object\n */\nexport function normalizeWorkspace(\n cwd: string,\n workspace?: {\n entry?: string | null | undefined\n members?: readonly string[] | null | undefined\n }\n): Workspace {\n let entry = workspace?.entry || '.'\n const members = workspace?.members ?? null\n\n entry = path.normalize(path.relative(cwd, path.resolve(cwd, entry)))\n\n return {\n entry,\n members,\n }\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type {\n ReleasePlugin,\n ReleasePluginDefinition,\n ReleasePluginFactory,\n ReleasePluginTuple,\n} from '#types'\nimport { createRequire } from 'node:module'\nimport { pathToFileURL } from 'node:url'\n\n/**\n * Resolve a release plugin definition into a factory tuple or plugin object.\n *\n * Handles string module specifiers by dynamically importing the package relative\n * to `cwd`. Unwraps ES module default exports, array configurations containing\n * options, function factories, and direct plugin objects.\n *\n * @param cwd The working directory path used to resolve string specifiers\n * @param plugin The plugin name, path, tuple configuration, or plugin object\n * @returns A factory tuple, plugin object, or null if resolution fails\n */\nexport async function resolvePlugin(\n cwd: string,\n plugin: unknown\n): Promise<ReleasePluginDefinition | ReleasePluginTuple | null> {\n let options: unknown\n\n if (Array.isArray(plugin)) {\n ;[plugin, options] = plugin\n }\n\n if (typeof plugin === 'string') {\n const require = createRequire(pathToFileURL(cwd))\n plugin = await import(require.resolve(plugin))\n }\n\n if (plugin != null && typeof plugin === 'object' && 'default' in plugin) {\n plugin = plugin.default\n }\n\n if (typeof plugin === 'function') {\n return [plugin as ReleasePluginFactory, options]\n }\n\n if (\n plugin != null &&\n typeof plugin === 'object' &&\n Object.hasOwn(plugin, 'name') &&\n typeof (plugin as ReleasePlugin).name === 'string'\n ) {\n return plugin as ReleasePlugin\n }\n\n return null\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { Package } from '#types'\n\ninterface PackageNode {\n package: Package\n level: number\n}\n\n/**\n * Sort workspace packages topologically based on their dependency graphs.\n *\n * Deepest dependents are placed first in the resulting array, ensuring that\n * a package always precedes its own dependencies. Ties and circular dependencies\n * are resolved deterministically using an alphabetical sort on the package directory (`dir`).\n *\n * @param packages The workspace packages to sort.\n * @returns A new array of packages sorted by dependency depth and directory path.\n */\nexport function sortPackages(packages: readonly Package[]): Package[] {\n const packageNodes: PackageNode[] = []\n const packageMap = new Map<string, PackageNode>()\n\n for (const pkg of packages.toSorted((a, b) =>\n a.location.localeCompare(b.location)\n )) {\n const node: PackageNode = {\n package: pkg,\n level: -1,\n }\n\n packageNodes.push(node)\n\n if (pkg.name) {\n packageMap.set(pkg.name, node)\n }\n }\n\n for (const node of packageNodes) {\n visit(node)\n }\n\n function visit(\n node: PackageNode,\n level = 0,\n visited = new Set<PackageNode>()\n ): void {\n if (node.level >= level) {\n return\n }\n\n if (visited.has(node)) {\n return\n }\n\n visited.add(node)\n\n for (const depName of node.package.dependencies) {\n const depNode = packageMap.get(depName)\n\n if (depNode && depNode !== node) {\n visit(depNode, level + 1, visited)\n }\n }\n\n node.level = level\n }\n\n const sorted = packageNodes\n .toSorted((a, b) => b.level - a.level)\n .map((node) => node.package)\n\n return sorted\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\n/**\n * Format filter patterns as a release filter trailer value.\n *\n * Escapes the commas within patterns and joins them with commas, so\n * `readReleaseFilterPatterns` can split the trailer value back into the\n * original patterns.\n *\n * @param patterns Filter patterns to format into a trailer value\n * @returns The comma-joined, escaped trailer value\n */\nexport function formatReleaseFilterPatterns(\n patterns: readonly string[]\n): string {\n return patterns.map((pattern) => pattern.replaceAll(',', '\\\\,')).join(', ')\n}\n"],"mappings":";;;;;;;;;;;;;;;AAYA,SAAgB,eAAe,OAAoC;CACjE,IAAI,CAAC,OAAO,OAAO;CAEnB,MAAM,aAAa,MAAM,YAAY,CAAC,CAAC,KAAK;CAE5C,OAAO,eAAe,UAAU,eAAe;AACjD;;;;;;;;;;;;ACHA,SAAgB,KAAK,KAA2C;CA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AAc;GAC/C,MAAM,UAAU,WAAW,IAAI,OAAO;GAEtC,IAAI,WAAW,YAAY,MACzB,MAAM,SAAS,QAAQ,GAAG,OAAO;EAErC;EAEA,KAAK,QAAQ;CACf;CAMA,OAJe,aACZ,UAAU,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,CACrC,KAAK,SAAS,KAAK,OAEf;AACT;;;;;;;;;;;;AC7DA,SAAgB,4BACd,UACQ;CACR,OAAO,SAAS,KAAK,YAAY,QAAQ,WAAW,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI;AAC5E"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/util/isTruthyString.ts","../src/util/isCI.ts","../src/util/isQuietEnvironment.ts","../src/config/normalizeCommitFilter.ts","../src/config/normalizeReleaseRule.ts","../src/config/normalizeWorkspace.ts","../src/config/resolvePlugin.ts","../src/workflow/discovery/sortPackages.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\n/**\n * Determine whether a string value represents a truthy boolean.\n *\n * Trims leading and trailing whitespace and coerces the target string to\n * lowercase. Evaluates the string as truthy if it equals `'true'` or `'1'`.\n *\n * @param value The raw string to evaluate\n * @returns `true` if `value` normalizes to `'true'` or `'1'`, otherwise `false`\n */\nexport function isTruthyString(value: string | undefined): boolean {\n if (!value) return false\n\n const normalized = value.toLowerCase().trim()\n\n return normalized === 'true' || normalized === '1'\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { isTruthyString } from './isTruthyString'\n\n/**\n * Determine whether the current process is running in a CI environment.\n *\n * Checks if the `CI` environment variable is set to a truthy value. Ignores\n * provider-specific variables such as `GITHUB_ACTIONS` to keep detection\n * generic.\n *\n * @param env Readonly process environment variables object\n * @returns `true` if `env.CI` normalizes to a truthy string, otherwise `false`\n */\nexport function isCI(env: Readonly<NodeJS.ProcessEnv>): boolean {\n return isTruthyString(env.CI)\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { ReleaseContext } from '../types'\nimport { isCI } from './isCI'\n\n/**\n * Determine whether the current run should stay quiet about verbose output.\n *\n * A run is quiet when nothing will keep what it prints: no terminal is attached\n * for a human, and no CI provider is recording a job log. A plain pipe outside\n * of CI — an agent sandbox, a script capturing output, a detached daemon — only\n * accumulates noise, so verbose output should be withheld and left to\n * `execCommand` for error reporting instead.\n *\n * CI is deliberately *not* quiet even though its streams are not TTYs: the\n * provider persists the job log, so the output does reach someone. A caller\n * that wants output from a pipe in a non-CI environment can set `CI=1` as an\n * escape hatch.\n *\n * The verdict is per environment, not per stream, so a redirected stdout inside\n * an interactive terminal still counts as quiet.\n *\n * @param context Release context carrying the destination stream and environment\n * @returns `true` when no TTY is attached and the run is not part of CI\n */\nexport function isQuietEnvironment(\n context: Pick<ReleaseContext, 'env' | 'stdout'>\n): boolean {\n if (isCI(context.env)) return false\n\n const stream = context.stdout as NodeJS.WriteStream | undefined\n\n return stream?.isTTY !== true\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { CommitClassifier, ReleaseConfig, ReleaseType } from '#types'\n\n/**\n * Normalize a commit classifier into a consistent function.\n *\n * Accepts `null`/`undefined` (returns no-op classifier), a function classifier,\n * or a config object mapping commit types to release types. Returns a classifier\n * function that maps commits to their corresponding release types.\n *\n * @param classifier Commit classifier config, function, or falsy value\n * @returns Normalized classifier function\n */\nexport function normalizeCommitFilter(\n classifier: ReleaseConfig['classifier'] | null | undefined\n): CommitClassifier {\n if (classifier == null) {\n return () => null\n }\n\n if (typeof classifier === 'function') {\n return classifier\n }\n\n const map = new Map(\n Object.entries(classifier).flatMap(([releaseType, commitTypes]) => {\n return commitTypes.map((commitType) => [\n commitType,\n releaseType as ReleaseType,\n ])\n })\n )\n\n return (commit) => (commit.type ? map.get(commit.type) : null)\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { ReleaseRule, ResolvedReleaseRule } from '#types'\nimport { sanitizePrereleaseLabel } from './sanitizePrereleaseLabel'\n\n/**\n * Normalize a release rule input into a resolved release rule object.\n *\n * Converts `string` shorthand inputs into structured rule objects with sanitized\n * labels. Resolves `versionQualifier` and `releaseChannel` against `pattern`.\n * Returns `null` if `rule` is invalid, falsy, or missing `pattern`.\n *\n * @param rule Raw release rule input, `string` shorthand, or falsy value\n * @returns Resolved `ResolvedReleaseRule` object, or `null` if `rule` is invalid\n */\nexport function normalizeReleaseRule(\n rule: ReleaseRule | string | false | null | undefined\n): ResolvedReleaseRule | null {\n if (typeof rule === 'string') {\n rule = {\n pattern: rule,\n qualifier: sanitizePrereleaseLabel(rule),\n channel: sanitizePrereleaseLabel(rule),\n }\n }\n\n if (typeof rule !== 'object' || rule == null) {\n return null\n }\n\n const { pattern } = rule\n\n if (pattern == null) {\n return null\n }\n\n return {\n type: rule.type,\n pattern,\n versionQualifier: resolveRuleValue(rule.qualifier, pattern),\n releaseChannel: resolveRuleValue(rule.channel, pattern),\n }\n}\n\n/**\n * Resolve a rule property value from an explicit `string` or pattern fallback.\n *\n * @param value Explicit `string` value, `boolean` flag, or `undefined`\n * @param pattern Fallback pattern string used when `value` is `true`\n * @returns Resolved `string` value or `undefined`\n */\nfunction resolveRuleValue(\n value: string | boolean | undefined,\n pattern: string\n): string | undefined {\n if (typeof value === 'string') {\n return value\n }\n\n if (value) {\n return sanitizePrereleaseLabel(pattern)\n }\n\n return undefined\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { Workspace } from '#types'\nimport path from 'node:path'\n\n/**\n * Normalize and validate workspace configuration for a repository.\n *\n * Resolves the workspace entry directory relative to `cwd` and normalizes\n * the path representation. Returns a workspace object with normalized `entry`\n * and optional workspace members.\n *\n * @param cwd Repository working directory\n * @param workspace Partial workspace configuration (optional)\n * @returns Normalized workspace object\n */\nexport function normalizeWorkspace(\n cwd: string,\n workspace?: {\n entry?: string | null | undefined\n members?: readonly string[] | null | undefined\n }\n): Workspace {\n let entry = workspace?.entry || '.'\n const members = workspace?.members ?? null\n\n entry = path.normalize(path.relative(cwd, path.resolve(cwd, entry)))\n\n return {\n entry,\n members,\n }\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type {\n ReleasePlugin,\n ReleasePluginDefinition,\n ReleasePluginFactory,\n ReleasePluginTuple,\n} from '#types'\nimport { createRequire } from 'node:module'\nimport { pathToFileURL } from 'node:url'\n\n/**\n * Resolve a release plugin definition into a factory tuple or plugin object.\n *\n * Handles string module specifiers by dynamically importing the package relative\n * to `cwd`. Unwraps ES module default exports, array configurations containing\n * options, function factories, and direct plugin objects.\n *\n * @param cwd The working directory path used to resolve string specifiers\n * @param plugin The plugin name, path, tuple configuration, or plugin object\n * @returns A factory tuple, plugin object, or null if resolution fails\n */\nexport async function resolvePlugin(\n cwd: string,\n plugin: unknown\n): Promise<ReleasePluginDefinition | ReleasePluginTuple | null> {\n let options: unknown\n\n if (Array.isArray(plugin)) {\n ;[plugin, options] = plugin\n }\n\n if (typeof plugin === 'string') {\n const require = createRequire(pathToFileURL(cwd))\n plugin = await import(require.resolve(plugin))\n }\n\n if (plugin != null && typeof plugin === 'object' && 'default' in plugin) {\n plugin = plugin.default\n }\n\n if (typeof plugin === 'function') {\n return [plugin as ReleasePluginFactory, options]\n }\n\n if (\n plugin != null &&\n typeof plugin === 'object' &&\n Object.hasOwn(plugin, 'name') &&\n typeof (plugin as ReleasePlugin).name === 'string'\n ) {\n return plugin as ReleasePlugin\n }\n\n return null\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { Package } from '#types'\n\ninterface PackageNode {\n package: Package\n level: number\n}\n\n/**\n * Sort workspace packages topologically based on their dependency graphs.\n *\n * Deepest dependents are placed first in the resulting array, ensuring that\n * a package always precedes its own dependencies. Ties and circular dependencies\n * are resolved deterministically using an alphabetical sort on the package directory (`dir`).\n *\n * @param packages The workspace packages to sort.\n * @returns A new array of packages sorted by dependency depth and directory path.\n */\nexport function sortPackages(packages: readonly Package[]): Package[] {\n const packageNodes: PackageNode[] = []\n const packageMap = new Map<string, PackageNode>()\n\n for (const pkg of packages.toSorted((a, b) =>\n a.location.localeCompare(b.location)\n )) {\n const node: PackageNode = {\n package: pkg,\n level: -1,\n }\n\n packageNodes.push(node)\n\n if (pkg.name) {\n packageMap.set(pkg.name, node)\n }\n }\n\n for (const node of packageNodes) {\n visit(node)\n }\n\n function visit(\n node: PackageNode,\n level = 0,\n visited = new Set<PackageNode>()\n ): void {\n if (node.level >= level) {\n return\n }\n\n if (visited.has(node)) {\n return\n }\n\n visited.add(node)\n\n for (const depName of node.package.dependencies) {\n const depNode = packageMap.get(depName)\n\n if (depNode && depNode !== node) {\n visit(depNode, level + 1, visited)\n }\n }\n\n node.level = level\n }\n\n const sorted = packageNodes\n .toSorted((a, b) => b.level - a.level)\n .map((node) => node.package)\n\n return sorted\n}\n"],"mappings":";;;;;;;;;;;;;;;AAYA,SAAgB,eAAe,OAAoC;CACjE,IAAI,CAAC,OAAO,OAAO;CAEnB,MAAM,aAAa,MAAM,YAAY,CAAC,CAAC,KAAK;CAE5C,OAAO,eAAe,UAAU,eAAe;AACjD;;;;;;;;;;;;ACHA,SAAgB,KAAK,KAA2C;CAC9D,OAAO,eAAe,IAAI,EAAE;AAC9B;;;;;;;;;;;;;;;;;;;;;;ACSA,SAAgB,mBACd,SACS;CACT,IAAI,KAAK,QAAQ,GAAG,GAAG,OAAO;CAI9B,OAFe,QAAQ,QAER,UAAU;AAC3B;;;;;;;;;;;;ACnBA,SAAgB,sBACd,YACkB;CAClB,IAAI,cAAc,MAChB,aAAa;CAGf,IAAI,OAAO,eAAe,YACxB,OAAO;CAGT,MAAM,MAAM,IAAI,IACd,OAAO,QAAQ,UAAU,CAAC,CAAC,SAAS,CAAC,aAAa,iBAAiB;EACjE,OAAO,YAAY,KAAK,eAAe,CACrC,YACA,WACF,CAAC;CACH,CAAC,CACH;CAEA,QAAQ,W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