@reelout/core 0.5.2 → 0.6.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.
@@ -0,0 +1,44 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import { showParsedGitHistory, type ShowGitHistoryOptions } from '#git'
5
+ import type { GitCommit } from '#types'
6
+ import type { ReleaseMarker } from '../committing/isReleaseCommit'
7
+ import { isReleaseCommit } from '../committing/isReleaseCommit'
8
+
9
+ export interface UnreleasedOptions extends ShowGitHistoryOptions {
10
+ marker?: ReleaseMarker | undefined
11
+ }
12
+
13
+ export interface UnreleasedWindow {
14
+ history: GitCommit[]
15
+ stop: GitCommit | null
16
+ }
17
+
18
+ /**
19
+ * Collect unreleased commits from repository history.
20
+ *
21
+ * Walks parsed commit history in order and gathers every commit preceding the
22
+ * first release commit. Exposes the release commit that ended the walk so
23
+ * callers can inspect it, for example to read its release filter trailer.
24
+ *
25
+ * @param cwd Path to the working directory for git commands
26
+ * @param options Options for configuring Git history retrieval
27
+ * @returns The unreleased commits and the release commit that stopped the walk
28
+ */
29
+ export async function collectUnreleased(
30
+ cwd: string,
31
+ options: UnreleasedOptions = {}
32
+ ): Promise<UnreleasedWindow> {
33
+ const history: GitCommit[] = []
34
+
35
+ for await (const commit of showParsedGitHistory(cwd, options)) {
36
+ if (await isReleaseCommit(cwd, commit, options.marker)) {
37
+ return { history, stop: commit }
38
+ }
39
+
40
+ history.push(commit)
41
+ }
42
+
43
+ return { history, stop: null }
44
+ }
@@ -16,7 +16,9 @@ import { isCommitForPackage } from './isCommitForPackage'
16
16
  * Maps commit `history` across package release `plans` to associate matching
17
17
  * commits with their target packages. Calculates the release type for each
18
18
  * plan based on classified `history` and applies overrides according to the
19
- * provided `hint` or existing release priority.
19
+ * provided `hint` or existing release priority. Downgrades breaking-change
20
+ * `major` release types to `minor` while the package version is zero-major
21
+ * (`0.y.z`).
20
22
  *
21
23
  * @param hint Release type override hint or default preference
22
24
  * @param classifier Classifier function to determine commit release types
@@ -46,7 +48,7 @@ export async function deriveChangeReleases(
46
48
  return plans.map((plan): ReleasePlan => {
47
49
  let { release } = plan
48
50
 
49
- let releaseType = deriveReleaseType(classifier, plan.history)
51
+ let releaseType = deriveReleaseType(classifier, plan)
50
52
 
51
53
  if (releaseType) {
52
54
  switch (hint) {
@@ -1,10 +1,12 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Copyright (c) 2026 Fai
3
3
 
4
+ export * from './collectUnreleased'
4
5
  export * from './deriveChangeReleases'
5
6
  export * from './deriveTransitionReleases'
6
7
  export * from './isCommitForPackage'
7
8
  export * from './promotePrereleaseVersions'
8
9
  export * from './propagateDependencyUpdates'
10
+ export * from './readPackageHistory'
9
11
  export * from './sliceUnreleased'
10
- export * from './streamPackageCommits'
12
+ export * from './sliceUnreleasedForPackage'
@@ -8,7 +8,7 @@ import { isCommitForPackage } from './isCommitForPackage'
8
8
  /**
9
9
  * Yield commits from git history associated with a package.
10
10
  *
11
- * Filters git commit history to stream only entries relevant to the target
11
+ * Filters git commit history to yield only entries relevant to the target
12
12
  * `pkg` directory.
13
13
  *
14
14
  * @param cwd Path to the working directory for git commands
@@ -16,7 +16,7 @@ import { isCommitForPackage } from './isCommitForPackage'
16
16
  * @param options Options for parsing and filtering git history
17
17
  * @yields Commits belonging to the specified package
18
18
  */
19
- export async function* streamPackageCommits(
19
+ export async function* readPackageHistory(
20
20
  cwd: string,
21
21
  pkg: Package,
22
22
  options: ShowGitHistoryOptions = {}
@@ -1,22 +1,14 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Copyright (c) 2026 Fai
3
3
 
4
- import { showParsedGitHistory, type ShowGitHistoryOptions } from '#git'
5
4
  import type { GitCommit } from '#types'
6
- import {
7
- isReleaseCommit,
8
- type ReleaseMarker,
9
- } from '../committing/isReleaseCommit'
10
-
11
- export interface SliceUnreleasedOptions extends ShowGitHistoryOptions {
12
- marker?: ReleaseMarker | undefined
13
- }
5
+ import { collectUnreleased, type UnreleasedOptions } from './collectUnreleased'
14
6
 
15
7
  /**
16
8
  * Yield parsed commits from the workspace until a release commit is found.
17
9
  *
18
- * Iterates through parsed commit history and yields unreleased commits in
19
- * order. Stops processing upon reaching the first release commit.
10
+ * Collects unreleased commits ahead of the most recent release commit and
11
+ * yields them in order.
20
12
  *
21
13
  * @param cwd Path to the working directory
22
14
  * @param options Options for configuring Git history retrieval
@@ -24,13 +16,9 @@ export interface SliceUnreleasedOptions extends ShowGitHistoryOptions {
24
16
  */
25
17
  export async function* sliceUnreleased(
26
18
  cwd: string,
27
- options?: SliceUnreleasedOptions
19
+ options?: UnreleasedOptions
28
20
  ): AsyncGenerator<GitCommit> {
29
- for await (const commit of showParsedGitHistory(cwd, options)) {
30
- if (await isReleaseCommit(cwd, commit, options?.marker)) {
31
- break
32
- }
21
+ const { history } = await collectUnreleased(cwd, options)
33
22
 
34
- yield commit
35
- }
23
+ yield* history
36
24
  }
@@ -0,0 +1,41 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import type { GitCommit, Package } from '#types'
5
+ import { isMatch } from '#util'
6
+ import { isReleaseCommit } from '../committing/isReleaseCommit'
7
+ import { readReleaseFilterPatterns } from '../committing/readReleaseFilterPatterns'
8
+ import type { UnreleasedOptions } from './collectUnreleased'
9
+ import { readPackageHistory } from './readPackageHistory'
10
+
11
+ /**
12
+ * Yield unreleased commits from the history of a single package.
13
+ *
14
+ * Streams commits that touch the package files in historical order and stops
15
+ * at the first release commit that released the package. Release commits
16
+ * created by filtered runs that excluded the package are themselves yielded
17
+ * as unreleased changes, so every package keeps its own release boundary
18
+ * instead of sharing the latest repository-wide release commit.
19
+ *
20
+ * @param cwd Path to the working directory for git commands
21
+ * @param pkg Package whose files scope the commit history
22
+ * @param options Options for configuring Git history retrieval
23
+ * @yields Parsed commits up to the package's most recent release commit
24
+ */
25
+ export async function* sliceUnreleasedForPackage(
26
+ cwd: string,
27
+ pkg: Package,
28
+ options: UnreleasedOptions = {}
29
+ ): AsyncGenerator<GitCommit> {
30
+ for await (const commit of readPackageHistory(cwd, pkg, options)) {
31
+ if (await isReleaseCommit(cwd, commit, options.marker)) {
32
+ const patterns = readReleaseFilterPatterns(commit)
33
+
34
+ if (patterns === null || isMatch(pkg.name ?? '', patterns)) {
35
+ break
36
+ }
37
+ }
38
+
39
+ yield commit
40
+ }
41
+ }
@@ -0,0 +1,18 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ /**
5
+ * Format filter patterns as a release filter trailer value.
6
+ *
7
+ * Escapes the commas within patterns and joins them with commas, so
8
+ * `readReleaseFilterPatterns` can split the trailer value back into the
9
+ * original patterns.
10
+ *
11
+ * @param patterns Filter patterns to format into a trailer value
12
+ * @returns The comma-joined, escaped trailer value
13
+ */
14
+ export function formatReleaseFilterPatterns(
15
+ patterns: readonly string[]
16
+ ): string {
17
+ return patterns.map((pattern) => pattern.replaceAll(',', '\\,')).join(', ')
18
+ }
@@ -1,5 +1,7 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Copyright (c) 2026 Fai
3
3
 
4
+ export * from './formatReleaseFilterPatterns'
4
5
  export * from './generateReleaseCommitMessage'
5
6
  export * from './isReleaseCommit'
7
+ export * from './readReleaseFilterPatterns'
@@ -0,0 +1,38 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import { GIT_TRAILER_RELEASE_FILTER } from '#config'
5
+ import type { GitCommit } from '#types'
6
+
7
+ /**
8
+ * Read release filter patterns from a parsed commit.
9
+ *
10
+ * Collects the release filter trailer values and splits them into individual
11
+ * comma-separated filter patterns, unescaping the commas within patterns.
12
+ * Returns `null` when the commit carries no release filter trailer, so
13
+ * callers can treat it as a release of every package.
14
+ *
15
+ * @param commit Parsed commit object or nullish value
16
+ * @returns Filter patterns carried by the trailer, or `null` when absent
17
+ */
18
+ export function readReleaseFilterPatterns(
19
+ commit: GitCommit | null | undefined
20
+ ): string[] | null {
21
+ if (!commit) {
22
+ return null
23
+ }
24
+
25
+ const values = commit.trailers
26
+ .filter((trailer) => trailer.key === GIT_TRAILER_RELEASE_FILTER)
27
+ .map((trailer) => trailer.value)
28
+
29
+ if (values.length === 0) {
30
+ return null
31
+ }
32
+
33
+ return values
34
+ .flatMap((value) => value.split(/(?<!\\),/))
35
+ .map((pattern) => pattern.trim())
36
+ .map((pattern) => pattern.replaceAll('\\,', ','))
37
+ .filter((pattern) => pattern.length > 0)
38
+ }
@@ -0,0 +1,27 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import type { Package } from '#types'
5
+ import { isMatch } from '#util'
6
+
7
+ /**
8
+ * Filter packages by name patterns.
9
+ *
10
+ * Keeps the packages whose names match `patterns`, scoping a release run to
11
+ * a subset of the discovered workspace. Returns a copy of every package when
12
+ * `patterns` is empty.
13
+ *
14
+ * @param packages Workspace packages to filter
15
+ * @param patterns Minimatch patterns to match package names against
16
+ * @returns Packages whose names match the patterns
17
+ */
18
+ export function filterPackages(
19
+ packages: readonly Package[],
20
+ patterns: readonly string[]
21
+ ): Package[] {
22
+ if (patterns.length === 0) {
23
+ return [...packages]
24
+ }
25
+
26
+ return packages.filter((pkg) => isMatch(pkg.name ?? '', patterns))
27
+ }
@@ -3,6 +3,7 @@
3
3
 
4
4
  export * from './buildDependencyGraph'
5
5
  export * from './discoverPackageTag'
6
+ export * from './filterPackages'
6
7
  export * from './resolvePackageStableTag'
7
8
  export * from './resolvePackageTag'
8
9
  export * from './sortPackages'
@@ -1,31 +1,33 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Copyright (c) 2026 Fai
3
3
 
4
- import type { CommitClassifier, GitCommit, ReleaseType } from '#types'
4
+ import type { CommitClassifier, ReleasePlan, ReleaseType } from '#types'
5
5
  import { determineReleaseType } from './determineReleaseType'
6
6
  import { pickPriorityReleaseType } from './pickPriorityReleaseType'
7
7
 
8
8
  /**
9
- * Derive the combined release type from a commit history collection.
9
+ * Derive the combined release type from a release plan.
10
10
  *
11
- * Processes commits sequentially, accumulating the highest-precedence release
12
- * type found by evaluating each individual commit and comparing it against the
13
- * current maximum via `pickPriorityReleaseType`.
11
+ * Processes the plan's commits sequentially, accumulating the
12
+ * highest-precedence release type found by evaluating each individual commit
13
+ * and comparing it against the current maximum via `pickPriorityReleaseType`.
14
+ * Breaking commits resolve to `minor` while the plan's package version is
15
+ * zero-major (`0.y.z`).
14
16
  *
15
17
  * @param classifier Function mapping commits to release types
16
- * @param history Array of parsed commits to evaluate
18
+ * @param plan Release plan carrying the commit history and package version
17
19
  * @returns `ReleaseType` string, or `null` when no matching rule applies
18
20
  */
19
21
  export function deriveReleaseType(
20
22
  classifier: CommitClassifier,
21
- history: readonly GitCommit[]
23
+ plan: Pick<ReleasePlan, 'history' | 'package'>
22
24
  ): ReleaseType | null {
23
25
  let releaseType: ReleaseType | null = null
24
26
 
25
- for (const commit of history) {
27
+ for (const commit of plan.history) {
26
28
  releaseType = pickPriorityReleaseType(
27
29
  releaseType,
28
- determineReleaseType(classifier, commit)
30
+ determineReleaseType(classifier, commit, plan.package.version)
29
31
  )
30
32
  }
31
33
 
@@ -2,24 +2,30 @@
2
2
  // Copyright (c) 2026 Fai
3
3
 
4
4
  import type { CommitClassifier, GitCommit, ReleaseType } from '#types'
5
+ import semver from 'semver'
5
6
 
6
7
  /**
7
8
  * Determine the release type for a single commit.
8
9
  *
9
- * Automatically returns `'major'` if the commit is marked as a breaking change.
10
- * Otherwise, routes the commit through the custom `classifier` and ensures the
11
- * resolved value is a valid semantic versioning release type.
10
+ * Returns `'minor'` for a commit marked as a breaking change while the
11
+ * supplied `version` is zero-major (`0.y.z`), and `'major'` otherwise, since
12
+ * SemVer treats `0.y.z` as initial development where breaking changes do not
13
+ * require a new major version. Otherwise, routes the commit through the
14
+ * custom `classifier` and ensures the resolved value is a valid semantic
15
+ * versioning release type.
12
16
  *
13
17
  * @param classifier Function mapping commits to release types
14
18
  * @param commit Parsed commit to evaluate
19
+ * @param version Current package version used to adjust zero-major breaking releases
15
20
  * @returns `ReleaseType` string, or `null` when no matching rule applies
16
21
  */
17
22
  export function determineReleaseType(
18
23
  classifier: CommitClassifier,
19
- commit: GitCommit
24
+ commit: GitCommit,
25
+ version?: string | null | undefined
20
26
  ): ReleaseType | null {
21
27
  if (commit.notes.length > 0) {
22
- return 'major'
28
+ return semver.parse(version)?.major === 0 ? 'minor' : 'major'
23
29
  }
24
30
 
25
31
  const type = classifier(commit)